Revision: 41386
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41386
Author:   kjym3
Date:     2011-10-30 16:00:35 +0000 (Sun, 30 Oct 2011)
Log Message:
-----------
Fix for stroke rendering instability with stroke geometry shaders.

* Stroke::Resample(int nPoints) was not properly working when a wrong
value was returned from Stroke::getLength2D(), resulting in repeated
warning messages "Warning: incorrect points number" during stroke
rendering.  The main cause was that stroke geometry shaders did not
update the two-dimensional (2D) length (also referred to as curvilinear
abscissa) after they modified the 2D points of stroke vertices.  Now
all stroke geometry shaders make explicit calls for Stroke::UpdateLength()
that has been introduced for recomputing the 2D length.  Many thanks to
Josef who reported the problem together with sample .blend files for
reproducing the issue.

* Missing Python wrapper of Stroke::getLength2D() was added.

Modified Paths:
--------------
    
branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py
    
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp
    
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp
    
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Stroke.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Stroke.h

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-10-30 14:53:26 UTC (rev 41385)
+++ 
branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py
     2011-10-30 16:00:35 UTC (rev 41386)
@@ -449,6 +449,7 @@
             u = v.u()
             n = n * self._amplitude * math.cos(distance / self._wavelength * 2 
* math.pi + self._phase)
             v.setPoint(p + n)
+        stroke.UpdateLength()
 
 class PerlinNoise1DShader(StrokeShader):
     def __init__(self, freq = 10, amp = 10, oct = 4, angle = 45, seed = -1):
@@ -468,6 +469,7 @@
             nres = self.__noise.turbulence1(v.u(), self.__freq, self.__amp, 
self.__oct)
             v.setPoint(v.getPoint() + nres * self.__dir)
             it.increment()
+        stroke.UpdateLength()
 
 class PerlinNoise2DShader(StrokeShader):
     def __init__(self, freq = 10, amp = 10, oct = 4, angle = 45, seed = -1):
@@ -488,6 +490,7 @@
             nres = self.__noise.turbulence2(vec, self.__freq, self.__amp, 
self.__oct)
             v.setPoint(v.getPoint() + nres * self.__dir)
             it.increment()
+        stroke.UpdateLength()
 
 # Predicates and helper functions
 

Modified: 
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp
===================================================================
--- 
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp
       2011-10-30 14:53:26 UTC (rev 41385)
+++ 
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp
       2011-10-30 16:00:35 UTC (rev 41386)
@@ -223,6 +223,29 @@
        Py_RETURN_NONE;
 }
 
+static char Stroke_UpdateLength___doc__[] =
+".. method:: UpdateLength()\n"
+"\n"
+"   Updates the 2D length of the Stroke.\n";
+
+static PyObject * Stroke_UpdateLength( BPy_Stroke *self ) {
+       self->s->UpdateLength();
+
+       Py_RETURN_NONE;
+}
+
+static char Stroke_getLength2D___doc__[] =
+".. method:: getLength2D()\n"
+"\n"
+"   Returns the 2D length of the Stroke.\n"
+"\n"
+"   :return: the 2D length of the Stroke.\n"
+"   :rtype: float\n";
+
+static PyObject * Stroke_getLength2D( BPy_Stroke *self ) {     
+       return PyFloat_FromDouble( self->s->getLength2D() );
+}
+
 static char Stroke_getMediumType___doc__[] =
 ".. method:: getMediumType()\n"
 "\n"
@@ -415,6 +438,8 @@
        {"Resample", ( PyCFunction ) Stroke_Resample, METH_VARARGS, 
Stroke_Resample___doc__},
        {"RemoveVertex", ( PyCFunction ) Stroke_RemoveVertex, METH_VARARGS, 
Stroke_RemoveVertex___doc__},
        {"InsertVertex", ( PyCFunction ) Stroke_InsertVertex, METH_VARARGS, 
Stroke_InsertVertex___doc__},
+       {"UpdateLength", ( PyCFunction ) Stroke_UpdateLength, METH_NOARGS, 
Stroke_UpdateLength___doc__},
+       {"getLength2D", ( PyCFunction ) Stroke_getLength2D, METH_NOARGS, 
Stroke_getLength2D___doc__},
        {"getMediumType", ( PyCFunction ) Stroke_getMediumType, METH_NOARGS, 
Stroke_getMediumType___doc__},
        {"getTextureId", ( PyCFunction ) Stroke_getTextureId, METH_NOARGS, 
Stroke_getTextureId___doc__},
        {"hasTips", ( PyCFunction ) Stroke_hasTips, METH_NOARGS, 
Stroke_hasTips___doc__},

