lasso
|
00001 #include "FBiGeom.h" 00002 #include "iMesh.h" 00003 #include "iRel.h" 00004 00005 #include "stdio.h" 00006 #include "stdlib.h" 00007 #include "string.h" 00008 00009 #define DEFAULT_TEST_FILE shell.h5m 00010 #define DEFAULT_TEST_FILE1 shellQuad.h5m 00011 00012 #define STRINGIFY_(X) #X 00013 #define STRINGIFY(X) STRINGIFY_(X) 00014 #ifdef SRCDIR 00015 # define DEFAULT_INPUT_FILE STRINGIFY(SRCDIR/DEFAULT_TEST_FILE) 00016 # define DEFAULT_INPUT_FILE1 STRINGIFY(SRCDIR/DEFAULT_TEST_FILE1) 00017 #else 00018 # define DEFAULT_INPUT_FILE STRINGIFY(DEFAULT_TEST_FILE) 00019 # define DEFAULT_INPUT_FILE1 STRINGIFY(DEFAULT_TEST_FILE1) 00020 #endif 00021 00022 #define CHECK_SIZE_C(type, array, allocated_size, size) \ 00023 if (NULL == *array || *allocated_size == 0) {\ 00024 *array = (type *) malloc(sizeof(type) * size); \ 00025 *allocated_size = size;} \ 00026 else if (*allocated_size < size) { \ 00027 printf(" Array passed in is non-zero but too short.\n"); } 00028 00029 typedef void* iRel_EntityHandle; 00030 00034 void handle_error_code(const int result, 00035 int *number_failed, 00036 int *number_not_implemented, 00037 int *number_successful) 00038 { 00039 if (result) { 00040 printf("Success"); 00041 (*number_successful)++; 00042 } 00043 else { 00044 printf("Failure"); 00045 (*number_failed)++; 00046 } 00047 } 00048 00049 int print_geom_info(FBiGeom_Instance geom, iBase_EntityHandle gent) 00050 { 00051 /* print information about this entity */ 00052 int ent_type; 00053 int result; 00054 const char *type_names[] = {"Vertex", "Edge", "Face", "Region"}; 00055 00056 FBiGeom_getEntType(geom, gent, &ent_type, &result); 00057 00058 if (iBase_SUCCESS != result) { 00059 printf("Trouble getting entity adjacencies or types."); 00060 return 0; 00061 } 00062 00063 printf("%s 0x%lx\n", type_names[ent_type], (unsigned long)gent); 00064 00065 return 1; 00066 } 00067 00068 int print_mesh_info(iMesh_Instance mesh, iBase_EntityHandle ment) 00069 { 00070 /* print information about this entity */ 00071 00072 /* get adjacencies first; assume not more than 50 */ 00073 iBase_EntityHandle adj_ents[50], *adj_ents_ptr = adj_ents; 00074 int ent_types[50], *ent_types_ptr = ent_types; 00075 int adj_ents_alloc = 50, adj_ents_size, ent_types_size, 00076 ent_types_allocated = 50; 00077 int result; 00078 iBase_TagHandle *ment_tags = NULL; 00079 int ment_tags_size, ment_tags_alloc; 00080 char **tag_names; 00081 int i; 00082 const char *type_names[] = {"Vertex", "Edge", "Face", "Region"}; 00083 int tag_type; 00084 00085 char *dum_handle = NULL; 00086 int dum_handle_alloc = 0, dum_handle_size = 0; 00087 int int_data; 00088 double dbl_data; 00089 iBase_EntityHandle eh_data; 00090 00091 iMesh_getEntAdj(mesh, ment, iBase_ALL_TYPES, 00092 &adj_ents_ptr, &adj_ents_alloc, &adj_ents_size, 00093 &result); 00094 00095 if (iBase_SUCCESS != result) return 0; 00096 00097 /* put this ent on the end, then get types */ 00098 adj_ents[adj_ents_size] = ment; 00099 iMesh_getEntArrType(mesh, adj_ents, adj_ents_size+1, 00100 &ent_types_ptr, &ent_types_allocated, 00101 &ent_types_size, &result); 00102 if (iBase_SUCCESS != result) { 00103 printf("Trouble getting entity adjacencies or types."); 00104 return 0; 00105 } 00106 00107 /* get tags on ment */ 00108 iMesh_getAllTags(mesh, ment, 00109 &ment_tags, &ment_tags_alloc, &ment_tags_size, 00110 &result); 00111 00112 printf("Trouble getting tags on an entity or their names."); 00113 00114 /* while we're at it, get all the tag names */ 00115 00116 tag_names = (char **) malloc(ment_tags_size * sizeof(char*)); 00117 00118 for (i = 0; i < ment_tags_size; i++) { 00119 tag_names[i] = (char*)malloc(120*sizeof(char)); 00120 iMesh_getTagName(mesh, ment_tags[i], tag_names[i], &result, 120); 00121 } 00122 00123 /* now print the information */ 00124 printf("%s %ld:\n", type_names[ent_types[ent_types_size-1]], (long)ment); 00125 printf("Adjacencies:"); 00126 for (i = 0; i < adj_ents_size; i++) { 00127 if (i > 0) printf(", "); 00128 printf("%s %ld", type_names[ent_types[i]], 00129 (long)adj_ents[i]); 00130 } 00131 printf("\nTags: \n"); 00132 for (i = 0; i < ment_tags_size; i++) { 00133 printf("%s ", tag_names[i]); 00134 iMesh_getTagType(mesh, ment_tags[i], &tag_type, &result); 00135 if (iBase_SUCCESS != result) 00136 printf("(trouble getting type...)\n"); 00137 else { 00138 dum_handle = NULL; 00139 dum_handle_alloc = 0, dum_handle_size = 0; 00140 00141 switch (tag_type) { 00142 case iBase_INTEGER: 00143 iMesh_getIntData(mesh, ment, ment_tags[i], &int_data, &result); 00144 printf("(Int value=%d)", int_data); 00145 break; 00146 case iBase_DOUBLE: 00147 iMesh_getDblData(mesh, ment, ment_tags[i], &dbl_data, &result); 00148 printf("(Dbl value=%f)", dbl_data); 00149 break; 00150 case iBase_ENTITY_HANDLE: 00151 iMesh_getEHData(mesh, ment, ment_tags[i], &eh_data, &result); 00152 printf("(EH value=%ld)", (long)eh_data); 00153 break; 00154 case iBase_BYTES: 00155 iMesh_getData(mesh, ment, ment_tags[i], 00156 (void**)&dum_handle, &dum_handle_alloc, 00157 &dum_handle_size, &result); 00158 if (NULL != dum_handle && dum_handle_size > 0) 00159 printf("(Opaque value=%c)", dum_handle[0]); 00160 break; 00161 } 00162 } 00163 00164 printf("\n"); 00165 } 00166 printf("(end tags)\n\n"); 00167 00168 return 1; 00169 } 00170 00176 int load_geom_mesh_test(const char *geom_filename, 00177 const char *mesh_filename, 00178 FBiGeom_Instance geom, 00179 iMesh_Instance mesh) 00180 { 00181 /* load a geom */ 00182 int result; 00183 FBiGeom_load(geom, geom_filename, 0, &result, strlen(geom_filename), 0); 00184 if (iBase_SUCCESS != result) { 00185 printf("ERROR : can not load a geometry\n"); 00186 return 0; 00187 } 00188 00189 /* load a mesh */ 00190 iMesh_load(mesh, 0, mesh_filename, 0, &result, strlen(mesh_filename), 0); 00191 if (iBase_SUCCESS != result) { 00192 printf("ERROR : can not load a mesh\n"); 00193 return 0; 00194 } 00195 00196 return 1; 00197 } 00198 00204 int create_relation_test(iRel_Instance assoc, 00205 FBiGeom_Instance geom, 00206 iMesh_Instance mesh, 00207 iRel_PairHandle *pair) 00208 { 00209 int result; 00210 00211 iBase_Instance iface1, iface2; 00212 int type1, type2; 00213 int ent_or_set1, ent_or_set2; 00214 int status1, status2; 00215 00216 iRel_PairHandle tmp_pair; 00217 iRel_PairHandle *pair_ptr = &tmp_pair; 00218 int pairs_alloc = 1, pairs_size; 00219 00220 /* create an relation, entity to set */ 00221 iRel_createPair(assoc, 00222 geom, iRel_ENTITY, iRel_FBIGEOM_IFACE, iRel_ACTIVE, 00223 mesh, iRel_SET, iRel_IMESH_IFACE, iRel_ACTIVE, 00224 pair, &result); 00225 if (iBase_SUCCESS != result) { 00226 printf("Couldn't create a new relation.\n"); 00227 return 0; 00228 } 00229 00230 iRel_getPairInfo(assoc, *pair, 00231 &iface1, &ent_or_set1, &type1, &status1, 00232 &iface2, &ent_or_set2, &type2, &status2, &result); 00233 if (iBase_SUCCESS != result) { 00234 printf("Couldn't retrieve relation info.\n"); 00235 return 0; 00236 } 00237 if (iface1 != geom || ent_or_set1 != iRel_ENTITY || 00238 type1 != iRel_FBIGEOM_IFACE || iface2 != mesh || ent_or_set2 != iRel_SET || 00239 type2 != iRel_IMESH_IFACE) { 00240 printf("Unexpected relation info returned.\n"); 00241 return 0; 00242 } 00243 00244 iRel_findPairs(assoc, geom, &pair_ptr, &pairs_alloc, &pairs_size, &result); 00245 if (iBase_SUCCESS != result) { 00246 printf("Couldn't find relation pair when querying geom.\n"); 00247 return 0; 00248 } 00249 if (pairs_size != 1 || tmp_pair != *pair) { 00250 printf("Unexpected relation pairs returned when querying geom.\n"); 00251 return 0; 00252 } 00253 00254 iRel_findPairs(assoc, mesh, &pair_ptr, &pairs_alloc, &pairs_size, &result); 00255 if (iBase_SUCCESS != result) { 00256 printf("Couldn't find relation pair when querying mesh.\n"); 00257 return 0; 00258 } 00259 if (pairs_size != 1 || tmp_pair != *pair) { 00260 printf("Unexpected relation pairs returned when querying mesh.\n"); 00261 return 0; 00262 } 00263 00264 return 1; 00265 } 00266 00272 int relate_geom_mesh_test(iRel_Instance assoc, 00273 FBiGeom_Instance geom, 00274 iMesh_Instance mesh, 00275 iRel_PairHandle pair) 00276 { 00277 /* relate geometry entities with coresponding mesh entity sets */ 00278 iBase_EntityHandle *gentities = NULL; 00279 int gentities_size = 0, gentities_alloc = 0; 00280 int result; 00281 00282 iBase_EntitySetHandle *mentity_handles = NULL; 00283 int mentity_handles_size = 0, mentity_handles_alloc = 0; 00284 00285 const char *dim_tag_name = "GEOM_DIMENSION"; 00286 iBase_TagHandle dim_tag_mesh; 00287 00288 iBase_EntitySetHandle *mentities_vec; 00289 int mentities_vec_size; 00290 int i; 00291 00292 iBase_EntitySetHandle *out_mentities = NULL; 00293 int out_mentities_size = 0, out_mentities_alloc = 0; 00294 00295 iBase_EntitySetHandle *out_mentities2 = NULL; 00296 int out_mentities2_size = 0, out_mentities2_alloc = 0; 00297 00298 iBase_EntityHandle *out_gentities = NULL; 00299 int out_gentities_size = 0, out_gentities_alloc = 0; 00300 00301 FBiGeom_getEntities(geom, NULL, 00302 iBase_VERTEX, 00303 &gentities, 00304 &gentities_alloc, 00305 &gentities_size, &result); 00306 if (iBase_SUCCESS != result) { 00307 printf("Failed to get gentities by type in relate_geom_mesh_test.\n"); 00308 return 0; 00309 } 00310 00311 iRel_inferEntArrRelations(assoc, pair, 00312 gentities, gentities_size, 0, 00313 &result); 00314 if (iBase_SUCCESS != result) { 00315 printf("Failed to relate geom entities in relate_geom_mesh_test.\n"); 00316 return 0; 00317 } 00318 00319 /* relate coresponding mesh entity sets for geometry entities */ 00320 /* get 1-dimensional mesh entitysets */ 00321 00322 iMesh_getEntSets(mesh, NULL, 1, 00323 &mentity_handles, &mentity_handles_alloc, 00324 &mentity_handles_size, &result); 00325 if (iBase_SUCCESS != result) { 00326 printf("Problem to get all entity sets.\n"); 00327 return 0; 00328 } 00329 00330 /* get geom dimension tags for mesh entitysets */ 00331 iMesh_createTag(mesh, dim_tag_name, 1, iBase_INTEGER, 00332 &dim_tag_mesh, &result, 15); 00333 if (iBase_SUCCESS != result && result != iBase_TAG_ALREADY_EXISTS) { 00334 printf("Couldn't create geom dim tag for mesh entities.\n"); 00335 return 0; 00336 } 00337 00338 /* get 1-dimensional mesh entitysets */ 00339 mentities_vec = (iBase_EntitySetHandle*)malloc(mentity_handles_size*sizeof(iBase_EntitySetHandle)); 00340 mentities_vec_size = 0; 00341 00342 for (i = 0; i < mentity_handles_size; i++) { 00343 int dim; 00344 iMesh_getEntSetIntData(mesh, mentity_handles[i], dim_tag_mesh, 00345 &dim, &result); 00346 if (iBase_SUCCESS != result) 00347 continue; 00348 00349 if (dim == 1) 00350 mentities_vec[mentities_vec_size++] = mentity_handles[i]; 00351 } 00352 00353 iRel_inferSetArrRelations(assoc, pair, 00354 mentities_vec, mentities_vec_size, 00355 1, &result); 00356 if (iBase_SUCCESS != result) { 00357 printf("Failed to relate mesh entities in relate_geom_mesh_test.\n"); 00358 return 0; 00359 } 00360 00361 /* relate all geometry and mesh entities */ 00362 iRel_inferAllRelations(assoc, pair, &result); 00363 if (iBase_SUCCESS != result) { 00364 printf("Failed to relate all geom and mesh entities in relate_geom_mesh_test.\n"); 00365 return 0; 00366 } 00367 00368 /* reset geom entities list and get all geom entities (prev 00369 only vertices) */ 00370 free(gentities); 00371 gentities = NULL; 00372 gentities_alloc = 0; 00373 FBiGeom_getEntities(geom, NULL, 00374 iBase_ALL_TYPES, 00375 &gentities, 00376 &gentities_alloc, 00377 &gentities_size, &result); 00378 if (iBase_SUCCESS != result) { 00379 printf("Failed to get gentities by type in relate_geom_mesh_test.\n"); 00380 return 0; 00381 } 00382 00383 /* get related mesh entity sets for geometry entities */ 00384 iRel_getEntArrSetArrRelation(assoc, pair, 00385 gentities, gentities_size, 0, 00386 &out_mentities, &out_mentities_alloc, 00387 &out_mentities_size, 00388 &result); 00389 if (iBase_SUCCESS != result) { 00390 printf("Failed to get geom entities in relate_geom_mesh_test.\n"); 00391 return 0; 00392 } 00393 00394 if (out_mentities_size != gentities_size) { 00395 printf("Number of input geom entities and output mesh entity sets should be same\n"); 00396 return 0; 00397 } 00398 00399 /* now try deleting this relation */ 00400 iRel_rmvEntArrRelation(assoc, pair, gentities, gentities_size, 0, &result); 00401 if (iBase_SUCCESS != result) { 00402 printf("Failed to remove relation in relate_geom_mesh_test.\n"); 00403 return 0; 00404 } 00405 iRel_getEntArrSetArrRelation(assoc, pair, 00406 gentities, gentities_size, 0, 00407 &out_mentities2, &out_mentities2_alloc, 00408 &out_mentities2_size, 00409 &result); 00410 if (iBase_SUCCESS == result) { 00411 printf("Shouldn't have gotten mesh sets in relate_geom_mesh_test.\n"); 00412 return 0; 00413 } 00414 00415 /* restore the relation, since we need it later */ 00416 iRel_setEntArrSetArrRelation(assoc, pair, gentities, gentities_size, 00417 out_mentities, out_mentities_size, &result); 00418 if (iBase_SUCCESS != result) { 00419 printf("Failed to restore relation in relate_geom_mesh_test.\n"); 00420 return 0; 00421 } 00422 00423 /* get related geometry entities for mesh entity sets */ 00424 iRel_getSetArrEntArrRelation(assoc, pair, 00425 out_mentities, out_mentities_size, 1, 00426 &out_gentities, &out_gentities_alloc, 00427 &out_gentities_size, 00428 &result); 00429 if (iBase_SUCCESS != result) { 00430 printf("Failed to get mesh entities in relate_geom_mesh_test.\n"); 00431 return 0; 00432 } 00433 00434 if (out_mentities_size != out_gentities_size) { 00435 printf("Number of input mesh entity sets and output geom entities should be same\n"); 00436 return 0; 00437 } 00438 00439 return 1; 00440 } 00441 00447 int query_relations_test(iRel_Instance assoc, 00448 FBiGeom_Instance geom, 00449 iMesh_Instance mesh, 00450 iRel_PairHandle pair) 00451 { 00452 /* get all the geom entities, and find relation to some mesh entity */ 00453 iBase_EntityHandle *gentities = NULL; 00454 int gentities_size = 0, gentities_alloc = 0; 00455 int result; 00456 00457 iBase_EntitySetHandle *out_mentities = NULL; 00458 int out_mentities_size, out_mentities_alloc = 0; 00459 00460 char descr[120]; 00461 int i; 00462 int is_list; 00463 00464 iBase_EntityHandle *out_gentities = NULL; 00465 int out_gentities_size, out_gentities_alloc = 0; 00466 00467 FBiGeom_getEntities(geom, NULL, iBase_ALL_TYPES, 00468 &gentities, &gentities_alloc, 00469 &gentities_size, &result); 00470 if (iBase_SUCCESS != result) { 00471 printf("Problem getting all geom entities.\n" ); 00472 return 0; 00473 } 00474 00475 iRel_getEntArrSetArrRelation(assoc, pair, 00476 gentities, gentities_size, 0, 00477 &out_mentities, &out_mentities_alloc, 00478 &out_mentities_size, 00479 &result); 00480 /* might not all be */ 00481 if (iBase_SUCCESS != result) { 00482 printf("Failed to get mesh entities related to geom entities in query_relations_test.\n"); 00483 00484 iRel_getDescription(assoc, descr, sizeof(descr)-1); 00485 printf("Entities missing relations: %s\n", descr); 00486 00487 for (i = 0; i < gentities_size; i++) { 00488 print_geom_info(geom, gentities[i]); 00489 } 00490 00491 return 0; 00492 } 00493 00494 /* check that they're all non-null */ 00495 if (out_mentities_size != gentities_size) { 00496 printf("Number of mesh & related geom entities don't match.\n"); 00497 return 0; 00498 } 00499 00500 /* check to make sure they're mesh sets; how to do that? */ 00501 for (i = 0; i < out_mentities_size; i++) { 00502 iMesh_isList(mesh, (iBase_EntitySetHandle)out_mentities[i], &is_list, &result); 00503 if (iBase_SUCCESS != result) { 00504 printf("Entity set returned from classification wasn't valid.\n"); 00505 return 0; 00506 } 00507 } 00508 00509 /* now turn around and check classification of those mesh entities */ 00510 iRel_getSetArrEntArrRelation(assoc, pair, 00511 out_mentities, out_mentities_size, 1, 00512 &out_gentities, &out_gentities_alloc, 00513 &out_gentities_size, 00514 &result); 00515 if (iBase_SUCCESS != result) { 00516 printf("Failed to get geom entities related to mesh entities in query_relations_test.\n"); 00517 return 0; 00518 } 00519 00520 /* check that they're all non-null */ 00521 if (out_mentities_size != out_gentities_size) { 00522 printf("Number of geom & related mesh entities don't match.\n" ); 00523 return 0; 00524 } 00525 00526 /* ok, we're done */ 00527 return 1; 00528 } 00529 00530 00531 int main( int argc, char *argv[] ) 00532 { 00533 /* Check command line arg */ 00534 const char *geom_filename = DEFAULT_INPUT_FILE; 00535 const char *mesh_filename = DEFAULT_INPUT_FILE1; 00536 00537 int result; 00538 int number_tests = 0; 00539 int number_tests_successful = 0; 00540 int number_tests_not_implemented = 0; 00541 int number_tests_failed = 0; 00542 00543 FBiGeom_Instance geom; 00544 iMesh_Instance mesh; 00545 iRel_Instance assoc; 00546 iRel_PairHandle pair; 00547 00548 if (argc == 2 && !strcmp(argv[1], "-h")) { 00549 printf("Usage: %s <geom_filename> <mesh_filename>\n", 00550 argv[0]); 00551 return 1; 00552 } 00553 else if (argc == 2) { 00554 geom_filename = argv[1]; 00555 mesh_filename = argv[1]; 00556 } 00557 else if (argc == 3) { 00558 geom_filename = argv[1]; 00559 mesh_filename = argv[2]; 00560 } 00561 00562 /* initialize the Geometry */ 00563 FBiGeom_newGeom(0, &geom, &result, 0); 00564 00565 /* initialize the Mesh */ 00566 iMesh_newMesh(0, &mesh, &result, 0); 00567 00568 /* initialize the Associate */ 00569 iRel_create(0, &assoc, &result, 0); 00570 00571 /* Print out Header information */ 00572 printf("\n\niRel TEST PROGRAM:\n\n"); 00573 00574 00575 /* load_geom_mesh test */ 00576 printf(" load_geom_mesh: "); 00577 result = load_geom_mesh_test(geom_filename, mesh_filename, 00578 geom, mesh); 00579 handle_error_code(result, &number_tests_failed, 00580 &number_tests_not_implemented, 00581 &number_tests_successful); 00582 number_tests++; 00583 printf("\n"); 00584 00585 /* create_relation test */ 00586 printf(" create_relation: "); 00587 result = create_relation_test(assoc, geom, mesh, &pair); 00588 handle_error_code(result, &number_tests_failed, 00589 &number_tests_not_implemented, 00590 &number_tests_successful); 00591 number_tests++; 00592 printf("\n"); 00593 00594 /* relate_geom_mesh test */ 00595 printf(" relate_geom_mesh: "); 00596 result = relate_geom_mesh_test(assoc, geom, mesh, pair); 00597 handle_error_code(result, &number_tests_failed, 00598 &number_tests_not_implemented, 00599 &number_tests_successful); 00600 number_tests++; 00601 printf("\n"); 00602 00603 /* query_relations test */ 00604 printf(" query_relations: "); 00605 result = query_relations_test(assoc, geom, mesh, pair); 00606 handle_error_code(result, &number_tests_failed, 00607 &number_tests_not_implemented, 00608 &number_tests_successful); 00609 number_tests++; 00610 printf("\n"); 00611 00612 /* summary */ 00613 00614 printf("\niRel TEST SUMMARY: \n"); 00615 printf(" Number Tests: %d\n", number_tests); 00616 printf(" Number Successful: %d\n", number_tests_successful); 00617 printf(" Number Not Implemented: %d\n", number_tests_not_implemented); 00618 printf(" Number Failed: %d\n", number_tests_failed); 00619 printf("\n\n"); 00620 00621 iRel_destroy(assoc, &result); 00622 00623 return number_tests_failed != 0; 00624 } 00625