[MOAB-dev] r2859 - MOAB/trunk

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Tue Apr 28 17:36:42 CDT 2009


Author: kraftche
Date: 2009-04-28 17:36:42 -0500 (Tue, 28 Apr 2009)
New Revision: 2859

Modified:
   MOAB/trunk/MBBSPTree.cpp
   MOAB/trunk/MBBSPTree.hpp
   MOAB/trunk/bsp_tree_test.cpp
Log:
add a few trivial utility methods for defining split planes

Modified: MOAB/trunk/MBBSPTree.cpp
===================================================================
--- MOAB/trunk/MBBSPTree.cpp	2009-04-28 20:49:55 UTC (rev 2858)
+++ MOAB/trunk/MBBSPTree.cpp	2009-04-28 22:36:42 UTC (rev 2859)
@@ -85,6 +85,16 @@
   return true;
 }
 
+void MBBSPTree::Plane::set( const double pt1[3], const double pt2[3], const double pt3[3] )
+{
+  const double v1[] = { pt2[0] - pt1[0], pt2[1] - pt1[1], pt2[2] - pt1[2] };
+  const double v2[] = { pt3[0] - pt1[0], pt3[1] - pt1[1], pt3[2] - pt1[2] };
+  const double norm[] = { v1[1]*v2[2] - v1[2]*v2[1],
+                          v1[2]*v2[0] - v1[0]*v2[2],
+                          v1[0]*v2[1] - v1[1]*v2[0] };
+  set( norm, pt1 );
+}
+
 MBErrorCode MBBSPTree::init_tags( const char* tagname )
 {
   if (!tagname) 

Modified: MOAB/trunk/MBBSPTree.hpp
===================================================================
--- MOAB/trunk/MBBSPTree.hpp	2009-04-28 20:49:55 UTC (rev 2858)
+++ MOAB/trunk/MBBSPTree.hpp	2009-04-28 22:36:42 UTC (rev 2859)
@@ -65,7 +65,7 @@
    */
   struct Plane {
     Plane() {}
-    Plane( double n[3], double d ) : coeff(d)
+    Plane( const double n[3], double d ) : coeff(d)
       { norm[0] = n[0]; norm[1] = n[1]; norm[2] = n[2]; }
       /** a x + b y + c z + d = 0 */
     Plane( double a, double b, double c, double d ) : coeff(d)
@@ -96,6 +96,14 @@
       /** reverse plane normal */
     void flip()
       { norm[0] = -norm[0]; norm[1] = -norm[1]; norm[2] = -norm[2]; coeff = -coeff; }
+  
+    void set( const double normal[3], const double point[3] )
+      { 
+         const double dot = normal[0]*point[0] + normal[1]*point[1] + normal[2]*point[2];
+        *this = Plane( normal, -dot ); 
+      }
+      
+    void set( const double pt1[3], const double pt2[3], const double pt3[3] );
   };
   
   //! Get split plane for tree node

Modified: MOAB/trunk/bsp_tree_test.cpp
===================================================================
--- MOAB/trunk/bsp_tree_test.cpp	2009-04-28 20:49:55 UTC (rev 2858)
+++ MOAB/trunk/bsp_tree_test.cpp	2009-04-28 22:36:42 UTC (rev 2859)
@@ -2,6 +2,7 @@
 #include "TestUtil.hpp"
 #include "MBBSPTree.hpp"
 
+void test_set_plane();
 void test_iterator();
 void test_box_iterator();
 void test_tree_create();
@@ -14,6 +15,7 @@
 {
   int failures = 0;
   
+  failures += RUN_TEST( test_set_plane );
   failures += RUN_TEST( test_iterator );
   failures += RUN_TEST( test_box_iterator );
   failures += RUN_TEST( test_tree_create );
@@ -49,6 +51,16 @@
   }    
 }         
 
+void test_set_plane()
+{
+  MBBSPTree::Plane p;
+  const double points[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
+  p.set( points[0], points[1], points[2] );
+  CHECK_REAL_EQUAL( 0.0, p.distance( points[0] ), 1e-10 );
+  CHECK_REAL_EQUAL( 0.0, p.distance( points[1] ), 1e-10 );
+  CHECK_REAL_EQUAL( 0.0, p.distance( points[2] ), 1e-10 );
+}
+
 void test_iterator()
 {
   MBCore moab;



More information about the moab-dev mailing list