MOAB: Mesh Oriented datABase  (version 5.5.0)
obb_time.cpp File Reference
#include "moab/Core.hpp"
#include "moab/CartVect.hpp"
#include "moab/OrientedBox.hpp"
#include "moab/OrientedBoxTreeTool.hpp"
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>
#include <csignal>
#include <cassert>
+ Include dependency graph for obb_time.cpp:

Go to the source code of this file.

Functions

static void usage ()
 
void generate_ray (const CartVect &sphere_center, double sphere_radius, CartVect &point, CartVect &dir)
 
ErrorCode read_tree (Interface *instance, const char *filename, EntityHandle &tree_root_out)
 
void signal_handler (int)
 
int main (int argc, char *argv[])
 

Variables

const int NUM_RAYS = 40000
 
const int NUM_XSCT = 20000
 
int num_rays = NUM_RAYS
 
int num_xsct = NUM_XSCT
 
const char * filename = 0
 
bool do_sets = false
 
bool do_trv_stats = false
 
int rays = 0
 
int xsct = 0
 
int gen = 0
 
clock_t ttimer
 

Function Documentation

◆ generate_ray()

void generate_ray ( const CartVect sphere_center,
double  sphere_radius,
CartVect point,
CartVect dir 
)

Definition at line 31 of file obb_time.cpp.

32 {
33  const int H = RAND_MAX / 2;
34  point[0] = (double)rand() / H - 1;
35  point[1] = (double)rand() / H - 1;
36  point[2] = (double)rand() / H - 1;
37  point *= sphere_radius;
38 
39  dir[0] = (double)rand() * -point[0];
40  dir[1] = (double)rand() * -point[1];
41  dir[2] = (double)rand() * -point[2];
42  dir.normalize();
43 
44  point += sphere_center;
45 }

References moab::CartVect::normalize().

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 84 of file obb_time.cpp.

85 {
86  signal( SIGINT, &signal_handler );
87 
88  for( int i = 1; i < argc; ++i )
89  {
90  if( !strcmp( argv[i], "-r" ) )
91  {
92  ++i;
93  if( i == argc || !argv[i][0] )
94  {
95  std::cerr << "Expected value following '-r'" << std::endl;
96  usage();
97  }
98  char* end;
99  long t1 = strtol( argv[i], &end, 0 );
100  num_rays = (int)t1;
101  if( *end || t1 < 0 || num_rays != t1 )
102  {
103  std::cerr << "Expected positive integer following '-r'" << std::endl;
104  usage();
105  }
106  }
107  else if( !strcmp( argv[i], "-i" ) )
108  {
109  ++i;
110  if( i == argc || !argv[i][0] )
111  {
112  std::cerr << "Expected value following '-i'" << std::endl;
113  usage();
114  }
115  char* end;
116  long t1 = strtol( argv[i], &end, 0 );
117  num_xsct = (int)t1;
118  if( *end || t1 < 0 || num_xsct != t1 )
119  {
120  std::cerr << "Expected positive integer following '-i'" << std::endl;
121  usage();
122  }
123  }
124  else if( !strcmp( argv[i], "-s" ) )
125  {
126  do_sets = true;
127  }
128  else if( !strcmp( argv[i], "-p" ) )
129  {
130  do_trv_stats = true;
131  }
132  else if( filename )
133  {
134  std::cerr << "Invalid options or multiple file names specified." << std::endl;
135  usage();
136  }
137  else
138  {
139  filename = argv[i];
140  }
141  }
142  if( !filename )
143  {
144  std::cerr << "No file name specified." << std::endl;
145  usage();
146  }
147 
148  Core instance;
149  Interface* iface = &instance;
150  EntityHandle root;
151  ErrorCode rval = read_tree( iface, filename, root );
152  if( MB_SUCCESS != rval )
153  {
154  std::cerr << "Failed to read \"" << filename << '"' << std::endl;
155  return 2;
156  }
157 
158  OrientedBoxTreeTool tool( iface );
160  rval = tool.box( root, box );
161  if( MB_SUCCESS != rval )
162  {
163  std::cerr << "Corrupt tree. Cannot get box for root node." << std::endl;
164  return 3;
165  }
166 
167  OrientedBoxTreeTool::TrvStats* stats = NULL;
168  if( do_trv_stats )
169  {
170  stats = new OrientedBoxTreeTool::TrvStats;
171  }
172 
173  const unsigned cached = 1000;
174  std::vector< double > intersections;
175  std::vector< EntityHandle > sets, facets;
176  CartVect point, dir;
177  std::vector< CartVect > randrays;
178  randrays.reserve( cached );
179  int cached_idx = 0;
180 
181  ttimer = clock();
182  for( ;; )
183  {
184  if( !num_rays )
185  {
186  if( xsct >= num_xsct ) break;
187  }
188  else if( !num_xsct )
189  {
190  if( rays >= num_rays ) break;
191  }
192  else if( rays >= num_rays && xsct >= num_xsct )
193  break;
194 
195  ++rays;
196  if( randrays.size() < cached )
197  {
198  generate_ray( box.center, box.outer_radius(), point, dir );
199  ++gen;
200  }
201  else
202  {
203  point = randrays[cached_idx++];
204  dir = randrays[cached_idx++];
205  cached_idx = cached_idx % randrays.size();
206  }
207 
208  intersections.clear();
209  if( do_sets )
210  {
211  sets.clear();
212  facets.clear();
213 
215  OrientedBoxTreeTool::IntRegCtxt int_reg_ctxt;
216  rval = tool.ray_intersect_sets( intersections, sets, facets, root, 1e-6, point.array(), dir.array(),
217  search_win, int_reg_ctxt, stats );
218  }
219  else
220  {
221  rval =
222  tool.ray_intersect_triangles( intersections, facets, root, 1e-6, point.array(), dir.array(), 0, stats );
223  }
224  if( MB_SUCCESS != rval )
225  {
226  std::cerr << "Rayfire #" << rays << " failed." << std::endl;
227  return 4;
228  }
229 
230  if( !intersections.empty() )
231  {
232  ++xsct;
233  }
234 
235  if( randrays.size() < cached && ( !intersections.empty() || !num_xsct || xsct >= num_xsct ) )
236  {
237  randrays.push_back( point );
238  randrays.push_back( dir );
239  }
240  }
241 
242  ttimer = clock() - ttimer;
243  std::cout << rays << " ray fires done" << std::endl
244  << gen << " unique rays used" << std::endl
245  << xsct << " intersecting fires" << std::endl
246  << (double)ttimer / CLOCKS_PER_SEC << " seconds" << std::endl;
247 
248  if( do_trv_stats )
249  {
250  std::cout << "Traversal statistics: " << std::endl;
251  stats->print( std::cout );
252  }
253 
254  return 0;
255 }

