Revision: 56776
          http://sourceforge.net/p/brlcad/code/56776
Author:   phoenixyjll
Date:     2013-08-13 12:16:02 +0000 (Tue, 13 Aug 2013)
Log Message:
-----------
Avoid getting nested polycurves, which makes ON_Brep::IsValid() to fail. If the 
curve we are going to append to a polycurve itself is a polycurve, we append 
each segments separately.

Modified Paths:
--------------
    brlcad/trunk/src/libbrep/boolean.cpp

Modified: brlcad/trunk/src/libbrep/boolean.cpp
===================================================================
--- brlcad/trunk/src/libbrep/boolean.cpp        2013-08-13 12:06:43 UTC (rev 
56775)
+++ brlcad/trunk/src/libbrep/boolean.cpp        2013-08-13 12:16:02 UTC (rev 
56776)
@@ -88,6 +88,22 @@
 }
 
 
+HIDDEN void
+AppendToPolyCurve(ON_Curve* curve, ON_PolyCurve& polycurve)
+{
+    // use this function rather than ON_PolyCurve::Append() to avoid
+    // getting nested polycurves, which makes ON_Brep::IsValid() to fail.
+    ON_PolyCurve* nested = ON_PolyCurve::Cast(curve);
+    if (nested != NULL) {
+       // The input curve is a polycurve
+       const ON_CurveArray& segments = nested->SegmentCurves();
+       for (int i = 0; i < segments.Count(); i++)
+           AppendToPolyCurve(segments[i], polycurve);
+    } else
+       polycurve.Append(curve);
+}
+
+
 HIDDEN bool
 IsLoopValid(const ON_SimpleArray<ON_Curve*>& loop, double tolerance, 
ON_PolyCurve* polycurve = NULL)
 {
@@ -112,10 +128,10 @@
 
     // Check the loop is continuous and closed or not.
     if (ret) {
-       polycurve->Append(loop[0]->Duplicate());
+       AppendToPolyCurve(loop[0]->Duplicate(), *polycurve);
        for (int i = 1 ; i < loop.Count(); i++) {
            if (loop[i] && loop[i - 1] && 
loop[i]->PointAtStart().DistanceTo(loop[i-1]->PointAtEnd()) < ON_ZERO_TOLERANCE)
-               polycurve->Append(loop[i]->Duplicate());
+               AppendToPolyCurve(loop[i]->Duplicate(), *polycurve);
            else {
                bu_log("The input loop is not continuous.\n");
                ret = false;
@@ -224,10 +240,10 @@
 
            if (c1 != NULL && c2 != NULL) {
                ON_PolyCurve* polycurve = new ON_PolyCurve;
-               polycurve->Append(c1);
+               AppendToPolyCurve(c1, *polycurve);
                if (dis > ON_ZERO_TOLERANCE)
-                   polycurve->Append(new ON_LineCurve(c1->PointAtEnd(), 
c2->PointAtStart()));
-               polycurve->Append(c2);
+                   AppendToPolyCurve(new ON_LineCurve(c1->PointAtEnd(), 
c2->PointAtStart()), *polycurve);
+               AppendToPolyCurve(c2, *polycurve);
                tmp[i] = polycurve;
                tmp[j] = NULL;
            }
@@ -238,8 +254,8 @@
                c1 = tmp[i];
                c2 = new ON_LineCurve(tmp[i]->PointAtEnd(), 
tmp[i]->PointAtStart());
                ON_PolyCurve* polycurve = new ON_PolyCurve;
-               polycurve->Append(c1);
-               polycurve->Append(c2);
+               AppendToPolyCurve(c1, *polycurve);
+               AppendToPolyCurve(c2, *polycurve);
                tmp[i] = polycurve;
            }
        }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to