MOAB: Mesh Oriented datABase  (version 5.4.1)
TagIterateC.cpp
Go to the documentation of this file.
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 <cstdio>
00009 #include <cstring>
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 )
00031     {
00032         filename = argv[1];
00033     }
00034     else
00035     {
00036         printf( "Usage: %s <mesh_filename>\n", argv[0] );
00037         return 0;
00038     }
00039 
00040     /* initialize the Mesh */
00041     iMesh_newMesh( NULL, &mesh, &err, 0 );CHKERR( err, "Failed to create a mesh instance.\n" );
00042     iMesh_getRootSet( mesh, &root_set, &err );CHKERR( err, "Failed to return a root set.\n" );
00043 
00044     iMesh_load( mesh, root_set, filename, NULL, &err, strlen( filename ), 0 );
00045 
00046     /* get the number of regions in the mesh */
00047     iMesh_getNumOfType( mesh, root_set, iBase_REGION, &num_regions, &err );CHKERR( err, "Failed to get number of regions." );
00048 
00049     /* get an iterator to all regions in the model */
00050     iMesh_initEntArrIter( mesh, root_set, iBase_REGION, iMesh_ALL_TOPOLOGIES, num_regions, 0, &iter, &err );CHKERR( err, "Failed to create iterator over regions." );
00051 
00052     /* create a tag to put on the regions */
00053     iMesh_createTagWithOptions( mesh, "dumtag", "moab:TAG_STORAGE_TYPE=DENSE moab:TAG_DEFAULT_VALUE=0.0", 1,
00054                                 iBase_DOUBLE, &tagh, &err, 6, 54 );CHKERR( err, "Failed to create a tag.\n" );
00055 
00056     atend = 0;
00057 
00058     while( !atend )
00059     {
00060 
00061         /* get a pointer to that tag data; this will allocate tag storage if it isn't allocated yet
00062          */
00063         iMesh_tagIterate( mesh, tagh, iter, &tag_data, &count, &err );CHKERR( err, "Failed to create a tag.\n" );
00064 
00065         /* step the iterator over count entities */
00066         iMesh_stepEntArrIter( mesh, iter, count, &atend, &err );CHKERR( err, "Failed to step iterator.\n" );
00067 
00068         /* operate on tag data, or store it for later */
00069     }
00070 
00071     iMesh_dtor( mesh, &err );CHKERR( err, "Failed to destroy iMesh instance.\n" );
00072 
00073     return 0;
00074 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines