Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
GeomSetHierarchy.cpp
Go to the documentation of this file.
1 #include "moab/Core.hpp"
2 #include "moab/Range.hpp"
3 #include "MBCN.hpp"
4 #include "MBTagConventions.hpp"
5 #include "moab/GeomTopoTool.hpp"
6 #include <iostream>
7 #include <cassert>
8 
9 const char* ent_names[] = { "Vertex", "Edge", "Face", "Region" };
10 
11 int main( int argc, char** argv )
12 {
13  if( 1 == argc )
14  {
15  std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
16  return 0;
17  }
18 
19  // instantiate & load a file
20  moab::Interface* mb = new moab::Core();
21  moab::ErrorCode rval = mb->load_file( argv[1] );
22  assert( moab::MB_SUCCESS == rval );
23 
24  // get the geometric topology tag handle
25  moab::Tag geom_tag, gid_tag;
26  rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, moab::MB_TYPE_INTEGER, geom_tag );
27  assert( moab::MB_SUCCESS == rval );
28  gid_tag = mb->globalId_tag();
29  assert( NULL != gid_tag );
30 
31  // traverse the model, from dimension 3 downward
32  moab::Range psets, chsets;
33  std::vector< moab::EntityHandle > sense_ents;
34  std::vector< int > senses;
35  int dim, pgid, chgid;
36  void* dim_ptr = &dim;
37  int sense;
38 
39  moab::GeomTopoTool gt( mb, true );
40 
41  for( dim = 3; dim >= 0; dim-- )
42  {
43  // get parents at this dimension
44  chsets.clear();
45  rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, &dim_ptr, 1, chsets, 1, false );
46  assert( moab::MB_SUCCESS == rval );
47 
48  // for each child, get parents and do something with them
49  moab::Range::iterator ch_it, p_it;
50  for( ch_it = chsets.begin(); ch_it != chsets.end(); ++ch_it )
51  {
52  // get the children and put in child set list
53  psets.clear();
54  rval = mb->get_parent_meshsets( *ch_it, psets );
55  assert( moab::MB_SUCCESS == rval );
56 
57  rval = mb->tag_get_data( gid_tag, &( *ch_it ), 1, &chgid );
58  assert( moab::MB_SUCCESS == rval );
59 
60  // print # parents
61  std::cout << ent_names[dim] << " " << chgid << " has " << psets.size() << " parents." << std::endl;
62 
63  if( 2 == dim )
64  {
65  for( p_it = psets.begin(); p_it != psets.end(); ++p_it )
66  {
67  rval = mb->tag_get_data( gid_tag, &( *p_it ), 1, &pgid );
68  assert( moab::MB_SUCCESS == rval );
69  rval = gt.get_sense( *ch_it, *p_it, sense );
70  if( moab::MB_SUCCESS != rval ) continue;
71  std::cout << ent_names[dim + 1] << " " << pgid << ", " << ent_names[dim] << " " << chgid
72  << " sense is: ";
73  if( 1 == sense )
74  std::cout << "FORWARD" << std::endl;
75  else
76  std::cout << "REVERSE" << std::endl;
77  }
78  }
79  else if( 1 == dim )
80  {
81  sense_ents.clear();
82  senses.clear();
83  rval = gt.get_senses( *ch_it, sense_ents, senses );
84  if( moab::MB_SUCCESS != rval ) continue;
85  for( unsigned int i = 0; i < sense_ents.size(); i++ )
86  {
87  rval = mb->tag_get_data( gid_tag, &sense_ents[i], 1, &pgid );
88  assert( moab::MB_SUCCESS == rval );
89  std::cout << ent_names[dim + 1] << " " << pgid << ", " << ent_names[dim] << " " << chgid
90  << " sense is: ";
91  if( -1 == senses[i] )
92  std::cout << "REVERSED" << std::endl;
93  else if( 0 == senses[i] )
94  std::cout << "BOTH" << std::endl;
95  else if( 1 == senses[i] )
96  std::cout << "FORWARD" << std::endl;
97  else
98  std::cout << "(invalid)" << std::endl;
99  }
100  }
101  }
102  }
103 
104  delete mb;
105 
106  return 0;
107 }