2013-02-24 23:43:40 +00:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
2013-03-24 00:53:05 +00:00
|
|
|
# Filename : PredicatesB1D.py
|
|
|
|
# Authors : Fredo Durand, Stephane Grabli, Francois Sillion, Emmanuel Turquin
|
|
|
|
# Date : 08/04/2005
|
|
|
|
# Purpose : Binary predicates (functors) to be used for 1D elements
|
|
|
|
|
2013-04-07 11:22:54 +00:00
|
|
|
from freestyle import BinaryPredicate1D, GetZF1D, IntegrationType, Nature, SameShapeIdBP1D, ZDiscontinuityF1D
|
2013-02-24 23:43:40 +00:00
|
|
|
from Functions1D import pyViewMapGradientNormF1D
|
|
|
|
|
|
|
|
import random
|
2009-09-19 22:02:15 +00:00
|
|
|
|
|
|
|
class pyZBP1D(BinaryPredicate1D):
|
2009-09-27 00:58:38 +00:00
|
|
|
def __call__(self, i1, i2):
|
2009-09-19 22:02:15 +00:00
|
|
|
func = GetZF1D()
|
|
|
|
return (func(i1) > func(i2))
|
|
|
|
|
|
|
|
class pyZDiscontinuityBP1D(BinaryPredicate1D):
|
|
|
|
def __init__(self, iType = IntegrationType.MEAN):
|
|
|
|
BinaryPredicate1D.__init__(self)
|
|
|
|
self._GetZDiscontinuity = ZDiscontinuityF1D(iType)
|
2009-09-27 00:58:38 +00:00
|
|
|
def __call__(self, i1, i2):
|
2009-09-19 22:02:15 +00:00
|
|
|
return (self._GetZDiscontinuity(i1) > self._GetZDiscontinuity(i2))
|
|
|
|
|
|
|
|
class pyLengthBP1D(BinaryPredicate1D):
|
2009-09-27 00:58:38 +00:00
|
|
|
def __call__(self, i1, i2):
|
Freestyle Python API improvements - part 3.
Major API updates were made to address code review comments.
This revision mostly focuses on Python wrappers of C++ 0D and 1D elements (i.e.,
Interface0D and Interface1D, as well as their subclasses).
* Most getter/setter methods were reimplemented as attributes using PyGetSetDef.
Vector attributes are now implemented based on mathutils callbacks. Boolean
attributes now only accept boolean values.
* The __getitem__ method was removed and the Sequence protocol was used instead.
* The naming of methods and attributes was fixed to follow the naming conventions
of the Blender Python API (i.e., lower case + underscores for methods and attributes,
and CamelCase for classes). Some naming inconsistency within the Freestyle Python
API was also addressed.
* The Freestyle API had a number of method names including prefix/suffix "A" and
"B", and their meanings were inconsistent (i.e., referring to different things
depending on the classes). The names with these two letters were replaced with
more straightforward names. Also some attribute names were changed so as to indicate
the type of the value (e.g., FEdge.next_fedge instead of FEdge.next_edge) in line
with other names explicitly indicating what the value is (e.g., SVertex.viewvertex).
* In addition, some code clean-up was done in both C++ and Python.
Notes:
In summary, the following irregular naming changes were made through this revision
(those resulting from regular changes of naming conventions are not listed):
- CurvePoint: {A,B} --> {first,second}_svertex
- FEdge: vertex{A,B} --> {first,second}_svertex
- FEdge: {next,previous}Edge --> {next,previous}_fedge
- FEdgeSharp: normal{A,B} --> normal_{right,left}
- FEdgeSharp: {a,b}FaceMark --> face_mark_{right,left}
- FEdgeSharp: {a,b}Material --> material_{right,left}
- FEdgeSharp: {a,b}MaterialIndex --> material_index_{right,left}
- FrsCurve: empty --> is_empty
- FrsCurve: nSegments --> segments_size
- TVertex: mate() --> get_mate()
- ViewEdge: fedge{A,B} --> {first,last}_fedge
- ViewEdge: setaShape, aShape --> occlude
- ViewEdge: {A,B} --> {first,last}_viewvertex
- ViewMap: getScene3dBBox --> scene_bbox
2013-02-14 23:48:34 +00:00
|
|
|
return (i1.length_2d > i2.length_2d)
|
2009-09-19 22:02:15 +00:00
|
|
|
|
|
|
|
class pySilhouetteFirstBP1D(BinaryPredicate1D):
|
2009-09-27 00:58:38 +00:00
|
|
|
def __call__(self, inter1, inter2):
|
2009-09-19 22:02:15 +00:00
|
|
|
bpred = SameShapeIdBP1D()
|
|
|
|
if (bpred(inter1, inter2) != 1):
|
|
|
|
return 0
|
Freestyle Python API improvements - part 3.
Major API updates were made to address code review comments.
This revision mostly focuses on Python wrappers of C++ 0D and 1D elements (i.e.,
Interface0D and Interface1D, as well as their subclasses).
* Most getter/setter methods were reimplemented as attributes using PyGetSetDef.
Vector attributes are now implemented based on mathutils callbacks. Boolean
attributes now only accept boolean values.
* The __getitem__ method was removed and the Sequence protocol was used instead.
* The naming of methods and attributes was fixed to follow the naming conventions
of the Blender Python API (i.e., lower case + underscores for methods and attributes,
and CamelCase for classes). Some naming inconsistency within the Freestyle Python
API was also addressed.
* The Freestyle API had a number of method names including prefix/suffix "A" and
"B", and their meanings were inconsistent (i.e., referring to different things
depending on the classes). The names with these two letters were replaced with
more straightforward names. Also some attribute names were changed so as to indicate
the type of the value (e.g., FEdge.next_fedge instead of FEdge.next_edge) in line
with other names explicitly indicating what the value is (e.g., SVertex.viewvertex).
* In addition, some code clean-up was done in both C++ and Python.
Notes:
In summary, the following irregular naming changes were made through this revision
(those resulting from regular changes of naming conventions are not listed):
- CurvePoint: {A,B} --> {first,second}_svertex
- FEdge: vertex{A,B} --> {first,second}_svertex
- FEdge: {next,previous}Edge --> {next,previous}_fedge
- FEdgeSharp: normal{A,B} --> normal_{right,left}
- FEdgeSharp: {a,b}FaceMark --> face_mark_{right,left}
- FEdgeSharp: {a,b}Material --> material_{right,left}
- FEdgeSharp: {a,b}MaterialIndex --> material_index_{right,left}
- FrsCurve: empty --> is_empty
- FrsCurve: nSegments --> segments_size
- TVertex: mate() --> get_mate()
- ViewEdge: fedge{A,B} --> {first,last}_fedge
- ViewEdge: setaShape, aShape --> occlude
- ViewEdge: {A,B} --> {first,last}_viewvertex
- ViewMap: getScene3dBBox --> scene_bbox
2013-02-14 23:48:34 +00:00
|
|
|
if (inter1.nature & Nature.SILHOUETTE):
|
|
|
|
return (inter2.nature & Nature.SILHOUETTE) != 0
|
|
|
|
return (inter1.nature == inter2.nature)
|
2009-09-19 22:02:15 +00:00
|
|
|
|
|
|
|
class pyNatureBP1D(BinaryPredicate1D):
|
2009-09-27 00:58:38 +00:00
|
|
|
def __call__(self, inter1, inter2):
|
Freestyle Python API improvements - part 3.
Major API updates were made to address code review comments.
This revision mostly focuses on Python wrappers of C++ 0D and 1D elements (i.e.,
Interface0D and Interface1D, as well as their subclasses).
* Most getter/setter methods were reimplemented as attributes using PyGetSetDef.
Vector attributes are now implemented based on mathutils callbacks. Boolean
attributes now only accept boolean values.
* The __getitem__ method was removed and the Sequence protocol was used instead.
* The naming of methods and attributes was fixed to follow the naming conventions
of the Blender Python API (i.e., lower case + underscores for methods and attributes,
and CamelCase for classes). Some naming inconsistency within the Freestyle Python
API was also addressed.
* The Freestyle API had a number of method names including prefix/suffix "A" and
"B", and their meanings were inconsistent (i.e., referring to different things
depending on the classes). The names with these two letters were replaced with
more straightforward names. Also some attribute names were changed so as to indicate
the type of the value (e.g., FEdge.next_fedge instead of FEdge.next_edge) in line
with other names explicitly indicating what the value is (e.g., SVertex.viewvertex).
* In addition, some code clean-up was done in both C++ and Python.
Notes:
In summary, the following irregular naming changes were made through this revision
(those resulting from regular changes of naming conventions are not listed):
- CurvePoint: {A,B} --> {first,second}_svertex
- FEdge: vertex{A,B} --> {first,second}_svertex
- FEdge: {next,previous}Edge --> {next,previous}_fedge
- FEdgeSharp: normal{A,B} --> normal_{right,left}
- FEdgeSharp: {a,b}FaceMark --> face_mark_{right,left}
- FEdgeSharp: {a,b}Material --> material_{right,left}
- FEdgeSharp: {a,b}MaterialIndex --> material_index_{right,left}
- FrsCurve: empty --> is_empty
- FrsCurve: nSegments --> segments_size
- TVertex: mate() --> get_mate()
- ViewEdge: fedge{A,B} --> {first,last}_fedge
- ViewEdge: setaShape, aShape --> occlude
- ViewEdge: {A,B} --> {first,last}_viewvertex
- ViewMap: getScene3dBBox --> scene_bbox
2013-02-14 23:48:34 +00:00
|
|
|
return (inter1.nature & inter2.nature)
|
2009-09-19 22:02:15 +00:00
|
|
|
|
|
|
|
class pyViewMapGradientNormBP1D(BinaryPredicate1D):
|
|
|
|
def __init__(self,l, sampling=2.0):
|
|
|
|
BinaryPredicate1D.__init__(self)
|
|
|
|
self._GetGradient = pyViewMapGradientNormF1D(l, IntegrationType.MEAN)
|
|
|
|
def __call__(self, i1,i2):
|
2009-09-27 00:58:38 +00:00
|
|
|
print("compare gradient")
|
2009-09-19 22:02:15 +00:00
|
|
|
return (self._GetGradient(i1) > self._GetGradient(i2))
|
|
|
|
|
|
|
|
class pyShuffleBP1D(BinaryPredicate1D):
|
|
|
|
def __init__(self):
|
|
|
|
BinaryPredicate1D.__init__(self)
|
2013-02-24 23:43:40 +00:00
|
|
|
random.seed(1)
|
2009-09-27 00:58:38 +00:00
|
|
|
def __call__(self, inter1, inter2):
|
2013-02-24 23:43:40 +00:00
|
|
|
r1 = random.uniform(0,1)
|
|
|
|
r2 = random.uniform(0,1)
|
2009-09-19 22:02:15 +00:00
|
|
|
return (r1<r2)
|