Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TagIterateC.cpp
Go to the documentation of this file.
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  */ 5  6 #include "iMesh.h" 7 #include "iMesh_extensions.h" 8 #include <cstdio> 9 #include <cstring> 10  11 #define CHKERR( e, m ) \ 12  if( iBase_SUCCESS != ( e ) ) \ 13  { \ 14  printf( m ); \ 15  return 1; \ 16  } 17  18 int main( int argc, char* argv[] ) 19 { 20  iMesh_Instance mesh; 21  iBase_EntitySetHandle root_set; 22  int err; 23  const char* filename; 24  iBase_EntityArrIterator iter; 25  iBase_TagHandle tagh; 26  int count, atend; 27  double* tag_data; 28  int num_regions; 29  30  if( argc == 2 ) 31  { 32  filename = argv[1]; 33  } 34  else 35  { 36  printf( "Usage: %s <mesh_filename>\n", argv[0] ); 37  return 0; 38  } 39  40  /* initialize the Mesh */ 41  iMesh_newMesh( NULL, &mesh, &err, 0 );CHKERR( err, "Failed to create a mesh instance.\n" ); 42  iMesh_getRootSet( mesh, &root_set, &err );CHKERR( err, "Failed to return a root set.\n" ); 43  44  iMesh_load( mesh, root_set, filename, NULL, &err, strlen( filename ), 0 ); 45  46  /* get the number of regions in the mesh */ 47  iMesh_getNumOfType( mesh, root_set, iBase_REGION, &num_regions, &err );CHKERR( err, "Failed to get number of regions." ); 48  49  /* get an iterator to all regions in the model */ 50  iMesh_initEntArrIter( mesh, root_set, iBase_REGION, iMesh_ALL_TOPOLOGIES, num_regions, 0, &iter, &err );CHKERR( err, "Failed to create iterator over regions." ); 51  52  /* create a tag to put on the regions */ 53  iMesh_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" ); 55  56  atend = 0; 57  58  while( !atend ) 59  { 60  61  /* get a pointer to that tag data; this will allocate tag storage if it isn't allocated yet 62  */ 63  iMesh_tagIterate( mesh, tagh, iter, &tag_data, &count, &err );CHKERR( err, "Failed to create a tag.\n" ); 64  65  /* step the iterator over count entities */ 66  iMesh_stepEntArrIter( mesh, iter, count, &atend, &err );CHKERR( err, "Failed to step iterator.\n" ); 67  68  /* operate on tag data, or store it for later */ 69  } 70  71  iMesh_dtor( mesh, &err );CHKERR( err, "Failed to destroy iMesh instance.\n" ); 72  73  return 0; 74 }