MOAB: Mesh Oriented datABase  (version 5.4.1)
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

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

Definition at line 12 of file h5legacy.cpp.

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

Referenced by test_moab_v3_poly_format().

{
    int len;
    const EntityHandle* conn;
    ErrorCode rval;
    rval = iface->get_connectivity( pent, conn, len );CHECK_ERR( rval );
    CHECK_EQUAL( 5, len );

    double coords[15];
    rval = iface->get_coords( conn, len, coords );CHECK_ERR( rval );

    for( int d = 0; d < 3; ++d )
    {
        result[d] = 0;
        for( int i = 0; i < 5; ++i )
            result[d] += coords[3 * i + d];
        result[d] /= 5;
    }
}
int main ( )

Definition at line 80 of file h5legacy.cpp.

References RUN_TEST, and test_moab_v3_poly_format().

{
    // only one test so far... should probably add second test
    // for really-old-format  entityset parent/child links
    return RUN_TEST( test_moab_v3_poly_format );
}

Definition at line 32 of file h5legacy.cpp.

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

Referenced by main().

{
    Core moab;
    Interface& mb = moab;
    ErrorCode rval;

    // load file containing a dodecahedron
    rval = mb.load_mesh( std::string( TestDir + "unittest/h5file/v3_dodec.h5m" ).c_str() );CHECK_ERR( rval );

    // get entities from file
    Range verts, faces, polyhedrons;
    rval = mb.get_entities_by_type( 0, MBVERTEX, verts );CHECK_ERR( rval );
    rval = mb.get_entities_by_type( 0, MBPOLYGON, faces );CHECK_ERR( rval );
    rval = mb.get_entities_by_type( 0, MBPOLYHEDRON, polyhedrons );CHECK_ERR( rval );

    // check expected number of entities
    CHECK_EQUAL( (size_t)20, verts.size() );
    CHECK_EQUAL( (size_t)12, faces.size() );
    CHECK_EQUAL( (size_t)1, polyhedrons.size() );
    const EntityHandle polyhedron = polyhedrons.front();

    // check the polyhedron connectivity list
    std::vector< EntityHandle > faces1, faces2;
    std::copy( faces.begin(), faces.end(), std::back_inserter( faces1 ) );
    rval = mb.get_connectivity( &polyhedron, 1, faces2 );CHECK_ERR( rval );
    std::sort( faces2.begin(), faces2.end() );
    CHECK( faces1 == faces2 );

    // each polygonshould have a tag value storing its centroid.
    // compare this value against the centroid calculated from
    // the vertex coords.

    // get tag for saved values
    Tag centroid;
    rval = mb.tag_get_handle( "CENTROID", 3, MB_TYPE_DOUBLE, centroid );CHECK_ERR( rval );

    // for each face...
    for( Range::iterator i = faces.begin(); i != faces.end(); ++i )
    {
        double saved[3], calc[3];
        rval = mb.tag_get_data( centroid, &*i, 1, saved );CHECK_ERR( rval );
        calc_centroid( &mb, *i, calc );
        CHECK_REAL_EQUAL( saved[0], calc[0], 1e-6 );
        CHECK_REAL_EQUAL( saved[1], calc[1], 1e-6 );
        CHECK_REAL_EQUAL( saved[2], calc[2], 1e-6 );
    }
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines