Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 /** ListSetsNTags: list sets & tags from a mesh 00002 * 00003 * This program shows how to read and list sets and tags from a mesh 00004 * 00005 * Usage: SetsNTags <mesh_file_name> 00006 * 00007 */ 00008 00009 #include <iostream> 00010 #include <cstdlib> 00011 #include <cstring> 00012 #include <vector> 00013 #include "iMesh.h" 00014 00015 #define ERRORR( a ) \ 00016 { \ 00017 if( iBase_SUCCESS != err ) \ 00018 { \ 00019 std::cout << ( a ) << std::endl; \ 00020 return err; \ 00021 } \ 00022 } 00023 00024 int main( int argc, char* argv[] ) 00025 { 00026 const char* filename; 00027 bool read_par = false; 00028 if( argc < 2 || !strcmp( argv[1], "-h" ) ) 00029 { 00030 std::cout << "Usage: " << argv[0] << " <filename> [-p]" << std::endl; 00031 return 0; 00032 } 00033 else 00034 { 00035 // Check command line arg 00036 filename = argv[1]; 00037 00038 if( argc > 2 && !strcmp( argv[2], "-p" ) ) read_par = true; 00039 } 00040 00041 // create the Mesh instance 00042 iMesh_Instance mesh; 00043 int err; 00044 iMesh_newMesh( NULL, &mesh, &err, 0 );ERRORR( "Error creating new mesh.\n" ); 00045 00046 iBase_EntitySetHandle root_set; 00047 iMesh_getRootSet( mesh, &root_set, &err );ERRORR( "Couldn't get root set." ); 00048 00049 // load the mesh 00050 if( read_par ) 00051 { 00052 const char* opt = " moab:PARALLEL=READ_PART moab:PARTITION=PARALLEL_PARTITION moab:PARTITION_DISTRIBUTE " 00053 "moab:PARALLEL_RESOLVE_SHARED_ENTS moab:DEBUG_PIO=2 moab:DEBUG_IO=2 moab:SETS=SETS "; 00054 iMesh_load( mesh, root_set, filename, opt, &err, strlen( filename ), strlen( opt ) ); 00055 } 00056 else 00057 iMesh_load( mesh, root_set, filename, NULL, &err, strlen( filename ), 0 );ERRORR( "Couldn't load mesh." ); 00058 00059 // get all sets 00060 iBase_EntitySetHandle* sets = NULL; 00061 int sets_alloc = 0, sets_size; 00062 iMesh_getEntSets( mesh, root_set, 1, &sets, &sets_alloc, &sets_size, &err );ERRORR( "Couldn't get all sets." ); 00063 00064 // iterate through them, checking whether they have tags 00065 iBase_TagHandle* tags = NULL; 00066 int tags_alloc = 0, tags_size; 00067 int i, j; 00068 for( i = 0; i < sets_size; i++ ) 00069 { 00070 // get connectivity 00071 iMesh_getAllEntSetTags( mesh, sets[i], &tags, &tags_alloc, &tags_size, &err );ERRORR( "Failed to get ent set tags." ); 00072 00073 if( 0 != tags_size ) 00074 { 00075 std::cout << "Set " << sets[i] << "; Tags:" << std::endl; 00076 00077 // list tag names on this set 00078 for( j = 0; j < tags_size; j++ ) 00079 { 00080 char tname[128]; 00081 std::vector< int > int_val; 00082 std::vector< double > dbl_val; 00083 iMesh_getTagName( mesh, tags[j], tname, &err, sizeof( tname ) ); 00084 tname[sizeof( tname ) - 1] = '\0'; 00085 int tag_type, tag_size; 00086 iMesh_getTagType( mesh, tags[j], &tag_type, &err );ERRORR( "Failed to get tag type." ); 00087 iMesh_getTagType( mesh, tags[j], &tag_size, &err );ERRORR( "Failed to get tag size." ); 00088 if( iBase_INTEGER == tag_type ) 00089 { 00090 int_val.resize( tag_size ); 00091 iMesh_getEntSetIntData( mesh, sets[i], tags[j], &int_val[0], &err );ERRORR( "Failed to get int data type." ); 00092 std::cout << tname << " = " << int_val[0]; 00093 if( tag_size > 1 ) 00094 for( int k = 1; k < tag_size; i++ ) 00095 std::cout << ", " << int_val[k]; 00096 std::cout << std::endl; 00097 } 00098 else if( iBase_DOUBLE == tag_type ) 00099 { 00100 dbl_val.resize( tag_size ); 00101 iMesh_getEntSetDblData( mesh, sets[i], tags[j], &dbl_val[0], &err ); 00102 std::cout << tname << " = " << dbl_val[0]; 00103 if( tag_size > 1 ) 00104 for( int k = 1; k < tag_size; i++ ) 00105 std::cout << ", " << dbl_val[k]; 00106 std::cout << std::endl; 00107 } 00108 else 00109 std::cout << tname << " (opaque) " << std::endl; 00110 } 00111 } 00112 std::cout << std::endl; 00113 00114 free( tags ); 00115 tags = NULL; 00116 tags_alloc = 0; 00117 } 00118 00119 free( sets ); 00120 00121 iMesh_dtor( mesh, &err );ERRORR( "Failed to destruct interface." ); 00122 00123 return 0; 00124 }