MOAB: Mesh Oriented datABase  (version 5.5.0)
kd_tree_tool.cpp File Reference
#include "moab/Core.hpp"
#include "moab/CartVect.hpp"
#include "moab/AdaptiveKDTree.hpp"
#include "moab/GeomUtil.hpp"
#include "Internals.hpp"
#include "moab/Range.hpp"
#include "moab/FileOptions.hpp"
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
+ Include dependency graph for kd_tree_tool.cpp:

Go to the source code of this file.

Functions

std::string clock_to_string (clock_t t)
 
std::string mem_to_string (unsigned long mem)
 
void build_tree (Interface *interface, const Range &elems, FileOptions &opts)
 
void build_grid (Interface *iface, const double dims[3])
 
void delete_existing_tree (Interface *interface)
 
void print_stats (Interface *interface)
 
void tag_elements (Interface *interface)
 
void tag_vertices (Interface *interface)
 
void write_tree_blocks (Interface *interface, const char *file)
 
static void usage (bool err=true)
 
static int parseint (int &i, int argc, char *argv[])
 
static void parsedims (int &i, int argc, char *argv[], double dims[3])
 
int main (int argc, char *argv[])
 
static int hash_handle (EntityHandle handle)
 

Variables

const int MAX_TAG_VALUE = 32
 
const char * TAG_NAME = "TREE_CELL"
 

Function Documentation

◆ build_grid()

void build_grid ( Interface iface,
const double  dims[3] 
)

Definition at line 386 of file kd_tree_tool.cpp.

387 {
388  ErrorCode rval;
389  EntityHandle root = 0;
390  AdaptiveKDTree tool( interface );
391  AdaptiveKDTreeIter iter;
392  AdaptiveKDTree::Plane plane;
393 
394  double min[3] = { -0.5 * dims[0], -0.5 * dims[1], -0.5 * dims[2] };
395  double max[3] = { 0.5 * dims[0], 0.5 * dims[1], 0.5 * dims[2] };
396  rval = tool.create_root( min, max, root );
397  if( MB_SUCCESS != rval || !root )
398  {
399  std::cerr << "Failed to create tree root." << std::endl;
400  exit( 4 );
401  }
402 
403  rval = tool.get_tree_iterator( root, iter );
404  if( MB_SUCCESS != rval )
405  {
406  std::cerr << "Failed to get tree iterator." << std::endl;
407  }
408 
409  do
410  {
411  while( iter.depth() < tool.get_max_depth() )
412  {
413  plane.norm = iter.depth() % 3;
414  plane.coord = 0.5 * ( iter.box_min()[plane.norm] + iter.box_max()[plane.norm] );
415  rval = tool.split_leaf( iter, plane );
416  if( MB_SUCCESS != rval )
417  {
418  std::cerr << "Failed to split tree leaf at depth " << iter.depth() << std::endl;
419  exit( 4 );
420  }
421  }
422  } while( ( rval = iter.step() ) == MB_SUCCESS );
423 
424  if( rval != MB_ENTITY_NOT_FOUND )
425  {
426  std::cerr << "Error stepping KDTree iterator." << std::endl;
427  exit( 4 );
428  }
429 }

References moab::AdaptiveKDTreeIter::box_max(), moab::AdaptiveKDTreeIter::box_min(), moab::AdaptiveKDTree::Plane::coord, moab::Tree::create_root(), moab::AdaptiveKDTreeIter::depth(), ErrorCode, moab::Tree::get_max_depth(), moab::AdaptiveKDTree::get_tree_iterator(), MB_ENTITY_NOT_FOUND, MB_SUCCESS, moab::AdaptiveKDTree::Plane::norm, moab::AdaptiveKDTree::split_leaf(), and moab::AdaptiveKDTreeIter::step().

Referenced by main().

◆ build_tree()

void build_tree ( Interface interface,
const Range elems,
FileOptions opts 
)

Definition at line 373 of file kd_tree_tool.cpp.

