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
This commit is contained in:
@@ -17,22 +17,18 @@ class pyHigherLengthUP1D(UnaryPredicate1D):
|
||||
def __init__(self,l):
|
||||
UnaryPredicate1D.__init__(self)
|
||||
self._l = l
|
||||
|
||||
def getName(self):
|
||||
return "HigherLengthUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
return (inter.getLength2D() > self._l)
|
||||
return (inter.length_2d > self._l)
|
||||
|
||||
class pyNatureUP1D(UnaryPredicate1D):
|
||||
def __init__(self,nature):
|
||||
UnaryPredicate1D.__init__(self)
|
||||
self._nature = nature
|
||||
self._getNature = CurveNatureF1D()
|
||||
|
||||
def getName(self):
|
||||
return "pyNatureUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
if(self._getNature(inter) & self._nature):
|
||||
return 1
|
||||
@@ -43,18 +39,16 @@ class pyHigherNumberOfTurnsUP1D(UnaryPredicate1D):
|
||||
UnaryPredicate1D.__init__(self)
|
||||
self._n = n
|
||||
self._a = a
|
||||
|
||||
def getName(self):
|
||||
return "HigherNumberOfTurnsUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
count = 0
|
||||
func = Curvature2DAngleF0D()
|
||||
it = inter.verticesBegin()
|
||||
while(it.isEnd() == 0):
|
||||
if(func(it) > self._a):
|
||||
it = inter.vertices_begin()
|
||||
while not it.isEnd():
|
||||
if func(it) > self._a:
|
||||
count = count+1
|
||||
if(count > self._n):
|
||||
if count > self._n:
|
||||
return 1
|
||||
it.increment()
|
||||
return 0
|
||||
@@ -66,12 +60,10 @@ class pyDensityUP1D(UnaryPredicate1D):
|
||||
self._threshold = threshold
|
||||
self._integration = integration
|
||||
self._func = DensityF1D(self._wsize, self._integration, sampling)
|
||||
|
||||
def getName(self):
|
||||
return "pyDensityUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
if(self._func(inter) < self._threshold):
|
||||
if self._func(inter) < self._threshold:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -81,15 +73,13 @@ class pyLowSteerableViewMapDensityUP1D(UnaryPredicate1D):
|
||||
self._threshold = threshold
|
||||
self._level = level
|
||||
self._integration = integration
|
||||
|
||||
def getName(self):
|
||||
return "pyLowSteerableViewMapDensityUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
func = GetSteerableViewMapDensityF1D(self._level, self._integration)
|
||||
v = func(inter)
|
||||
print(v)
|
||||
if(v < self._threshold):
|
||||
if v < self._threshold:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -100,15 +90,13 @@ class pyLowDirectionalViewMapDensityUP1D(UnaryPredicate1D):
|
||||
self._orientation = orientation
|
||||
self._level = level
|
||||
self._integration = integration
|
||||
|
||||
def getName(self):
|
||||
return "pyLowDirectionalViewMapDensityUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
func = GetDirectionalViewMapDensityF1D(self._orientation, self._level, self._integration)
|
||||
v = func(inter)
|
||||
#print(v)
|
||||
if(v < self._threshold):
|
||||
if v < self._threshold:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -121,11 +109,9 @@ class pyHighSteerableViewMapDensityUP1D(UnaryPredicate1D):
|
||||
self._func = GetSteerableViewMapDensityF1D(self._level, self._integration)
|
||||
def getName(self):
|
||||
return "pyHighSteerableViewMapDensityUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
|
||||
v = self._func(inter)
|
||||
if(v > self._threshold):
|
||||
if v > self._threshold:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -139,11 +125,10 @@ class pyHighDirectionalViewMapDensityUP1D(UnaryPredicate1D):
|
||||
self._sampling = sampling
|
||||
def getName(self):
|
||||
return "pyLowDirectionalViewMapDensityUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
func = GetDirectionalViewMapDensityF1D(self._orientation, self._level, self._integration, self._sampling)
|
||||
v = func(inter)
|
||||
if(v > self._threshold):
|
||||
if v > self._threshold:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -155,16 +140,14 @@ class pyHighViewMapDensityUP1D(UnaryPredicate1D):
|
||||
self._integration = integration
|
||||
self._sampling = sampling
|
||||
self._func = GetCompleteViewMapDensityF1D(self._level, self._integration, self._sampling) # 2.0 is the smpling
|
||||
|
||||
def getName(self):
|
||||
return "pyHighViewMapDensityUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
#print("toto")
|
||||
#print(func.getName())
|
||||
#print(inter.getExactTypeName())
|
||||
v= self._func(inter)
|
||||
if(v > self._threshold):
|
||||
if v > self._threshold:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -177,15 +160,13 @@ class pyDensityFunctorUP1D(UnaryPredicate1D):
|
||||
self._funcmin = float(funcmin)
|
||||
self._funcmax = float(funcmax)
|
||||
self._integration = integration
|
||||
|
||||
def getName(self):
|
||||
return "pyDensityFunctorUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
func = DensityF1D(self._wsize, self._integration)
|
||||
res = self._functor(inter)
|
||||
k = (res-self._funcmin)/(self._funcmax-self._funcmin)
|
||||
if(func(inter) < self._threshold*k):
|
||||
if func(inter) < self._threshold*k:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -196,10 +177,9 @@ class pyZSmallerUP1D(UnaryPredicate1D):
|
||||
self._integration = integration
|
||||
def getName(self):
|
||||
return "pyZSmallerUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
func = GetProjectedZF1D(self._integration)
|
||||
if(func(inter) < self._z):
|
||||
if func(inter) < self._z:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -213,32 +193,32 @@ class pyIsOccludedByUP1D(UnaryPredicate1D):
|
||||
func = GetShapeF1D()
|
||||
shapes = func(inter)
|
||||
for s in shapes:
|
||||
if(s.getId() == self._id):
|
||||
if(s.id == self._id):
|
||||
return 0
|
||||
it = inter.verticesBegin()
|
||||
itlast = inter.verticesEnd()
|
||||
it = inter.vertices_begin()
|
||||
itlast = inter.vertices_end()
|
||||
itlast.decrement()
|
||||
v = it.getObject()
|
||||
vlast = itlast.getObject()
|
||||
tvertex = v.viewvertex()
|
||||
tvertex = v.viewvertex
|
||||
if type(tvertex) is TVertex:
|
||||
print("TVertex: [ ", tvertex.getId().getFirst(), ",", tvertex.getId().getSecond()," ]")
|
||||
eit = tvertex.edgesBegin()
|
||||
while(eit.isEnd() == 0):
|
||||
print("TVertex: [ ", tvertex.id.first, ",", tvertex.id.second," ]")
|
||||
eit = tvertex.edges_begin()
|
||||
while not eit.isEnd():
|
||||
ve, incoming = eit.getObject()
|
||||
if(ve.getId() == self._id):
|
||||
if ve.id == self._id:
|
||||
return 1
|
||||
print("-------", ve.getId().getFirst(), "-", ve.getId().getSecond())
|
||||
print("-------", ve.id.first, "-", ve.id.second)
|
||||
eit.increment()
|
||||
tvertex = vlast.viewvertex()
|
||||
tvertex = vlast.viewvertex
|
||||
if type(tvertex) is TVertex:
|
||||
print("TVertex: [ ", tvertex.getId().getFirst(), ",", tvertex.getId().getSecond()," ]")
|
||||
eit = tvertex.edgesBegin()
|
||||
while(eit.isEnd() == 0):
|
||||
print("TVertex: [ ", tvertex.id.first, ",", tvertex.id.second," ]")
|
||||
eit = tvertex.edges_begin()
|
||||
while not eit.isEnd():
|
||||
ve, incoming = eit.getObject()
|
||||
if(ve.getId() == self._id):
|
||||
if ve.id == self._id:
|
||||
return 1
|
||||
print("-------", ve.getId().getFirst(), "-", ve.getId().getSecond())
|
||||
print("-------", ve.id.first, "-", ve.id.second)
|
||||
eit.increment()
|
||||
return 0
|
||||
|
||||
@@ -252,7 +232,7 @@ class pyIsInOccludersListUP1D(UnaryPredicate1D):
|
||||
func = GetOccludersF1D()
|
||||
occluders = func(inter)
|
||||
for a in occluders:
|
||||
if(a.getId() == self._id):
|
||||
if a.id == self._id:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -268,7 +248,7 @@ class pyIsOccludedByItselfUP1D(UnaryPredicate1D):
|
||||
lst2 = self.__func2(inter)
|
||||
for vs1 in lst1:
|
||||
for vs2 in lst2:
|
||||
if vs1.getId() == vs2.getId():
|
||||
if vs1.id == vs2.id:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -282,8 +262,8 @@ class pyIsOccludedByIdListUP1D(UnaryPredicate1D):
|
||||
def __call__(self, inter):
|
||||
lst1 = self.__func1(inter)
|
||||
for vs1 in lst1:
|
||||
for id in self._idlist:
|
||||
if vs1.getId() == id:
|
||||
for _id in self._idlist:
|
||||
if vs1.id == _id:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -292,29 +272,28 @@ class pyShapeIdListUP1D(UnaryPredicate1D):
|
||||
UnaryPredicate1D.__init__(self)
|
||||
self._idlist = idlist
|
||||
self._funcs = []
|
||||
for id in idlist :
|
||||
self._funcs.append(ShapeUP1D(id.getFirst(), id.getSecond()))
|
||||
|
||||
for _id in idlist :
|
||||
self._funcs.append(ShapeUP1D(_id.first, _id.second))
|
||||
def getName(self):
|
||||
return "pyShapeIdUP1D"
|
||||
def __call__(self, inter):
|
||||
for func in self._funcs :
|
||||
if(func(inter) == 1) :
|
||||
if func(inter) == 1:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
## deprecated
|
||||
class pyShapeIdUP1D(UnaryPredicate1D):
|
||||
def __init__(self,id):
|
||||
def __init__(self, _id):
|
||||
UnaryPredicate1D.__init__(self)
|
||||
self._id = id
|
||||
self._id = _id
|
||||
def getName(self):
|
||||
return "pyShapeIdUP1D"
|
||||
def __call__(self, inter):
|
||||
func = GetShapeF1D()
|
||||
shapes = func(inter)
|
||||
for a in shapes:
|
||||
if(a.getId() == self._id):
|
||||
if a.id == self._id:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -352,30 +331,28 @@ class pyDensityVariableSigmaUP1D(UnaryPredicate1D):
|
||||
self._tmax = tmax
|
||||
self._integration = integration
|
||||
self._sampling = sampling
|
||||
|
||||
def getName(self):
|
||||
return "pyDensityUP1D"
|
||||
|
||||
def __call__(self, inter):
|
||||
sigma = (self._sigmaMax-self._sigmaMin)/(self._lmax-self._lmin)*(self._functor(inter)-self._lmin) + self._sigmaMin
|
||||
t = (self._tmax-self._tmin)/(self._lmax-self._lmin)*(self._functor(inter)-self._lmin) + self._tmin
|
||||
if(sigma<self._sigmaMin):
|
||||
if sigma < self._sigmaMin:
|
||||
sigma = self._sigmaMin
|
||||
self._func = DensityF1D(sigma, self._integration, self._sampling)
|
||||
d = self._func(inter)
|
||||
if(d<t):
|
||||
if d < t:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
class pyClosedCurveUP1D(UnaryPredicate1D):
|
||||
def __call__(self, inter):
|
||||
it = inter.verticesBegin()
|
||||
itlast = inter.verticesEnd()
|
||||
it = inter.vertices_begin()
|
||||
itlast = inter.vertices_end()
|
||||
itlast.decrement()
|
||||
vlast = itlast.getObject()
|
||||
v = it.getObject()
|
||||
print(v.getId().getFirst(), v.getId().getSecond())
|
||||
print(vlast.getId().getFirst(), vlast.getId().getSecond())
|
||||
if(v.getId() == vlast.getId()):
|
||||
print(v.id.first, v.id.second)
|
||||
print(vlast.id.first, vlast.id.second)
|
||||
if v.id == vlast.id:
|
||||
return 1
|
||||
return 0
|
||||
|
Reference in New Issue
Block a user