MeshKit
1.0
|
00001 #ifndef MESHKIT_ITAPS_MESH_HPP 00002 #define MESHKIT_ITAPS_MESH_HPP 00003 00007 #include "moab/EntityType.hpp" 00008 #include "iMesh.h" 00009 #include "iRel.hpp" 00010 #include <string.h> 00011 #include <stdlib.h> 00012 #include <vector> 00013 #include <limits> 00014 #include <string> 00015 00016 #define ITAPS_PREFIX iMesh 00017 #include "meshkit/iBase.hpp" 00018 #undef ITAPS_PREFIX 00019 00031 class iMesh : public iMeshBase { 00032 public: 00033 inline iRel::IfaceType iface_type() const { 00034 return iRel::IMESH_IFACE; 00035 } 00036 00037 00038 /* map to MB's entity type from TSTT's entity topology */ 00039 static const moab::EntityType mb_topology_table[iMesh_ALL_TOPOLOGIES+1]; 00040 00041 typedef iMesh_EntityTopology EntityTopology; 00042 typedef iBase_AdjacencyCost AdjacencyCost; 00043 00044 explicit inline iMesh( const char* options = 0 ); 00045 inline iMesh( iMesh_Instance imesh ); 00046 00047 inline ~iMesh(); 00048 00049 inline Error load( EntitySetHandle set, 00050 const char* file_name, 00051 const char* options = 0 ); 00052 00053 inline Error save( EntitySetHandle set, 00054 const char* file_name, 00055 const char* options = 0 ); 00056 00057 inline int getGeometricDimension() const; 00058 00059 inline Error setGeometricDimension( int dim ); 00060 00061 inline StorageOrder getDfltStorage() const; 00062 00063 typedef AdjacencyCost (*AdjTableType)[4]; 00064 inline AdjTableType getAdjTable(); 00065 00066 inline Error setAdjTable( int* adj_table, int table_size); 00067 00068 inline Error getNumOfType( EntitySetHandle set, EntityType type, int& count_out ) const; 00069 00070 inline Error getNumOfTopo( EntitySetHandle set, EntityTopology topo, int& count_out ) const; 00071 00072 inline bool optimize(); 00073 00074 inline Error getEntities( EntitySetHandle set, 00075 EntityType type, 00076 EntityTopology topo, 00077 std::vector<EntityHandle>& entities_out ) const; 00078 00079 inline Error getVtxCoord( EntityHandle vertex, double& x, double& y, double& z ) const; 00080 inline Error setVtxCoord( EntityHandle vertex, double x, double y, double z ); 00081 00082 00083 inline Error getVtxArrCoords( const EntityHandle* vertex_handles, 00084 int vertex_handles_size, 00085 StorageOrder storage_order, 00086 double* coords_out ) const; 00087 00088 inline Error setVtxArrCoords( const EntityHandle* vertex_handles, 00089 int vertex_handles_size, 00090 StorageOrder storage_order, 00091 const double* new_coords ); 00092 00093 inline Error createVtx( double x, double y, double z, EntityHandle& vertex_out ); 00094 00095 inline Error createVtxArr( int num_verts, 00096 StorageOrder storage_order, 00097 const double* new_coords, 00098 EntityHandle* new_vertex_handles_out ); 00099 00100 inline Error createEnt( EntityTopology topology, 00101 const EntityHandle* lower_order_entity_handles, 00102 int lower_order_entity_handles_size, 00103 EntityHandle& new_entity_handle_out ); 00104 00105 inline Error createEntArr( EntityTopology new_entity_topology, 00106 const EntityHandle* lower_order_entity_handles, 00107 int lower_order_entity_handles_size, 00108 EntityHandle* new_entity_handles_out ); 00109 00110 inline Error deleteEnt( EntityHandle handle ); 00111 00112 inline Error deleteEntArr( const EntityHandle* entity_handles, int num_handles ); 00113 00114 inline Error getAdjEntities( EntitySetHandle set, 00115 EntityType type_requestor, 00116 EntityTopology topo_requestor, 00117 EntityType type_requested, 00118 std::vector<EntityHandle>& adj_entity_handles, 00119 std::vector<int>& offset ) const; 00120 00124 class EntArrIter { 00125 private: 00126 friend class iMesh; 00127 iBase_EntityArrIterator mHandle; 00128 iMesh_Instance mInstance; 00129 int mSize; 00130 public: 00131 EntArrIter() : mHandle(0), mInstance(0), mSize(0) {} 00132 inline ~EntArrIter(); 00133 inline Error getNext( EntityHandle* entity_handles_out, 00134 int& size_out, 00135 bool& has_more_data_out ); 00136 inline Error reset(); 00137 }; 00138 00142 class EntIter { 00143 private: 00144 friend class iMesh; 00145 iBase_EntityIterator mHandle; 00146 iMesh_Instance mInstance; 00147 public: 00148 EntIter() : mHandle(0), mInstance(0) {} 00149 inline ~EntIter(); 00150 inline Error getNext( EntityHandle& entity_handle_out, 00151 bool& has_more_data_out ); 00152 inline Error reset(); 00153 }; 00154 00155 inline Error initEntIter( EntitySetHandle set, 00156 EntityType requested_type, 00157 EntityTopology requested_topo, 00158 int resilient, 00159 EntIter& iter ); 00160 inline Error initEntArrIter( EntitySetHandle set, 00161 EntityType requested_type, 00162 EntityTopology requested_topo, 00163 int requested_array_size, 00164 int resilient, 00165 EntArrIter& iter ); 00166 00167 inline Error getEntTopo( EntityHandle handle, EntityTopology& topo_out ) const; 00168 inline Error getEntArrTopo( const EntityHandle* entity_handles, 00169 int entity_handles_Size, 00170 EntityTopology* topos_out ) const; 00171 00172 inline Error getEntType( EntityHandle handle, EntityType& type_out ) const; 00173 inline Error getEntArrType( const EntityHandle* entity_handles, 00174 int entity_handles_Size, 00175 EntityType* types_out ) const; 00176 00177 inline Error getEntAdj( EntityHandle handle, 00178 EntityType type_requested, 00179 std::vector<EntityHandle>& adj_entities_out ) const; 00180 inline Error getEntArrAdj( const EntityHandle* entity_handles, 00181 int entity_handles_size, 00182 EntityType type_requested, 00183 std::vector<EntityHandle>& adjacent_entity_handles_out, 00184 int* offsets_out ) const ; 00185 00186 inline Error getEnt2ndAdj( EntityHandle handle, 00187 EntityType bridge_entity_type, 00188 EntityType type_requested, 00189 std::vector<EntityHandle>& adj_entities_out ) const; 00190 inline Error getEntArr2ndAdj( const EntityHandle* entity_handles, 00191 int entity_handles_size, 00192 EntityType order_key, 00193 EntityType type_requested, 00194 std::vector<EntityHandle>& adjacent_entity_handles_out, 00195 int* offsets_out ) const; 00196 00197 inline Error getAdjEntIndices( EntitySetHandle set, 00198 EntityType requestor_type, 00199 EntityTopology requestor_topo, 00200 EntityType type_requested, 00201 std::vector<EntityHandle>& entity_handles_out, 00202 std::vector<EntityHandle>& adj_entity_handles_out, 00203 std::vector<int>& adj_entity_indices_out, 00204 std::vector<int>& offsets_out ) const; 00205 00206 private: 00207 bool iMeshInstanceOwner; 00208 AdjacencyCost adjTable[4][4]; 00209 Error adjTableErr; 00210 00211 void cacheAdjTable(); 00212 00213 // prohibit copying 00214 iMesh( const iMesh& ) {} 00215 void operator=(const iMesh&) {} 00216 }; 00217 00218 inline void 00219 iMesh::cacheAdjTable() 00220 { 00221 int err; 00222 if (sizeof(int) == sizeof(AdjacencyCost)) { 00223 int* ptr = (int*)&adjTable[0][0]; 00224 int size = 16, alloc = 16; 00225 iMesh_getAdjTable( mInstance, &ptr, &alloc, &size, &err ); 00226 adjTableErr = (Error)err; 00227 } 00228 else { 00229 int data[16]; 00230 int* ptr = data; 00231 int size = 16, alloc = 16; 00232 iMesh_getAdjTable( mInstance, &ptr, &alloc, &size, &err ); 00233 adjTableErr = (Error)err; 00234 for (int i = 0; i < 4; ++i) 00235 for (int j = 0; j < 4; ++j) 00236 adjTable[i][j] = (AdjacencyCost)data[4*i+1]; 00237 } 00238 } 00239 00240 inline 00241 iMesh::iMesh( const char* options ) 00242 { 00243 int err, len = options ? strlen(options) : 0; 00244 iMesh_newMesh( options, &mInstance, &err, len ); 00245 if (iBase_SUCCESS != err) { 00246 mInstance = 0; 00247 iMeshInstanceOwner = false; 00248 } 00249 else { 00250 iMeshInstanceOwner = true; 00251 cacheAdjTable(); 00252 } 00253 } 00254 00255 inline 00256 iMesh::iMesh( iMesh_Instance instance ) 00257 : iMeshInstanceOwner(false) 00258 { 00259 mInstance = instance; 00260 cacheAdjTable(); 00261 } 00262 00263 inline iMesh::~iMesh() 00264 { 00265 if (iMeshInstanceOwner) { 00266 int err; 00267 iMesh_dtor( mInstance, &err ); 00268 } 00269 } 00270 00271 inline iMesh::Error 00272 iMesh::load( EntitySetHandle set, 00273 const char* file_name, 00274 const char* options ) 00275 { 00276 int err, len = options ? strlen(options) : 0; 00277 iMesh_load( mInstance, set, file_name, options, &err, strlen(file_name), len ); 00278 return (Error)err; 00279 } 00280 00281 00282 inline iMesh::Error 00283 iMesh::save( EntitySetHandle set, 00284 const char* file_name, 00285 const char* options ) 00286 { 00287 int err, len = options ? strlen(options) : 0; 00288 iMesh_save( mInstance, set, file_name, options, &err, strlen(file_name), len ); 00289 return (Error)err; 00290 } 00291 00292 00293 inline int 00294 iMesh::getGeometricDimension() const 00295 { 00296 int err, result; 00297 iMesh_getGeometricDimension( mInstance, &result, &err ); 00298 return iBase_SUCCESS == err ? result : -err; 00299 } 00300 00301 00302 inline iMesh::Error 00303 iMesh::setGeometricDimension( int dim ) 00304 { 00305 int err; 00306 iMesh_setGeometricDimension( mInstance, dim, &err ); 00307 return (Error)err; 00308 } 00309 00310 inline iMesh::StorageOrder 00311 iMesh::getDfltStorage() const 00312 { 00313 int err, order; 00314 iMesh_getDfltStorage( mInstance, &order, &err ); 00315 return (iBase_SUCCESS == err) ? (StorageOrder)order : iBase_BLOCKED; 00316 } 00317 00318 inline iMesh::AdjTableType iMesh::getAdjTable() 00319 { 00320 cacheAdjTable(); //retrieve the most up-to-date table 00321 return (iBase_SUCCESS == adjTableErr) ? adjTable : 0; 00322 } 00323 00324 00325 inline iMesh::Error 00326 iMesh::setAdjTable( int adj_table[], int table_size) 00327 { 00328 00329 int err; 00330 iMesh_setAdjTable( mInstance, adj_table, table_size, &err); 00331 00332 return (Error)err; 00333 00334 } 00335 00336 inline iMesh::Error 00337 iMesh::getNumOfType( EntitySetHandle set, EntityType type, int& count_out ) const 00338 { 00339 int err; 00340 iMesh_getNumOfType( mInstance, set, type, &count_out, &err ); 00341 return (Error)err; 00342 } 00343 00344 inline iMesh::Error 00345 iMesh::getNumOfTopo( EntitySetHandle set, EntityTopology topo, int& count_out ) const 00346 { 00347 int err; 00348 iMesh_getNumOfTopo( mInstance, set, topo, &count_out, &err ); 00349 return (Error)err; 00350 } 00351 00352 inline bool 00353 iMesh::optimize() 00354 { 00355 int err, result; 00356 iMesh_optimize( mInstance, &result, &err ); 00357 return (iBase_SUCCESS == err) ? !!result : true; 00358 } 00359 00360 inline iMesh::Error 00361 iMesh::getEntities( EntitySetHandle set, 00362 EntityType type, 00363 EntityTopology topo, 00364 std::vector<EntityHandle>& entities_out ) const 00365 { 00366 // if input vect has no allocated space, allocate some so 00367 // we don't accidentally ask the impl to allocate an array 00368 if (entities_out.capacity() == 0) { 00369 Error err2; 00370 int count; 00371 if (topo == iMesh_ALL_TOPOLOGIES) 00372 err2 = getNumOfType( set, type, count ); 00373 else 00374 err2 = getNumOfTopo( set, topo, count ); 00375 if (err2 != iBase_SUCCESS) 00376 return err2; 00377 entities_out.resize( count ); 00378 } 00379 00380 // try getting results using whatever space input vector has allocated 00381 int err, size = 0, alloc = entities_out.capacity(); 00382 entities_out.resize( entities_out.capacity() ); 00383 EntityHandle* ptr = &entities_out[0]; 00384 iMesh_getEntities( mInstance, set, type, topo, &ptr, &alloc, &size, &err ); 00385 entities_out.resize(size); 00386 00387 // if input vector was too small, try again with increased size 00388 if (iBase_BAD_ARRAY_DIMENSION == err || iBase_BAD_ARRAY_SIZE == err) { 00389 alloc = entities_out.size(); 00390 ptr = &entities_out[0]; 00391 iMesh_getEntities( mInstance, set, type, topo, &ptr, &alloc, &size, &err ); 00392 } 00393 00394 return (Error)err; 00395 } 00396 00397 inline iMesh::Error 00398 iMesh::getVtxCoord( EntityHandle vertex, double& x, double& y, double& z ) const 00399 { 00400 int err; 00401 iMesh_getVtxCoord( mInstance, vertex, &x, &y, &z, &err ); 00402 return (Error)err; 00403 } 00404 00405 inline iMesh::Error 00406 iMesh::setVtxCoord( EntityHandle vertex, double x, double y, double z ) 00407 { 00408 int err; 00409 iMesh_setVtxCoord( mInstance, vertex, x, y, z, &err ); 00410 return (Error)err; 00411 } 00412 00413 00414 inline iMesh::Error 00415 iMesh::getVtxArrCoords( const EntityHandle* vertex_handles, 00416 int vertex_handles_size, 00417 StorageOrder storage_order, 00418 double* coords_out ) const 00419 { 00420 int err, alloc = 3*vertex_handles_size, junk, order = storage_order; 00421 iMesh_getVtxArrCoords( mInstance, vertex_handles, vertex_handles_size, 00422 order, &coords_out, &alloc, &junk, &err ); 00423 return (Error)err; 00424 } 00425 00426 inline iMesh::Error 00427 iMesh::setVtxArrCoords( const EntityHandle* vertex_handles, 00428 int vertex_handles_size, 00429 StorageOrder storage_order, 00430 const double* new_coords ) 00431 { 00432 int err, dim = getGeometricDimension(); 00433 iMesh_setVtxArrCoords( mInstance, vertex_handles, vertex_handles_size, 00434 storage_order, new_coords, dim*vertex_handles_size, 00435 &err ); 00436 return (Error)err; 00437 } 00438 00439 inline iMesh::Error 00440 iMesh::createVtx( double x, double y, double z, EntityHandle& vertex_out ) 00441 { 00442 int err; 00443 iMesh_createVtx( mInstance, x, y, z, &vertex_out, &err ); 00444 return (Error)err; 00445 } 00446 00447 00448 inline iMesh::Error 00449 iMesh::createVtxArr( int num_verts, 00450 StorageOrder storage_order, 00451 const double* new_coords, 00452 EntityHandle* new_vertex_handles_out ) 00453 { 00454 int err, alloc = num_verts, junk, dim = getGeometricDimension(); 00455 iMesh_createVtxArr( mInstance, num_verts, storage_order, new_coords, 00456 dim * num_verts, &new_vertex_handles_out, 00457 &alloc, &junk, &err ); 00458 return (Error)err; 00459 } 00460 00461 inline iMesh::Error 00462 iMesh::createEnt( EntityTopology topology, 00463 const EntityHandle* entities, 00464 int entities_size, 00465 EntityHandle& new_entity_out ) 00466 { 00467 int err, status; 00468 iMesh_createEnt( mInstance, topology, entities, entities_size, &new_entity_out, &status, &err ); 00469 if (err == iBase_SUCCESS) 00470 if (status == iBase_ALREADY_EXISTED || status == iBase_CREATION_FAILED) 00471 err = iBase_ENTITY_CREATION_ERROR; 00472 return (Error)err; 00473 } 00474 00475 inline iMesh::Error 00476 iMesh::createEntArr( EntityTopology new_entity_topology, 00477 const EntityHandle* lower_order_handles, 00478 int lower_order_handles_size, 00479 EntityHandle* new_entity_handles_out ) 00480 { 00481 std::vector<int> status(lower_order_handles_size, iBase_CREATION_FAILED); 00482 int err, alloc = lower_order_handles_size, size = 0; 00483 int status_alloc = status.size(), junk, *stat_ptr = &status[0]; 00484 00485 iMesh_createEntArr( mInstance, new_entity_topology, 00486 lower_order_handles, lower_order_handles_size, 00487 &new_entity_handles_out, &alloc, &size, 00488 &stat_ptr, &status_alloc, &junk, &err ); 00489 00490 if (iBase_SUCCESS == err) { 00491 for (int i = 0; i < size; ++i) 00492 if (status[i] != iBase_NEW && status[i] != iBase_CREATED_DUPLICATE) 00493 err = iBase_ENTITY_CREATION_ERROR; 00494 } 00495 00496 if (iBase_SUCCESS != err) { 00497 int err2, w = 0; 00498 for (int r = 0; r < size; ++r) 00499 if (status[r] == iBase_NEW || status[r] == iBase_CREATED_DUPLICATE) 00500 new_entity_handles_out[w++] = new_entity_handles_out[r]; 00501 iMesh_deleteEntArr( mInstance, new_entity_handles_out, w, &err2 ); 00502 } 00503 00504 return (Error)err; 00505 } 00506 00507 inline iMesh::Error 00508 iMesh::deleteEnt( EntityHandle handle ) 00509 { 00510 int err; 00511 iMesh_deleteEnt( mInstance, handle, &err ); 00512 return (Error)err; 00513 } 00514 00515 inline iMesh::Error 00516 iMesh::deleteEntArr( const EntityHandle* entity_handles, int num_handles ) 00517 { 00518 int err; 00519 iMesh_deleteEntArr( mInstance, entity_handles, num_handles, &err ); 00520 return (Error)err; 00521 } 00522 00523 inline iMesh::Error 00524 iMesh::getAdjEntities( EntitySetHandle set, 00525 EntityType type_requestor, 00526 EntityTopology topo_requestor, 00527 EntityType type_requested, 00528 std::vector<EntityHandle>& adj_entity_handles, 00529 std::vector<int>& offset ) const 00530 { 00531 std::vector<EntityHandle> entities; 00532 Error err = getEntities( set, type_requestor, topo_requestor, entities ); 00533 if (iBase_SUCCESS != err) 00534 return err; 00535 00536 offset.resize( entities.size() + 1 ); 00537 return getEntArrAdj( &entities[0], entities.size(), type_requested, 00538 adj_entity_handles, &offset[0] ); 00539 } 00540 00541 inline iMesh::Error 00542 iMesh::initEntIter( EntitySetHandle set, 00543 EntityType requested_type, 00544 EntityTopology requested_topo, 00545 int resilient, 00546 iMesh::EntIter& iter ) 00547 { 00548 int err; 00549 iter.mInstance = mInstance; 00550 iMesh_initEntIter( mInstance, set, requested_type, requested_topo, resilient, 00551 &iter.mHandle, &err ); 00552 return (Error)err; 00553 } 00554 00555 inline iMesh::Error 00556 iMesh::initEntArrIter( EntitySetHandle set, 00557 EntityType requested_type, 00558 EntityTopology requested_topo, 00559 int requested_array_size, 00560 int resilient, 00561 iMesh::EntArrIter& iter ) 00562 { 00563 int err; 00564 iter.mInstance = mInstance; 00565 iter.mSize = requested_array_size; 00566 iMesh_initEntArrIter( mInstance, set, requested_type, requested_topo, 00567 requested_array_size, resilient, &iter.mHandle, &err ); 00568 return (Error)err; 00569 } 00570 00571 inline 00572 iMesh::EntArrIter::~EntArrIter() 00573 { 00574 int err; 00575 if (mHandle != 0) { 00576 iMesh_endEntArrIter( mInstance, mHandle, &err ); 00577 mHandle = 0; 00578 } 00579 } 00580 00581 inline 00582 iMesh::EntIter::~EntIter() 00583 { 00584 int err; 00585 if (mHandle != 0) { 00586 iMesh_endEntIter( mInstance, mHandle, &err ); 00587 mHandle = 0; 00588 } 00589 } 00590 00591 inline iMesh::Error 00592 iMesh::EntArrIter::getNext( EntityHandle* entity_handles, 00593 int& size_out, 00594 bool& has_more_data_out ) 00595 { 00596 int err, alloc = mSize, has_data; 00597 iMesh_getNextEntArrIter( mInstance, mHandle, &entity_handles, &alloc, 00598 &size_out, &has_data, &err ); 00599 has_more_data_out = (has_data != 0); 00600 return (Error)err; 00601 } 00602 00603 inline iMesh::Error 00604 iMesh::EntIter::getNext( EntityHandle& handle_out, bool& has_more_data_out ) 00605 { 00606 int err, has_data; 00607 iMesh_getNextEntIter( mInstance, mHandle, &handle_out, &has_data, &err ); 00608 has_more_data_out = (has_data != 0); 00609 return (Error)err; 00610 } 00611 00612 inline iMesh::Error 00613 iMesh::EntArrIter::reset() 00614 { 00615 int err; 00616 iMesh_resetEntArrIter( mInstance, mHandle, &err ); 00617 return (Error)err; 00618 } 00619 00620 inline iMesh::Error 00621 iMesh::EntIter::reset() 00622 { 00623 int err; 00624 iMesh_resetEntIter( mInstance, mHandle, &err ); 00625 return (Error)err; 00626 } 00627 00628 inline iMesh::Error 00629 iMesh::getEntTopo( EntityHandle handle, EntityTopology& topo_out ) const 00630 { 00631 int err, result; 00632 iMesh_getEntTopo( mInstance, handle, &result, &err ); 00633 topo_out = (EntityTopology)result; 00634 return (Error)err; 00635 } 00636 00637 inline iMesh::Error 00638 iMesh::getEntArrTopo( const EntityHandle* entity_handles, 00639 int entity_handles_size, 00640 EntityTopology* topos_out ) const 00641 { 00642 int err, alloc = entity_handles_size, junk, *ptr; 00643 std::vector<int> storage; 00644 if (sizeof(EntityTopology) == sizeof(int)) 00645 ptr = reinterpret_cast<int*>(topos_out); 00646 else { 00647 storage.resize( entity_handles_size ); 00648 ptr = &storage[0]; 00649 } 00650 00651 iMesh_getEntArrTopo( mInstance, entity_handles, entity_handles_size, 00652 &ptr, &alloc, &junk, &err ); 00653 00654 if (sizeof(EntityTopology) != sizeof(int)) 00655 for (int i = 0; i < entity_handles_size; ++i) 00656 topos_out[i] = (EntityTopology)storage[i]; 00657 00658 return (Error)err; 00659 } 00660 00661 inline iMesh::Error 00662 iMesh::getEntType( EntityHandle handle, EntityType& type_out ) const 00663 { 00664 int err, result; 00665 iMesh_getEntType( mInstance, handle, &result, &err ); 00666 type_out = (EntityType)result; 00667 return (Error)err; 00668 } 00669 00670 inline iMesh::Error 00671 iMesh::getEntArrType( const EntityHandle* entity_handles, 00672 int entity_handles_size, 00673 EntityType* types_out ) const 00674 { 00675 int err, alloc = entity_handles_size, junk, *ptr; 00676 std::vector<int> storage; 00677 if (sizeof(EntityType) == sizeof(int)) 00678 ptr = reinterpret_cast<int*>(types_out); 00679 else { 00680 storage.resize( entity_handles_size ); 00681 ptr = &storage[0]; 00682 } 00683 00684 iMesh_getEntArrType( mInstance, entity_handles, entity_handles_size, 00685 &ptr, &alloc, &junk, &err ); 00686 00687 if (sizeof(EntityType) != sizeof(int)) 00688 for (int i = 0; i < entity_handles_size; ++i) 00689 types_out[i] = (EntityType)storage[i]; 00690 00691 return (Error)err; 00692 } 00693 00694 inline iMesh::Error 00695 iMesh::getEntAdj( EntityHandle handle, 00696 EntityType type_requested, 00697 std::vector<EntityHandle>& adj_entities_out ) const 00698 { 00699 if (adj_entities_out.capacity() == 0) 00700 adj_entities_out.resize(12); 00701 else 00702 adj_entities_out.resize( adj_entities_out.capacity() ); 00703 00704 int err, alloc = adj_entities_out.size(), size = 0; 00705 EntityHandle* ptr = &adj_entities_out[0]; 00706 iMesh_getEntAdj( mInstance, handle, type_requested, 00707 &ptr, &alloc, &size, &err ); 00708 adj_entities_out.resize(size); 00709 00710 if (iBase_BAD_ARRAY_DIMENSION == err || iBase_BAD_ARRAY_SIZE == err) { 00711 alloc = adj_entities_out.size(); 00712 ptr = &adj_entities_out[0]; 00713 iMesh_getEntAdj( mInstance, handle, type_requested, 00714 &ptr, &alloc, &size, &err ); 00715 } 00716 00717 return (Error)err; 00718 } 00719 00720 inline iMesh::Error 00721 iMesh::getEntArrAdj( const EntityHandle* entity_handles, 00722 int entity_handles_size, 00723 EntityType type_requested, 00724 std::vector<EntityHandle>& adj_entities_out, 00725 int* offsets_out ) const 00726 { 00727 if (adj_entities_out.capacity() == 0) 00728 adj_entities_out.resize(12*entity_handles_size); 00729 else 00730 adj_entities_out.resize( adj_entities_out.capacity() ); 00731 00732 int err, alloc = adj_entities_out.size(), size = 0; 00733 int off_alloc = entity_handles_size+1, junk; 00734 EntityHandle* ptr = &adj_entities_out[0]; 00735 iMesh_getEntArrAdj( mInstance, entity_handles, entity_handles_size, 00736 type_requested, 00737 &ptr, &alloc, &size, 00738 &offsets_out, &off_alloc, &junk, 00739 &err ); 00740 adj_entities_out.resize(size); 00741 00742 if (iBase_BAD_ARRAY_DIMENSION == err || iBase_BAD_ARRAY_SIZE == err) { 00743 alloc = adj_entities_out.size(); 00744 ptr = &adj_entities_out[0]; 00745 iMesh_getEntArrAdj( mInstance, entity_handles, entity_handles_size, 00746 type_requested, 00747 &ptr, &alloc, &size, 00748 &offsets_out, &off_alloc, &junk, 00749 &err ); 00750 } 00751 00752 return (Error)err; 00753 } 00754 00755 00756 inline iMesh::Error 00757 iMesh::getEnt2ndAdj( EntityHandle handle, 00758 EntityType bridge_entity_type, 00759 EntityType type_requested, 00760 std::vector<EntityHandle>& adj_entities_out ) const 00761 { 00762 if (adj_entities_out.capacity() == 0) 00763 adj_entities_out.resize(12); 00764 else 00765 adj_entities_out.resize( adj_entities_out.capacity() ); 00766 00767 int err, alloc = adj_entities_out.size(), size = 0; 00768 EntityHandle* ptr = &adj_entities_out[0]; 00769 iMesh_getEnt2ndAdj( mInstance, handle, bridge_entity_type, type_requested, 00770 &ptr, &alloc, &size, &err ); 00771 adj_entities_out.resize(size); 00772 00773 if (iBase_BAD_ARRAY_DIMENSION == err || iBase_BAD_ARRAY_SIZE == err) { 00774 alloc = adj_entities_out.size(); 00775 ptr = &adj_entities_out[0]; 00776 iMesh_getEnt2ndAdj( mInstance, handle, bridge_entity_type, type_requested, 00777 &ptr, &alloc, &size, &err ); 00778 } 00779 00780 return (Error)err; 00781 } 00782 00783 inline iMesh::Error 00784 iMesh::getEntArr2ndAdj( const EntityHandle* entity_handles, 00785 int entity_handles_size, 00786 EntityType order_key, 00787 EntityType type_requested, 00788 std::vector<EntityHandle>& adj_entities_out, 00789 int* offsets_out ) const 00790 { 00791 if (adj_entities_out.capacity() == 0) 00792 adj_entities_out.resize(12*entity_handles_size); 00793 else 00794 adj_entities_out.resize( adj_entities_out.capacity() ); 00795 00796 int err, alloc = adj_entities_out.size(), size = 0; 00797 int off_alloc = entity_handles_size+1, junk; 00798 EntityHandle* ptr = &adj_entities_out[0]; 00799 iMesh_getEntArr2ndAdj( mInstance, entity_handles, entity_handles_size, 00800 order_key, type_requested, 00801 &ptr, &alloc, &size, 00802 &offsets_out, &off_alloc, &junk, 00803 &err ); 00804 adj_entities_out.resize(size); 00805 00806 if (iBase_BAD_ARRAY_DIMENSION == err || iBase_BAD_ARRAY_SIZE == err) { 00807 alloc = adj_entities_out.size(); 00808 ptr = &adj_entities_out[0]; 00809 iMesh_getEntArr2ndAdj( mInstance, entity_handles, entity_handles_size, 00810 order_key, type_requested, 00811 &ptr, &alloc, &size, 00812 &offsets_out, &off_alloc, &junk, 00813 &err ); 00814 } 00815 00816 return (Error)err; 00817 } 00818 00819 00820 inline iMesh::Error 00821 iMesh::getAdjEntIndices( EntitySetHandle set, 00822 EntityType requestor_type, 00823 EntityTopology requestor_topo, 00824 EntityType type_requested, 00825 std::vector<EntityHandle>& entities_out, 00826 std::vector<EntityHandle>& adj_entities_out, 00827 std::vector<int>& adj_indices_out, 00828 std::vector<int>& offsets_out ) const 00829 { 00830 // if input vects have no allocated space, allocate some so 00831 // we don't accidentally ask the impl to allocate an array 00832 if (entities_out.capacity() == 0) { 00833 Error err2; 00834 int count; 00835 if (requestor_topo == iMesh_ALL_TOPOLOGIES) 00836 err2 = getNumOfType( set, requestor_type, count ); 00837 else 00838 err2 = getNumOfTopo( set, requestor_topo, count ); 00839 if (err2 != iBase_SUCCESS) 00840 return err2; 00841 entities_out.resize( count ); 00842 } 00843 else 00844 entities_out.resize( entities_out.capacity() ); 00845 00846 if (adj_entities_out.capacity() == 0) 00847 adj_entities_out.resize( 12*entities_out.size() ); 00848 else 00849 adj_entities_out.resize( adj_entities_out.capacity() ); 00850 00851 if (adj_indices_out.capacity() == 0) 00852 adj_indices_out.resize( 12*entities_out.size() ); 00853 else 00854 adj_indices_out.resize( adj_indices_out.capacity() ); 00855 00856 if (offsets_out.capacity() == 0) 00857 offsets_out.resize( entities_out.size() + 1 ); 00858 else 00859 offsets_out.resize( offsets_out.capacity() ); 00860 00861 int err; 00862 int entities_size = 0, entities_alloc = entities_out.size(); 00863 int adj_entities_size = 0, adj_entities_alloc = adj_entities_out.size(); 00864 int adj_indices_size = 0, adj_indices_alloc = adj_indices_out.size(); 00865 int offsets_size = 0, offsets_alloc = offsets_out.size(); 00866 EntityHandle* entities_ptr = & entities_out[0]; 00867 EntityHandle* adj_entities_ptr = &adj_entities_out[0]; 00868 int * adj_indices_ptr = & adj_indices_out[0]; 00869 int * offsets_ptr = & offsets_out[0]; 00870 00871 iMesh_getAdjEntIndices( mInstance, 00872 set, requestor_type, requestor_topo, 00873 type_requested, 00874 & entities_ptr, & entities_alloc, & entities_size, 00875 &adj_entities_ptr, &adj_entities_alloc, &adj_entities_size, 00876 & adj_indices_ptr, & adj_indices_alloc, & adj_indices_size, 00877 & offsets_ptr, & offsets_alloc, & offsets_size, 00878 &err ); 00879 00880 entities_out.resize( entities_size ); 00881 adj_entities_out.resize( adj_entities_size ); 00882 adj_indices_out.resize( adj_indices_size ); 00883 offsets_out.resize( offsets_size ); 00884 00885 if (iBase_BAD_ARRAY_DIMENSION == err || iBase_BAD_ARRAY_SIZE == err) { 00886 entities_alloc = entities_out.size(); 00887 adj_entities_alloc = adj_entities_out.size(); 00888 adj_indices_alloc = adj_indices_out.size(); 00889 offsets_alloc = offsets_out.size(); 00890 entities_ptr = & entities_out[0]; 00891 adj_entities_ptr = &adj_entities_out[0]; 00892 adj_indices_ptr = & adj_indices_out[0]; 00893 offsets_ptr = & offsets_out[0]; 00894 00895 iMesh_getAdjEntIndices( mInstance, 00896 set, requestor_type, requestor_topo, 00897 type_requested, 00898 & entities_ptr, & entities_alloc, & entities_size, 00899 &adj_entities_ptr, &adj_entities_alloc, &adj_entities_size, 00900 & adj_indices_ptr, & adj_indices_alloc, & adj_indices_size, 00901 & offsets_ptr, & offsets_alloc, & offsets_size, 00902 &err ); 00903 } 00904 00905 return (Error)err; 00906 } 00907 00908 #endif 00909