[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35043] branches/soc-2008-mxcurioni/source /blender/freestyle/intern: Consolidation of stroke drawing.

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Tue Feb 22 02:39:56 CET 2011


Revision: 35043
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35043
Author:   kjym3
Date:     2011-02-22 01:39:56 +0000 (Tue, 22 Feb 2011)
Log Message:
-----------
Consolidation of stroke drawing.

Fixed a complicated bug that caused a failure of CurvePoint::getFEdge()
which had affected a number of C/Python API functions such as MaterialF0D.

The current view map building procedure may generate ViewEdges whose
two-dimensional (2D) length is almost or exactly zero.  Such a zero-length
ViewEdge is possibly chained with other ViewEdges to form a stroke.  When
the stroke is finally generated by Operators::create(), an attempt to remove
redundant vertices at the same 2D point is made.  This possibly breaks the
links of ViewEdges on top of which the stroke has been built, and eventually
result in a fatal error of CurvePoint::getFEdge() when API functions that
rely on this method are called from within a style module.

The present fix addresses this issue by automatically removing zero-length
ViewEdges (and Chains of them) before stroke drawing is started and after
splitting is performed (e.g., using Operators::sequentialSplit()).

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Curve.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Operators.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMap.h

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Curve.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Curve.cpp	2011-02-21 23:44:11 UTC (rev 35042)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Curve.cpp	2011-02-22 01:39:56 UTC (rev 35043)
@@ -195,8 +195,10 @@
 FEdge* CurvePoint::getFEdge(Interface0D& inter)
 {
   CurvePoint* iVertexB = dynamic_cast<CurvePoint*>(&inter);
-  if (!iVertexB)
+  if (!iVertexB) {
+    cerr << "Warning: CurvePoint::getFEdge() failed to cast the given 0D element to CurvePoint." << endl;
     return 0;
+  }
   if(((__A == iVertexB->__A) && (__B == iVertexB->__B))
     ||
     ((__A == iVertexB->__B) && (__B == iVertexB->__A)))
@@ -245,8 +247,15 @@
     if((_t2d != 0) && (iVertexB->_t2d == 1))
       return __A->getFEdge(*__B);
   }
-  
-  cerr << "Warning: you should not be there..." << endl;
+#if 0
+  printf("__A           0x%p p (%f, %f)\n", __A, __A->getPoint2D().x(), __A->getPoint2D().y());
+  printf("__B           0x%p p (%f, %f)\n", __B, __B->getPoint2D().x(), __B->getPoint2D().y());
+  printf("iVertexB->A() 0x%p p (%f, %f)\n", iVertexB->A(), iVertexB->A()->getPoint2D().x(), iVertexB->A()->getPoint2D().y());
+  printf("iVertexB->B() 0x%p p (%f, %f)\n", iVertexB->B(), iVertexB->B()->getPoint2D().x(), iVertexB->B()->getPoint2D().y());
+  printf("_t2d            %f p (%f, %f)\n", _t2d, getPoint2D().x(), getPoint2D().y());
+  printf("iVertexB->t2d() %f p (%f, %f)\n", iVertexB->t2d(), iVertexB->getPoint2D().x(), iVertexB->getPoint2D().y());
+#endif
+  cerr << "Warning: CurvePoint::getFEdge() failed." << endl;
 
   return 0;
 }

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Operators.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Operators.cpp	2011-02-21 23:44:11 UTC (rev 35042)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Operators.cpp	2011-02-22 01:39:56 UTC (rev 35043)
@@ -464,7 +464,19 @@
     delete (*cit);
   }
   _current_chains_set.clear();
+#if 0
   _current_chains_set = splitted_chains;
+#else
+  for (cit = splitted_chains.begin(), citend = splitted_chains.end();
+	   cit != citend;
+	   ++cit) {
+	if ((*cit)->getLength2D() < M_EPSILON) {
+	  delete (*cit);
+	  continue;
+	}
+    _current_chains_set.push_back(*cit);
+  }
+#endif
   splitted_chains.clear();
 
   if (!_current_chains_set.empty())
@@ -554,7 +566,19 @@
     delete (*cit);
   }
   _current_chains_set.clear();
+#if 0
   _current_chains_set = splitted_chains;
+#else
+  for (cit = splitted_chains.begin(), citend = splitted_chains.end();
+	   cit != citend;
+	   ++cit) {
+	if ((*cit)->getLength2D() < M_EPSILON) {
+	  delete (*cit);
+	  continue;
+	}
+    _current_chains_set.push_back(*cit);
+  }
+#endif
   splitted_chains.clear();
   
   if (!_current_chains_set.empty())
@@ -711,7 +735,19 @@
   } 
   
   _current_chains_set.clear();
+#if 0
   _current_chains_set = newChains;
+#else
+  for (cit = newChains.begin(), citend = newChains.end();
+	   cit != citend;
+	   ++cit) {
+	if ((*cit)->getLength2D() < M_EPSILON) {
+	  delete (*cit);
+	  continue;
+	}
+    _current_chains_set.push_back(*cit);
+  }
+#endif
   newChains.clear();
 
   if (!_current_chains_set.empty())
@@ -868,7 +904,19 @@
   } 
   
   _current_chains_set.clear();
+#if 0
   _current_chains_set = newChains;
+#else
+  for (cit = newChains.begin(), citend = newChains.end();
+	   cit != citend;
+	   ++cit) {
+	if ((*cit)->getLength2D() < M_EPSILON) {
+	  delete (*cit);
+	  continue;
+	}
+    _current_chains_set.push_back(*cit);
+  }
+#endif
   newChains.clear();
 
   if (!_current_chains_set.empty())
@@ -944,6 +992,13 @@
       // previous one. We remove it to avoid having to deal
       // with this kind of singularities in the strip creation
       delete stroke_vertex;
+	  /*
+	   * This seems a wrong place to clean stroke topology, since just
+	   * deleting this `stroke_vertex' possibly breaks the continuity of
+	   * the underlying series of FEdges on top of which the stroke has
+	   * been built.  Such a break of linked FEdges will cause a failure
+	   * of CurvePoint::getFEdge(). (22 Feb 2011, T.K.)
+	   */
     }else{
       currentCurvilignAbscissa += vec_tmp.norm();
       stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa);
@@ -1037,9 +1092,19 @@
        ++it)
     delete *it;
   _current_chains_set.clear();
+#if 0
   _current_view_edges_set.insert(_current_view_edges_set.begin(),
 				 vm->ViewEdges().begin(),
 				 vm->ViewEdges().end());
+#else
+  ViewMap::viewedges_container& vedges = vm->ViewEdges();
+  ViewMap::viewedges_container::iterator ve=vedges.begin(), veend=vedges.end();
+  for (; ve != veend; ++ve) {
+    if ((*ve)->getLength2D() < M_EPSILON)
+      continue;
+    _current_view_edges_set.push_back(*ve);
+  }
+#endif
   _current_set = &_current_view_edges_set;
   _current_strokes_set.clear();
 }

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMap.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMap.h	2011-02-21 23:44:11 UTC (rev 35042)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMap.h	2011-02-22 01:39:56 UTC (rev 35043)
@@ -1353,6 +1353,10 @@
       
       // a new edge, A'B is created.
       FEdge *newEdge = shape->SplitEdgeIn2(fe, sv);
+	  /*
+	   * One of the two FEdges (fe and newEdge) may have a 2D length less than M_EPSILON.
+	   * (22 Feb 2011, T.K.)
+	   */
 
       ioNewEdges.push_back(newEdge);
       ViewEdge *newVEdge;




More information about the Bf-blender-cvs mailing list