1 #include "moab/Core.hpp"
2 #include "TestUtil.hpp"
3 #include "moab/Range.hpp"
4
5 #include <algorithm>
6 #include <iostream>
7 #include <stdlib.h>
8 #include <math.h>
9
10 using namespace moab;
11
calc_centroid(Interface * iface,EntityHandle pent,double result[3])12 void calc_centroid( Interface* iface, EntityHandle pent, double result[3] )
13 {
14 int len;
15 const EntityHandle* conn;
16 ErrorCode rval;
17 rval = iface->get_connectivity( pent, conn, len );
18 CHECK_ERR(rval);
19 CHECK_EQUAL( 5, len );
20
21 double coords[15];
22 rval = iface->get_coords( conn, len, coords );
23 CHECK_ERR(rval);
24
25 for (int d = 0; d < 3; ++d) {
26 result[d] = 0;
27 for (int i = 0; i < 5; ++i)
28 result[d] += coords[3*i+d];
29 result[d] /= 5;
30 }
31 }
32
test_moab_v3_poly_format()33 void test_moab_v3_poly_format()
34 {
35 Core moab;
36 Interface& mb = moab;
37 ErrorCode rval;
38
39 // load file containing a dodecahedron
40 rval = mb.load_mesh( std::string( TestDir + "/h5file/v3_dodec.h5m").c_str() );
41 CHECK_ERR(rval);
42
43 // get entities from file
44 Range verts, faces, polyhedrons;
45 rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
46 CHECK_ERR(rval);
47 rval = mb.get_entities_by_type( 0, MBPOLYGON, faces );
48 CHECK_ERR(rval);
49 rval = mb.get_entities_by_type( 0, MBPOLYHEDRON, polyhedrons );
50 CHECK_ERR(rval);
51
52 // check expected number of entities
53 CHECK_EQUAL( (size_t)20, verts.size() );
54 CHECK_EQUAL( (size_t)12, faces.size() );
55 CHECK_EQUAL( (size_t)1, polyhedrons.size() );
56 const EntityHandle polyhedron = polyhedrons.front();
57
58 // check the polyhedron connectivity list
59 std::vector<EntityHandle> faces1, faces2;
60 std::copy( faces.begin(), faces.end(), std::back_inserter(faces1) );
61 rval = mb.get_connectivity( &polyhedron, 1, faces2 );
62 CHECK_ERR(rval);
63 std::sort( faces2.begin(), faces2.end() );
64 CHECK( faces1 == faces2 );
65
66 // each polygonshould have a tag value storing its centroid.
67 // compare this value against the centroid calculated from
68 // the vertex coords.
69
70 // get tag for saved values
71 Tag centroid;
72 rval = mb.tag_get_handle( "CENTROID", 3, MB_TYPE_DOUBLE, centroid );
73 CHECK_ERR(rval);
74
75 // for each face...
76 for (Range::iterator i = faces.begin(); i != faces.end(); ++i) {
77 double saved[3], calc[3];
78 rval = mb.tag_get_data( centroid, &*i, 1, saved );
79 CHECK_ERR(rval);
80 calc_centroid( &mb, *i, calc );
81 CHECK_REAL_EQUAL( saved[0], calc[0], 1e-6 );
82 CHECK_REAL_EQUAL( saved[1], calc[1], 1e-6 );
83 CHECK_REAL_EQUAL( saved[2], calc[2], 1e-6 );
84 }
85 }
86
87
88
89
main()90 int main()
91 {
92 // only one test so far... should probably add second test
93 // for really-old-format entityset parent/child links
94 return RUN_TEST( test_moab_v3_poly_format );
95 }
96
97
98