blender/release/scripts/freestyle/style_modules/PredicatesU0D.py

97 lines
3.0 KiB
Python
Raw Normal View History

# ##### 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 #####
# Filename : PredicatesU0D.py
# Authors : Fredo Durand, Stephane Grabli, Francois Sillion, Emmanuel Turquin
# Date : 08/04/2005
# Purpose : Unary predicates (functors) to be used for 0D elements
from freestyle import Curvature2DAngleF0D, Nature, QuantitativeInvisibilityF0D, UnaryPredicate0D
from Functions0D import pyCurvilinearLengthF0D
class pyHigherCurvature2DAngleUP0D(UnaryPredicate0D):
def __init__(self,a):
UnaryPredicate0D.__init__(self)
self._a = a
def __call__(self, inter):
func = Curvature2DAngleF0D()
a = func(inter)
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 (a > self._a)
class pyUEqualsUP0D(UnaryPredicate0D):
def __init__(self,u, w):
UnaryPredicate0D.__init__(self)
self._u = u
self._w = w
def __call__(self, inter):
func = pyCurvilinearLengthF0D()
u = func(inter)
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 (u > (self._u-self._w)) and (u < (self._u+self._w))
class pyVertexNatureUP0D(UnaryPredicate0D):
def __init__(self,nature):
UnaryPredicate0D.__init__(self)
self._nature = nature
def __call__(self, inter):
v = inter.object
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 (v.nature & self._nature) != 0
## check whether an Interface0DIterator
## is a TVertex and is the one that is
## hidden (inferred from the context)
class pyBackTVertexUP0D(UnaryPredicate0D):
def __init__(self):
UnaryPredicate0D.__init__(self)
self._getQI = QuantitativeInvisibilityF0D()
def __call__(self, iter):
if (iter.object.nature & Nature.T_VERTEX) == 0:
return 0
if iter.is_end:
return 0
if self._getQI(iter) != 0:
return 1
return 0
class pyParameterUP0DGoodOne(UnaryPredicate0D):
def __init__(self,pmin,pmax):
UnaryPredicate0D.__init__(self)
self._m = pmin
self._M = pmax
#self.getCurvilinearAbscissa = GetCurvilinearAbscissaF0D()
def __call__(self, inter):
#s = self.getCurvilinearAbscissa(inter)
u = inter.u
#print(u)
return ((u>=self._m) and (u<=self._M))
class pyParameterUP0D(UnaryPredicate0D):
def __init__(self,pmin,pmax):
UnaryPredicate0D.__init__(self)
self._m = pmin
self._M = pmax
#self.getCurvilinearAbscissa = GetCurvilinearAbscissaF0D()
def __call__(self, inter):
func = Curvature2DAngleF0D()
c = func(inter)
b1 = (c>0.1)
#s = self.getCurvilinearAbscissa(inter)
u = inter.u
#print(u)
b = ((u>=self._m) and (u<=self._M))
return b and b1