moab
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 "stdio.h"
00009 #include "string.h"
00010 
00011 #define CHKERR(e, m) if (iBase_SUCCESS != e) {printf(m); return 1;}
00012     
00013 int main( int argc, char *argv[] )
00014 {
00015   iMesh_Instance mesh;
00016   iBase_EntitySetHandle root_set;
00017   int err;
00018   const char *filename;
00019   iBase_EntityArrIterator iter;
00020   iBase_TagHandle tagh;
00021   int count, atend;
00022   double *tag_data;
00023   int num_regions;
00024 
00025   if (argc == 2) {
00026     filename = argv[1];
00027   }
00028   else {
00029     printf("Usage: %s <mesh_filename>\n", argv[0]);
00030     return 0;
00031   }
00032 
00033     /* initialize the Mesh */
00034   iMesh_newMesh(NULL, &mesh, &err, 0);
00035   CHKERR(err, "Failed to create a mesh instance.\n");
00036   iMesh_getRootSet(mesh, &root_set, &err);
00037   CHKERR(err, "Failed to return a root set.\n");
00038 
00039   iMesh_load(mesh, root_set, filename, NULL, &err, strlen(filename), 0);
00040 
00041     /* get the number of regions in the mesh */
00042   iMesh_getNumOfType(mesh, root_set, iBase_REGION, &num_regions, &err);
00043   CHKERR(err, "Failed to get number of regions.");
00044   
00045     /* get an iterator to all regions in the model */
00046   iMesh_initEntArrIter( mesh, root_set, iBase_REGION, iMesh_ALL_TOPOLOGIES, num_regions, 0, &iter, &err );
00047   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, iBase_DOUBLE, &tagh, &err, 6, 54);
00051   CHKERR(err, "Failed to create a tag.\n");
00052   
00053   atend = 0;
00054   
00055   while (!atend) {
00056     
00057       /* get a pointer to that tag data; this will allocate tag storage if it isn't allocated yet */
00058     iMesh_tagIterate(mesh, tagh, iter, &tag_data, &count, &err);
00059     CHKERR(err, "Failed to create a tag.\n");
00060     
00061       /* step the iterator over count entities */
00062     iMesh_stepEntArrIter(mesh, iter, count, &atend, &err);
00063     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);
00069   CHKERR(err, "Failed to destroy iMesh instance.\n");
00070 
00071   return 0;
00072 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines