moab
|
00001 #include "TestRunner.hpp" 00002 #include "iMesh.h" 00003 #include "iMesh_extensions.h" 00004 #include "MBiMesh.hpp" 00005 #include "moab/Core.hpp" 00006 #include <algorithm> 00007 00008 void test_tag_iterate(); 00009 void test_step_iter(); 00010 00011 int main( int argc, char* argv[] ) 00012 { 00013 REGISTER_TEST( test_tag_iterate ); 00014 REGISTER_TEST( test_step_iter ); 00015 00016 return RUN_TESTS( argc, argv ); 00017 } 00018 00019 void test_tag_iterate() 00020 { 00021 iMesh_Instance mesh; 00022 int err; 00023 iMesh_newMesh("", &mesh, &err, 0); 00024 CHECK_EQUAL( iBase_SUCCESS, err ); 00025 00026 iBase_EntitySetHandle root_set, entset; 00027 iMesh_getRootSet(mesh, &root_set, &err); 00028 CHECK_EQUAL( iBase_SUCCESS, err ); 00029 00030 iBase_EntityHandle *verts = 0; 00031 int verts_alloc, verts_size; 00032 double coords[] = { 0,0,0, 1,1,1, 2,2,2, 3,3,3, 4,4,4, 5,5,5 }; 00033 iMesh_createVtxArr(mesh,6,iBase_INTERLEAVED,coords,18,&verts,&verts_alloc, 00034 &verts_size,&err); 00035 CHECK_EQUAL( iBase_SUCCESS, err ); 00036 00037 /* create an entity set with two subranges */ 00038 iMesh_createEntSet( mesh, 0, &entset, &err ); 00039 CHECK_EQUAL( iBase_SUCCESS, err ); 00040 iMesh_addEntArrToSet( mesh, verts, 2, entset, &err ); 00041 CHECK_EQUAL( iBase_SUCCESS, err ); 00042 iMesh_addEntArrToSet( mesh, &verts[3], 3, entset, &err ); 00043 CHECK_EQUAL( iBase_SUCCESS, err ); 00044 00045 /* create a dbl tag and set vertices */ 00046 iBase_TagHandle tagh; 00047 iMesh_createTagWithOptions(mesh, "dum", "moab:TAG_STORAGE_TYPE=DENSE", 1, iBase_DOUBLE, &tagh, &err, 3, 27); 00048 CHECK_EQUAL( iBase_SUCCESS, err ); 00049 iMesh_setDblArrData(mesh, verts, 6, tagh, coords+3, 6, &err); 00050 CHECK_EQUAL( iBase_SUCCESS, err ); 00051 00052 /* get an iterator over the root set, and check tag iterator for that */ 00053 iBase_EntityArrIterator iter; 00054 int count, atend; 00055 double *data; 00056 iMesh_initEntArrIter( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 00057 6, 0, &iter, &err ); 00058 CHECK_EQUAL( iBase_SUCCESS, err ); 00059 iMesh_tagIterate(mesh, tagh, iter, &data, &count, &err); 00060 CHECK_EQUAL( iBase_SUCCESS, err ); 00061 if (count != 6) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00062 00063 for (int i = 0; i < 6; i++) { 00064 if (data[i] != coords[i+3]) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00065 } 00066 iMesh_endEntArrIter(mesh, iter, &err); 00067 CHECK_EQUAL( iBase_SUCCESS, err ); 00068 00069 /* get an iterator over the set with two subranges, and check tag iterator for that */ 00070 iMesh_initEntArrIter( mesh, entset, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 6, 00071 0, &iter, &err ); 00072 CHECK_EQUAL( iBase_SUCCESS, err ); 00073 iMesh_tagIterate(mesh, tagh, iter, &data, &count, &err); 00074 CHECK_EQUAL( iBase_SUCCESS, err ); 00075 if (count != 2 || data[0] != coords[3] || data[1] != coords[4]) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00076 iMesh_stepEntArrIter(mesh, iter, 2, &atend, &err); 00077 CHECK_EQUAL( iBase_SUCCESS, err ); 00078 /* shouldn't be at end yet */ 00079 if (atend) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00080 00081 iMesh_tagIterate(mesh, tagh, iter, &data, &count, &err); 00082 CHECK_EQUAL( iBase_SUCCESS, err ); 00083 if (count != 3 || data[0] != coords[6] || data[1] != coords[7]) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00084 iMesh_stepEntArrIter(mesh, iter, 3, &atend, &err); 00085 CHECK_EQUAL( iBase_SUCCESS, err ); 00086 /* should be at end now */ 00087 if (!atend) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00088 iMesh_endEntArrIter(mesh, iter, &err); 00089 CHECK_EQUAL( iBase_SUCCESS, err ); 00090 00091 iMesh_dtor(mesh,&err); 00092 CHECK_EQUAL( iBase_SUCCESS, err ); 00093 } 00094 00095 void test_step_iter() 00096 { 00097 iMesh_Instance mesh; 00098 int err; 00099 iMesh_newMesh("", &mesh, &err, 0); 00100 CHECK_EQUAL( iBase_SUCCESS, err ); 00101 00102 iBase_EntitySetHandle root_set; 00103 iMesh_getRootSet(mesh, &root_set, &err); 00104 CHECK_EQUAL( iBase_SUCCESS, err ); 00105 00106 iBase_EntityHandle *verts = 0; 00107 int verts_alloc, verts_size; 00108 double coords[] = { 0,0,0, 1,1,1, 2,2,2, 3,3,3, 4,4,4, 5,5,5 }; 00109 iMesh_createVtxArr(mesh,6,iBase_INTERLEAVED,coords,18,&verts,&verts_alloc, 00110 &verts_size,&err); 00111 CHECK_EQUAL( iBase_SUCCESS, err ); 00112 00113 /* make a non-array iterator and test stepping over it */ 00114 iBase_EntityIterator iter; 00115 int atend; 00116 iMesh_initEntIter( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 00117 0, &iter, &err ); 00118 CHECK_EQUAL( iBase_SUCCESS, err ); 00119 iMesh_stepEntIter(mesh, iter, 2, &atend, &err); 00120 CHECK_EQUAL( iBase_SUCCESS, err ); 00121 /* shouldn't be at end yet */ 00122 if (atend) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00123 00124 iMesh_stepEntIter(mesh, iter, 4, &atend, &err); 00125 CHECK_EQUAL( iBase_SUCCESS, err ); 00126 /* should be at end now */ 00127 if (!atend) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00128 iMesh_endEntIter(mesh, iter, &err); 00129 CHECK_EQUAL( iBase_SUCCESS, err ); 00130 00131 /* make an array iterator and test stepping over it */ 00132 iBase_EntityArrIterator arr_iter; 00133 iMesh_initEntArrIter( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 00134 6, 0, &arr_iter, &err ); 00135 CHECK_EQUAL( iBase_SUCCESS, err ); 00136 iMesh_stepEntArrIter(mesh, arr_iter, 2, &atend, &err); 00137 CHECK_EQUAL( iBase_SUCCESS, err ); 00138 /* shouldn't be at end yet */ 00139 if (atend) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00140 00141 iMesh_stepEntArrIter(mesh, arr_iter, 4, &atend, &err); 00142 CHECK_EQUAL( iBase_SUCCESS, err ); 00143 /* should be at end now */ 00144 if (!atend) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00145 iMesh_endEntArrIter(mesh, arr_iter, &err); 00146 CHECK_EQUAL( iBase_SUCCESS, err ); 00147 00148 iMesh_dtor(mesh,&err); 00149 CHECK_EQUAL( iBase_SUCCESS, err ); 00150 }