13 fprintf( stderr,
"usage: %s [-t] [-d <result_file>] <tree_file> <point_file> [<count>]\n",
argv0 );
22 unsigned long long set_mem, set_am, tag_mem, tag_am;
24 rval =
moab.get_number_entities_by_type( 0,
MBTRI, num_tri );
29 moab.estimated_memory_use( sets, 0, 0, &set_mem, &set_am, 0, 0, 0, 0, &tag_mem, &tag_am );
30 printf(
"Triangles: %d\n", num_tri );
31 printf(
"Sets: %lu\n", (
unsigned long)sets.
size() );
32 printf(
"Set storage: %llu (%llu)\n", set_mem, set_am );
33 printf(
"Tag storage: %llu (%llu)\n", tag_mem, tag_am );
36 int main(
int argc,
char* argv[] )
40 FILE *file, *rfile = 0;
41 unsigned long count = 0;
44 const char* tree_file = 0;
45 const char* point_file = 0;
46 const char* result_file = 0;
47 bool query_triangles =
false;
49 if( argc < 3 || argc > 7 )
usage( argv[0] );
51 for(
int i = 1; i < argc; ++i )
53 if( !strcmp(
"-t", argv[i] ) )
54 query_triangles =
true;
55 else if( !strcmp(
"-d", argv[i] ) )
58 if( i == argc )
usage( argv[0] );
59 result_file = argv[i];
63 else if( !point_file )
68 count = strtol( argv[i], &endptr, 0 );
69 if( *endptr || count < 1 )
usage( argv[0] );
73 file = fopen( point_file,
"rb" );
79 fseek( file, 0, SEEK_END );
80 length = ftell( file ) / ( 3 *
sizeof( double ) );
81 fseek( file, 0, SEEK_SET );
82 values =
new double[3 *
length];
83 if(
length != fread( values, 3 *
sizeof(
double ),
length, file ) )
85 fprintf( stderr,
"Error reading %lu points from file \"%s\"\n",
length, argv[2] );
93 rfile = fopen( result_file,
"w" );
96 perror( result_file );
102 if( !count ) count =
length;
104 printf(
"Loading tree..." );
111 fprintf( stderr,
"Failed to read file: %s\n", tree_file );
115 printf(
"%0.2f seconds\n", ( clock() -
t ) / (
double)CLOCKS_PER_SEC );
121 if( range.
size() != 1 )
123 fprintf( stderr,
"%s : found %d kd-trees\n", argv[1], (
int)range.
size() );
131 printf(
"Running point queries..." );
136 for(
unsigned long i = 0; i < count; ++i )
138 const double* coords = values + 3 * ( i %
length );
139 if( query_triangles )
145 fprintf( stderr,
"Failure (ErrorCode == %d) for point %d (%f, %f, %f)\n", (
int)rval,
146 (
int)( count %
length ), coords[0], coords[1], coords[2] );
150 if( query_triangles )
151 fprintf( rfile,
"%f %f %f %f %f %f %lu\n", coords[0], coords[1], coords[2], pt[0], pt[1], pt[2],
152 (
unsigned long)
leaf );
154 fprintf( rfile,
"%f %f %f %lu\n", coords[0], coords[1], coords[2], (
unsigned long)
leaf );
157 printf(
"%0.2f seconds\n", ( clock() -
t ) / (
double)CLOCKS_PER_SEC );