1/*
2 * This program shows how to get a pointer to tag memory, allowing an application to work
3 * directly with tag memory instead of calling through the api.
4 */56#include"iMesh.h"7#include"iMesh_extensions.h"8#include<cstdio>9#include<cstring>1011#define CHKERR( e, m ) \
12 if( iBase_SUCCESS != ( e ) ) \
13 { \
14 printf( m ); \
15 return 1; \
16 }1718intmain( int argc, char* argv[] )
19 {
20 iMesh_Instance mesh;
21 iBase_EntitySetHandle root_set;
22int err;
23constchar* filename;
24 iBase_EntityArrIterator iter;
25 iBase_TagHandle tagh;
26int count, atend;
27double* tag_data;
28int num_regions;
2930if( argc == 2 )
31 {
32 filename = argv[1];
33 }
34else35 {
36printf( "Usage: %s <mesh_filename>\n", argv[0] );
37return0;
38 }
3940/* initialize the Mesh */41iMesh_newMesh( NULL, &mesh, &err, 0 );CHKERR( err, "Failed to create a mesh instance.\n" );
42iMesh_getRootSet( mesh, &root_set, &err );CHKERR( err, "Failed to return a root set.\n" );
4344iMesh_load( mesh, root_set, filename, NULL, &err, strlen( filename ), 0 );
4546/* get the number of regions in the mesh */47iMesh_getNumOfType( mesh, root_set, iBase_REGION, &num_regions, &err );CHKERR( err, "Failed to get number of regions." );
4849/* get an iterator to all regions in the model */50iMesh_initEntArrIter( mesh, root_set, iBase_REGION, iMesh_ALL_TOPOLOGIES, num_regions, 0, &iter, &err );CHKERR( err, "Failed to create iterator over regions." );
5152/* create a tag to put on the regions */53iMesh_createTagWithOptions( mesh, "dumtag", "moab:TAG_STORAGE_TYPE=DENSE moab:TAG_DEFAULT_VALUE=0.0", 1,
54 iBase_DOUBLE, &tagh, &err, 6, 54 );CHKERR( err, "Failed to create a tag.\n" );
5556 atend = 0;
5758while( !atend )
59 {
6061/* get a pointer to that tag data; this will allocate tag storage if it isn't allocated yet
62 */63iMesh_tagIterate( mesh, tagh, iter, &tag_data, &count, &err );CHKERR( err, "Failed to create a tag.\n" );
6465/* step the iterator over count entities */66iMesh_stepEntArrIter( mesh, iter, count, &atend, &err );CHKERR( err, "Failed to step iterator.\n" );
6768/* operate on tag data, or store it for later */69 }
7071iMesh_dtor( mesh, &err );CHKERR( err, "Failed to destroy iMesh instance.\n" );
7273return0;
74 }