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:
Tamito Kajiyama
2013-02-14 23:48:34 +00:00
parent 9e3bf44011
commit 731d08d497
27 changed files with 3149 additions and 3551 deletions

View File

@@ -8,9 +8,9 @@ class CurveMaterialF0D(UnaryFunction0DMaterial):
def __call__(self, inter):
cp = inter.getObject()
assert(isinstance(cp, CurvePoint))
fe = cp.A().getFEdge(cp.B())
fe = cp.first_svertex.get_fedge(cp.second_svertex)
assert(fe is not None)
return fe.material() if fe.isSmooth() else fe.bMaterial()
return fe.material if fe.is_smooth else fe.material_left
class pyInverseCurvature2DAngleF0D(UnaryFunction0DDouble):
def getName(self):
@@ -26,13 +26,9 @@ class pyCurvilinearLengthF0D(UnaryFunction0DDouble):
return "CurvilinearLengthF0D"
def __call__(self, inter):
i0d = inter.getObject()
s = i0d.getExactTypeName()
if (string.find(s, "CurvePoint") == -1):
print("CurvilinearLengthF0D: not implemented yet for", s)
return -1
cp = castToCurvePoint(i0d)
return cp.t2d()
cp = inter.getObject()
assert(isinstance(cp, CurvePoint))
return cp.t2d
## estimate anisotropy of density
class pyDensityAnisotropyF0D(UnaryFunction0DDouble):
@@ -51,13 +47,13 @@ class pyDensityAnisotropyF0D(UnaryFunction0DDouble):
c_1 = self.d1Density(inter)
c_2 = self.d2Density(inter)
c_3 = self.d3Density(inter)
cMax = max( max(c_0,c_1), max(c_2,c_3))
cMin = min( min(c_0,c_1), min(c_2,c_3))
if ( c_iso == 0 ):
cMax = max(max(c_0,c_1), max(c_2,c_3))
cMin = min(min(c_0,c_1), min(c_2,c_3))
if c_iso == 0:
v = 0
else:
v = (cMax-cMin)/c_iso
return (v)
return v
## Returns the gradient vector for a pixel
## l
@@ -70,9 +66,9 @@ class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f):
def getName(self):
return "pyViewMapGradientVectorF0D"
def __call__(self, iter):
p = iter.getObject().getPoint2D()
gx = ReadCompleteViewMapPixelCF(self._l, int(p.x()+self._step), int(p.y()))- ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()))
gy = ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()+self._step))- ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()))
p = iter.getObject().point_2d
gx = ReadCompleteViewMapPixelCF(self._l, int(p.x+self._step), int(p.y))- ReadCompleteViewMapPixelCF(self._l, int(p.x), int(p.y))
gy = ReadCompleteViewMapPixelCF(self._l, int(p.x), int(p.y+self._step))- ReadCompleteViewMapPixelCF(self._l, int(p.x), int(p.y))
return Vector([gx, gy])
class pyViewMapGradientNormF0D(UnaryFunction0DDouble):
@@ -83,9 +79,9 @@ class pyViewMapGradientNormF0D(UnaryFunction0DDouble):
def getName(self):
return "pyViewMapGradientNormF0D"
def __call__(self, iter):
p = iter.getObject().getPoint2D()
gx = ReadCompleteViewMapPixelCF(self._l, int(p.x()+self._step), int(p.y()))- ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()))
gy = ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()+self._step))- ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()))
p = iter.getObject().point_2d
gx = ReadCompleteViewMapPixelCF(self._l, int(p.x+self._step), int(p.y))- ReadCompleteViewMapPixelCF(self._l, int(p.x), int(p.y))
gy = ReadCompleteViewMapPixelCF(self._l, int(p.x), int(p.y+self._step))- ReadCompleteViewMapPixelCF(self._l, int(p.x), int(p.y))
grad = Vector([gx, gy])
return grad.length