MOAB: Mesh Oriented datABase  (version 5.2.1)
testSmooth2.cpp File Reference
#include "FBiGeom.h"
#include "FBiGeom_MOAB.hpp"
#include "iMesh.h"
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <iterator>
#include <iomanip>
#include <assert.h>
#include <string.h>
#include <math.h>
+ Include dependency graph for testSmooth2.cpp:

Go to the source code of this file.

Classes

class  SimpleArray< T >

Defines

#define CHECK(STR)   if( err != iBase_SUCCESS ) return print_error( STR, err, geom, __FILE__, __LINE__ )
#define STRINGIFY(S)   XSTRINGIFY( S )
#define XSTRINGIFY(S)   #S
#define ARRAY_INOUT(A)   A.ptr(), &A.capacity(), &A.size()
#define ARRAY_IN(A)   &A[0], A.size()

Typedefs

typedef iBase_TagHandle TagHandle
typedef iBase_EntityHandle GentityHandle
typedef iBase_EntitySetHandle GentitysetHandle

Functions

static bool print_error (const char *desc, int err, FBiGeom_Instance geom, const char *file, int line)
void FBiGeom_newGeomFromMesh (iMesh_Instance mesh, iBase_EntitySetHandle set, const char *options, FBiGeom_Instance *geom, int *err, int options_len)
void FBiGeom_dtor2 (FBiGeom_Instance instance, int *err)
bool smooth_test (const std::string &filename, FBiGeom_Instance)
bool tags_test (FBiGeom_Instance geom)
bool tag_get_set_test (FBiGeom_Instance geom)
bool tag_info_test (FBiGeom_Instance geom)
bool gentityset_test (FBiGeom_Instance geom, bool, bool)
bool topology_adjacencies_test (FBiGeom_Instance geom)
bool geometry_evaluation_test (FBiGeom_Instance geom)
bool construct_test (FBiGeom_Instance geom)
bool primitives_test (FBiGeom_Instance geom)
bool transforms_test (FBiGeom_Instance geom)
bool booleans_test (FBiGeom_Instance geom)
bool shutdown_test2 (FBiGeom_Instance geom, std::string &engine_opt)
bool save_entset_test (FBiGeom_Instance geom)
bool mesh_size_test (FBiGeom_Instance geom)
bool normals_test (FBiGeom_Instance geom)
bool ray_test (FBiGeom_Instance geom)
void handle_error_code (const bool result, int &number_failed, int &, int &number_successful)
int main (int argc, char *argv[])
static bool compare_box (const double *expected_min, const double *expected_max, const double *actual_min, const double *actual_max)
static int get_entities (FBiGeom_Instance geom, int entity_type, std::vector< iBase_EntityHandle > &entities_out, iBase_TagHandle id_tag=0, std::vector< int > *ids_out=0)
static int check_firmness (FBiGeom_Instance geom, const std::vector< iBase_EntityHandle > &entities, const std::vector< int > &ids, iBase_TagHandle firmness_tag, const char *expected_value, const char *ent_type_str)
static int count_num_with_tag (FBiGeom_Instance geom, const std::vector< iBase_EntityHandle > &ents, iBase_TagHandle tag)

Define Documentation

#define ARRAY_IN (   A)    &A[0], A.size()

Definition at line 131 of file testSmooth2.cpp.

#define ARRAY_INOUT (   A)    A.ptr(), &A.capacity(), &A.size()

Definition at line 130 of file testSmooth2.cpp.

#define CHECK (   STR)    if( err != iBase_SUCCESS ) return print_error( STR, err, geom, __FILE__, __LINE__ )

Definition at line 27 of file testSmooth2.cpp.

Referenced by main(), and shutdown_test2().

#define STRINGIFY (   S)    XSTRINGIFY( S )

Definition at line 30 of file testSmooth2.cpp.

Referenced by main().

#define XSTRINGIFY (   S)    #S

