MeshKit
1.0
|
00001 00007 #include "meshkit/MKCore.hpp" 00008 #include "meshkit/SurfaceFacetMeshReader.hpp" 00009 #include "meshkit/CurveFacetMeshReader.hpp" 00010 #include "meshkit/ModelEnt.hpp" 00011 #include "MBTagConventions.hpp" 00012 #include "moab/GeomTopoTool.hpp" 00013 #include "moab/Types.hpp" 00014 00015 using namespace MeshKit; 00016 00017 #include "TestUtil.hpp" 00018 00019 MKCore *mk = NULL; 00020 00021 #ifdef HAVE_ACIS 00022 std::string extension = ".sat"; 00023 #elif HAVE_OCC 00024 std::string extension = ".stp"; 00025 #endif 00026 00027 00028 //test functions 00029 void cylcube_curve_senses_test(); 00030 void cylcube_surf_senses_test(); 00031 00032 00033 //support functions 00034 int geom_id_by_handle( moab::EntityHandle ent ); 00035 void load_sat_curve_sense_data( ModelEnt* curve, std::vector<int>& curve_ids_out, std::vector<int>& senses_out ); 00036 void load_stp_curve_sense_data( ModelEnt* curve, std::vector<int>& curve_ids_out, std::vector<int>& senses_out ); 00037 void load_sat_surf_sense_data( ModelEnt *surf, std::vector<int>& vol_ids_out, std::vector<int>& senses_out ); 00038 void load_stp_surf_sense_data( ModelEnt *surf, std::vector<int>& vol_ids_out, std::vector<int>& senses_out ); 00039 void check_sense_data( std::vector<moab::EntityHandle> wrt_ents, std::vector<int> senses, 00040 std::vector<int> known_wrt_ids, std::vector<int> known_senses ); 00041 00042 int main(int argc, char **argv) 00043 { 00044 00045 // start up MK and load the geometry 00046 mk = new MKCore(); 00047 00048 std::string filename = "cylcube" ; 00049 00050 filename = TestDir + "/" + filename + extension; 00051 00052 mk->load_geometry(&filename[0]); 00053 00054 MEntVector surfs; 00055 mk->get_entities_by_dimension(2,surfs); 00056 SurfaceFacetMeshReader *sfmr; 00057 00058 sfmr = (SurfaceFacetMeshReader*) mk->construct_meshop("SurfaceFacetMeshReader", surfs); 00059 00060 double facet_tol = 1e-04, geom_resabs = 1e-06; 00061 sfmr->set_mesh_params(facet_tol, geom_resabs); 00062 00063 mk->setup(); 00064 mk->execute(); 00065 00066 00067 //RUN TESTS 00068 int num_fail = 0; 00069 num_fail += RUN_TEST(cylcube_curve_senses_test); 00070 00071 00072 return num_fail; 00073 } 00074 00075 void cylcube_curve_senses_test() 00076 { 00077 00078 //check that we retrieve the correct number of curves from the model 00079 MEntVector curves; 00080 mk->get_entities_by_dimension( 1, curves); 00081 00082 #ifdef HAVE_OCC 00083 CHECK( 18 == int(curves.size()) ); 00084 #else 00085 CHECK( 14 == int(curves.size()) ); 00086 #endif 00087 00088 // Establish GeomTopoTool instance needed to get curve data 00089 moab::GeomTopoTool gt( mk->moab_instance() ); 00090 00091 // Initialize vectors for sense checking 00092 std::vector<moab::EntityHandle> curve_list; 00093 std::vector<int> senses; 00094 std::vector<int> known_curve_ids; 00095 std::vector<int> known_senses; 00096 00097 //load_sat_curve_sense_data( 00098 //for each curve get the sense data from the model 00099 for(MEntVector::iterator i = curves.begin(); i != curves.end(); i++) 00100 { 00101 00102 ModelEnt *curve = *i; 00103 00104 curve_list.clear(); 00105 senses.clear(); 00106 00107 //get the senses for this curve 00108 moab::EntityHandle curve_sh = curve->mesh_handle(); 00109 moab::ErrorCode result = gt.get_senses( curve_sh, curve_list, senses); 00110 if( result != moab::MB_SUCCESS ) CHECK(false); // return failed test if this call fails 00111 00112 //clear reference data 00113 known_curve_ids.clear(); 00114 known_senses.clear(); 00115 00116 //Load known curve-sense data 00117 #ifdef HAVE_OCC 00118 load_stp_curve_sense_data( curve, known_curve_ids, known_senses); 00119 #else 00120 load_sat_curve_sense_data( curve, known_curve_ids, known_senses); 00121 #endif 00122 //check that each surf and sense has a match in our reference data 00123 00124 } 00125 } 00126 00127 void cylcube_surf_senses_test() 00128 { 00129 00130 MEntVector surfs; 00131 00132 mk->get_entities_by_dimension( 2, surfs ); 00133 00134 //make sure we've retrieved the right number of surfaces for the model 00135 #ifdef HAVE_OCC 00136 CHECK_EQUAL( 10, int(surfs.size()) ); 00137 #else 00138 CHECK_EQUAL( 9, int(surfs.size()) ); 00139 #endif 00140 00141 //Create a Geomtopotool and declare containers for sense data 00142 moab::GeomTopoTool gt( mk->moab_instance() ); 00143 moab::ErrorCode rval; 00144 std::vector<moab::EntityHandle> vols; 00145 std::vector<int> senses; 00146 std::vector<int> known_volume_ids; 00147 std::vector<int> known_senses; 00148 00149 for( unsigned int i = 0; i < surfs.size(); i++) 00150 { 00151 //clear out the old containers from the previous surface 00152 vols.clear(); 00153 senses.clear(); 00154 00155 moab::EntityHandle sh = surfs[i]->mesh_handle(); 00156 00157 rval = gt.get_senses( sh, vols, senses); 00158 CHECK_ERR(rval); 00159 00160 //clear previous reference data 00161 known_volume_ids.clear(); 00162 known_senses.clear(); 00163 //Load the known surface to volume sense data 00164 #ifdef HAVE_OCC 00165 load_stp_surf_sense_data( surfs[i], known_volume_ids, known_senses); 00166 #else 00167 load_sat_surf_sense_data( surfs[i], known_volume_ids, known_senses); 00168 #endif 00169 00170 check_sense_data( vols, senses, known_volume_ids, known_senses); 00171 } 00172 } 00173 00174 00175 //Loads reference surface to volume sense data into the reference vectors 00176 void load_sat_surf_sense_data( ModelEnt *surf, std::vector<int>& vol_ids_out, std::vector<int>& senses_out ){ 00177 00178 int surf_id = geom_id_by_handle( surf->mesh_handle() ); 00179 switch(surf_id) 00180 { 00181 case 1: 00182 vol_ids_out.push_back(1); 00183 senses_out.push_back(SENSE_FORWARD); 00184 break; 00185 00186 case 2: 00187 vol_ids_out.push_back(1); 00188 senses_out.push_back(SENSE_FORWARD); 00189 break; 00190 00191 case 3: 00192 vol_ids_out.push_back(1); 00193 senses_out.push_back(SENSE_FORWARD); 00194 break; 00195 00196 case 4: 00197 vol_ids_out.push_back(1); 00198 senses_out.push_back(SENSE_FORWARD); 00199 break; 00200 00201 case 5: 00202 vol_ids_out.push_back(1); 00203 senses_out.push_back(SENSE_FORWARD); 00204 break; 00205 00206 case 6: 00207 vol_ids_out.push_back(1); 00208 senses_out.push_back(SENSE_FORWARD); 00209 break; 00210 00211 case 7: 00212 vol_ids_out.push_back(2); 00213 senses_out.push_back(SENSE_FORWARD); 00214 break; 00215 00216 case 8: 00217 vol_ids_out.push_back(2); 00218 senses_out.push_back(SENSE_FORWARD); 00219 break; 00220 00221 case 9: 00222 vol_ids_out.push_back(2); 00223 senses_out.push_back(SENSE_FORWARD); 00224 break; 00225 default: 00226 std::cout << "Could not match the surface id to sense data." << std::endl; 00227 CHECK(false); 00228 00229 } 00230 00231 } 00232 00233 //Loads reference surface to volume sense data into the reference vectors 00234 void load_stp_surf_sense_data( ModelEnt *surf, std::vector<int>& vol_ids_out, std::vector<int>& senses_out ){ 00235 00236 int surf_id = geom_id_by_handle( surf->mesh_handle() ); 00237 switch(surf_id) 00238 { 00239 case 1: 00240 vol_ids_out.push_back(1); 00241 senses_out.push_back(SENSE_FORWARD); 00242 break; 00243 00244 case 2: 00245 vol_ids_out.push_back(1); 00246 senses_out.push_back(SENSE_FORWARD); 00247 break; 00248 00249 case 3: 00250 vol_ids_out.push_back(1); 00251 senses_out.push_back(SENSE_FORWARD); 00252 break; 00253 00254 case 4: 00255 vol_ids_out.push_back(1); 00256 senses_out.push_back(SENSE_FORWARD); 00257 break; 00258 00259 case 5: 00260 vol_ids_out.push_back(1); 00261 senses_out.push_back(SENSE_FORWARD); 00262 break; 00263 00264 case 6: 00265 vol_ids_out.push_back(1); 00266 senses_out.push_back(SENSE_FORWARD); 00267 break; 00268 00269 case 7: 00270 vol_ids_out.push_back(2); 00271 senses_out.push_back(SENSE_FORWARD); 00272 break; 00273 00274 case 8: 00275 vol_ids_out.push_back(2); 00276 senses_out.push_back(SENSE_FORWARD); 00277 break; 00278 00279 case 9: 00280 vol_ids_out.push_back(2); 00281 senses_out.push_back(SENSE_FORWARD); 00282 break; 00283 00284 case 10: 00285 vol_ids_out.push_back(2); 00286 senses_out.push_back(SENSE_FORWARD); 00287 break; 00288 default: 00289 std::cout << "Could not match surface id to sense data." << std::endl; 00290 CHECK(false); 00291 } 00292 } 00293 00294 //Loads two vectors with reference curve and curve_sense data 00295 void load_sat_curve_sense_data( ModelEnt* curve, std::vector<int>& surf_ids_out, std::vector<int>& senses_out ) 00296 { 00297 00298 int curve_id = geom_id_by_handle( curve->mesh_handle() ); 00299 switch(curve_id) 00300 { 00301 case 1: 00302 surf_ids_out.push_back(1); surf_ids_out.push_back(6); 00303 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00304 break; 00305 00306 case 2: 00307 surf_ids_out.push_back(1); surf_ids_out.push_back(5); 00308 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00309 break; 00310 00311 case 3: 00312 surf_ids_out.push_back(1); surf_ids_out.push_back(4); 00313 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00314 break; 00315 00316 case 4: 00317 surf_ids_out.push_back(1); surf_ids_out.push_back(3); 00318 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00319 break; 00320 00321 case 5: 00322 surf_ids_out.push_back(2); surf_ids_out.push_back(6); 00323 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00324 break; 00325 00326 case 6: 00327 surf_ids_out.push_back(2); surf_ids_out.push_back(3); 00328 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00329 break; 00330 00331 case 7: 00332 surf_ids_out.push_back(2); surf_ids_out.push_back(4); 00333 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00334 break; 00335 00336 case 8: 00337 surf_ids_out.push_back(2); surf_ids_out.push_back(5); 00338 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00339 break; 00340 00341 case 9: 00342 surf_ids_out.push_back(3); surf_ids_out.push_back(4); 00343 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00344 break; 00345 00346 case 10: 00347 surf_ids_out.push_back(3); surf_ids_out.push_back(6); 00348 senses_out.push_back(SENSE_REVERSE); senses_out.push_back(SENSE_FORWARD); 00349 break; 00350 00351 case 11: 00352 surf_ids_out.push_back(4); surf_ids_out.push_back(5); 00353 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00354 break; 00355 00356 case 12: 00357 surf_ids_out.push_back(5); surf_ids_out.push_back(6); 00358 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00359 break; 00360 00361 case 13: 00362 surf_ids_out.push_back(7); surf_ids_out.push_back(8); 00363 senses_out.push_back(SENSE_REVERSE); senses_out.push_back(SENSE_FORWARD); 00364 break; 00365 00366 case 14: 00367 surf_ids_out.push_back(7); surf_ids_out.push_back(9); 00368 senses_out.push_back(SENSE_REVERSE); senses_out.push_back(SENSE_FORWARD); 00369 break; 00370 default: 00371 std::cout << "Could not match curve id to sense data" << std::endl; 00372 CHECK(false); 00373 00374 } 00375 00376 } 00377 00378 00379 //Loads two vectors with reference curve and curve_sense data 00380 void load_stp_curve_sense_data( ModelEnt* curve, std::vector<int>& surf_ids_out, std::vector<int>& senses_out ) 00381 { 00382 00383 int curve_id = geom_id_by_handle( curve->mesh_handle() ); 00384 switch(curve_id) 00385 { 00386 case 1: 00387 surf_ids_out.push_back(1); surf_ids_out.push_back(6); 00388 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00389 break; 00390 00391 case 2: 00392 surf_ids_out.push_back(1); surf_ids_out.push_back(5); 00393 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00394 break; 00395 00396 case 3: 00397 surf_ids_out.push_back(1); surf_ids_out.push_back(4); 00398 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00399 break; 00400 00401 case 4: 00402 surf_ids_out.push_back(1); surf_ids_out.push_back(3); 00403 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00404 break; 00405 00406 case 5: 00407 surf_ids_out.push_back(2); surf_ids_out.push_back(6); 00408 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00409 break; 00410 00411 case 6: 00412 surf_ids_out.push_back(2); surf_ids_out.push_back(3); 00413 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00414 break; 00415 00416 case 7: 00417 surf_ids_out.push_back(2); surf_ids_out.push_back(4); 00418 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00419 break; 00420 00421 case 8: 00422 surf_ids_out.push_back(2); surf_ids_out.push_back(5); 00423 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00424 break; 00425 00426 case 9: 00427 surf_ids_out.push_back(3); surf_ids_out.push_back(4); 00428 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00429 break; 00430 00431 case 10: 00432 surf_ids_out.push_back(3); surf_ids_out.push_back(6); 00433 senses_out.push_back(SENSE_REVERSE); senses_out.push_back(SENSE_FORWARD); 00434 break; 00435 00436 case 11: 00437 surf_ids_out.push_back(4); surf_ids_out.push_back(5); 00438 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00439 break; 00440 00441 case 12: 00442 surf_ids_out.push_back(5); surf_ids_out.push_back(6); 00443 senses_out.push_back(SENSE_FORWARD); senses_out.push_back(SENSE_REVERSE); 00444 break; 00445 00446 case 13: 00447 surf_ids_out.push_back(7); surf_ids_out.push_back(8); 00448 senses_out.push_back(SENSE_REVERSE); senses_out.push_back(SENSE_FORWARD); 00449 break; 00450 00451 case 14: 00452 surf_ids_out.push_back(7); surf_ids_out.push_back(9); 00453 senses_out.push_back(SENSE_REVERSE); senses_out.push_back(SENSE_FORWARD); 00454 break; 00455 case 15: 00456 surf_ids_out.push_back(7); surf_ids_out.push_back(8); 00457 senses_out.push_back(SENSE_REVERSE); senses_out.push_back(SENSE_FORWARD); 00458 break; 00459 case 16: 00460 surf_ids_out.push_back(7); surf_ids_out.push_back(10); 00461 senses_out.push_back(SENSE_REVERSE); senses_out.push_back(SENSE_FORWARD); 00462 break; 00463 case 17: 00464 surf_ids_out.push_back(8); surf_ids_out.push_back(10); 00465 senses_out.push_back(SENSE_REVERSE); senses_out.push_back(SENSE_FORWARD); 00466 break; 00467 case 18: 00468 surf_ids_out.push_back(8); surf_ids_out.push_back(9); 00469 senses_out.push_back(SENSE_REVERSE); senses_out.push_back(SENSE_FORWARD); 00470 break; 00471 default: 00472 std::cout << "Could not match curve id to sense data" << std::endl; 00473 CHECK(false); 00474 00475 } 00476 00477 } 00478 00479 00480 void check_sense_data( std::vector<moab::EntityHandle> wrt_ents, std::vector<int> senses, 00481 std::vector<int> known_wrt_ids, std::vector<int> known_senses ) 00482 { 00483 00484 //Get ID's of the wrt entities 00485 std::vector<int> wrt_ent_ids; 00486 00487 for(unsigned int i=0 ; i<wrt_ents.size() ; i++) 00488 { 00489 wrt_ent_ids.push_back( geom_id_by_handle( wrt_ents[i] ) ); 00490 } 00491 00492 for(unsigned int i=0; i< wrt_ent_ids.size() ; i++) 00493 { 00494 for(unsigned int j=0; j< known_wrt_ids.size(); j++) 00495 { 00496 if( wrt_ent_ids[i] == known_wrt_ids [j] ) 00497 { 00498 // Make sure the senses of the matching wrt entities 00499 // are correct 00500 CHECK_EQUAL( senses[i], known_senses[j] ); 00501 //Once a wrt entity is matched with a known entity, 00502 // remove it from the list 00503 wrt_ent_ids.erase( wrt_ent_ids.begin()+i ); 00504 senses.erase( senses.begin()+i ); 00505 } 00506 } 00507 } 00508 00509 // After both loops are complete, known_wrt_ents should be empty 00510 int leftovers = wrt_ent_ids.size(); 00511 CHECK_EQUAL( leftovers, 0 ); 00512 00513 } 00514 00515 00516 int geom_id_by_handle( moab::EntityHandle ent ) 00517 { 00518 00519 moab::ErrorCode rval; 00520 //Get the id_tag handle 00521 moab::Tag id_tag; 00522 rval = mk->moab_instance()->tag_get_handle( GLOBAL_ID_TAG_NAME, 1, moab::MB_TYPE_INTEGER, id_tag, moab::MB_TAG_DENSE ); 00523 CHECK_ERR(rval); 00524 00525 //Load the ID for the EntHandle given to the function 00526 int id; 00527 rval = mk->moab_instance()->tag_get_data( id_tag, &ent, 1, &id ); 00528 CHECK_ERR(rval); 00529 00530 return id; 00531 00532 } 00533