[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34588] branches/soc-2008-mxcurioni: Made stroke rendering stability fixes, with the aim of addressing

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Mon Jan 31 21:57:40 CET 2011


Revision: 34588
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34588
Author:   kjym3
Date:     2011-01-31 20:57:39 +0000 (Mon, 31 Jan 2011)
Log Message:
-----------
Made stroke rendering stability fixes, with the aim of addressing
occasional unexpected long lines.

1. The Parameter Editor mode was extended to prevent strokes from
doing quick U-turns that "enable" a known bug in strip creation
that generates unexpected long lines in question.

2. A verbose warning message was added to make the existence of
the strip creation bug visible to users.  When the bug affects the
stroke rendering, the following warning shows up in the console:

> Warning: problem in strip creation (the strip is most likely doing a U-turn).

3. The extrapolation option of CurveMapping (used in alpha and
thickness modifiers in the Parameter Editor mode) was identified
as another source of unexpected long lines.  Now the extrapolation
option is unconditionally disabled (even when users enable it
through the GUI).

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Freestyle.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StrokeRep.cpp

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	2011-01-31 20:02:51 UTC (rev 34587)
+++ branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py	2011-01-31 20:57:39 UTC (rev 34588)
@@ -467,6 +467,53 @@
             return True
         return False
 
+# predicates for chaining
+
+class AngleLargerThanBP1D(BinaryPredicate1D):
+    def __init__(self, angle):
+        BinaryPredicate1D.__init__(self)
+        self._angle = math.pi * angle / 180.0
+    def getName(self):
+        return "AngleLargerThanBP1D"
+    def __call__(self, i1, i2):
+        fe1a = i1.fedgeA()
+        fe1b = i1.fedgeB()
+        fe2a = i2.fedgeA()
+        fe2b = i2.fedgeB()
+        sv1a = fe1a.vertexA().getPoint2D()
+        sv1b = fe1b.vertexB().getPoint2D()
+        sv2a = fe2a.vertexA().getPoint2D()
+        sv2b = fe2b.vertexB().getPoint2D()
+        if (sv1a - sv2a).length < 1e-6:
+            dir1 = sv1a - sv1b
+            dir2 = sv2b - sv2a
+        elif (sv1b - sv2b).length < 1e-6:
+            dir1 = sv1b - sv1a
+            dir2 = sv2a - sv2b
+        elif (sv1a - sv2b).length < 1e-6:
+            dir1 = sv1a - sv1b
+            dir2 = sv2a - sv2b
+        elif (sv1b - sv2a).length < 1e-6:
+            dir1 = sv1b - sv1a
+            dir2 = sv2b - sv2a
+        else:
+            return False
+        denom = dir1.length * dir2.length
+        if denom < 1e-6:
+            return False
+        x = (dir1 * dir2) / denom
+        return math.acos(min(max(x, -1.0), 1.0)) > self._angle
+
+class AndBP1D(BinaryPredicate1D):
+    def __init__(self, pred1, pred2):
+        BinaryPredicate1D.__init__(self)
+        self.__pred1 = pred1
+        self.__pred2 = pred2
+    def getName(self):
+        return "AndBP1D"
+    def __call__(self, i1, i2):
+        return self.__pred1(i1, i2) and self.__pred2(i1, i2)
+
 # main function for parameter processing
 
 def process(layer_name, lineset_name):
@@ -561,12 +608,10 @@
         upred = TrueUP1D()
     Operators.select(upred)
     # join feature edges
+    bpred = AngleLargerThanBP1D(1.0) # XXX temporary fix for occasional unexpected long lines
     if linestyle.same_object:
-        bpred = SameShapeIdBP1D()
-        chaining_iterator = ChainPredicateIterator(upred, bpred)
-    else:
-        chaining_iterator = ChainSilhouetteIterator()
-    Operators.bidirectionalChain(chaining_iterator, NotUP1D(upred))
+        bpred = AndBP1D(bpred, SameShapeIdBP1D())
+    Operators.bidirectionalChain(ChainPredicateIterator(upred, bpred), NotUP1D(upred))
     # dashed line
     if linestyle.use_dashed_line:
         pattern = []

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Freestyle.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Freestyle.cpp	2011-01-31 20:02:51 UTC (rev 34587)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Freestyle.cpp	2011-01-31 20:57:39 UTC (rev 34588)
@@ -172,6 +172,7 @@
 	return newVectorObject( out, 4, Py_NEW, NULL);
 }
 
+#include "DNA_color_types.h"
 #include "BKE_colortools.h" /* curvemapping_evaluateF() */
 
 static char Freestyle_evaluateCurveMappingF___doc__[] =
@@ -206,6 +207,11 @@
 		return NULL;
 	}
 	cumap = (CurveMapping *)py_srna->ptr.data;
+	/* disable extrapolation if enabled */
+	if ((cumap->cm[cur].flag & CUMA_EXTEND_EXTRAPOLATE)) {
+		cumap->cm[cur].flag &= ~( CUMA_EXTEND_EXTRAPOLATE );
+		curvemapping_changed(cumap, 0);
+	}
 	return PyFloat_FromDouble(curvemapping_evaluateF(cumap, cur, value));
 }
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StrokeRep.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StrokeRep.cpp	2011-01-31 20:02:51 UTC (rev 34587)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StrokeRep.cpp	2011-01-31 20:57:39 UTC (rev 34588)
@@ -259,6 +259,7 @@
         // the strip is most likely doing a U-turn, we can't compute the average vector.
         // We just continue and hope it's ok
         vPrev = v;
+        cerr << "Warning: problem in strip creation (the strip is most likely doing a U-turn).\n";
         continue;
       }
       




More information about the Bf-blender-cvs mailing list