diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2011-02-22 04:39:56 +0300 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2011-02-22 04:39:56 +0300 |
commit | ecd76d99d64d76846f9f1ed24c54a82b6e9ad041 (patch) | |
tree | c58c376e7c82cbb42838630c3a109cdf16019b84 /source/blender/freestyle/intern/stroke | |
parent | 70aa63306ad3ec1402275ed623b745d06d14db18 (diff) |
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()).
Diffstat (limited to 'source/blender/freestyle/intern/stroke')
-rwxr-xr-x | source/blender/freestyle/intern/stroke/Curve.cpp | 15 | ||||
-rwxr-xr-x | source/blender/freestyle/intern/stroke/Operators.cpp | 65 |
2 files changed, 77 insertions, 3 deletions
diff --git a/source/blender/freestyle/intern/stroke/Curve.cpp b/source/blender/freestyle/intern/stroke/Curve.cpp index a4bf2ae85f2..d865d9be8e4 100755 --- a/source/blender/freestyle/intern/stroke/Curve.cpp +++ b/source/blender/freestyle/intern/stroke/Curve.cpp @@ -195,8 +195,10 @@ FEdge *CurvePoint::fedge() 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 @@ FEdge* CurvePoint::getFEdge(Interface0D& inter) 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; } diff --git a/source/blender/freestyle/intern/stroke/Operators.cpp b/source/blender/freestyle/intern/stroke/Operators.cpp index 4f6fb08fa0e..72380656322 100755 --- a/source/blender/freestyle/intern/stroke/Operators.cpp +++ b/source/blender/freestyle/intern/stroke/Operators.cpp @@ -464,7 +464,19 @@ int Operators::sequentialSplit(UnaryPredicate0D& pred, 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 @@ int Operators::sequentialSplit(UnaryPredicate0D& startingPred, UnaryPredicate0D& 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 @@ int Operators::recursiveSplit(UnaryFunction0D<double>& func, UnaryPredicate1D& p } _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 @@ int Operators::recursiveSplit(UnaryFunction0D<double>& func, UnaryPredicate0D& p } _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 @@ Stroke* createStroke(Interface1D& inter) { // 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 @@ void Operators::reset() { ++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(); } |