Revision: 56829
          http://sourceforge.net/p/brlcad/code/56829
Author:   phoenixyjll
Date:     2013-08-14 07:09:52 +0000 (Wed, 14 Aug 2013)
Log Message:
-----------
Don't assume that the starting point is outside. Use IsPointInsideLoop() to 
help determine m_in_out.

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

Modified: brlcad/trunk/src/libbrep/boolean.cpp
===================================================================
--- brlcad/trunk/src/libbrep/boolean.cpp        2013-08-14 06:15:22 UTC (rev 
56828)
+++ brlcad/trunk/src/libbrep/boolean.cpp        2013-08-14 07:09:52 UTC (rev 
56829)
@@ -64,6 +64,7 @@
     int m_rank;                // rank on the chain
     double m_t_for_rank;// param on the SSI curve
     enum {
+       UNSET,
        IN,
        OUT
     } m_in_out;                // dir is going inside/outside
@@ -335,32 +336,72 @@
 
     // rank these intersection points
     ON_SimpleArray<ON_SimpleArray<IntersectPoint*>*> 
pts_on_curves(curves.Count());
-    ON_SimpleArray<IntersectPoint*> sorted_pointers;
     for (int i = 0; i < curves.Count(); i++)
        pts_on_curves[i] = new ON_SimpleArray<IntersectPoint*>();
     for (int i = 0; i < intersect.Count(); i++) {
        pts_on_curves[intersect[i].m_type]->Append(&(intersect[i]));
-       sorted_pointers.Append(&(intersect[i]));
     }
     for (int i = 0; i < curves.Count(); i++) {
        pts_on_curves[i]->QuickSort(compare_for_rank);
        for (int j = 0; j < pts_on_curves[i]->Count(); j++)
            (*pts_on_curves[i])[j]->m_rank = j;
     }
+    // Determine whether it's going inside or outside.
     for (int i = 0; i < curves.Count(); i++) {
+       for (int j = 0;  j < pts_on_curves[i]->Count(); j++) {
+           IntersectPoint* ipt = (*pts_on_curves[i])[j];
+           if (pts_on_curves[i]->Count() < 2)
+               ipt->m_in_out = IntersectPoint::UNSET;
+           else {
+               ON_3dPoint left = j == 0 ? curves[i]->PointAtStart() :
+                   
curves[i]->PointAt((ipt->m_t_for_rank+(*pts_on_curves[i])[j-1]->m_t_for_rank)*0.5);
+               ON_3dPoint right = j == pts_on_curves[i]->Count() - 1 ? 
curves[i]->PointAtEnd() :
+                   
curves[i]->PointAt((ipt->m_t_for_rank+(*pts_on_curves[i])[j+1]->m_t_for_rank)*0.5);
+               int left_in = IsPointInsideLoop(left, in->outerloop);
+               int right_in = IsPointInsideLoop(right, in->outerloop);
+               if (left_in < 0 || right_in < 0) {
+                   // not a loop
+                   ipt->m_in_out = IntersectPoint::UNSET;
+                   continue;
+               }
+               if (j == 0 && ON_NearZero(ipt->m_t_for_rank - 
curves[i]->Domain().Min())) {
+                   ipt->m_in_out = right_in ? IntersectPoint::IN : 
IntersectPoint::OUT;
+               } else if (j == pts_on_curves[i]->Count() - 1 && 
ON_NearZero(ipt->m_t_for_rank - curves[i]->Domain().Max())) {
+                   ipt->m_in_out = left_in ? IntersectPoint::OUT : 
IntersectPoint::IN;
+               } else {
+                   if (left_in && right_in) {
+                       // tangent point, both sides in, duplicate that point
+                       intersect.Append(*ipt);
+                       intersect.Last()->m_in_out = IntersectPoint::IN;
+                       intersect.Last()->m_rank = ipt->m_rank+1;
+                       for (int k = j + 1; k < pts_on_curves[i]->Count(); k++)
+                           (*pts_on_curves[i])[k]->m_rank++;
+                       ipt->m_in_out = IntersectPoint::OUT;
+                   } else if (!left_in && !right_in) {
+                       // tangent point, both sides out, useless
+                       ipt->m_in_out = IntersectPoint::UNSET;
+                   } else if (left_in && !right_in) {
+                       // transversal point, going outside
+                       ipt->m_in_out = IntersectPoint::OUT;
+                   } else {
+                       // transversal point, going inside
+                       ipt->m_in_out = IntersectPoint::IN;
+                   }
+               }
+           }
+           if (DEBUG_BREP_BOOLEAN)
+               bu_log("[%d][%d] in_out = %d\n", i, j, ipt->m_in_out);
+       }
+    }
+    for (int i = 0; i < curves.Count(); i++) {
        delete pts_on_curves[i];
     }
+
+    ON_SimpleArray<IntersectPoint*> sorted_pointers;
+    for (int i = 0; i < intersect.Count(); i++)
+       sorted_pointers.Append(&(intersect[i]));
     sorted_pointers.QuickSort(compare_t);
 
-    for (int i = 0; i < intersect.Count(); i++) {
-       // We assume that the starting point is outside.
-       if (intersect[i].m_rank % 2 == 0) {
-           intersect[i].m_in_out = IntersectPoint::IN;
-       } else {
-           intersect[i].m_in_out = IntersectPoint::OUT;
-       }
-    }
-
     // Split the outer loop.
     ON_SimpleArray<ON_Curve*> outerloop;
     int isect_iter = 0;

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