Revision: 57718
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57718
Author:   kjym3
Date:     2013-06-24 22:48:00 +0000 (Mon, 24 Jun 2013)
Log Message:
-----------
Fix for invalid zero-length orientation vectors.
Problem report by flokkievids in the BA Freestyle thread, thanks!

Also made changes to suppress warnings in strip creation when Freestyle 
debugging is disabled.

Modified Paths:
--------------
    trunk/blender/source/blender/freestyle/intern/stroke/StrokeRep.cpp

Modified: trunk/blender/source/blender/freestyle/intern/stroke/StrokeRep.cpp
===================================================================
--- trunk/blender/source/blender/freestyle/intern/stroke/StrokeRep.cpp  
2013-06-24 22:41:40 UTC (rev 57717)
+++ trunk/blender/source/blender/freestyle/intern/stroke/StrokeRep.cpp  
2013-06-24 22:48:00 UTC (rev 57718)
@@ -31,6 +31,8 @@
 #include "StrokeRenderer.h"
 #include "StrokeRep.h"
 
+#include "BKE_global.h"
+
 using namespace std;
 
 namespace Freestyle {
@@ -109,7 +111,9 @@
 {
        //computeParameterization();
        if (iStrokeVertices.size() < 2) {
-               cerr << "Warning: strip has less than 2 vertices" << endl;
+               if (G.debug & G_DEBUG_FREESTYLE) {
+                       cout << "Warning: strip has less than 2 vertices" << 
endl;
+               }
                return;
        }
        _vertices.reserve(2 * iStrokeVertices.size());
@@ -123,6 +127,7 @@
 
        vector<StrokeVertex *>::const_iterator v, vend, v2, vPrev;
        StrokeVertex *sv, *sv2, *svPrev;
+       int orientationErrors = 0;
 
        //special case of first vertex
        v = iStrokeVertices.begin();
@@ -138,11 +143,15 @@
        // check whether the orientation was user defined
        if (sv->attribute().isAttributeAvailableVec2f("orientation")) {
                Vec2r userDir = 
sv->attribute().getAttributeVec2f("orientation");
-               userDir.normalize();
-               real dp = userDir * orthDir;
-               if (dp < 0)
-               userDir = userDir * (-1.0f);
-               stripDir = userDir;
+               if (userDir.norm() > 1e-6) {
+                       userDir.normalize();
+                       real dp = userDir * orthDir;
+                       if (dp < 0)
+                               userDir = userDir * (-1.0f);
+                       stripDir = userDir;
+               } else {
+                       ++orientationErrors;
+               }
        }
        const float *thickness = sv->attribute().getThickness();
        _vertices.push_back(new StrokeVertexRep(sv->getPoint() + thickness[1] * 
stripDir));
@@ -192,11 +201,15 @@
                Vec2r stripDir = orthDir;
                if (sv->attribute().isAttributeAvailableVec2f("orientation")) {
                        Vec2r userDir = 
sv->attribute().getAttributeVec2f("orientation");
-                       userDir.normalize();
-                       real dp = userDir * orthDir;
-                       if (dp < 0)
-                               userDir = userDir * (-1.0f);
-                       stripDir = userDir;
+                       if (userDir.norm() > 1e-6) {
+                               userDir.normalize();
+                               real dp = userDir * orthDir;
+                               if (dp < 0)
+                                       userDir = userDir * (-1.0f);
+                               stripDir = userDir;
+                       } else {
+                               ++orientationErrors;
+                       }
                }
 
                //direction and orthogonal vector to the previous segment
@@ -207,11 +220,15 @@
                Vec2r stripDirPrev = orthDirPrev;
                if 
(svPrev->attribute().isAttributeAvailableVec2f("orientation")) {
                        Vec2r userDir = 
svPrev->attribute().getAttributeVec2f("orientation");
-                       userDir.normalize();
-                       real dp = userDir * orthDir;
-                       if (dp < 0)
-                               userDir = userDir * (-1.0f);
-                       stripDirPrev = userDir;
+                       if (userDir.norm() > 1e-6) {
+                               userDir.normalize();
+                               real dp = userDir * orthDir;
+                               if (dp < 0)
+                                       userDir = userDir * (-1.0f);
+                               stripDirPrev = userDir;
+                       } else {
+                               ++orientationErrors;
+                       }
                }
 
                const float *thickness = sv->attribute().getThickness();
@@ -279,11 +296,15 @@
        // check whether the orientation was user defined
        if (sv->attribute().isAttributeAvailableVec2f("orientation")) {
                Vec2r userDir = 
sv->attribute().getAttributeVec2f("orientation");
-               userDir.normalize();
-               real dp = userDir * orthDir;
-               if (dp < 0)
-                       userDir = userDir * (-1.0f);
-               stripDirLast = userDir;
+               if (userDir.norm() > 1e-6) {
+                       userDir.normalize();
+                       real dp = userDir * orthDir;
+                       if (dp < 0)
+                               userDir = userDir * (-1.0f);
+                       stripDirLast = userDir;
+               } else {
+                       ++orientationErrors;
+               }
        }
        const float *thicknessLast = sv->attribute().getThickness();
        _vertices.push_back(new StrokeVertexRep(sv->getPoint() + 
thicknessLast[1] * stripDirLast));
@@ -322,9 +343,18 @@
        if (iStrokeVertices.size() < 3)
                _averageThickness = 0.5 * (thicknessLast[1] + thicknessLast[0] 
+ thickness[0] + thickness[1]);
 
-       if (i != 2 * (int)iStrokeVertices.size())
-               cerr << "Warning: problem with stripe size\n";
+       if (orientationErrors > 0) {
+               if (G.debug & G_DEBUG_FREESTYLE) {
+                       cout << "Warning: " << orientationErrors <<" invalid 
zero-length orientation vector(s) found.\n";
+               }
+       }
 
+       if (i != 2 * (int)iStrokeVertices.size()) {
+               if (G.debug & G_DEBUG_FREESTYLE) {
+                       cout << "Warning: problem with stripe size\n";
+               }
+       }
+
        cleanUpSingularities (iStrokeVertices);
 }
 
@@ -338,7 +368,9 @@
 
        for (k = 0; k < sizeStrip; k++) {
                if (notValid(_vertices[k]->point2d())) {
-                       cerr << "Warning: strip vertex " << k << " non valid" 
<< endl;
+                       if (G.debug & G_DEBUG_FREESTYLE) {
+                               cout << "Warning: strip vertex " << k << " non 
valid" << endl;
+                       }
                        return;
                }
        }
@@ -437,7 +469,9 @@
 
        for (k = 0; k < sizeStrip; k++) {
                if (notValid(_vertices[k]->point2d())) {
-                       cerr << "Warning: strip vertex " << k << " non valid 
after cleanup" << endl;
+                       if (G.debug & G_DEBUG_FREESTYLE) {
+                               cout << "Warning: strip vertex " << k << " non 
valid after cleanup" << endl;
+                       }
                        return;
                }
        }

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

Reply via email to