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