From 38b7cbbd004ef7268a1c39114d8503906361c1f7 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Sun, 4 Jul 2010 23:08:37 +0000 Subject: =?UTF-8?q?Bug=20fixes=20from=20St=C3=A9phane=20Grabli,=20one=20of?= =?UTF-8?q?=20the=20coauthors=20of=20the=20original=20Freestyle:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix for making the stroke construction more robust to nearly overlapping vertices. * Fix for a bug in the computation of the occluded surfaces. These changes make the visibility computation more robust and the line quality generally higher. --- .../blender/freestyle/intern/stroke/Operators.cpp | 30 +++++++++++++++++----- .../blender/freestyle/intern/stroke/StrokeRep.cpp | 9 ++++++- .../freestyle/intern/view_map/Functions0D.cpp | 21 +++++++-------- .../freestyle/intern/view_map/ViewMapBuilder.cpp | 6 ++--- 4 files changed, 42 insertions(+), 24 deletions(-) (limited to 'source/blender/freestyle/intern') diff --git a/source/blender/freestyle/intern/stroke/Operators.cpp b/source/blender/freestyle/intern/stroke/Operators.cpp index ef1b2662998..ea996c67785 100755 --- a/source/blender/freestyle/intern/stroke/Operators.cpp +++ b/source/blender/freestyle/intern/stroke/Operators.cpp @@ -938,10 +938,18 @@ Stroke* createStroke(Interface1D& inter) { stroke_vertex = new StrokeVertex(cp); current = stroke_vertex->point2d(); Vec3r vec_tmp(current - previous); - currentCurvilignAbscissa += vec_tmp.norm(); - stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa); - stroke->push_back(stroke_vertex); - previous = current; + real vec_tmp_norm = vec_tmp.norm(); + if((stroke->strokeVerticesSize() > 0) && (vec_tmp_norm < 1.e-06)){ + // The point we just created is superimposed with the + // previous one. We remove it to avoid having to deal + // with this kind of singularities in the strip creation + delete stroke_vertex; + }else{ + currentCurvilignAbscissa += vec_tmp.norm(); + stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa); + stroke->push_back(stroke_vertex); + previous = current; + } ++it; } while((it != itend) && (it != itfirst)); @@ -959,9 +967,17 @@ Stroke* createStroke(Interface1D& inter) { stroke_vertex = new StrokeVertex(cp); current = stroke_vertex->point2d(); Vec3r vec_tmp(current - previous); - currentCurvilignAbscissa += vec_tmp.norm(); - stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa); - stroke->push_back(stroke_vertex); + real vec_tmp_norm = vec_tmp.norm(); + if((stroke->strokeVerticesSize() > 0) && (vec_tmp_norm < 1.e-06)){ + // The point we just created is superimposed with the + // previous one. We remove it to avoid having to deal + // with this kind of singularities in the strip creation + delete stroke_vertex; + }else{ + currentCurvilignAbscissa += vec_tmp.norm(); + stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa); + stroke->push_back(stroke_vertex); + } } stroke->setLength(currentCurvilignAbscissa); return stroke; diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.cpp b/source/blender/freestyle/intern/stroke/StrokeRep.cpp index fbe1273bac0..6ae15c71833 100755 --- a/source/blender/freestyle/intern/stroke/StrokeRep.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeRep.cpp @@ -254,7 +254,14 @@ Strip::createStrip (const vector& iStrokeVertices) else _vertices.push_back(new StrokeVertexRep(p-thickness[0]*stripDir)); ++i; - + + if((stripDir+stripDirPrev).norm() <= 1.e-06){ + // 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; + continue; + } + // if the angle is obtuse, we simply average the directions to avoid the singularity stripDir=stripDir+stripDirPrev; if ((dirNormisSmooth()) result = ((FEdgeSmooth*)fe1)->frs_material(); else diff --git a/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp b/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp index b010895a621..dbd046f050a 100755 --- a/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp +++ b/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp @@ -241,8 +241,7 @@ void ViewMapBuilder::ComputeRayCastingVisibility(ViewMap *ioViewMap, Grid* iGrid maxIndex = tmpQI; } } - else - FindOccludee(fe, iGrid, epsilon, &aFace, timestamp++); + FindOccludee(fe, iGrid, epsilon, &aFace, timestamp++); if(aFace) { fe->setaFace(*aFace); @@ -361,8 +360,7 @@ void ViewMapBuilder::ComputeFastRayCastingVisibility(ViewMap *ioViewMap, Grid* i maxIndex = tmpQI; } } - else - FindOccludee(fe, iGrid, epsilon, &aFace, timestamp++); + FindOccludee(fe, iGrid, epsilon, &aFace, timestamp++); if(aFace) { -- cgit v1.2.3