374 {
375  EntityHandle root = 0;
376 
377  if( elems.empty() )
378  {
379  std::cerr << "No elements from which to build tree." << std::endl;
380  exit( 4 );
381  }
382 
383  AdaptiveKDTree tool( interface, elems, &root, &opts );
384 }

References moab::Range::empty().

Referenced by main().

◆ clock_to_string()

std::string clock_to_string ( clock_t  t)

Definition at line 431 of file kd_tree_tool.cpp.

432 {
433  char unit[5] = "s";
434  char buffer[256];
435  double dt = t / (double)CLOCKS_PER_SEC;
436  // if (dt > 300) {
437  // dt /= 60;
438  // strcpy( unit, "min" );
439  //}
440  // if (dt > 300) {
441  // dt /= 60;
442  // strcpy( unit, "hr" );
443  //}
444  // if (dt > 100) {
445  // dt /= 24;
446  // strcpy( unit, "days" );
447  //}
448  sprintf( buffer, "%0.2f%s", dt, unit );
449  return buffer;
450 }

References buffer, t, and moab::unit().

Referenced by main().

◆ delete_existing_tree()

void delete_existing_tree ( Interface interface)

Definition at line 354 of file kd_tree_tool.cpp.

355 {
356  Range trees;
357  AdaptiveKDTree tool( interface );
358 
359  tool.find_all_trees( trees );
360  if( !trees.empty() ) std::cout << "Destroying existing tree(s) contained in file" << std::endl;
361  for( Range::iterator i = trees.begin(); i != trees.end(); ++i )
362  tool.reset_tree();
363 
364  trees.clear();
365  tool.find_all_trees( trees );
366  if( !trees.empty() )
367  {
368  std::cerr << "Failed to destroy existing trees. Aborting" << std::endl;
369  exit( 5 );
370  }
371 }

References moab::Range::begin(), moab::Range::clear(), moab::Range::empty(), moab::Range::end(), moab::Tree::find_all_trees(), and moab::AdaptiveKDTree::reset_tree().

Referenced by main().

◆ hash_handle()

static int hash_handle ( EntityHandle  handle)
static

Definition at line 452 of file kd_tree_tool.cpp.

453 {
454  EntityID h = ID_FROM_HANDLE( handle );
455  return (int)( ( h * 13 + 7 ) % MAX_TAG_VALUE ) + 1;
456 }

References moab::ID_FROM_HANDLE(), and MAX_TAG_VALUE.

Referenced by tag_elements(), tag_vertices(), and write_tree_blocks().

◆ main()

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

Definition at line 155 of file kd_tree_tool.cpp.