References moab::CartVect::array(), box(), moab::OrientedBoxTreeTool::box(), do_sets, do_trv_stats, ErrorCode, filename, gen, generate_ray(), iface, MB_SUCCESS, num_rays, num_xsct, moab::OrientedBoxTreeTool::TrvStats::print(), moab::OrientedBoxTreeTool::ray_intersect_sets(), moab::OrientedBoxTreeTool::ray_intersect_triangles(), rays, read_tree(), signal_handler(), ttimer, usage(), and xsct.

◆ read_tree()

ErrorCode read_tree ( Interface instance,
const char *  filename,
EntityHandle tree_root_out 
)

Definition at line 47 of file obb_time.cpp.

48 {
49  ErrorCode rval = instance->load_mesh( filename );
50  if( MB_SUCCESS != rval ) return rval;
51 
52  Tag tag;
53  rval = instance->tag_get_handle( "OBB_ROOT", 1, MB_TYPE_HANDLE, tag );
54  if( MB_SUCCESS != rval ) return rval;
55 
56  const EntityHandle root = 0;
57  return instance->tag_get_data( tag, &root, 1, &tree_root_out );
58 }

References ErrorCode, filename, moab::Interface::load_mesh(), MB_SUCCESS, MB_TYPE_HANDLE, moab::Interface::tag_get_data(), and moab::Interface::tag_get_handle().

Referenced by main().

◆ signal_handler()

void signal_handler ( int  )

Definition at line 72 of file obb_time.cpp.

73 {
74  ttimer = clock() - ttimer;
75  std::cout << filename << ":" << std::endl
76  << rays << " of " << num_rays << " ray fires done" << std::endl
77  << xsct << " of " << num_xsct << " intersecting fires" << std::endl
78  << gen << " unique rays used" << std::endl
79  << (double)ttimer / CLOCKS_PER_SEC << " seconds" << std::endl;
80  exit( 1 );
81 }

References filename, gen, num_rays, num_xsct, rays, ttimer, and xsct.

Referenced by main().

◆ usage()

static void usage ( )
static

Definition at line 17 of file obb_time.cpp.

18 {
19  std::cerr << "obb_time [-r <int>] [-i <int>] <filename>" << std::endl
20  << " -r - Specify total rays to fire." << std::endl
21  << " Zero implies unbounded. Default: " << NUM_RAYS << std::endl
22  << " -i - Specify total intersecting rays to fire." << std::endl
23  << " Zero implies unbounded. Default: " << NUM_XSCT << std::endl
24  << " -s - Use set-based tree." << std::endl
25  << " -p - Measure and report traversal performance statistics" << std::endl
26  << " The input file should be generated using the '-s'" << std::endl
27  << " option with 'obb_test'" << std::endl;
28  exit( 1 );
29 }

References NUM_RAYS, and NUM_XSCT.

Referenced by main().

Variable Documentation

◆ do_sets

bool do_sets = false

Definition at line 64 of file obb_time.cpp.

Referenced by main().

◆ do_trv_stats

bool do_trv_stats = false

Definition at line 65 of file obb_time.cpp.

Referenced by main().

◆ filename

const char* filename = 0

Definition at line 63 of file obb_time.cpp.

Referenced by main(), read_tree(), and signal_handler().

◆ gen

int gen = 0

Definition at line 68 of file obb_time.cpp.

Referenced by main(), and signal_handler().

◆ NUM_RAYS

const int NUM_RAYS = 40000

Definition at line 12 of file obb_time.cpp.

Referenced by usage().

◆ num_rays

int num_rays = NUM_RAYS

Definition at line 61 of file obb_time.cpp.

Referenced by main(), and signal_handler().

◆ NUM_XSCT

const int NUM_XSCT = 20000

Definition at line 13 of file obb_time.cpp.

Referenced by usage().

◆ num_xsct

int num_xsct = NUM_XSCT

Definition at line 62 of file obb_time.cpp.

Referenced by main(), and signal_handler().

◆ rays

int rays = 0

Definition at line 68 of file obb_time.cpp.

Referenced by main(), and signal_handler().

◆ ttimer

clock_t ttimer

Definition at line 69 of file obb_time.cpp.

Referenced by main(), and signal_handler().

◆ xsct

int xsct = 0

Definition at line 68 of file obb_time.cpp.

Referenced by main(), and signal_handler().