[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54698] branches/soc-2008-mxcurioni: Freestyle Python API improvements - part 5.

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Thu Feb 21 03:57:45 CET 2013


Revision: 54698
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54698
Author:   kjym3
Date:     2013-02-21 02:57:44 +0000 (Thu, 21 Feb 2013)
Log Message:
-----------
Freestyle Python API improvements - part 5.

Handling of keyword arguments in Python wrapper class constructors was revised.
This revision is mainly focused on Interface0D, Interface1D, Iterator, and
their subclasses, as well as a few additional view map component classes.

Implementation notes: Because of the extensive use of constructor overloading
in the underlying C++ classes, the corresponding Python wrappers try to parse
arguments through multiple calls of PyArg_ParseTupleAndKeywords() if needed.
The downside of this implementation is that most argument errors result in the
same error message ("invalid argument(s)") without indicating what is wrong.
For now this issue is left for future work.

* Now the instantiation of ViewVertex is prohibited since the underlying
C++ class is an abstract class.

* Removed the .cast_to_interface0diterator() method from CurvePointIterator
and StrokeVertexIterator.  Instead the constructor of Interface0DIterator now
accepts the instances of these two iterator classes to construct a nested
Interface0DIterator instance that can be passed to Function0D functor objects.
Specifically, an iterator 'it' is passed to a functor 'func' as follows:

  func(Interface0DIterator(it))

instead of:

  func(it.cast_to_interface0diterator())

* Boolean arguments of class constructors only accept values of boolean type.
Input values of other types are considered as error.

* Additional code clean-up was made.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/ChainingIterators.py
    branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py
    branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/shaders.py
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BBox.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Id.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface1D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Iterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_SShape.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ViewMap.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ViewShape.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ViewShape.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp

Modified: branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/ChainingIterators.py
===================================================================
--- branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/ChainingIterators.py	2013-02-20 17:06:33 UTC (rev 54697)
+++ branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/ChainingIterators.py	2013-02-21 02:57:44 UTC (rev 54698)
@@ -33,8 +33,8 @@
 ## then suggestive contours, then everything else. It doesn't chain the same ViewEdge twice
 ## You can specify whether to stay in the selection or not.
 class pyChainSilhouetteIterator(ChainingIterator):
-	def __init__(self, stayInSelection=1):
-		ChainingIterator.__init__(self, stayInSelection, 1,None,1)
+	def __init__(self, stayInSelection=True):
+		ChainingIterator.__init__(self, stayInSelection, True, None, True)
 	def getExactTypeName(self):
 		return "pyChainSilhouetteIterator"
 	def init(self):
@@ -85,8 +85,8 @@
 ## You can specify whether to chain iterate over edges that were 
 ## already visited or not.
 class pyChainSilhouetteGenericIterator(ChainingIterator):
-	def __init__(self, stayInSelection=1, stayInUnvisited=1):
-		ChainingIterator.__init__(self, stayInSelection, stayInUnvisited,None,1)
+	def __init__(self, stayInSelection=True, stayInUnvisited=True):
+		ChainingIterator.__init__(self, stayInSelection, stayInUnvisited, None, True)
 	def getExactTypeName(self):
 		return "pyChainSilhouetteGenericIterator"
 	def init(self):
@@ -135,7 +135,7 @@
 			
 class pyExternalContourChainingIterator(ChainingIterator):
 	def __init__(self):
-		ChainingIterator.__init__(self, 0, 1,None,1)
+		ChainingIterator.__init__(self, False, True, None, True)
 		self._isExternalContour = ExternalContourUP1D()
 	def getExactTypeName(self):
 		return "pyExternalContourIterator"
@@ -182,8 +182,8 @@
 ## the natural chaining iterator
 ## with a sketchy multiple touch
 class pySketchyChainSilhouetteIterator(ChainingIterator):
-	def __init__(self, nRounds=3,stayInSelection=1):
-		ChainingIterator.__init__(self, stayInSelection, 0,None,1)
+	def __init__(self, nRounds=3,stayInSelection=True):
+		ChainingIterator.__init__(self, stayInSelection, False, None, True)
 		self._timeStamp = GetTimeStampCF()+nRounds
 		self._nRounds = nRounds
 	def getExactTypeName(self):
@@ -241,8 +241,8 @@
 # can chain several times the same ViewEdge
 # in order to produce multiple strokes per ViewEdge.
 class pySketchyChainingIterator(ChainingIterator):