156 {
157  bool surf_elems = false, vol_elems = false;
158  const char* input_file = 0;
159  const char* output_file = 0;
160  const char* tree_file = 0;
161  std::ostringstream options;
162  bool tag_elems = false;
163  clock_t load_time, build_time, stat_time, tag_time, write_time, block_time;
164  bool make_grid = false;
165  double dims[3];
166 
167  for( int i = 1; i < argc; ++i )
168  {
169  if( argv[i][0] != '-' )
170  {
171  if( !input_file )
172  input_file = argv[i];
173  else if( !output_file )
174  output_file = argv[i];
175  else
176  usage();
177  continue;
178  }
179 
180  if( !argv[i][1] || argv[i][2] ) usage();
181 
182  switch( argv[i][1] )
183  {
184  case '2':
185  surf_elems = true;
186  break;
187  case '3':
188  vol_elems = true;
189  break;
190  case 'S':
191  options << "MESHSET_FLAGS=" << MESHSET_ORDERED << ";";
192  break;
193  case 's':
194  break;
195  case 'd':
196  options << "MAX_DEPTH=" << parseint( i, argc, argv ) << ";";
197  break;
198  case 'n':
199  options << "MAX_PER_LEAF=" << parseint( i, argc, argv ) << ";";
200  break;
201  case 'u':
202  options << "CANDIDATE_PLANE_SET=" << AdaptiveKDTree::SUBDIVISION << ";";
203  break;
204  case 'p':
205  options << "CANDIDATE_PLANE_SET=" << AdaptiveKDTree::SUBDIVISION_SNAP << ";";
206  break;
207  case 'm':
208  options << "CANDIDATE_PLANE_SET=" << AdaptiveKDTree::VERTEX_MEDIAN << ";";
209  break;
210  case 'v':
211  options << "CANDIDATE_PLANE_SET=" << AdaptiveKDTree::VERTEX_SAMPLE << ";";
212  break;
213  case 'N':
214  options << "SPLITS_PER_DIR=" << parseint( i, argc, argv ) << ";";
215  break;
216  case 't':
217  tag_elems = true;
218  break;
219  case 'T':
220  tree_file = argv[++i];
221  break;
222  case 'G':
223  make_grid = true;
224  parsedims( i, argc, argv, dims );
225  break;
226  case 'h':
227  usage( false );
228  break;
229  default:
230  usage();
231  }
232  }
233 
234  // this test relies on not cleaning up trees
235  options << "CLEAN_UP=false;";
236 
237  if( make_grid != !output_file ) usage();
238 
239  // default to both
240  if( !surf_elems && !vol_elems ) surf_elems = vol_elems = true;
241 
242  ErrorCode rval;
243  Core moab_core;
244  Interface* interface = &moab_core;
245  FileOptions opts( options.str().c_str() );
246 
247  if( make_grid )
248  {
249  load_time = 0;
250  output_file = input_file;
251  input_file = 0;
252  build_time = clock();
253  build_grid( interface, dims );
254  build_time = clock() - build_time;
255  }
256  else
257  {
258  load_time = clock();
259  rval = interface->load_mesh( input_file );
260  if( MB_SUCCESS != rval )
261  {
262  std::cerr << "Error reading file: " << input_file << std::endl;
263  exit( 2 );
264  }
265  load_time = clock() - load_time;
266 
267  delete_existing_tree( interface );
268 
269  std::cout << "Building tree..." << std::endl;
270  build_time = clock();
271  Range elems;
272  if( !surf_elems )
273  {
274  interface->get_entities_by_dimension( 0, 3, elems );
275  }
276  else
277  {
278  interface->get_entities_by_dimension( 0, 2, elems );
279  if( vol_elems )
280  {
281  Range tmp;
282  interface->get_entities_by_dimension( 0, 3, tmp );
283  elems.merge( tmp );
284  }
285  }
286 
287  build_tree( interface, elems, opts );
288  build_time = clock() - build_time;
289  }
290 
291  std::cout << "Calculating stats..." << std::endl;
292  AdaptiveKDTree tool( interface );
293  Range range;
294  tool.find_all_trees( range );
295  if( range.size() != 1 )
296  {
297  if( range.empty() )
298  std::cerr << "Internal error: Failed to retreive tree." << std::endl;
299  else
300  std::cerr << "Internal error: Multiple tree roots." << std::endl;
301  exit( 5 );
302  }
303  tool.print();
304 
305  stat_time = clock() - build_time;
306 
307  if( tag_elems )
308  {
309  std::cout << "Tagging tree..." << std::endl;
310  tag_elements( interface );
311  tag_vertices( interface );
312  }
313  tag_time = clock() - stat_time;
314 
315  std::cout << "Writing file... ";
316  std::cout.flush();
317  rval = interface->write_mesh( output_file );
318  if( MB_SUCCESS != rval )
319  {
320  std::cerr << "Error writing file: " << output_file << std::endl;
321  exit( 3 );
322  }
323  write_time = clock() - tag_time;
324  std::cout << "Wrote " << output_file << std::endl;
325 
326  if( tree_file )
327  {
328  std::cout << "Writing tree block rep...";
329  std::cout.flush();
330  write_tree_blocks( interface, tree_file );
331  std::cout << "Wrote " << tree_file << std::endl;
332  }
333  block_time = clock() - write_time;
334 
335  std::cout << "Times: "
336  << " Load"
337  << " Build"
338  << " Stats"
339  << " Write";
340  if( tag_elems ) std::cout << "Tag Sets";
341  if( tree_file ) std::cout << "Block ";
342  std::cout << std::endl;
343 
344  std::cout << " " << std::setw( 8 ) << clock_to_string( load_time ) << std::setw( 8 )
345  << clock_to_string( build_time ) << std::setw( 8 ) << clock_to_string( stat_time ) << std::setw( 8 )
346  << clock_to_string( write_time );
347  if( tag_elems ) std::cout << std::setw( 8 ) << clock_to_string( tag_time );
348  if( tree_file ) std::cout << std::setw( 8 ) << clock_to_string( block_time );
349  std::cout << std::endl;
350 
351  return 0;
352 }