Definition at line 31 of file testSmooth2.cpp.


Typedef Documentation

Definition at line 48 of file testSmooth2.cpp.

Definition at line 49 of file testSmooth2.cpp.

Definition at line 47 of file testSmooth2.cpp.


Function Documentation

static int check_firmness ( FBiGeom_Instance  geom,
const std::vector< iBase_EntityHandle > &  entities,
const std::vector< int > &  ids,
iBase_TagHandle  firmness_tag,
const char *  expected_value,
const char *  ent_type_str 
) [static]

Definition at line 1443 of file testSmooth2.cpp.

References FBiGeom_getArrData, iBase_FAILURE, and iBase_SUCCESS.

{
    const int firmness_size = 4;
    std::vector< char > firmness( firmness_size * entities.size() );

    char* byte_ptr = &firmness[0];
    int err, junk1 = firmness.size(), junk2 = entities.size() * firmness_size;
    FBiGeom_getArrData( geom, &entities[0], entities.size(), firmness_tag, (void**)&byte_ptr, &junk1, &junk2, &err );
    if( iBase_SUCCESS != err ) return err;

    bool all_correct = true;
    for( unsigned i = 0; i < entities.size(); ++i )
        if( std::string( &firmness[firmness_size * i], firmness_size ) != expected_value ) all_correct = false;
    if( !all_correct )
    {
        std::cout << "ERROR: Expected \"" << expected_value << "\" firmness "
                  << "for all " << ent_type_str << "." << std::endl;
        std::cout << "ID  Actual  " << std::endl;
        for( unsigned i = 0; i < entities.size(); ++i )
            std::cout << std::setw( 2 ) << ids[i] << "  " << std::string( &firmness[firmness_size * i], firmness_size )
                      << std::endl;
        return iBase_FAILURE;
    }

    return iBase_SUCCESS;
}
static bool compare_box ( const double *  expected_min,
const double *  expected_max,
const double *  actual_min,
const double *  actual_max 
) [static]

Definition at line 1237 of file testSmooth2.cpp.

{
    bool same   = true;
    double dtol = 1.0e-6;

    for( int i = 0; i < 3; ++i )
    {
        if( expected_min[i] < actual_min[i] - dtol || expected_min[i] * 10 > actual_min[i] ||
            expected_max[i] > actual_max[i] + dtol || expected_max[i] * 10 < actual_max[i] )
            same = false;
    }
    return same;
}
Test:
TSTTG construct Test
  • Check construction of geometry
static int count_num_with_tag ( FBiGeom_Instance  geom,
const std::vector< iBase_EntityHandle > &  ents,
iBase_TagHandle  tag 
) [static]

Definition at line 1472 of file testSmooth2.cpp.

References FBiGeom_getData, FBiGeom_getTagSizeBytes, iBase_SUCCESS, and iBase_TAG_NOT_FOUND.

{
    int err, bytes;
    FBiGeom_getTagSizeBytes( geom, tag, &bytes, &err );
    if( iBase_SUCCESS != err ) return -1;
    std::vector< char > data( bytes );

    int success_count = 0;
    for( size_t i = 0; i < ents.size(); ++i )
    {
        char* ptr = &data[0];
        int junk1 = bytes, junk2;
        FBiGeom_getData( geom, ents[i], tag, (void**)&ptr, &junk1, &junk2, &err );
        if( iBase_TAG_NOT_FOUND == err ) continue;
        if( iBase_SUCCESS != err ) return -1;
        ++success_count;
    }

    return success_count;
}
void FBiGeom_dtor2 ( FBiGeom_Instance  instance,
int *  err 
)

Definition at line 115 of file FBiGeom_MOAB.cpp.

References FBE_cast(), moab::FBEngine::get_gtt(), and iBase_SUCCESS.

Referenced by shutdown_test2().

