Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 #include "moab/Core.hpp" 00002 #include "moab/Range.hpp" 00003 #include "MBCN.hpp" 00004 #include "MBTagConventions.hpp" 00005 #include "moab/GeomTopoTool.hpp" 00006 #include <iostream> 00007 #include <cassert> 00008 00009 const char* ent_names[] = { "Vertex", "Edge", "Face", "Region" }; 00010 00011 int main( int argc, char** argv ) 00012 { 00013 if( 1 == argc ) 00014 { 00015 std::cout << "Usage: " << argv[0] << " <filename>" << std::endl; 00016 return 0; 00017 } 00018 00019 // instantiate & load a file 00020 moab::Interface* mb = new moab::Core(); 00021 moab::ErrorCode rval = mb->load_file( argv[1] ); 00022 assert( moab::MB_SUCCESS == rval ); 00023 00024 // get the geometric topology tag handle 00025 moab::Tag geom_tag, gid_tag; 00026 rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, moab::MB_TYPE_INTEGER, geom_tag ); 00027 assert( moab::MB_SUCCESS == rval ); 00028 gid_tag = mb->globalId_tag(); 00029 assert( NULL != gid_tag ); 00030 00031 // traverse the model, from dimension 3 downward 00032 moab::Range psets, chsets; 00033 std::vector< moab::EntityHandle > sense_ents; 00034 std::vector< int > senses; 00035 int dim, pgid, chgid; 00036 void* dim_ptr = &dim; 00037 int sense; 00038 00039 moab::GeomTopoTool gt( mb, true ); 00040 00041 for( dim = 3; dim >= 0; dim-- ) 00042 { 00043 // get parents at this dimension 00044 chsets.clear(); 00045 rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, &dim_ptr, 1, chsets, 1, false ); 00046 assert( moab::MB_SUCCESS == rval ); 00047 00048 // for each child, get parents and do something with them 00049 moab::Range::iterator ch_it, p_it; 00050 for( ch_it = chsets.begin(); ch_it != chsets.end(); ++ch_it ) 00051 { 00052 // get the children and put in child set list 00053 psets.clear(); 00054 rval = mb->get_parent_meshsets( *ch_it, psets ); 00055 assert( moab::MB_SUCCESS == rval ); 00056 00057 rval = mb->tag_get_data( gid_tag, &( *ch_it ), 1, &chgid ); 00058 assert( moab::MB_SUCCESS == rval ); 00059 00060 // print # parents 00061 std::cout << ent_names[dim] << " " << chgid << " has " << psets.size() << " parents." << std::endl; 00062 00063 if( 2 == dim ) 00064 { 00065 for( p_it = psets.begin(); p_it != psets.end(); ++p_it ) 00066 { 00067 rval = mb->tag_get_data( gid_tag, &( *p_it ), 1, &pgid ); 00068 assert( moab::MB_SUCCESS == rval ); 00069 rval = gt.get_sense( *ch_it, *p_it, sense ); 00070 if( moab::MB_SUCCESS != rval ) continue; 00071 std::cout << ent_names[dim + 1] << " " << pgid << ", " << ent_names[dim] << " " << chgid 00072 << " sense is: "; 00073 if( 1 == sense ) 00074 std::cout << "FORWARD" << std::endl; 00075 else 00076 std::cout << "REVERSE" << std::endl; 00077 } 00078 } 00079 else if( 1 == dim ) 00080 { 00081 sense_ents.clear(); 00082 senses.clear(); 00083 rval = gt.get_senses( *ch_it, sense_ents, senses ); 00084 if( moab::MB_SUCCESS != rval ) continue; 00085 for( unsigned int i = 0; i < sense_ents.size(); i++ ) 00086 { 00087 rval = mb->tag_get_data( gid_tag, &sense_ents[i], 1, &pgid ); 00088 assert( moab::MB_SUCCESS == rval ); 00089 std::cout << ent_names[dim + 1] << " " << pgid << ", " << ent_names[dim] << " " << chgid 00090 << " sense is: "; 00091 if( -1 == senses[i] ) 00092 std::cout << "REVERSED" << std::endl; 00093 else if( 0 == senses[i] ) 00094 std::cout << "BOTH" << std::endl; 00095 else if( 1 == senses[i] ) 00096 std::cout << "FORWARD" << std::endl; 00097 else 00098 std::cout << "(invalid)" << std::endl; 00099 } 00100 } 00101 } 00102 } 00103 00104 delete mb; 00105 00106 return 0; 00107 }