References build_grid(), build_time, build_tree(), clock_to_string(), delete_existing_tree(), moab::Range::empty(), ErrorCode, moab::Tree::find_all_trees(), input_file, load_time, MB_SUCCESS, moab::Range::merge(), parsedims(), parseint(), moab::AdaptiveKDTree::print(), moab::Range::size(), moab::AdaptiveKDTree::SUBDIVISION, moab::AdaptiveKDTree::SUBDIVISION_SNAP, tag_elements(), tag_time(), tag_vertices(), usage(), moab::AdaptiveKDTree::VERTEX_MEDIAN, moab::AdaptiveKDTree::VERTEX_SAMPLE, and write_tree_blocks().

◆ mem_to_string()

std::string mem_to_string ( unsigned long  mem)

Definition at line 360 of file obb_tree_tool.cpp.

361 {
362  char unit[3] = "B";
363  if( mem > 9 * 1024 )
364  {
365  mem = ( mem + 512 ) / 1024;
366  strcpy( unit, "kB" );
367  }
368  if( mem > 9 * 1024 )
369  {
370  mem = ( mem + 512 ) / 1024;
371  strcpy( unit, "MB" );
372  }
373  if( mem > 9 * 1024 )
374  {
375  mem = ( mem + 512 ) / 1024;
376  strcpy( unit, "GB" );
377  }
378  char buffer[256];
379  sprintf( buffer, "%lu %s", mem, unit );
380  return buffer;
381 }

References buffer, and moab::unit().

Referenced by print_stats().

◆ parsedims()

static void parsedims ( int &  i,
int  argc,
char *  argv[],
double  dims[3] 
)
static

Definition at line 116 of file kd_tree_tool.cpp.

117 {
118  char* end;
119  ++i;
120  if( i == argc )
121  {
122  std::cerr << "Expected value following '" << argv[i - 1] << "'" << std::endl;
123  usage();
124  }
125 
126  dims[0] = strtod( argv[i], &end );
127  if( *end == '\0' )
128  {
129  dims[2] = dims[1] = dims[0];
130  return;
131  }
132  else if( *end != 'x' && *end != 'X' )
133  goto error;
134 
135  ++end;
136  dims[1] = strtod( end, &end );
137  if( *end == '\0' )
138  {
139  dims[2] = dims[1];
140  return;
141  }
142  else if( *end != 'x' && *end != 'X' )
143  goto error;
144 
145  ++end;
146  dims[2] = strtod( end, &end );
147  if( *end != '\0' ) goto error;
148 
149  return;
150 error:
151  std::cerr << "Invaild dimension specification." << std::endl;
152  usage();
153 }

References moab::error(), and usage().

Referenced by main().

◆ parseint()

static int parseint ( int &  i,
int  argc,
char *  argv[] 
)
static

Definition at line 96 of file kd_tree_tool.cpp.

97 {
98  char* end;
99  ++i;
100  if( i == argc )
101  {
102  std::cerr << "Expected value following '" << argv[i - 1] << "'" << std::endl;
103  usage();
104  }
105 
106  int result = strtol( argv[i], &end, 0 );
107  if( result < 0 || *end )
108  {
109  std::cerr << "Expected positive integer following '" << argv[i - 1] << "'" << std::endl;
110  usage();
111  }
112 
113  return result;
114 }

References usage().

Referenced by main().

