19 #define STRINGIFY_( X ) #X
20 #define STRINGIFY( X ) STRINGIFY_( X )
23 #define DEFAULT_GEOM STRINGIFY( MESHDIR / irel / cyl2.stp )
24 #define DEFAULT_MESH STRINGIFY( MESHDIR / irel / cyl2.h5m )
26 #define DEFAULT_GEOM STRINGIFY( MESHDIR / irel / brick.facet )
27 #define DEFAULT_MESH STRINGIFY( MESHDIR / irel / brick.h5m )
31 #define CHECK_SIZE_C( type, array, allocated_size, size ) \
32 if( NULL == *( array ) || *( allocated_size ) == 0 ) \
34 *( array ) = (type*)malloc( sizeof( type ) * ( size ) ); \
35 *( allocated_size ) = size; \
37 else if( *( allocated_size ) < ( size ) ) \
39 printf( " Array passed in is non-zero but too short.\n" ); \
49 const char* type_names[] = {
"Vertex",
"Edge",
"Face",
"Region" };
51 iGeom_getEntType(
geom, gent, &ent_type, &result );
55 printf(
"Trouble getting entity adjacencies or types." );
59 printf(
"%s 0x%lx\n", type_names[ent_type], (
unsigned long)gent );
70 int ent_types[500], *ent_types_ptr = ent_types;
71 int adj_ents_alloc = 500, adj_ents_size, ent_types_size, ent_types_allocated = 500;
75 int ment_tags_size, ment_tags_alloc;
80 const char* type_names[] = {
"Vertex",
"Edge",
"Face",
"Region" };
87 adj_ents[adj_ents_size] = ment;
92 printf(
"Trouble getting entity adjacencies or types." );
99 printf(
"Trouble getting tags on an entity or their names." );
103 tag_names = (
char**)malloc( ment_tags_size *
sizeof(
char* ) );
105 for( i = 0; i < ment_tags_size; i++ )
107 tag_names[i] = (
char*)malloc( 120 *
sizeof(
char ) );
112 printf(
"%s %ld:\n", type_names[ent_types[ent_types_size - 1]], (
long)ment );
113 printf(
"Adjacencies:" );
114 for( i = 0; i < adj_ents_size; i++ )
116 if( i > 0 ) printf(
", " );
117 printf(
"%s %ld", type_names[ent_types[i]], (
long)adj_ents[i] );
119 printf(
"\nTags: \n" );
120 for( i = 0; i < ment_tags_size; i++ )
124 printf(
"%s ", tag_names[i] );
127 printf(
"(trouble getting type...)\n" );
130 char* dum_handle = NULL;
131 int dum_handle_alloc = 0, dum_handle_size = 0;
140 printf(
"(Int value=%d)", int_data );
144 printf(
"(Dbl value=%f)", dbl_data );
148 printf(
"(EH value=%ld)", (
long)eh_data );
151 iMesh_getData(
mesh, ment, ment_tags[i], (
void**)&dum_handle, &dum_handle_alloc, &dum_handle_size,
153 if( NULL != dum_handle && dum_handle_size > 0 ) printf(
"(Opaque value=%c)", dum_handle[0] );
160 printf(
"(end tags)\n\n" );
173 iGeom_load(
geom, geom_filename, 0, &result, strlen( geom_filename ), 0 );
176 printf(
"ERROR : can not load a geometry\n" );
181 iMesh_load(
mesh, 0, mesh_filename, 0, &result, strlen( mesh_filename ), 0 );
184 printf(
"ERROR : can not load a mesh\n" );
200 int ent_or_set1, ent_or_set2;
201 int status1, status2;
205 int pairs_alloc = 1, pairs_size;
212 printf(
"Couldn't create a new relation.\n" );
216 iRel_getPairInfo( assoc, *pair, &iface1, &ent_or_set1, &type1, &status1, &iface2, &ent_or_set2, &type2, &status2,
220 printf(
"Couldn't retrieve relation info.\n" );
226 printf(
"Unexpected relation info returned.\n" );
233 printf(
"Couldn't find relation pair when querying geom.\n" );
236 if( pairs_size != 1 || tmp_pair != *pair )
238 printf(
"Unexpected relation pairs returned when querying geom.\n" );
245 printf(
"Couldn't find relation pair when querying mesh.\n" );
248 if( pairs_size != 1 || tmp_pair != *pair )
250 printf(
"Unexpected relation pairs returned when querying mesh.\n" );
265 int gentities_size = 0, gentities_alloc = 0;
268 int mentity_handles_size = 0, mentity_handles_alloc = 0;
270 const char* dim_tag_name =
"GEOM_DIMENSION";
274 int mentities_vec_size = 0;
278 int out_mentities_size = 0, out_mentities_alloc = 0;
281 int out_mentities2_size = 0, out_mentities2_alloc = 0;
284 int out_gentities_size = 0, out_gentities_alloc = 0;
287 iGeom_getEntities(
geom, NULL,
iBase_VERTEX, &gentities, &gentities_alloc, &gentities_size, &result );
290 printf(
"Failed to get gentities by type in relate_geom_mesh.\n" );
297 printf(
"Failed to relate geom entities in relate_geom_mesh.\n" );
303 iMesh_getEntSets(
mesh, NULL, 1, &mentity_handles, &mentity_handles_alloc, &mentity_handles_size, &result );
306 printf(
"Problem to get all entity sets.\n" );
314 printf(
"Couldn't create geom dim tag for mesh entities.\n" );
320 for( i = 0; i < mentity_handles_size; i++ )
326 if(
dim == 1 ) mentities_vec[mentities_vec_size++] = mentity_handles[i];
332 printf(
"Failed to relate mesh entities in relate_geom_mesh.\n" );
340 printf(
"Failed to relate all geom and mesh entities in relate_geom_mesh.\n" );
349 iGeom_getEntities(
geom, NULL,
iBase_ALL_TYPES, &gentities, &gentities_alloc, &gentities_size, &result );
352 printf(
"Failed to get gentities by type in relate_geom_mesh.\n" );
358 &out_mentities_size, &result );
361 printf(
"Failed to get geom entities in relate_geom_mesh.\n" );
365 if( out_mentities_size != gentities_size )
367 printf(
"Number of input geom entities and output mesh entity sets should be same\n" );
375 printf(
"Failed to remove relation in relate_geom_mesh.\n" );
380 &out_mentities2_size, &result );
383 printf(
"Shouldn't have gotten mesh sets in relate_geom_mesh.\n" );
391 printf(
"Failed to restore relation in relate_geom_mesh.\n" );
397 &out_gentities_alloc, &out_gentities_size, &result );
400 printf(
"Failed to get mesh entities in relate_geom_mesh.\n" );
404 if( out_mentities_size != out_gentities_size )
406 printf(
"Number of input mesh entity sets and output geom entities should be same\n" );
409 free( mentity_handles );
410 mentity_handles = NULL;
413 free( mentity_handles );
414 mentity_handles = NULL;
415 free( out_mentities );
416 out_mentities = NULL;
417 free( mentities_vec );
418 mentities_vec = NULL;
419 free( out_gentities );
420 out_gentities = NULL;
433 int gentities_size = 0, gentities_alloc = 0;
436 int out_mentities_size, out_mentities_alloc = 0;
439 iGeom_getEntities(
geom, NULL,
iBase_FACE, &gentities, &gentities_alloc, &gentities_size, &result );
442 printf(
"Problem getting all geom entities.\n" );
445 for( i = 0; i < gentities_size; i++ )
451 &out_mentities_size, &result );
455 printf(
"Failed to get mesh entities related to geom entities in compute_normals.\n" );
460 if( out_mentities_size != gentities_size )
462 printf(
"Number of mesh & related geom entities don't match.\n" );
467 for( i = 0; i < out_mentities_size; i++ )
473 printf(
"Entity set returned from classification wasn't valid.\n" );
486 for( i = 0; i < gentities_size; i++ )
496 std::vector< double > coords;
497 coords.resize( vertices.
size() * 3 );
502 printf(
"surface %d has %d faces and %d vertices \n",
id, (
int)faces.
size(), (
int)vertices.
size() );
504 std::vector< double > normals;
505 normals.resize( 3 * vertices.
size() );
507 std::vector< double > on_coordinates;
508 on_coordinates.resize( 3 * vertices.
size() );
510 for(
int j = 0; j < (int)vertices.
size(); j++ )
512 iGeom_getEntNrmlXYZ(
geom, gentities[i], coords[3 * j], coords[3 * j + 1], coords[3 * j + 2],
513 &normals[3 * j], &normals[3 * j + 1], &normals[3 * j + 2], &result );
516 printf(
"Problem getting normals.\n" );
521 printf(
"v: %4d coor: %12.6f %12.6f %12.6f norm: %12.6f %12.6f %12.6f \n",
id, coords[3 * j],
522 coords[3 * j + 1], coords[3 * j + 2], normals[3 * j], normals[3 * j + 1], normals[3 * j + 2] );
529 free( out_mentities );
530 out_mentities = NULL;
535 int main(
int argc,
char* argv[] )
538 const char* geom_filename = DEFAULT_GEOM;
539 const char* mesh_filename = DEFAULT_MESH;
548 printf(
"Usage: %s %s\n", geom_filename, mesh_filename );
550 if( argc == 2 && !strcmp( argv[1],
"-h" ) )
552 printf(
"Usage: %s <geom_filename> <mesh_filename>\n", argv[0] );
557 geom_filename = argv[1];
558 mesh_filename = argv[1];
562 geom_filename = argv[1];
563 mesh_filename = argv[2];
567 iGeom_newGeom( 0, &
geom, &result, 0 );
575 printf(
" load_geom_mesh: \n" );
578 printf(
" create_relation: \n" );
581 printf(
" relate_geom_mesh: \n" );
585 printf(
" compute normals: \n" );
592 iGeom_dtor(
geom, &result );