{
    moab::FBEngine* fbe = FBE_cast( instance );
    if( fbe )
    {
        moab::GeomTopoTool* gtt = fbe->get_gtt();
        if( gtt ) delete gtt;
        delete fbe;
    }
    MBiGeom** mbigeom = reinterpret_cast< MBiGeom** >( &instance );
    if( *mbigeom ) delete *mbigeom;
    *err = iBase_SUCCESS;
}
void FBiGeom_newGeomFromMesh ( iMesh_Instance  mesh,
iBase_EntitySetHandle  set,
const char *  options,
FBiGeom_Instance geom,
int *  err,
int  options_len 
)

Definition at line 94 of file FBiGeom_MOAB.cpp.

References geom, iBase_SUCCESS, moab::FBEngine::Init(), MBiMesh::mbImpl, and mesh.

Referenced by main().

{
    MBiMesh* mbimesh           = reinterpret_cast< MBiMesh* >( mesh );
    moab::Interface* mbi       = mbimesh->mbImpl;
    moab::EntityHandle rootSet = reinterpret_cast< moab::EntityHandle >( set );
    moab::GeomTopoTool* gtt    = new moab::GeomTopoTool( mbi, true, rootSet );
    bool smooth                = false;  // decide from options
    char smth[]                = "SMOOTH;";
    const char* res            = strstr( options, smth );
    if( res != NULL ) smooth = true;
    moab::FBEngine* fbe = new moab::FBEngine( mbi, gtt, smooth );
    MBiGeom** mbigeom   = reinterpret_cast< MBiGeom** >( geom );
    *mbigeom            = NULL;
    *mbigeom            = new MBiGeom( mbimesh, fbe );
    // will do now the initialization of the engine;
    // heavy duty computation
    fbe->Init();
    *err = iBase_SUCCESS;
}
bool gentityset_test ( FBiGeom_Instance  geom,
bool  ,
bool   
)
Test:
TSTT gentity sets test (just implemented parts for now)
  • Check gentity sets
Test:
FBiGeom_MOAB topology adjacencies Test
  • Check topology information
  • Check adjacency
static int get_entities ( FBiGeom_Instance  geom,
int  entity_type,
std::vector< iBase_EntityHandle > &  entities_out,
iBase_TagHandle  id_tag = 0,
std::vector< int > *  ids_out = 0 
) [static]

Definition at line 1414 of file testSmooth2.cpp.

References FBiGeom_getEntities, FBiGeom_getIntArrData, FBiGeom_getNumOfType, FBiGeom_getRootSet, iBase_SUCCESS, and id_tag.

{
    int err, num;
    iBase_EntitySetHandle root;
    FBiGeom_getRootSet( geom, &root, &err );
    if( iBase_SUCCESS != err ) return err;
    FBiGeom_getNumOfType( geom, root, entity_type, &num, &err );
    if( iBase_SUCCESS != err ) return err;

    entities_out.resize( num );
    int junk1                    = entities_out.size(), junk2;
    iBase_EntityHandle* junk_ptr = &entities_out[0];
    ;
    FBiGeom_getEntities( geom, root, entity_type, &junk_ptr, &junk1, &junk2, &err );
    if( iBase_SUCCESS != err ) return err;
    assert( num == junk1 && num == junk2 );

    if( !ids_out ) return iBase_SUCCESS;

    ids_out->resize( num );
    int* int_ptr = &( *ids_out )[0];
    FBiGeom_getIntArrData( geom, &entities_out[0], num, id_tag, &int_ptr, &junk1, &junk2, &err );
    if( iBase_SUCCESS != err ) return err;
    assert( num == junk1 && num == junk2 );

    return iBase_SUCCESS;
}
void handle_error_code ( const bool  result,
int &  number_failed,
int &  ,
int &  number_successful 
)

Definition at line 152 of file testSmooth2.cpp.