-	def __init__(self, nRounds=3, stayInSelection=1):
-		ChainingIterator.__init__(self, stayInSelection, 0,None,1)
+	def __init__(self, nRounds=3, stayInSelection=True):
+		ChainingIterator.__init__(self, stayInSelection, False, None, True)
 		self._timeStamp = GetTimeStampCF()+nRounds
 		self._nRounds = nRounds
 	def getExactTypeName(self):
@@ -272,7 +272,7 @@
 ##		expressed in % of the total chain length
 class pyFillOcclusionsRelativeChainingIterator(ChainingIterator):
 	def __init__(self, percent):
-		ChainingIterator.__init__(self, 0, 1,None,1)
+		ChainingIterator.__init__(self, False, True, None, True)
 		self._length = 0
 		self._percent = float(percent)
 	def getExactTypeName(self):
@@ -375,7 +375,7 @@
 ##		expressed in pixels
 class pyFillOcclusionsAbsoluteChainingIterator(ChainingIterator):
 	def __init__(self, length):
-		ChainingIterator.__init__(self, 0, 1,None,1)
+		ChainingIterator.__init__(self, False, True, None, True)
 		self._length = float(length)
 	def getExactTypeName(self):
 		return "pySmallFillOcclusionsChainingIterator"
@@ -445,7 +445,7 @@
 ##		expressed in % of the total chain length
 class pyFillOcclusionsAbsoluteAndRelativeChainingIterator(ChainingIterator):
 	def __init__(self, percent, l):
-		ChainingIterator.__init__(self, 0, 1,None,1)
+		ChainingIterator.__init__(self, False, True, None, True)
 		self._length = 0
 		self._absLength = l
 		self._percent = float(percent)
@@ -550,7 +550,7 @@
 ##		expressed in % of the total chain length
 class pyFillQi0AbsoluteAndRelativeChainingIterator(ChainingIterator):
 	def __init__(self, percent, l):
-		ChainingIterator.__init__(self, 0, 1,None,1)
+		ChainingIterator.__init__(self, False, True, None, True)
 		self._length = 0
 		self._absLength = l
 		self._percent = float(percent)
@@ -655,8 +655,8 @@
 ## then suggestive contours, then everything else. It doesn't chain the same ViewEdge twice
 ## You can specify whether to stay in the selection or not.
 class pyNoIdChainSilhouetteIterator(ChainingIterator):
-	def __init__(self, stayInSelection=1):
-		ChainingIterator.__init__(self, stayInSelection, 1,None,1)
+	def __init__(self, stayInSelection=True):
+		ChainingIterator.__init__(self, stayInSelection, True, None, True)
 	def getExactTypeName(self):
 		return "pyChainSilhouetteIterator"
 	def init(self):

Modified: branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py
===================================================================
--- branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py	2013-02-20 17:06:33 UTC (rev 54697)
+++ branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py	2013-02-21 02:57:44 UTC (rev 54698)
@@ -363,7 +363,7 @@
     func = CurveMaterialF0D()
     it = stroke.stroke_vertices_begin()
     while not it.is_end:
