MOAB: Mesh Oriented datABase
(version 5.4.1)
|
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 = 0, verts_size = 0; 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, &verts_size, &err ); 00034 CHECK_EQUAL( iBase_SUCCESS, err ); 00035 00036 /* create an entity set with two subranges */ 00037 iMesh_createEntSet( mesh, 0, &entset, &err ); 00038 CHECK_EQUAL( iBase_SUCCESS, err ); 00039 iMesh_addEntArrToSet( mesh, verts, 2, entset, &err ); 00040 CHECK_EQUAL( iBase_SUCCESS, err ); 00041 iMesh_addEntArrToSet( mesh, &verts[3], 3, entset, &err ); 00042 CHECK_EQUAL( iBase_SUCCESS, err ); 00043 00044 /* create a dbl tag and set vertices */ 00045 iBase_TagHandle tagh; 00046 iMesh_createTagWithOptions( mesh, "dum", "moab:TAG_STORAGE_TYPE=DENSE", 1, iBase_DOUBLE, &tagh, &err, 3, 27 ); 00047 CHECK_EQUAL( iBase_SUCCESS, err ); 00048 iMesh_setDblArrData( mesh, verts, 6, tagh, coords + 3, 6, &err ); 00049 CHECK_EQUAL( iBase_SUCCESS, err ); 00050 00051 /* get an iterator over the root set, and check tag iterator for that */ 00052 iBase_EntityArrIterator iter; 00053 int count, atend; 00054 double* data; 00055 iMesh_initEntArrIter( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 6, 0, &iter, &err ); 00056 CHECK_EQUAL( iBase_SUCCESS, err ); 00057 iMesh_tagIterate( mesh, tagh, iter, &data, &count, &err ); 00058 CHECK_EQUAL( iBase_SUCCESS, err ); 00059 if( count != 6 ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00060 00061 for( int i = 0; i < 6; i++ ) 00062 { 00063 if( data[i] != coords[i + 3] ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00064 } 00065 iMesh_endEntArrIter( mesh, iter, &err ); 00066 CHECK_EQUAL( iBase_SUCCESS, err ); 00067 iter = 0; // iMesh_endEntArrIter frees iter 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, 0, &iter, &err ); 00071 CHECK_EQUAL( iBase_SUCCESS, err ); 00072 iMesh_tagIterate( mesh, tagh, iter, &data, &count, &err ); 00073 CHECK_EQUAL( iBase_SUCCESS, err ); 00074 if( count != 2 || data[0] != coords[3] || data[1] != coords[4] ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00075 iMesh_stepEntArrIter( mesh, iter, 2, &atend, &err ); 00076 CHECK_EQUAL( iBase_SUCCESS, err ); 00077 /* shouldn't be at end yet */ 00078 if( atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00079 00080 iMesh_tagIterate( mesh, tagh, iter, &data, &count, &err ); 00081 CHECK_EQUAL( iBase_SUCCESS, err ); 00082 if( count != 3 || data[0] != coords[6] || data[1] != coords[7] ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00083 iMesh_stepEntArrIter( mesh, iter, 3, &atend, &err ); 00084 CHECK_EQUAL( iBase_SUCCESS, err ); 00085 /* should be at end now */ 00086 if( !atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00087 iMesh_endEntArrIter( mesh, iter, &err ); 00088 CHECK_EQUAL( iBase_SUCCESS, err ); 00089 00090 iMesh_dtor( mesh, &err ); 00091 CHECK_EQUAL( iBase_SUCCESS, err ); 00092 00093 free( verts ); 00094 } 00095 00096 void test_step_iter() 00097 { 00098 iMesh_Instance mesh; 00099 int err; 00100 iMesh_newMesh( "", &mesh, &err, 0 ); 00101 CHECK_EQUAL( iBase_SUCCESS, err ); 00102 00103 iBase_EntitySetHandle root_set; 00104 iMesh_getRootSet( mesh, &root_set, &err ); 00105 CHECK_EQUAL( iBase_SUCCESS, err ); 00106 00107 iBase_EntityHandle* verts = 0; 00108 int verts_alloc = 0, verts_size = 0; 00109 double coords[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 }; 00110 iMesh_createVtxArr( mesh, 6, iBase_INTERLEAVED, coords, 18, &verts, &verts_alloc, &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, 0, &iter, &err ); 00117 CHECK_EQUAL( iBase_SUCCESS, err ); 00118 iMesh_stepEntIter( mesh, iter, 2, &atend, &err ); 00119 CHECK_EQUAL( iBase_SUCCESS, err ); 00120 /* shouldn't be at end yet */ 00121 if( atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00122 00123 iMesh_stepEntIter( mesh, iter, 4, &atend, &err ); 00124 CHECK_EQUAL( iBase_SUCCESS, err ); 00125 /* should be at end now */ 00126 if( !atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00127 iMesh_endEntIter( mesh, iter, &err ); 00128 CHECK_EQUAL( iBase_SUCCESS, err ); 00129 00130 /* make an array iterator and test stepping over it */ 00131 iBase_EntityArrIterator arr_iter; 00132 iMesh_initEntArrIter( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 6, 0, &arr_iter, &err ); 00133 CHECK_EQUAL( iBase_SUCCESS, err ); 00134 iMesh_stepEntArrIter( mesh, arr_iter, 2, &atend, &err ); 00135 CHECK_EQUAL( iBase_SUCCESS, err ); 00136 /* shouldn't be at end yet */ 00137 if( atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00138 00139 iMesh_stepEntArrIter( mesh, arr_iter, 4, &atend, &err ); 00140 CHECK_EQUAL( iBase_SUCCESS, err ); 00141 /* should be at end now */ 00142 if( !atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE ); 00143 iMesh_endEntArrIter( mesh, arr_iter, &err ); 00144 CHECK_EQUAL( iBase_SUCCESS, err ); 00145 00146 iMesh_dtor( mesh, &err ); 00147 CHECK_EQUAL( iBase_SUCCESS, err ); 00148 00149 free( verts ); 00150 }