Modified: 
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp
===================================================================
--- 
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp
   2011-10-30 14:53:26 UTC (rev 41385)
+++ 
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp
   2011-10-30 16:00:35 UTC (rev 41386)
@@ -586,6 +586,8 @@
     (v0)->setPoint(newFirst[0], newFirst[1]);
     Vec2d newLast(last+_amount*dn);
     (vn)->setPoint(newLast[0], newLast[1]);
+
+       stroke.UpdateLength();
        return 0;
   }
 
@@ -611,6 +613,7 @@
        sv->setPoint(newPoint[0], newPoint[1]);
        ++it;
       }
+       stroke.UpdateLength();
        return 0;
   }
 
@@ -726,6 +729,7 @@
        ++it;
        ++n;
       }
+       stroke.UpdateLength();
        return 0;
   }
 
@@ -844,6 +848,7 @@
        ++p;
        ++n;
       }
+       stroke.UpdateLength();
 
     // Deal with extra vertices:
     if(nExtraVertex == 0)
@@ -931,6 +936,7 @@
        sv->setPoint(newPoint[0], newPoint[1]);
        ++it;
       }
+       stroke.UpdateLength();
        return 0;
   }
 
@@ -1038,6 +1044,7 @@
        //    u.normalize();
        //    (*a)->setPoint((*a)->x()-u.x()*10, (*a)->y()-u.y()*10);
       }
+       stroke.UpdateLength();
 
     // delete stuff
     for(cp=_results.begin(), cpend=_results.end();
@@ -1076,6 +1083,7 @@
       {
        v->setPoint(piece.A.x()+v->u()*u.x()+n.x()*offset, 
piece.A.y()+v->u()*u.y()+n.y()*offset);
       }
+       stroke.UpdateLength();
        return 0;
   }
 

Modified: 
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Stroke.cpp
===================================================================
--- 
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Stroke.cpp   
    2011-10-30 14:53:26 UTC (rev 41385)
+++ 
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Stroke.cpp   
    2011-10-30 16:00:35 UTC (rev 41386)
@@ -674,28 +674,7 @@
       break;
     }
   }
-  // recompute various values (length, curvilign abscissa)
-  float curvabsc = 0.f;
-  it=_Vertices.begin();
-  itend=_Vertices.end();
-  vertex_container::iterator previous=it;
-  for(;
-  (it!=itend);
-  ++it)
-  {
-    if(it != previous)
-      curvabsc += ((*it)->point2d()-(*previous)->point2d()).norm();
-    (*it)->setCurvilinearAbscissa(curvabsc);
-    previous = it;
-  }
-  _Length = curvabsc;
-  it=_Vertices.begin();
-  for(;
-  (it!=itend);
-  ++it)
-  {
-    (*it)->setStrokeLength(_Length);
-  }
+  UpdateLength();
 }
 
 void Stroke::InsertVertex(StrokeVertex *iVertex, 
StrokeInternal::StrokeVertexIterator next)
@@ -704,10 +683,14 @@
 
   vertex_container::iterator itnext = next.getIt();
   _Vertices.insert(itnext, iVertex);
+  UpdateLength();
+}
+
+void Stroke::UpdateLength()
+{
   // recompute various values (length, curvilign abscissa)
   float curvabsc = 0.f;
-  it=_Vertices.begin();
-  itend=_Vertices.end();
+  vertex_container::iterator it=_Vertices.begin(), itend=_Vertices.end();
   vertex_container::iterator previous=it;
   for(;
   (it!=itend);

Modified: 
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Stroke.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Stroke.h 
2011-10-30 14:53:26 UTC (rev 41385)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Stroke.h 
2011-10-30 16:00:35 UTC (rev 41386)
@@ -466,6 +466,9 @@
    */
   void InsertVertex(StrokeVertex *iVertex, 
StrokeInternal::StrokeVertexIterator next);
 
+  /*! Updates the 2D length of the Stroke */
+  void UpdateLength();
+
   /* Render method */
   void Render(const StrokeRenderer *iRenderer );
   void RenderBasic(const StrokeRenderer *iRenderer );

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to