MeshKit
1.0
|
00001 //** \file test_imesh.cpp 00002 00003 #include "meshkit/MKCore.hpp" 00004 #include <stdlib.h> 00005 00006 using namespace MeshKit; 00007 00008 #include "TestUtil.hpp" 00009 00010 MKCore *mk; 00011 00012 void test_Adj(); 00013 void test_setAdjTable(); 00014 00015 00016 int main(int argc, char **argv) 00017 { 00018 00019 00020 mk = new MKCore(); 00021 int num_fail = 0; 00022 #ifdef HAVE_MOAB 00023 num_fail+= RUN_TEST(test_Adj); 00024 num_fail+= RUN_TEST(test_setAdjTable); 00025 #endif 00026 return num_fail; 00027 } 00028 00029 void test_Adj() 00030 { 00031 00032 //create a new tet in the mesh 00033 iMesh::EntityHandle v1, v2, v3, v4; 00034 00035 //setup the adjacency table values such that intermediate dimension entities are created 00036 int table_vals[16] = { 1, 0, 0, 0, 00037 0, 1, 0, 0, 00038 0, 0, 1, 0, 00039 0, 0, 0, 0}; 00040 int table_size = 16; 00041 mk->imesh_instance()->setAdjTable( table_vals, table_size ); 00042 00043 00044 //create the vertices 00045 mk->imesh_instance()->createVtx( 0, 0, 0, v1); 00046 mk->imesh_instance()->createVtx( 1, 0, 0, v2); 00047 mk->imesh_instance()->createVtx( 0, 1, 0, v3); 00048 mk->imesh_instance()->createVtx( 0, 0, 1, v4); 00049 00050 std::vector<iMesh::EntityHandle> tet_tris(4); 00051 //generate the triangles using the proper vertices 00052 iMesh::EntityHandle verts[] = {v1, v2, v3, 00053 v2, v3, v4, 00054 v3, v4, v1, 00055 v1, v3, v4}; 00056 mk->imesh_instance()->createEntArr( iMesh_TRIANGLE, verts, 12, &tet_tris[0]); 00057 00058 00059 //get all of the triangles in the model 00060 std::vector<iMesh::EntityHandle> tris; 00061 mk->imesh_instance()->getEntities( 0, iBase_FACE, iMesh_TRIANGLE, tris); 00062 00063 //make sure we get the correct number of triangles 00064 int expected_num_of_tris = 4; 00065 CHECK( expected_num_of_tris == int(tris.size())); 00066 00067 //now start checking the adjacencies 00068 int expected_num_of_adj = 3; 00069 00070 //check first adj 00071 std::vector<iMesh::EntityHandle>::iterator i; 00072 for( i = tris.begin(); i != tris.end(); i++) 00073 { 00074 00075 //each triangle should be adjacent to three vertices and three edges 00076 std::vector<iMesh::EntityHandle> adj; 00077 mk->imesh_instance()->getEntAdj( *i, iBase_VERTEX, adj); 00078 CHECK( expected_num_of_adj == int(adj.size()) ); 00079 00080 adj.clear(); 00081 mk->imesh_instance()->getEntAdj( *i, iBase_EDGE, adj); 00082 CHECK( expected_num_of_adj == int(adj.size()) ); 00083 00084 } 00085 00086 //check 2nd adj 00087 for( i = tris.begin(); i != tris.end(); i++) 00088 { 00089 std::vector<iMesh::EntityHandle> adj; 00090 //each triangle should be adjacent to three other triangles via the edges 00091 adj.clear(); 00092 mk->imesh_instance()->getEnt2ndAdj( *i, iBase_EDGE, iBase_FACE, adj); 00093 00094 //make sure these are all triangles 00095 std::vector<iMesh::EntityHandle>::iterator j; 00096 for( j = adj.begin(); j != adj.end(); j++) 00097 { 00098 iMesh::EntityTopology topo; 00099 mk->imesh_instance()->getEntTopo( *j, topo); 00100 CHECK( iMesh_TRIANGLE == topo ); 00101 } 00102 00103 CHECK( expected_num_of_adj == int(adj.size()) ); 00104 00105 } 00106 00107 } 00108 00109 void test_setAdjTable() 00110 { 00111 00112 00113 //setup the test adjacency table 00114 int table_vals[16] = { 1, 1, 1, 1, 00115 1, 1, 1, 1, 00116 1, 1, 1, 1, 00117 1, 1, 1, 1}; 00118 int table_size = 16; 00119 00120 //set the adjacency table for the iMesh instance 00121 mk->imesh_instance()->setAdjTable( table_vals, table_size ); 00122 00123 //get the adjacancy table back and make sure all the values are non-zero 00124 iMesh::AdjTableType adjTable = mk->imesh_instance()->getAdjTable(); 00125 00126 for( unsigned int i = 0; i < 4; i++) 00127 for(unsigned int j = 0; j < 4; j++) 00128 { 00129 { 00130 if( i == j ) CHECK( iBase_AVAILABLE == adjTable[i][j] ); 00131 else CHECK( iBase_ALL_ORDER_1 == adjTable[i][j] ); 00132 } 00133 } 00134 00135 00136 } 00137 00138