MOAB: Mesh Oriented datABase  (version 5.5.0)
h5legacy.cpp File Reference
#include "moab/Core.hpp"
#include "TestUtil.hpp"
#include "moab/Range.hpp"
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cmath>
+ Include dependency graph for h5legacy.cpp:

Go to the source code of this file.

Functions

void calc_centroid (Interface *iface, EntityHandle pent, double result[3])
 
void test_moab_v3_poly_format ()
 
int main ()
 

Function Documentation

◆ calc_centroid()

void calc_centroid ( Interface iface,
EntityHandle  pent,
double  result[3] 
)

Definition at line 12 of file h5legacy.cpp.

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 }

References CHECK_EQUAL, CHECK_ERR, ErrorCode, moab::Interface::get_connectivity(), moab::Interface::get_coords(), iface, and pent().

Referenced by test_moab_v3_poly_format().

◆ main()

int main ( )

Definition at line 80 of file h5legacy.cpp.

81 {
82  // only one test so far... should probably add second test
83  // for really-old-format entityset parent/child links
85 }

References RUN_TEST, and test_moab_v3_poly_format().

◆ test_moab_v3_poly_format()

void test_moab_v3_poly_format ( )

Definition at line 32 of file h5legacy.cpp.

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 }

References moab::Range::begin(), calc_centroid(), CHECK, CHECK_EQUAL, CHECK_ERR, CHECK_REAL_EQUAL, moab::Range::end(), ErrorCode, moab::Range::front(), moab::Core::get_connectivity(), moab::Core::get_entities_by_type(), moab::Core::load_mesh(), mb, MB_TYPE_DOUBLE, MBPOLYGON, MBPOLYHEDRON, MBVERTEX, moab::Range::size(), moab::Core::tag_get_data(), and moab::Core::tag_get_handle().

Referenced by main().