[MOAB-dev] r3693 - MOAB/trunk/examples

hongjun at mcs.anl.gov hongjun at mcs.anl.gov
Mon Mar 22 18:42:21 CDT 2010


Author: hongjun
Date: 2010-03-22 18:42:20 -0500 (Mon, 22 Mar 2010)
New Revision: 3693

Added:
   MOAB/trunk/examples/ObbTree.cpp
Modified:
   MOAB/trunk/examples/Makefile.am
Log:
o added a simple obb tree ray tracing example


Modified: MOAB/trunk/examples/Makefile.am
===================================================================
--- MOAB/trunk/examples/Makefile.am	2010-03-22 23:41:19 UTC (rev 3692)
+++ MOAB/trunk/examples/Makefile.am	2010-03-22 23:42:20 UTC (rev 3693)
@@ -2,6 +2,7 @@
                  GeomSetHierarchy \
                  GetEntities \
                  KDTree \
+		 ObbTree \
                  SetsNTags \
                  SkinMesh \
                  SurfArea
@@ -18,6 +19,7 @@
 SkinMesh_SOURCES = SkinMesh.cpp
 SurfArea_SOURCES = SurfArea.cpp
 KDTree_SOURCES = KDTree.cpp
+ObbTree_SOURCES = ObbTree.cpp
 
 exampledir = ${docdir}/examples
 nobase_example_DATA = \
@@ -27,6 +29,7 @@
                simple/GetEntities.cpp \
                simple/makefile \
                KDTree.cpp \
+	       ObbTree.cpp \
                SetsNTags.cpp \
                SkinMesh.cpp \
                SurfArea.cpp 

Added: MOAB/trunk/examples/ObbTree.cpp
===================================================================
--- MOAB/trunk/examples/ObbTree.cpp	                        (rev 0)
+++ MOAB/trunk/examples/ObbTree.cpp	2010-03-22 23:42:20 UTC (rev 3693)
@@ -0,0 +1,74 @@
+// simple example construct obb tree and ray-tracing the tree
+// it reads triangle mesh, construct obb tree and get intersection distances
+
+#include "moab/Core.hpp"
+#include "moab/Range.hpp"
+#include "moab/OrientedBoxTreeTool.hpp"
+#include <iostream>
+#include <math.h>
+
+int main(int argc, char **argv) {
+  if (1 == argc) {
+    std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
+    return 0;
+  }
+
+  // instantiate & load a mesh from a file
+  moab::Core *mb = new moab::Core();
+  moab::ErrorCode rval = mb->load_mesh(argv[1]);
+
+  // get all triangles
+  int err;
+  moab::EntityHandle tree_root;
+  moab::Range tris;
+  //moab::OrientedBoxTreeTool::Settings settings;
+
+  rval = mb->get_entities_by_type( 0, moab::MBTRI, tris );
+  if (rval != moab::MB_SUCCESS) {
+    std::cerr << "Couldn't get triangles." << std::endl;
+    return 1;
+  }
+
+  // build OBB trees for all triangles
+  moab::OrientedBoxTreeTool tool(mb);
+  //rval = tool.build(tris, tree_root, &settings);
+  rval = tool.build(tris, tree_root);
+  if (rval != moab::MB_SUCCESS) {
+    std::cerr << "Could'nt build tree." << std::endl;    
+    return 1;
+  }
+  
+  // build box
+  double box_center[3], box_axis1[3], box_axis2[3], box_axis3[3], start_pnt[3],
+    ray_length;
+  rval = tool.box(tree_root, box_center, box_axis1, box_axis2, box_axis3);
+  if (rval != moab::MB_SUCCESS) {
+    std::cerr << "Couldn't get box for tree root set.";
+    return 1;
+  }
+
+  ray_length = 2.*sqrt(box_axis1[0]*box_axis1[0] + box_axis1[1]*box_axis1[1] +
+		       box_axis1[2]*box_axis1[2]);
+  
+  // do ray-tracing from box center to x direction
+  std::vector<double> intersections;
+  double dir[3] = {1., 0., 0.};
+  rval = tool.ray_intersect_triangles(intersections, tree_root,
+				      10e-12, box_center, dir,
+				      &ray_length);
+  if (rval != moab::MB_SUCCESS) {
+    std::cerr << "Couldn't ray tracing.";
+    return 1;
+  }
+  
+  std::cout << "ray start point: " << start_pnt[0] << " "
+	    << start_pnt[1] << " " << start_pnt[2] << std::endl;
+  std::cout << "# of intersections : " << intersections.size() << std::endl;
+  std::cout << "intersection distances are on";
+  for (int i = 0; i < intersections.size(); i++) {
+    std::cout << " " << intersections[i];
+  }
+  std::cout << " of ray length " << ray_length << std::endl;
+
+  return 0;
+}



More information about the moab-dev mailing list