{
    if( result )
    {
        std::cout << "Success";
        number_successful++;
    }
    else
    {
        std::cout << "Failure";
        number_failed++;
    }
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 166 of file testSmooth2.cpp.

References CHECK, FBiGeom_newGeomFromMesh(), filename, geom, geometry_evaluation_test(), handle_error_code(), iBase_SUCCESS, iMesh_createEntSet, iMesh_dtor, iMesh_load, iMesh_newMesh, mesh, normals_test(), number_tests, number_tests_failed, number_tests_successful, ray_test(), root_set, shutdown_test2(), smooth_test(), STRINGIFY, tags_test(), and topology_adjacencies_test().

{
    std::string filename = STRINGIFY( MESHDIR ) "/shell.h5m";

    if( argc == 1 ) { std::cout << "Using default input file: " << filename << std::endl; }
    else if( argc == 2 )
    {
        filename = argv[1];
    }
    else
    {
        std::cerr << "Usage: " << argv[0] << " [geom_filename]" << std::endl;
        return 1;
    }

    int err;
    int number_tests                 = 0;
    int number_tests_successful      = 0;
    int number_tests_not_implemented = 0;
    int number_tests_failed          = 0;

    // initialize the FBiGeom, in a different way
    iMesh_Instance mesh = NULL;
    FBiGeom_Instance geom;
    iMesh_newMesh( NULL, &mesh, &err, 0 );
    if( err != iBase_SUCCESS )
        std::cerr << " Error code: " << err << "  At        : " << __FILE__ << ':' << __LINE__ << std::endl;

    iBase_EntitySetHandle root_set;
    iMesh_createEntSet( mesh, 0, &root_set, &err );
    if( err != iBase_SUCCESS )
        std::cerr << " Error code: " << err << " failed to create a model set"
                  << "  At        : " << __FILE__ << ':' << __LINE__ << std::endl;

    iMesh_load( mesh, root_set, filename.c_str(), NULL, &err, filename.length(), 0 );
    if( err != iBase_SUCCESS )
        std::cerr << " Error code: " << err << " failed load the file"
                  << "  At        : " << __FILE__ << ':' << __LINE__ << std::endl;

    std::string opts( "SMOOTH;" );
    // new constructor
    FBiGeom_newGeomFromMesh( mesh, root_set, opts.c_str(), &geom, &err, opts.length() );

    CHECK( "Interface initialization didn't work properly." );

    // Print out Header information
    std::cout << "\n\nITAPS GEOMETRY INTERFACE TEST PROGRAM:\n\n";
    // gLoad test

    bool result;
    std::cout << "   Smooth faceting load and initialization: \n";
    result = smooth_test( filename, geom );
    handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );

    number_tests++;
    std::cout << "\n";

    // tags test
    std::cout << "   tags: ";
    result = tags_test( geom );
    handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
    number_tests++;
    std::cout << "\n";
    /*
     // gentitysets test
     std::cout << "   gentity sets: ";
     result = gentityset_test(geom, false, false);
     handle_error_code(result, number_tests_failed,
     number_tests_not_implemented,
     number_tests_successful);
     number_tests++;
     std::cout << "\n";
     */
    // topology adjacencies test
    std::cout << "   topology adjacencies: ";
    result = topology_adjacencies_test( geom );
    handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
    number_tests++;
    std::cout << "\n";

    // geometry evaluation test
    std::cout << "   geometry evaluation: \n";
    result = geometry_evaluation_test( geom );
    handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
    number_tests++;
    std::cout << "\n";

    // normals evaluation test
    std::cout << "   normals geometry evaluation: \n";
    result = normals_test( geom );
    handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
    number_tests++;
    std::cout << "\n";

    // ray tracing test
    std::cout << "   ray intersection test: \n";
    result = ray_test( geom );
    handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
    number_tests++;
    std::cout << "\n";
    /*
     // construct test
     std::cout << "   construct: ";
     result = construct_test(geom);
     handle_error_code(result, number_tests_failed,
     number_tests_not_implemented,
     number_tests_successful);
     number_tests++;
     std::cout << "\n";

     // primitives test
     std::cout << "   primitives: ";
     result = primitives_test(geom);
     handle_error_code(result, number_tests_failed,
     number_tests_not_implemented,
     number_tests_successful);
     number_tests++;
     std::cout << "\n";

     // transforms test
     std::cout << "   transforms: ";
     result = transforms_test(geom);
     handle_error_code(result, number_tests_failed,
     number_tests_not_implemented,
     number_tests_successful);
     number_tests++;
     std::cout << "\n";

     // booleans test
     std::cout << "   booleans: ";
     result = booleans_test(geom);
     handle_error_code(result, number_tests_failed,
     number_tests_not_implemented,
     number_tests_successful);
     number_tests++;
     std::cout << "\n";

     #if defined(HAVE_ACIS) && !defined(FORCE_OCC)
     std::cout << "   mesh size: ";
     result = mesh_size_test(geom);
     handle_error_code(result, number_tests_failed,
     number_tests_not_implemented,
     number_tests_successful);
     number_tests++;
     std::cout << "\n";

     // save entset test
     std::cout << "   save entset: ";
     result = save_entset_test(geom);
     handle_error_code(result, number_tests_failed,
     number_tests_not_implemented,
     number_tests_successful);
     number_tests++;
     std::cout << "\n";
     #endif
     */
    // shutdown test
    std::cout << "   shutdown: ";
    std::string engine_opt;
    result = shutdown_test2( geom, engine_opt );
    handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
    number_tests++;
    std::cout << "\n";

    // shutdown imesh instance too
    iMesh_dtor( mesh, &err );
    CHECK( "shutdown imesh error" );
    // summary

    std::cout << "\nTSTT TEST SUMMARY: \n"
              << "   Number Tests:           " << number_tests << "\n"
              << "   Number Successful:      " << number_tests_successful << "\n"
              << "   Number Not Implemented: " << number_tests_not_implemented << "\n"
              << "   Number Failed:          " << number_tests_failed << "\n\n"
              << std::endl;

    return number_tests_failed;
}
static bool print_error ( const char *  desc,
int  err,
FBiGeom_Instance  geom,
const char *  file,
int  line 
) [static]

