moab
GeomSetHierarchy.cpp
Go to the documentation of this file.
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 
00008 const char *ent_names[] = {"Vertex", "Edge", "Face", "Region"};
00009 
00010 int main(int argc, char **argv) {
00011   if (1 == argc) {
00012     std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
00013     return 0;
00014   }
00015   
00016     // instantiate & load a file
00017   moab::Interface *mb = new moab::Core();
00018   moab::ErrorCode rval = mb->load_file(argv[1]);
00019 
00020     // get the geometric topology tag handle
00021   moab::Tag geom_tag, gid_tag;
00022   rval = mb->tag_get_handle(GEOM_DIMENSION_TAG_NAME, 1, moab::MB_TYPE_INTEGER, geom_tag);
00023   rval = mb->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, moab::MB_TYPE_INTEGER, gid_tag);
00024 
00025     // traverse the model, from dimension 3 downward
00026   moab::Range psets, chsets;
00027   std::vector<moab::EntityHandle> sense_ents;
00028   std::vector<int> senses, pgids;
00029   int dim, pgid, chgid;
00030   void *dim_ptr = &dim;
00031   int sense;
00032 
00033   moab::GeomTopoTool gt(mb, true);
00034   
00035   for (dim = 3; dim >= 0; dim--) {
00036       // get parents at this dimension
00037     chsets.clear();
00038     rval = mb->get_entities_by_type_and_tag(0, MBENTITYSET, 
00039                                             &geom_tag, &dim_ptr, 1, 
00040                                             chsets, 1, false);
00041 
00042       // for each child, get parents and do something with them
00043     moab::Range::iterator ch_it, p_it;
00044     for (ch_it = chsets.begin(); ch_it != chsets.end(); ch_it++) {
00045         // get the children and put in child set list
00046       psets.clear();
00047       rval = mb ->get_parent_meshsets(*ch_it, psets);
00048 
00049       rval = mb->tag_get_data(gid_tag, &(*ch_it), 1, &chgid);
00050       
00051         // print # parents
00052       std::cout << ent_names[dim] << " " << chgid << " has " << psets.size() 
00053                 << " parents." << std::endl;
00054 
00055       if (2 == dim) {
00056         for (p_it = psets.begin(); p_it != psets.end(); p_it++) {
00057           rval = mb->tag_get_data(gid_tag, &(*p_it), 1, &pgid);
00058           rval = gt.get_sense(*ch_it, *p_it, sense);
00059           if (moab::MB_SUCCESS != rval) continue;
00060           std::cout << ent_names[dim+1] << " "   << pgid << ", " 
00061                     << ent_names[dim] << " " << chgid << " sense is: ";
00062           if (1==sense) std::cout << "FORWARD" << std::endl;
00063           else std::cout << "REVERSE" << std::endl;
00064         }
00065       }
00066       else if (1 == dim) {
00067         sense_ents.clear();
00068         senses.clear();
00069         rval = gt.get_senses(*ch_it, sense_ents, senses);
00070         if (moab::MB_SUCCESS != rval) continue;
00071         for (unsigned int i = 0; i < sense_ents.size(); i++) {
00072           rval = mb->tag_get_data(gid_tag, &sense_ents[i], 1, &pgid);
00073           std::cout << ent_names[dim+1] << " "   << pgid << ", " 
00074                     << ent_names[dim] << " " << chgid << " sense is: ";
00075           if (-1 == senses[i]) std::cout << "REVERSED" << std::endl;
00076           else if (0 == senses[i]) std::cout << "BOTH" << std::endl;
00077           else if (1 == senses[i]) std::cout << "FORWARD" << std::endl;
00078           else std::cout << "(invalid)" << std::endl;
00079         }
00080       }
00081     }
00082   }
00083 
00084   delete mb;
00085 
00086   return 0;
00087 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines