15 #if !defined( _MSC_VER ) && !defined( __MINGW32__ )
39 static void usage(
bool err =
true )
41 std::ostream& s = err ? std::cerr : std::cout;
42 s <<
"obb_tree_tool [-s|-S] [-d <int>] [-n <int>] <input file> <output file>" << std::endl
43 <<
"obb_tree_tool [-h]" << std::endl;
47 s <<
"Tool to build adaptive kd-Tree from triangles" << std::endl;
48 s <<
" -s Use range-based sets for tree nodes" << std::endl
49 <<
" -S Use vector-based sets for tree nodes" << std::endl
50 <<
" -d <int> Specify maximum depth for tree. Default: " << st.
max_depth << std::endl
51 <<
" -n <int> Specify maximum entities per leaf. Default: " << st.
max_leaf_entities << std::endl
52 <<
" -m <real> Specify worst split ratio. Default: " << st.
worst_split_ratio << std::endl
53 <<
" -M <real> Specify best split ratio. Default: " << st.
best_split_ratio << std::endl
54 <<
" -t Tag triangles will tree cell number." << std::endl
55 <<
" -T Write tree boxes to file." << std::endl
56 <<
" -N Specify mesh tag containing tree root. Default: \"" <<
TREE_TAG <<
'"' << std::endl
62 #if defined( _MSC_VER ) || defined( __MINGW32__ )
63 static void memory_use(
unsigned long long& vsize,
unsigned long long& rss )
68 static void memory_use(
unsigned long long& vsize,
unsigned long long& rss )
73 int filp = open(
"/proc/self/stat", O_RDONLY );
90 rss = lrss * getpagesize();
95 static int parseint(
int& i,
int argc,
char* argv[] )
101 std::cerr <<
"Expected value following '" << argv[i - 1] <<
"'" << std::endl;
105 int result = strtol( argv[i], &end, 0 );
106 if( result < 0 || *end )
108 std::cerr <<
"Expected positive integer following '" << argv[i - 1] <<
"'" << std::endl;
121 std::cerr <<
"Expected value following '" << argv[i - 1] <<
"'" << std::endl;
125 double result = strtod( argv[i], &end );
126 if( result < 0 || *end )
128 std::cerr <<
"Expected positive real number following '" << argv[i - 1] <<
"'" << std::endl;
135 int main(
int argc,
char* argv[] )
138 const char* output_file = 0;
139 const char* tree_file = 0;
141 bool tag_tris =
false;
144 for(
int i = 1; i < argc; ++i )
146 if( argv[i][0] !=
'-' )
150 else if( !output_file )
151 output_file = argv[i];
157 if( !argv[i][1] || argv[i][2] )
usage();
183 if( ++i == argc )
usage();
187 if( ++i == argc )
usage();
198 if( !output_file )
usage();
208 std::cerr <<
"Error reading file: " <<
input_file << std::endl;
215 std::cout <<
"Building tree..." << std::endl;
220 std::cout <<
"Calculating stats..." << std::endl;
226 std::cout <<
"Tagging tree..." << std::endl;
232 std::cout <<
"Writing file... ";
234 rval = interface->write_mesh( output_file );
237 std::cerr <<
"Error writing file: " << output_file << std::endl;
241 std::cout <<
"Wrote " << output_file << std::endl;
245 std::cout <<
"Writing tree block rep...";
248 std::cout <<
"Wrote " << tree_file << std::endl;
250 block_time = clock() - write_time;
252 std::cout <<
"Times: "
257 if( tag_tris ) std::cout <<
"Tag Sets";
258 if( tree_file ) std::cout <<
"Block ";
259 std::cout << std::endl;
265 if( tree_file ) std::cout << std::setw( 8 ) <<
clock_to_string( block_time );
266 std::cout << std::endl;
280 return moab->tag_get_data( tag, &
mesh, 1, &root );
293 std::cerr <<
"Failed to destroy existing trees. Aborting" << std::endl;
308 std::cerr <<
"No triangles from which to build tree." << std::endl;
316 std::cerr <<
"Tree construction failed." << std::endl;
325 std::cout <<
"Failed to create root tag: \"" <<
root_tag <<
'"' << std::endl;
332 std::cout <<
"Failed to set root tag: \"" <<
root_tag <<
'"' << std::endl;
343 double dt =
t / (double)CLOCKS_PER_SEC;
365 mem = ( mem + 512 ) / 1024;
366 strcpy(
unit,
"kB" );
370 mem = ( mem + 512 ) / 1024;
371 strcpy(
unit,
"MB" );
375 mem = ( mem + 512 ) / 1024;
376 strcpy(
unit,
"GB" );
383 template <
typename T >
404 template <
typename T >
406 : min( std::numeric_limits<
T >::max() ), max( std::numeric_limits<
T >::min() ),
sum( 0 ), sqr( 0 ), count( 0 )
418 std::cerr <<
"Internal error: Failed to retrieve root." << std::endl;
423 Range tree_sets, triangles, verts;
426 tree_sets.
erase( tree_sets.
begin(), Range::lower_bound( tree_sets.
begin(), tree_sets.
end(), root ) );
429 triangles.
merge( verts );
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 );
440 tool.
stats( root, std::cout );
442 unsigned long long real_rss, real_vsize;
445 printf(
"------------------------------------------------------------------\n" );
446 printf(
"\nmemory: used amortized\n" );
447 printf(
" ---------- ----------\n" );
450 printf(
"sets %10s %10s\n",
mem_to_string( set_store_used ).c_str(),
452 printf(
"set tags %10s %10s\n",
mem_to_string( set_tag_used ).c_str(),
455 printf(
"------------------------------------------------------------------\n" );
498 std::cerr <<
"Internal error: Failed to retrieve tree." << std::endl;
511 std::cerr <<
"Internal error tagging triangles" << std::endl;
553 std::cerr <<
"Internal error: Failed to retrieve tree." << std::endl;
566 std::cerr <<
"Internal error tagging vertices" << std::endl;
596 rval =
box.make_hex( h,
mOut );
609 std::cerr <<
"Internal error: Failed to retrieve tree." << std::endl;
623 std::cerr <<
"Internal error: failed to construct leaf hexes" << std::endl;