MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 #include "moab/Core.hpp" 00002 #include "TestUtil.hpp" 00003 #include "moab/Range.hpp" 00004 00005 #include <algorithm> 00006 #include <iostream> 00007 #include <cstdlib> 00008 #include <cmath> 00009 00010 using namespace moab; 00011 00012 void calc_centroid( Interface* iface, EntityHandle pent, double result[3] ) 00013 { 00014 int len; 00015 const EntityHandle* conn; 00016 ErrorCode rval; 00017 rval = iface->get_connectivity( pent, conn, len );CHECK_ERR( rval ); 00018 CHECK_EQUAL( 5, len ); 00019 00020 double coords[15]; 00021 rval = iface->get_coords( conn, len, coords );CHECK_ERR( rval ); 00022 00023 for( int d = 0; d < 3; ++d ) 00024 { 00025 result[d] = 0; 00026 for( int i = 0; i < 5; ++i ) 00027 result[d] += coords[3 * i + d]; 00028 result[d] /= 5; 00029 } 00030 } 00031 00032 void test_moab_v3_poly_format() 00033 { 00034 Core moab; 00035 Interface& mb = moab; 00036 ErrorCode rval; 00037 00038 // load file containing a dodecahedron 00039 rval = mb.load_mesh( std::string( TestDir + "unittest/h5file/v3_dodec.h5m" ).c_str() );CHECK_ERR( rval ); 00040 00041 // get entities from file 00042 Range verts, faces, polyhedrons; 00043 rval = mb.get_entities_by_type( 0, MBVERTEX, verts );CHECK_ERR( rval ); 00044 rval = mb.get_entities_by_type( 0, MBPOLYGON, faces );CHECK_ERR( rval ); 00045 rval = mb.get_entities_by_type( 0, MBPOLYHEDRON, polyhedrons );CHECK_ERR( rval ); 00046 00047 // check expected number of entities 00048 CHECK_EQUAL( (size_t)20, verts.size() ); 00049 CHECK_EQUAL( (size_t)12, faces.size() ); 00050 CHECK_EQUAL( (size_t)1, polyhedrons.size() ); 00051 const EntityHandle polyhedron = polyhedrons.front(); 00052 00053 // check the polyhedron connectivity list 00054 std::vector< EntityHandle > faces1, faces2; 00055 std::copy( faces.begin(), faces.end(), std::back_inserter( faces1 ) ); 00056 rval = mb.get_connectivity( &polyhedron, 1, faces2 );CHECK_ERR( rval ); 00057 std::sort( faces2.begin(), faces2.end() ); 00058 CHECK( faces1 == faces2 ); 00059 00060 // each polygonshould have a tag value storing its centroid. 00061 // compare this value against the centroid calculated from 00062 // the vertex coords. 00063 00064 // get tag for saved values 00065 Tag centroid; 00066 rval = mb.tag_get_handle( "CENTROID", 3, MB_TYPE_DOUBLE, centroid );CHECK_ERR( rval ); 00067 00068 // for each face... 00069 for( Range::iterator i = faces.begin(); i != faces.end(); ++i ) 00070 { 00071 double saved[3], calc[3]; 00072 rval = mb.tag_get_data( centroid, &*i, 1, saved );CHECK_ERR( rval ); 00073 calc_centroid( &mb, *i, calc ); 00074 CHECK_REAL_EQUAL( saved[0], calc[0], 1e-6 ); 00075 CHECK_REAL_EQUAL( saved[1], calc[1], 1e-6 ); 00076 CHECK_REAL_EQUAL( saved[2], calc[2], 1e-6 ); 00077 } 00078 } 00079 00080 int main() 00081 { 00082 // only one test so far... should probably add second test 00083 // for really-old-format entityset parent/child links 00084 return RUN_TEST( test_moab_v3_poly_format ); 00085 }