Revision: 56019
          http://sourceforge.net/p/brlcad/code/56019
Author:   phoenixyjll
Date:     2013-07-12 06:11:33 +0000 (Fri, 12 Jul 2013)
Log Message:
-----------
Eliminate unnecessary collinear points on the polyline curves.

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

Modified: brlcad/trunk/src/libbrep/intersect.cpp
===================================================================
--- brlcad/trunk/src/libbrep/intersect.cpp      2013-07-12 05:45:34 UTC (rev 
56018)
+++ brlcad/trunk/src/libbrep/intersect.cpp      2013-07-12 06:11:33 UTC (rev 
56019)
@@ -1860,6 +1860,32 @@
     if (in == NULL)
        return NULL;
 
+    // First, eliminate some unnecessary points (if three neighbor points
+    // are collinear, the middle one can be removed (for a polyline))
+    ON_3dPointArray points;
+    if (in->IsPolyline(&points)) {
+       int point_count = points.Count();
+       ON_3dPointArray new_points;
+       ON_3dPoint start = points[0];
+       new_points.Append(start);
+       for (int i = 2; i < point_count; i++) {
+           ON_3dVector v1 = points[i-1] - start;
+           ON_3dVector v2 = points[i] - points[i-1];
+           if (!ON_NearZero(ON_CrossProduct(v1, v2).Length())) {
+               // start, points[i-1], points[i] are not collinear
+               start = points[i-1];
+               new_points.Append(start);
+           }
+       }
+       new_points.Append(points[point_count-1]);
+       if (new_points.Count() != point_count) {
+           // Some points have been eliminated
+           if (delete_curve) delete in;
+           in = new ON_PolylineCurve(new_points);
+           bu_log("fitting: %d => %d points.\n", point_count, 
new_points.Count());
+       }
+    }
+
     // Linear fitting
     if (in->IsLinear(fitting_tolerance)) {
        ON_LineCurve *linecurve = new ON_LineCurve(in->PointAtStart(), 
in->PointAtEnd());

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


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to