◆ print_stats()

void print_stats ( Interface interface)

Definition at line 410 of file obb_tree_tool.cpp.

411 {
412  EntityHandle root;
413  Range range;
414  ErrorCode rval;
415  rval = get_root( interface, root );
416  if( MB_SUCCESS != rval )
417  {
418  std::cerr << "Internal error: Failed to retrieve root." << std::endl;
419  exit( 5 );
420  }
421  OrientedBoxTreeTool tool( interface );
422 
423  Range tree_sets, triangles, verts;
424  // interface->get_child_meshsets( root, tree_sets, 0 );
425  interface->get_entities_by_type( 0, MBENTITYSET, tree_sets );
426  tree_sets.erase( tree_sets.begin(), Range::lower_bound( tree_sets.begin(), tree_sets.end(), root ) );
427  interface->get_entities_by_type( 0, MBTRI, triangles );
428  interface->get_entities_by_type( 0, MBVERTEX, verts );
429  triangles.merge( verts );
430  tree_sets.insert( root );
431  unsigned long long set_used, set_amortized, set_store_used, set_store_amortized, set_tag_used, set_tag_amortized,
432  tri_used, tri_amortized;
433  interface->estimated_memory_use( tree_sets, &set_used, &set_amortized, &set_store_used, &set_store_amortized, 0, 0,
434  0, 0, &set_tag_used, &set_tag_amortized );
435  interface->estimated_memory_use( triangles, &tri_used, &tri_amortized );
436 
437  int num_tri = 0;
438  interface->get_number_entities_by_type( 0, MBTRI, num_tri );
439 
440  tool.stats( root, std::cout );
441 
442  unsigned long long real_rss, real_vsize;
443  memory_use( real_vsize, real_rss );
444 
445  printf( "------------------------------------------------------------------\n" );
446  printf( "\nmemory: used amortized\n" );
447  printf( " ---------- ----------\n" );
448  printf( "triangles %10s %10s\n", mem_to_string( tri_used ).c_str(), mem_to_string( tri_amortized ).c_str() );
449  printf( "sets (total)%10s %10s\n", mem_to_string( set_used ).c_str(), mem_to_string( set_amortized ).c_str() );
450  printf( "sets %10s %10s\n", mem_to_string( set_store_used ).c_str(),
451  mem_to_string( set_store_amortized ).c_str() );
452  printf( "set tags %10s %10s\n", mem_to_string( set_tag_used ).c_str(),
453  mem_to_string( set_tag_amortized ).c_str() );
454  printf( "total real %10s %10s\n", mem_to_string( real_rss ).c_str(), mem_to_string( real_vsize ).c_str() );
455  printf( "------------------------------------------------------------------\n" );
456 }

References moab::Range::begin(), moab::Range::end(), moab::Range::erase(), ErrorCode, moab::Interface::estimated_memory_use(), moab::Interface::get_entities_by_type(), moab::Interface::get_number_entities_by_type(), get_root(), moab::Range::insert(), MB_SUCCESS, MBENTITYSET, MBTRI, MBVERTEX, mem_to_string(), memory_use(), moab::Range::merge(), and moab::OrientedBoxTreeTool::stats().

Referenced by main().

◆ tag_elements()

void tag_elements ( Interface interface)

Definition at line 458 of file kd_tree_tool.cpp.

459 {
460  EntityHandle root;
461  Range range;
462  AdaptiveKDTree tool( moab );
463 
464  tool.find_all_trees( range );
465  if( range.size() != 1 )
466  {
467  if( range.empty() )
468  std::cerr << "Internal error: Failed to retreive tree." << std::endl;
469  else
470  std::cerr << "Internal error: Multiple tree roots." << std::endl;
471  exit( 5 );
472  }
473 
474  root = *range.begin();
475  range.clear();
476 
477  Tag tag;
478  int zero = 0;
479  moab->tag_get_handle( TAG_NAME, 1, MB_TYPE_INTEGER, tag, MB_TAG_DENSE | MB_TAG_CREAT, &zero );
480 
481  AdaptiveKDTreeIter iter;
482  tool.get_tree_iterator( root, iter );
483 
484  std::vector< int > tag_vals;
485  do
486  {
487  range.clear();
488  moab->get_entities_by_handle( iter.handle(), range );
489  tag_vals.clear();
490  tag_vals.resize( range.size(), hash_handle( iter.handle() ) );
491  moab->tag_set_data( tag, range, &tag_vals[0] );
492  } while( MB_SUCCESS == iter.step() );
493 }

