1 /** @example GetEntities.cpp 2 * Description: Get entities and report non-vertex entity connectivity and vertex adjacencies.\n 3 * This example shows how to get connectivity and adjacencies.\n 4 * 5 * To run: ./GetEntities [meshfile]\n 6 * (default values can run if users don't specify a mesh file) 7 */ 8 9 #include "moab/Core.hpp" 10 #include "moab/Range.hpp" 11 #include "moab/CN.hpp" 12 #include <iostream> 13 14 using namespace moab; 15 using namespace std; 16 17 #ifndef MESH_DIR 18 #define MESH_DIR "." 19 #endif 20 21 string test_file_name = string(MESH_DIR) + string("/hex01.vtk"); 22 main(int argc,char ** argv)23int main(int argc, char **argv) 24 { 25 if (argc > 1) { 26 // User has input a mesh file 27 test_file_name = argv[1]; 28 } 29 30 // Instantiate & load a mesh from a file 31 Core* mb = new (std::nothrow) Core; 32 if (NULL == mb) 33 return 1; 34 ErrorCode rval = mb->load_mesh(test_file_name.c_str());MB_CHK_ERR(rval); 35 36 Range ents; 37 38 // Get all entities in the database 39 rval = mb->get_entities_by_handle(0, ents);MB_CHK_ERR(rval); 40 41 for (Range::iterator it = ents.begin(); it != ents.end(); ++it) { 42 if (MBVERTEX == mb->type_from_handle(*it)) { 43 Range adjs; 44 rval = mb->get_adjacencies(&(*it), 1, 3, false, adjs);MB_CHK_ERR(rval); 45 cout << "Vertex " << mb->id_from_handle(*it) << " adjacencies:" << endl; 46 adjs.print(); 47 } 48 else if (mb->type_from_handle(*it) < MBENTITYSET) { 49 const EntityHandle *connect; 50 int num_connect; 51 rval = mb->get_connectivity(*it, connect, num_connect);MB_CHK_ERR(rval); 52 cout << CN::EntityTypeName(mb->type_from_handle(*it)) << " " << mb->id_from_handle(*it) 53 << " vertex connectivity is: "; 54 for (int i = 0; i < num_connect; i++) 55 cout << mb->id_from_handle(connect[i]) << " "; 56 cout << endl; 57 } 58 } 59 60 delete mb; 61 62 return 0; 63 } 64