Definition at line 33 of file testSmooth2.cpp.

References buffer, and FBiGeom_getDescription.

{
    char buffer[1024];
    FBiGeom_getDescription( geom, buffer, sizeof( buffer ) );
    buffer[sizeof( buffer ) - 1] = '\0';

    std::cerr << "ERROR: " << desc << std::endl
              << "  Error code: " << err << std::endl
              << "  Error desc: " << buffer << std::endl
              << "  At        : " << file << ':' << line << std::endl;

    return false;  // must always return false or CHECK macro will break
}
bool ray_test ( FBiGeom_Instance  geom)
bool shutdown_test2 ( FBiGeom_Instance  geom,
std::string &  engine_opt 
)

Definition at line 1595 of file testSmooth2.cpp.

References CHECK, and FBiGeom_dtor2().

Referenced by main().

{
    int err;

    // test shutdown2
    FBiGeom_dtor2( geom, &err );
    CHECK( "Interface destruction didn't work properly." );

    //   FBiGeom_newGeom(engine_opt.c_str(), &geom, &err, engine_opt.length());
    //   CHECK( "Interface re-construction didn't work properly." );
    //
    //   FBiGeom_dtor(geom, &err);
    //   CHECK( "2nd Interface destruction didn't work properly." );

    return true;
}
bool smooth_test ( const std::string &  filename,
FBiGeom_Instance  geom 
)
Test:
Load Mesh
  • Load a mesh file
bool tags_test ( FBiGeom_Instance  geom)
Test:
Test tag creating, reading, writing, deleting
  • Load a mesh file
Test:
TSTTG topology adjacencies Test
  • Check topology information
  • Check adjacency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines