Revision: 54174
          http://brlcad.svn.sourceforge.net/brlcad/?rev=54174&view=rev
Author:   starseeker
Date:     2013-01-14 23:49:25 +0000 (Mon, 14 Jan 2013)
Log Message:
-----------
Add a function for testing whether a bot patch is planar

Modified Paths:
--------------
    brlcad/trunk/src/librt/test_botpatches.cpp

Modified: brlcad/trunk/src/librt/test_botpatches.cpp
===================================================================
--- brlcad/trunk/src/librt/test_botpatches.cpp  2013-01-14 22:44:51 UTC (rev 
54173)
+++ brlcad/trunk/src/librt/test_botpatches.cpp  2013-01-14 23:49:25 UTC (rev 
54174)
@@ -228,6 +228,32 @@
     }
 }
 
+// Check if a mesh is planar
+int planar_patch_test(size_t patch_id, std::set<size_t> *faces, struct 
Manifold_Info *info, fastf_t tol) {
+    if (faces->size() == 1) return 1;
+    if (faces->size() > 0) {
+       std::set<size_t> verts;
+       std::set<size_t>::iterator f_it, v_it;
+        fastf_t max_dist = 0.0;
+        ON_Plane best_fit_plane;
+        fit_plane(patch_id, faces, info, &best_fit_plane);
+       for(f_it = faces->begin(); f_it != faces->end(); f_it++) {
+           verts.insert(info->bot->faces[(*f_it)*3+0]*3);
+           verts.insert(info->bot->faces[(*f_it)*3+1]*3);
+           verts.insert(info->bot->faces[(*f_it)*3+2]*3);
+       }
+       for(v_it = verts.begin(); v_it != verts.end(); v_it++) {
+           point_t pt;
+           VMOVE(pt, &info->bot->vertices[*v_it]);
+            fastf_t curr_dist = best_fit_plane.DistanceTo(ON_3dPoint(pt[0], 
pt[1], pt[2]));
+           if (curr_dist > max_dist) max_dist = curr_dist;
+       }
+        if (max_dist < tol) return 1;
+        return 0;
+    } else {
+      return 0;
+    }
+}
 
/**********************************************************************************
  *
  *   Debugging code for plotting structures commonly generated during fitting
@@ -1155,7 +1181,7 @@
                       istart++;
                     }
                } else {
-                  std::cout << "Pullback failure on first pt (" << patch_id << 
"," << (double)(istart-1)/(double)50 << "): " << pt_3d.x << "," << pt_3d.y << 
"," << pt_3d.z << "\n";
+                  std::cout << "Pullback failure on first pt (" << patch_id << 
"," << curr_edge << "," << (double)(istart-1)/(double)50 << "): " << pt_3d.x << 
"," << pt_3d.y << "," << pt_3d.z << "\n";
                   pullback_failures++;
                  istart++;
                }
@@ -1174,7 +1200,7 @@
                        pt_2d_prev = pt_2d;
                    }
                } else {
-                  std::cout << "Pullback failure (" << patch_id << "," << 
(double)(i)/(double)50 << "): " << pt_3d.x << "," << pt_3d.y << "," << pt_3d.z 
<< "\n";
+                  std::cout << "Pullback failure (" << patch_id <<  "," << 
curr_edge << "," << (double)(i)/(double)50 << "): " << pt_3d.x << "," << 
pt_3d.y << "," << pt_3d.z << "\n";
                   pullback_failures++;
                 }
            }
@@ -1187,7 +1213,7 @@
                        pt_2d_prev = pt_2d;
                    }
                } else {
-                  std::cout << "Pullback failure (" << patch_id << "," << 
(double)(i)/(double)50 << "): " << pt_3d.x << "," << pt_3d.y << "," << pt_3d.z 
<< "\n";
+                  std::cout << "Pullback failure (" << patch_id <<  "," << 
curr_edge << "," << (double)(i)/(double)50 << "): " << pt_3d.x << "," << 
pt_3d.y << "," << pt_3d.z << "\n";
                   pullback_failures++;
                 }
            }

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


------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to