References moab::Range::begin(), moab::Range::clear(), moab::Range::empty(), moab::Tree::find_all_trees(), moab::AdaptiveKDTree::get_tree_iterator(), moab::AdaptiveKDTreeIter::handle(), hash_handle(), MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, moab::Range::size(), moab::AdaptiveKDTreeIter::step(), and TAG_NAME.

Referenced by main().

◆ tag_vertices()

void tag_vertices ( Interface interface)

Definition at line 495 of file kd_tree_tool.cpp.

496 {
497  EntityHandle root;
498  Range range;
499  AdaptiveKDTree tool( moab );
500 
501  tool.find_all_trees( range );
502  if( range.size() != 1 )
503  {
504  if( range.empty() )
505  std::cerr << "Internal error: Failed to retreive tree." << std::endl;
506  else
507  std::cerr << "Internal error: Multiple tree roots." << std::endl;
508  exit( 5 );
509  }
510 
511  root = *range.begin();
512  range.clear();
513 
514  Tag tag;
515  int zero = 0;
516  moab->tag_get_handle( TAG_NAME, 1, MB_TYPE_INTEGER, tag, MB_TAG_DENSE | MB_TAG_CREAT, &zero );
517 
518  AdaptiveKDTreeIter iter;
519  tool.get_tree_iterator( root, iter );
520 
521  do
522  {
523  range.clear();
524  moab->get_entities_by_handle( iter.handle(), range );
525 
526  int tag_val = hash_handle( iter.handle() );
527  Range verts;
528  moab->get_adjacencies( range, 0, false, verts, Interface::UNION );
529  for( Range::iterator i = verts.begin(); i != verts.end(); ++i )
530  {
531  CartVect coords;
532  moab->get_coords( &*i, 1, coords.array() );
533  if( GeomUtil::box_point_overlap( CartVect( iter.box_min() ), CartVect( iter.box_max() ), coords, 1e-7 ) )
534  moab->tag_set_data( tag, &*i, 1, &tag_val );
535  }
536  } while( MB_SUCCESS == iter.step() );
537 }

References moab::CartVect::array(), moab::Range::begin(), moab::AdaptiveKDTreeIter::box_max(), moab::AdaptiveKDTreeIter::box_min(), moab::GeomUtil::box_point_overlap(), moab::Range::clear(), moab::Range::empty(), moab::Range::end(), moab::Tree::find_all_trees(), moab::AdaptiveKDTree::get_tree_iterator(), moab::AdaptiveKDTreeIter::handle(), hash_handle(), MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, moab::Range::size(), moab::AdaptiveKDTreeIter::step(), TAG_NAME, and moab::Interface::UNION.

Referenced by main().

◆ usage()

static void usage ( bool  err = true)
static

Definition at line 37 of file kd_tree_tool.cpp.

