MOAB: Mesh Oriented datABase  (version 5.4.1)
read_cgm_basic_test.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include "moab/Interface.hpp"
00003 #ifndef IS_BUILDING_MB
00004 #define IS_BUILDING_MB
00005 #endif
00006 #include "TestUtil.hpp"
00007 #include "Internals.hpp"
00008 #include "moab/Core.hpp"
00009 #include "MBTagConventions.hpp"
00010 #include "InitCGMA.hpp"
00011 #include "GeometryQueryTool.hpp"
00012 
00013 using namespace moab;
00014 
00015 #define CHKERR( A )                                                                                        \
00016     do                                                                                                     \
00017     {                                                                                                      \
00018         if( MB_SUCCESS != ( A ) )                                                                          \
00019         {                                                                                                  \
00020             std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
00021             return A;                                                                                      \
00022         }                                                                                                  \
00023     } while( false )
00024 
00025 #ifdef HAVE_OCC_STEP
00026 const std::string input_cube = TestDir + "unittest/io/cube.stp";
00027 #else
00028 const std::string input_cube = TestDir + "unittest/io/cube.sat";
00029 #endif
00030 
00031 // Function used to load the test file
00032 void read_file( Interface* moab, const char* input_file );
00033 
00034 // List of tests in this file
00035 void read_cube_verts_test();
00036 void read_cube_curves_test();
00037 void read_cube_tris_test();
00038 void read_cube_surfs_test();
00039 void read_cube_vols_test();
00040 void read_cube_vertex_pos_test();
00041 // void delete_mesh_test();
00042 
00043 int main( int /* argc */, char** /* argv */ )
00044 {
00045     int result = 0;
00046 
00047     result += RUN_TEST( read_cube_verts_test );
00048     result += RUN_TEST( read_cube_curves_test );
00049     result += RUN_TEST( read_cube_tris_test );
00050     result += RUN_TEST( read_cube_surfs_test );
00051     result += RUN_TEST( read_cube_vols_test );
00052     result += RUN_TEST( read_cube_vertex_pos_test );
00053 
00054     return result;
00055 }
00056 
00057 void read_file( Interface* moab, const char* input_file )
00058 {
00059     InitCGMA::initialize_cgma();
00060     GeometryQueryTool::instance()->delete_geometry();
00061 
00062     ErrorCode rval = moab->load_file( input_file );CHECK_ERR( rval );
00063 }
00064 
00065 // Gets the vertex entities from a simple cube file load and checks that the
00066 // correct number of them exist.
00067 void read_cube_verts_test()
00068 {
00069     ErrorCode rval;
00070     // Open the test file
00071     Core moab;
00072     Interface* mb = &moab;
00073     read_file( mb, input_cube.c_str() );
00074 
00075     int number_of_vertices;
00076     rval = mb->get_number_entities_by_type( 0, MBVERTEX, number_of_vertices );CHECK_ERR( rval );
00077     // For a cube there should be exactly 8 vertices
00078     CHECK_EQUAL( 8, number_of_vertices );
00079 }
00080 
00081 // Gets the triangle entities from a simple cube file load and checks that the
00082 // correct number of them exist.
00083 void read_cube_tris_test()
00084 {
00085     ErrorCode rval;
00086     // Open the test file
00087     Core moab;
00088     Interface* mb = &moab;
00089     read_file( mb, input_cube.c_str() );
00090 
00091     int number_of_tris;
00092 
00093     rval = mb->get_number_entities_by_type( 0, MBTRI, number_of_tris );
00094     std::cout << "Number of Triangles = " << number_of_tris << std::endl;CHECK_ERR( rval );
00095     // For a cube, there should be exactly 2 triangles per face
00096     CHECK_EQUAL( 12, number_of_tris );
00097 }
00098 
00099 // Gets the curve entities from a simple cube file load and checks that the
00100 // correct number of them exist.
00101 void read_cube_curves_test()
00102 {
00103     ErrorCode rval;
00104     // Open the test file
00105     Core moab;
00106     Interface* mb = &moab;
00107     read_file( mb, input_cube.c_str() );
00108     // Get the geometry tag handle from the mesh
00109     Tag geom_tag;
00110     rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, geom_tag,
00111                                moab::MB_TAG_DENSE | moab::MB_TAG_CREAT );CHECK_ERR( rval );
00112     // Get the curves from the mesh
00113     int dim     = 1;
00114     void* val[] = { &dim };
00115     int number_of_curves;
00116     rval = mb->get_number_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, val, 1, number_of_curves );CHECK_ERR( rval );
00117     // For a cube, there should be exactly 12 curves loaded from the file
00118     CHECK_EQUAL( 12, number_of_curves );
00119 }
00120 
00121 // Gets the surface entities from a simple cube file load and checks that the
00122 // correct number of them exist.
00123 void read_cube_surfs_test()
00124 {
00125     ErrorCode rval;
00126     // Open the test file
00127     Core moab;
00128     Interface* mb = &moab;
00129     read_file( mb, input_cube.c_str() );
00130 
00131     // Get geometry tag for pulling curve data from the mesh
00132     Tag geom_tag;
00133     rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, geom_tag,
00134                                moab::MB_TAG_DENSE | moab::MB_TAG_CREAT );CHECK_ERR( rval );
00135 
00136     // Get the number of surface from the mesh geometry data
00137     int dim     = 2;
00138     void* val[] = { &dim };
00139     int number_of_surfs;
00140     rval = mb->get_number_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, val, 1, number_of_surfs );CHECK_ERR( rval );
00141     // For a cube, there should be exactly 6 surfaces
00142     CHECK_EQUAL( 6, number_of_surfs );
00143 }
00144 
00145 void read_cube_vols_test()
00146 {
00147     ErrorCode rval;
00148     // Open the test file
00149     Core moab;
00150     Interface* mb = &moab;
00151     read_file( mb, input_cube.c_str() );
00152 
00153     // Get geometry tag for pulling curve data from the mesh
00154     Tag geom_tag;
00155     rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, geom_tag,
00156                                moab::MB_TAG_DENSE | moab::MB_TAG_CREAT );CHECK_ERR( rval );
00157 
00158     // Get the number of volumes from the mesh geometry data
00159     int dim     = 3;
00160     void* val[] = { &dim };
00161     int number_of_vols;
00162     rval = mb->get_number_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, val, 1, number_of_vols );CHECK_ERR( rval );
00163     CHECK_EQUAL( 1, number_of_vols );
00164 }
00165 
00166 // Gets the vertex eitities from a simple cube file load and checks that
00167 // they are in the correct locations.
00168 void read_cube_vertex_pos_test()
00169 {
00170 
00171     ErrorCode rval;
00172     // Open the test file
00173     Core moab;
00174     Interface* mb = &moab;
00175     read_file( mb, input_cube.c_str() );
00176 
00177     // Retrieve all vertex handles from the mesh
00178     Range verts;
00179     rval = mb->get_entities_by_type( 0, MBVERTEX, verts );CHECK_ERR( rval );
00180 
00181     int number_of_verts = verts.size();
00182     CHECK_EQUAL( 8, number_of_verts );
00183     // Get the vertex coordinates
00184     double x[8];
00185     double y[8];
00186     double z[8];
00187     rval = mb->get_coords( verts, &x[0], &y[0], &z[0] );CHECK_ERR( rval );
00188 
00189     // Check against known locations of the vertices
00190 
00191     std::vector< double > x_ref;
00192     std::vector< double > y_ref;
00193     std::vector< double > z_ref;
00194 
00195     // Vertex 1
00196     x_ref.push_back( 5 );
00197     y_ref.push_back( -5 );
00198     z_ref.push_back( 5 );
00199 
00200     // Vertex 2
00201     x_ref.push_back( 5 );
00202     y_ref.push_back( 5 );
00203     z_ref.push_back( 5 );
00204 
00205     // Vertex 3
00206     x_ref.push_back( -5 );
00207     y_ref.push_back( 5 );
00208     z_ref.push_back( 5 );
00209 
00210     // Vertex 4
00211     x_ref.push_back( -5 );
00212     y_ref.push_back( -5 );
00213     z_ref.push_back( 5 );
00214 
00215     // Vertex 5
00216     x_ref.push_back( 5 );
00217     y_ref.push_back( 5 );
00218     z_ref.push_back( -5 );
00219 
00220     // Vertex 6
00221     x_ref.push_back( 5 );
00222     y_ref.push_back( -5 );
00223     z_ref.push_back( -5 );
00224 
00225     // Vertex 7
00226     x_ref.push_back( -5 );
00227     y_ref.push_back( -5 );
00228     z_ref.push_back( -5 );
00229 
00230     // Vertex 8
00231     x_ref.push_back( -5 );
00232     y_ref.push_back( 5 );
00233     z_ref.push_back( -5 );
00234 
00235     std::cout << verts.size() << std::endl;
00236     std::cout << x_ref.size() << std::endl;
00237 
00238     for( unsigned int i = 0; i < verts.size(); i++ )
00239     {
00240         for( unsigned int j = 0; j < x_ref.size(); j++ )
00241         {
00242             if( x[i] == x_ref[j] && y[i] == y_ref[j] && z[i] == z_ref[j] )
00243             {
00244                 x_ref.erase( x_ref.begin() + j );
00245                 y_ref.erase( y_ref.begin() + j );
00246                 z_ref.erase( z_ref.begin() + j );
00247             }
00248         }
00249     }
00250 
00251     // After looping through each vertex loaded from the mesh
00252     // there should be no entities left in the reference vector
00253     int leftovers = x_ref.size();
00254     CHECK_EQUAL( 0, leftovers );
00255 }
00256 
00257 // Superfluous test for ReadCGM, but perhaps better
00258 // than the test in place for moab::delete_geometry()
00259 
00260 /*
00261 void delete_mesh_test()
00262 {
00263  Core moab;
00264  Interface* mb = &moab;
00265  read_file( mb, input_cube );
00266 
00267  ErrorCode rval;
00268 
00269  //Get geometry tag for pulling curve data from the mesh
00270  Tag geom_tag;
00271  rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER,
00272                             geom_tag, moab::MB_TAG_DENSE|moab::MB_TAG_CREAT );CHECK_ERR(rval);
00273 
00274  Range geom_sets[4];
00275 
00276  for(unsigned dim=0; dim<4; dim++)
00277  {
00278     void *val[] = {&dim};
00279     rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag,
00280                             val, 1, geom_sets[dim] );CHECK_ERR(rval);
00281 
00282         if( geom_sets[dim].size() == 0 ) std::cout << "Warning: No geom sets to begin with" <<
00283 std::endl;
00284 
00285  }
00286 
00287  mb->delete_mesh();
00288 
00289  Range geom_sets_after[4];
00290  for(unsigned dim=0; dim<4; dim++)
00291  {
00292     void *val_after[] = {&dim};
00293     rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag,
00294                             val_after, 1, geom_sets_after[dim] );CHECK_ERR(rval);
00295 
00296         if( 0 != geom_sets_after[dim].size() ) rval = MB_FAILURE;
00297 
00298         CHECK_ERR(rval);
00299  }
00300 
00301 }
00302 
00303 */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines