MOAB: Mesh Oriented datABase
(version 5.4.1)
|
#include "FBiGeom.h"
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <iterator>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <cmath>
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) |
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_test (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) |
Definition at line 125 of file testSmooth.cpp.
#define ARRAY_INOUT | ( | A | ) | A.ptr(), &( A ).capacity(), &( A ).size() |
Definition at line 124 of file testSmooth.cpp.
Referenced by normals_test(), and ray_test().
#define CHECK | ( | STR | ) | if( err != iBase_SUCCESS ) return print_error( STR, err, geom, __FILE__, __LINE__ ) |
Definition at line 25 of file testSmooth.cpp.
Referenced by main(), normals_test(), ray_test(), and smooth_test().
#define STRINGIFY | ( | S | ) | XSTRINGIFY( S ) |
Definition at line 28 of file testSmooth.cpp.
Referenced by main().
#define XSTRINGIFY | ( | S | ) | #S |
Definition at line 29 of file testSmooth.cpp.
typedef iBase_EntityHandle GentityHandle |
Definition at line 46 of file testSmooth.cpp.
Definition at line 47 of file testSmooth.cpp.
typedef iBase_TagHandle TagHandle |
Definition at line 45 of file testSmooth.cpp.
bool booleans_test | ( | FBiGeom_Instance | geom | ) |
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 1423 of file testSmooth.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 1212 of file testSmooth.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; }
bool construct_test | ( | FBiGeom_Instance | geom | ) |
static int count_num_with_tag | ( | FBiGeom_Instance | geom, |
const std::vector< iBase_EntityHandle > & | ents, | ||
iBase_TagHandle | tag | ||
) | [static] |
Definition at line 1455 of file testSmooth.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; }
bool gentityset_test | ( | FBiGeom_Instance | geom, |
bool | , | ||
bool | |||
) |
bool geometry_evaluation_test | ( | FBiGeom_Instance | geom | ) |
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 1391 of file testSmooth.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 146 of file testSmooth.cpp.
{ if( result ) { std::cout << "Success"; number_successful++; } else { std::cout << "Failure"; number_failed++; } }
int main | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 160 of file testSmooth.cpp.
References CHECK, FBiGeom_newGeom, filename, geom, geometry_evaluation_test(), handle_error_code(), normals_test(), number_tests, number_tests_failed, number_tests_successful, ray_test(), shutdown_test(), smooth_test(), STRINGIFY, tags_test(), and topology_adjacencies_test().
{ std::string filename = STRINGIFY( MESHDIR ) "/shell.h5m"; std::string engine_opt; 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; } bool result; int number_tests = 0; int number_tests_successful = 0; int number_tests_not_implemented = 0; int number_tests_failed = 0; // initialize the Mesh int err; FBiGeom_Instance geom; FBiGeom_newGeom( engine_opt.c_str(), &geom, &err, engine_opt.length() ); CHECK( "Interface initialization didn't work properly." ); // Print out Header information std::cout << "\n\nITAPS GEOMETRY INTERFACE TEST PROGRAM:\n\n"; // gLoad test 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: "; result = shutdown_test( geom, engine_opt ); handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful ); number_tests++; std::cout << "\n"; // 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; }
bool mesh_size_test | ( | FBiGeom_Instance | geom | ) |
bool normals_test | ( | FBiGeom_Instance | geom | ) |
Definition at line 1050 of file testSmooth.cpp.
References ARRAY_INOUT, SimpleArray< T >::begin(), CHECK, SimpleArray< T >::end(), FBiGeom_getEntBoundBox, FBiGeom_getEntities, FBiGeom_getEntNrmlXYZ, FBiGeom_getRootSet, iBase_ALL_TYPES, iBase_EDGE, iBase_VERTEX, root_set, and SimpleArray< T >::size().
Referenced by check_split(), main(), and split_quads_test().
{ int i, err; iBase_EntitySetHandle root_set; FBiGeom_getRootSet( geom, &root_set, &err ); CHECK( "ERROR : getRootSet failed!" ); int top = iBase_VERTEX; int num_test_top = iBase_ALL_TYPES; std::vector< std::vector< iBase_EntityHandle > > gentity_vectors( num_test_top ); // fill the vectors of each topology entities // like lines vector, polygon vector, triangle vector, // quadrilateral, polyhedrron, tet, hex, prism, pyramid, // septahedron vectors for( i = top; i < num_test_top; i++ ) { SimpleArray< iBase_EntityHandle > gentities; FBiGeom_getEntities( geom, root_set, i, ARRAY_INOUT( gentities ), &err ); CHECK( "Failed to get gentities in adjacencies_test." ); gentity_vectors[i].resize( gentities.size() ); std::copy( gentities.begin(), gentities.end(), gentity_vectors[i].begin() ); } // check adjacencies in both directions double min[3], max[3]; double normal[3] = { .0, .0, .0 }; std::vector< iBase_EntityHandle >::iterator vit; for( i = iBase_REGION; i > iBase_EDGE; i-- ) { for( vit = gentity_vectors[i].begin(); vit != gentity_vectors[i].end(); ++vit ) { iBase_EntityHandle this_gent = *vit; FBiGeom_getEntBoundBox( geom, this_gent, &min[0], &min[1], &min[2], &max[0], &max[1], &max[2], &err ); CHECK( "Failed to get bounding box of entity." ); FBiGeom_getEntNrmlXYZ( geom, this_gent, ( max[0] + min[0] ) / 2, ( max[1] + min[1] ) / 2, ( max[2] + min[2] ) / 2, &normal[0], &normal[1], &normal[2], &err ); CHECK( "Failed to get normal to the closest point." ); std::cout << " entity of type " << i << " closest normal to center:\n " << normal[0] << " " << normal[1] << " " << normal[2] << "\n"; } } return true; }
bool primitives_test | ( | FBiGeom_Instance | geom | ) |
static bool print_error | ( | const char * | desc, |
int | err, | ||
FBiGeom_Instance | geom, | ||
const char * | file, | ||
int | line | ||
) | [static] |
Definition at line 31 of file testSmooth.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 | ) |
Definition at line 1100 of file testSmooth.cpp.
References ARRAY_INOUT, CHECK, FBiGeom_getEntBoundBox, FBiGeom_getEntities, FBiGeom_getEntType, FBiGeom_getPntRayIntsct, FBiGeom_getRootSet, iBase_FACE, iBase_INTERLEAVED, root_set, and SimpleArray< T >::size().
Referenced by check_split(), main(), and split_quads_test().
{ int err; iBase_EntitySetHandle root_set; FBiGeom_getRootSet( geom, &root_set, &err ); CHECK( "ERROR : getRootSet failed!" ); int top = iBase_FACE; SimpleArray< iBase_EntityHandle > faces; FBiGeom_getEntities( geom, root_set, top, ARRAY_INOUT( faces ), &err ); CHECK( "Failed to get gentities in adjacencies_test." ); // check only the first face // check adjacencies in both directions double min[3], max[3]; iBase_EntityHandle first_face = faces[0]; FBiGeom_getEntBoundBox( geom, first_face, &min[0], &min[1], &min[2], &max[0], &max[1], &max[2], &err ); CHECK( "Failed to get bounding box of entity." ); // assume that the ray shot from the bottom of the box (middle) is a pretty good candidate // in z direction double x = ( min[0] + max[0] ) / 2, y = ( min[1] + max[1] ) / 2, z = min[2]; SimpleArray< iBase_EntityHandle > intersect_entity_handles; SimpleArray< double > intersect_coords; SimpleArray< double > param_coords; FBiGeom_getPntRayIntsct( geom, x, y, z, // shot from 0., 0., 1., // direction ARRAY_INOUT( intersect_entity_handles ), iBase_INTERLEAVED, ARRAY_INOUT( intersect_coords ), ARRAY_INOUT( param_coords ), &err ); CHECK( "Failed to find ray intersections points " ); for( int i = 0; i < intersect_entity_handles.size(); i++ ) { int j; FBiGeom_getEntType( geom, intersect_entity_handles[i], &j, &err ); CHECK( "Failed to get type of entity." ); std::cout << " entity of type " << j << " n: " << intersect_entity_handles[i] << "\n" << intersect_coords[3 * i] << " " << intersect_coords[3 * i + 1] << " " << intersect_coords[3 * i + 2] << "\n" << " distance: " << param_coords[i] << "\n"; } return true; }
bool save_entset_test | ( | FBiGeom_Instance | geom | ) |
bool shutdown_test | ( | FBiGeom_Instance | geom, |
std::string & | engine_opt | ||
) |
bool smooth_test | ( | const std::string & | filename, |
FBiGeom_Instance | geom | ||
) |
Definition at line 326 of file testSmooth.cpp.
References CHECK, FBiGeom_getNumOfType, FBiGeom_getRootSet, FBiGeom_load, and root_set.
Referenced by main().
{ int err; char opts[] = "SMOOTH;"; FBiGeom_load( geom, &filename[0], opts, &err, filename.length(), 8 ); // FBiGeom_load( geom, &filename[0], 0, &err, filename.length(), 0 ); CHECK( "ERROR : can not load a geometry" ); iBase_EntitySetHandle root_set; FBiGeom_getRootSet( geom, &root_set, &err ); CHECK( "ERROR : getRootSet failed!" ); // print out the number of entities std::cout << "Model contents: " << std::endl; const char* gtype[] = { "vertices: ", "edges: ", "faces: ", "regions: " }; for( int i = 0; i <= 3; ++i ) { int count; FBiGeom_getNumOfType( geom, root_set, i, &count, &err ); CHECK( "Error: problem getting entities after gLoad." ); std::cout << gtype[i] << count << std::endl; } return true; }
bool tag_get_set_test | ( | FBiGeom_Instance | geom | ) |
bool tag_info_test | ( | FBiGeom_Instance | geom | ) |
bool tags_test | ( | FBiGeom_Instance | geom | ) |
bool topology_adjacencies_test | ( | FBiGeom_Instance | geom | ) |
bool transforms_test | ( | FBiGeom_Instance | geom | ) |