-        material = func(it.cast_to_interface0diterator())
+        material = func(Interface0DIterator(it))
         if material_attr == "DIFF":
             color = (material.diffuse[0],
                      material.diffuse[1],
@@ -381,7 +381,7 @@
     func = CurveMaterialF0D()
     it = stroke.stroke_vertices_begin()
     while not it.is_end:
-        material = func(it.cast_to_interface0diterator())
+        material = func(Interface0DIterator(it))
         if material_attr == "DIFF":
             r = material.diffuse[0]
             g = material.diffuse[1]
@@ -478,7 +478,7 @@
         func = VertexOrientation2DF0D()
         it = stroke.stroke_vertices_begin()
         while not it.is_end:
-            dir = func(it.cast_to_interface0diterator())
+            dir = func(Interface0DIterator(it))
             orthDir = mathutils.Vector((-dir.y, dir.x))
             orthDir.normalize()
             fac = abs(orthDir * self.__orientation)
@@ -515,7 +515,7 @@
     def shade(self, stroke):
         for it, distance in iter_distance_along_stroke(stroke):
             v = it.object
-            n = self._getNormal(it.cast_to_interface0diterator())
+            n = self._getNormal(Interface0DIterator(it))
             n = n * self._amplitude * math.cos(distance / self._wavelength * 2 * math.pi + self._phase)
             v.point = v.point + n
         stroke.update_length()
@@ -575,7 +575,7 @@
             v = it.object
             u = v.u
             a = self.__start + u * (self.__end - self.__start)
-            n = self.__getNormal(it.cast_to_interface0diterator())
+            n = self.__getNormal(Interface0DIterator(it))
             n = n * a
             v.point = v.point + n + self.__xy
             it.increment()

Modified: branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/shaders.py
===================================================================
--- branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/shaders.py	2013-02-20 17:06:33 UTC (rev 54697)
+++ branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/shaders.py	2013-02-21 02:57:44 UTC (rev 54698)
@@ -25,7 +25,7 @@
 		b = (self.__min*z_max-self.__max*z_min)/(z_max-z_min)
 		it = stroke.stroke_vertices_begin()
 		while not it.is_end:
-			z = self.__func(it.cast_to_interface0diterator())
+			z = self.__func(Interface0DIterator(it))
 			thickness = a*z+b
 			it.object.attribute.thickness = (thickness, thickness)
 			it.increment()
@@ -72,8 +72,7 @@
 		it = stroke.stroke_vertices_begin()
 		func = DensityF0D(self.wsize)
 		while not it.is_end:
-			toto = it.cast_to_interface0diterator()
-			c= func(toto)
+			c = func(Interface0DIterator(it))
 			if c < self.threshold_min:
 				c = self.threshold_min
 			if c > self.threshold_max:
@@ -332,7 +331,7 @@
 		z_min = 1
 		z_max = 0
 		while not it.is_end:
-			z = self.__func(it.cast_to_interface0diterator())
+			z = self.__func(Interface0DIterator(it))
 			if z < z_min:
 				z_min = z
 			if z > z_max:
@@ -341,7 +340,7 @@
 		z_diff = 1 / (z_max - z_min)
 		it = stroke.stroke_vertices_begin()
 		while not it.is_end:
-			z = (self.__func(it.cast_to_interface0diterator()) - z_min) * z_diff
+			z = (self.__func(Interface0DIterator(it)) - z_min) * z_diff
 			thickness = (1 - z) * self.__max + z * self.__min
 			it.object.attribute.thickness = (thickness, thickness)
 			it.increment()
@@ -428,8 +427,7 @@
 		un = 4.* xn/ ( -2.*xn + 12.*yn + 3. )
 		vn= 9.* yn/ ( -2.*xn + 12.*yn +3. )	
 		while not it.is_end:
-			toto = it.cast_to_interface0diterator()
-			mat = func(toto)
+			mat = func(Interface0DIterator(it))
 			
 			r = mat.diffuse[0]
 			g = mat.diffuse[1]
@@ -499,7 +497,7 @@
 		it = stroke.stroke_vertices_begin()
 		func = Curvature2DAngleF0D()
 		while not it.is_end:
-			c = func(it.cast_to_interface0diterator())
+			c = func(Interface0DIterator(it))
 			if c < 0:
 				print("negative 2D curvature")
 			color = 10.0 * c/3.1415
@@ -680,7 +678,7 @@
 			while not it.is_end:
 				v = it.object
 				p1 = v.point
-				p2 = self._normalInfo(it.cast_to_interface0diterator())*self._lambda*self._curvatureInfo(it.cast_to_interface0diterator())
+				p2 = self._normalInfo(Interface0DIterator(it))*self._lambda*self._curvatureInfo(Interface0DIterator(it))
 				v.point = p1+p2
 				it.increment()
 		stroke.update_length()
@@ -869,7 +867,7 @@
 		while not it.is_end:
 			v = it.object
 			#print(self._getNormal.getName())
-			n = self._getNormal(it.cast_to_interface0diterator())
+			n = self._getNormal(Interface0DIterator(it))
 			p = v.point
 			u = v.u
 			a = self._a*(1-2*(fabs(u-0.5)))
@@ -1265,7 +1263,7 @@
 	def shade(self, stroke):
 		it = stroke.stroke_vertices_begin()
 		while not it.is_end:
-			toto = it.cast_to_interface0diterator()
+			toto = Interface0DIterator(it)
 			att = it.object.attribute
 			att.color = (0.3, 0.4, 0.4)
 			att.thickness = (0, 5)

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BBox.cpp
===================================================================

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list