38 {
39  std::ostream& s = err ? std::cerr : std::cout;
40  s << "kd_tree_tool [-d <int>] [-2|-3] [-n <int>] [-u|-p|-m|-v] [-N <int>] [-s|-S] <input file> "
41  "<output file>"
42  << std::endl
43  << "kd_tree_tool [-d <int>] -G <dims> [-s|-S] <output file>" << std::endl
44  << "kd_tree_tool [-h]" << std::endl;
45  if( !err )
46  {
47  s << "Tool to build adaptive kd-Tree" << std::endl;
48  s << " -d <int> Specify maximum depth for tree. Default: 30" << std::endl
49  << " -n <int> Specify maximum entities per leaf. Default: 6" << std::endl
50  << " -2 Build tree from surface elements. Default: yes" << std::endl
51  << " -3 Build tree from volume elements. Default: yes" << std::endl
52  << " -u Use 'SUBDIVISION' scheme for tree construction" << std::endl
53  << " -p Use 'SUBDIVISION_SNAP' tree construction algorithm." << std::endl
54  << " -m Use 'VERTEX_MEDIAN' tree construction algorithm." << std::endl
55  << " -v Use 'VERTEX_SAMPLE' tree construction algorithm." << std::endl
56  << " -N <int> Specify candidate split planes per axis. Default: 3" << std::endl
57  << " -t Tag elements will tree cell number." << std::endl
58  << " -T Write tree boxes to file." << std::endl
59  << " -G <dims> Generate grid - no input elements. Dims must be " << std::endl
60  << " HxWxD or H." << std::endl
61  << " -s Use range-based sets for tree nodes" << std::endl
62  << " -S Use vector-based sets for tree nodes" << std::endl
63  << std::endl;
64  }
65  exit( err );
66 }

Referenced by main(), parsedims(), and parseint().

◆ write_tree_blocks()

void write_tree_blocks ( Interface interface,
const char *  file 
)

Definition at line 539 of file kd_tree_tool.cpp.

540 {
541  EntityHandle root;
542  Range range;
543  AdaptiveKDTree tool( interface );
544 
545  tool.find_all_trees( range );
546  if( range.size() != 1 )
547  {
548  if( range.empty() )
549  std::cerr << "Internal error: Failed to retreive tree." << std::endl;
550  else
551  std::cerr << "Internal error: Multiple tree roots." << std::endl;
552  exit( 5 );
553  }
554 
555  root = *range.begin();
556  range.clear();
557 
558  Core moab2;
559  Tag tag;
560  int zero = 0;
562 
563  AdaptiveKDTreeIter iter;
564  tool.get_tree_iterator( root, iter );
565 
566  do
567  {
568  double x1 = iter.box_min()[0];
569  double y1 = iter.box_min()[1];
570  double z1 = iter.box_min()[2];
571  double x2 = iter.box_max()[0];
572  double y2 = iter.box_max()[1];
573  double z2 = iter.box_max()[2];
574  double coords[24] = { x1, y1, z1, x2, y1, z1, x2, y2, z1, x1, y2, z1,
575  x1, y1, z2, x2, y1, z2, x2, y2, z2, x1, y2, z2 };
576  EntityHandle verts[8], elem;
577  for( int i = 0; i < 8; ++i )
578  moab2.create_vertex( coords + 3 * i, verts[i] );
579  moab2.create_element( MBHEX, verts, 8, elem );
580  int tag_val = hash_handle( iter.handle() );
581  moab2.tag_set_data( tag, &elem, 1, &tag_val );
582  } while( MB_SUCCESS == iter.step() );
583 
584  moab2.write_mesh( file );
585 }

References moab::Range::begin(), moab::AdaptiveKDTreeIter::box_max(), moab::AdaptiveKDTreeIter::box_min(), moab::Range::clear(), moab::Core::create_element(), moab::Core::create_vertex(), moab::Range::empty(), moab::Tree::find_all_trees(), moab::AdaptiveKDTree::get_tree_iterator(), moab::AdaptiveKDTreeIter::handle(), hash_handle(), MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, MBHEX, moab::Range::size(), moab::AdaptiveKDTreeIter::step(), moab::Core::tag_get_handle(), TAG_NAME, moab::Core::tag_set_data(), and moab::Core::write_mesh().

Referenced by main().

Variable Documentation

◆ MAX_TAG_VALUE

const int MAX_TAG_VALUE = 32

Definition at line 23 of file kd_tree_tool.cpp.

Referenced by hash_handle().

◆ TAG_NAME

const char* TAG_NAME = "TREE_CELL"

Definition at line 24 of file kd_tree_tool.cpp.

Referenced by tag_elements(), tag_vertices(), and write_tree_blocks().