MOAB: Mesh Oriented datABase  (version 5.4.1)
GetEntities.cpp
Go to the documentation of this file.
00001 /** @example GetEntities.cpp
00002  * Description: Get entities and report non-vertex entity connectivity and vertex adjacencies.\n
00003  * This example shows how to get connectivity and adjacencies.\n
00004  *
00005  * To run: ./GetEntities [meshfile]\n
00006  * (default values can run if users don't specify a mesh file)
00007  */
00008 
00009 #include "moab/Core.hpp"
00010 #include "moab/Range.hpp"
00011 #include "moab/CN.hpp"
00012 #include <iostream>
00013 
00014 using namespace moab;
00015 using namespace std;
00016 
00017 #ifndef MESH_DIR
00018 #define MESH_DIR "."
00019 #endif
00020 
00021 string test_file_name = string( MESH_DIR ) + string( "/hex01.vtk" );
00022 
00023 int main( int argc, char** argv )
00024 {
00025     if( argc > 1 )
00026     {
00027         // User has input a mesh file
00028         test_file_name = argv[1];
00029     }
00030 
00031     // Instantiate & load a mesh from a file
00032     Core* mb = new( std::nothrow ) Core;
00033     if( NULL == mb ) return 1;
00034     ErrorCode rval = mb->load_mesh( test_file_name.c_str() );MB_CHK_ERR( rval );
00035 
00036     Range ents;
00037 
00038     // Get all entities in the database
00039     rval = mb->get_entities_by_handle( 0, ents );MB_CHK_ERR( rval );
00040 
00041     for( Range::iterator it = ents.begin(); it != ents.end(); ++it )
00042     {
00043         if( MBVERTEX == mb->type_from_handle( *it ) )
00044         {
00045             Range adjs;
00046             rval = mb->get_adjacencies( &( *it ), 1, 3, false, adjs );MB_CHK_ERR( rval );
00047             cout << "Vertex " << mb->id_from_handle( *it ) << " adjacencies:" << endl;
00048             adjs.print();
00049         }
00050         else if( mb->type_from_handle( *it ) < MBENTITYSET )
00051         {
00052             const EntityHandle* connect;
00053             int num_connect;
00054             rval = mb->get_connectivity( *it, connect, num_connect );MB_CHK_ERR( rval );
00055             cout << CN::EntityTypeName( mb->type_from_handle( *it ) ) << " " << mb->id_from_handle( *it )
00056                  << " vertex connectivity is: ";
00057             for( int i = 0; i < num_connect; i++ )
00058                 cout << mb->id_from_handle( connect[i] ) << " ";
00059             cout << endl;
00060         }
00061     }
00062 
00063     delete mb;
00064 
00065     return 0;
00066 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines