MOAB: Mesh Oriented datABase
(version 5.2.1)
|
00001 /* 00002 * This program shows how to get a pointer to tag memory, allowing an application to work 00003 * directly with tag memory instead of calling through the api. 00004 */ 00005 00006 #include "iMesh.h" 00007 #include "iMesh_extensions.h" 00008 #include "stdio.h" 00009 #include "string.h" 00010 00011 #define CHKERR( e, m ) \ 00012 if( iBase_SUCCESS != e ) \ 00013 { \ 00014 printf( m ); \ 00015 return 1; \ 00016 } 00017 00018 int main( int argc, char* argv[] ) 00019 { 00020 iMesh_Instance mesh; 00021 iBase_EntitySetHandle root_set; 00022 int err; 00023 const char* filename; 00024 iBase_EntityArrIterator iter; 00025 iBase_TagHandle tagh; 00026 int count, atend; 00027 double* tag_data; 00028 int num_regions; 00029 00030 if( argc == 2 ) { filename = argv[1]; } 00031 else 00032 { 00033 printf( "Usage: %s <mesh_filename>\n", argv[0] ); 00034 return 0; 00035 } 00036 00037 /* initialize the Mesh */ 00038 iMesh_newMesh( NULL, &mesh, &err, 0 );CHKERR( err, "Failed to create a mesh instance.\n" ); 00039 iMesh_getRootSet( mesh, &root_set, &err );CHKERR( err, "Failed to return a root set.\n" ); 00040 00041 iMesh_load( mesh, root_set, filename, NULL, &err, strlen( filename ), 0 ); 00042 00043 /* get the number of regions in the mesh */ 00044 iMesh_getNumOfType( mesh, root_set, iBase_REGION, &num_regions, &err );CHKERR( err, "Failed to get number of regions." ); 00045 00046 /* get an iterator to all regions in the model */ 00047 iMesh_initEntArrIter( mesh, root_set, iBase_REGION, iMesh_ALL_TOPOLOGIES, num_regions, 0, &iter, &err );CHKERR( err, "Failed to create iterator over regions." ); 00048 00049 /* create a tag to put on the regions */ 00050 iMesh_createTagWithOptions( mesh, "dumtag", "moab:TAG_STORAGE_TYPE=DENSE moab:TAG_DEFAULT_VALUE=0.0", 1, 00051 iBase_DOUBLE, &tagh, &err, 6, 54 );CHKERR( err, "Failed to create a tag.\n" ); 00052 00053 atend = 0; 00054 00055 while( !atend ) 00056 { 00057 00058 /* get a pointer to that tag data; this will allocate tag storage if it isn't allocated yet 00059 */ 00060 iMesh_tagIterate( mesh, tagh, iter, &tag_data, &count, &err );CHKERR( err, "Failed to create a tag.\n" ); 00061 00062 /* step the iterator over count entities */ 00063 iMesh_stepEntArrIter( mesh, iter, count, &atend, &err );CHKERR( err, "Failed to step iterator.\n" ); 00064 00065 /* operate on tag data, or store it for later */ 00066 } 00067 00068 iMesh_dtor( mesh, &err );CHKERR( err, "Failed to destroy iMesh instance.\n" ); 00069 00070 return 0; 00071 }