MOAB: Mesh Oriented datABase  (version 5.4.1)
read_obj_test.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include "moab/Interface.hpp"
00003 #include "TestUtil.hpp"
00004 #include "Internals.hpp"
00005 #include "moab/Core.hpp"
00006 #include "MBTagConventions.hpp"
00007 #include "moab/Types.hpp"
00008 #include "moab/GeomTopoTool.hpp"
00009 
00010 using namespace moab;
00011 
00012 #define CHKERR( A )                                                                                        \
00013     do                                                                                                     \
00014     {                                                                                                      \
00015         if( MB_SUCCESS != ( A ) )                                                                          \
00016         {                                                                                                  \
00017             std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
00018             return A;                                                                                      \
00019         }                                                                                                  \
00020     } while( false )
00021 
00022 std::string test    = TestDir + "unittest/io/test.obj";
00023 std::string shuttle = TestDir + "unittest/io/shuttle.obj";
00024 
00025 GeomTopoTool* myGeomTool;
00026 
00027 Tag geom_tag;
00028 Tag name_tag;
00029 Tag id_tag;
00030 
00031 void read_file( Interface& moab, const char* input_file );
00032 void test_check_num_entities();
00033 void test_check_meshsets();
00034 void test_check_groups();
00035 
00036 int main()
00037 {
00038     int result = 0;
00039 
00040     result += RUN_TEST( test_check_num_entities );
00041     result += RUN_TEST( test_check_meshsets );
00042     result += RUN_TEST( test_check_groups );
00043 
00044     return result;
00045 }
00046 
00047 void read_file( Interface& moab, const char* input_file )
00048 {
00049     ErrorCode rval = moab.load_file( input_file );CHECK_ERR( rval );
00050 }
00051 
00052 void test_check_num_entities()
00053 {
00054     ErrorCode rval;
00055     Core core;
00056     Interface* mbi = &core;
00057     read_file( core, test.c_str() );
00058 
00059     // check that number of verts created is 7
00060     Range verts;
00061     int vert_dim = 0;
00062     rval         = mbi->get_entities_by_dimension( 0, vert_dim, verts );CHECK_ERR( rval );
00063     CHECK_EQUAL( 7, (int)verts.size() );
00064 
00065     // check that number of tris created is 3
00066     Range tris;
00067     int tri_dim = 2;
00068     rval        = mbi->get_entities_by_dimension( 0, tri_dim, tris );CHECK_ERR( rval );
00069     CHECK_EQUAL( 3, (int)tris.size() );
00070 }
00071 
00072 void test_check_meshsets()
00073 {
00074     ErrorCode rval;
00075     Core core;
00076     Interface* mbi = &core;
00077     read_file( core, test.c_str() );
00078 
00079     myGeomTool = new GeomTopoTool( mbi );
00080 
00081     Range ent_sets;
00082     rval = mbi->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, geom_tag );CHECK_ERR( rval );
00083     rval = mbi->get_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, NULL, 1, ent_sets );CHECK_ERR( rval );
00084 
00085     Range::iterator it;
00086     Range parents, children;
00087     int sense;
00088     int dim, num_surfs = 0, num_vols = 0;
00089 
00090     for( it = ent_sets.begin(); it != ent_sets.end(); ++it )
00091     {
00092         rval = mbi->tag_get_data( geom_tag, &( *it ), 1, &dim );
00093 
00094         if( dim == 2 )
00095         {
00096             num_surfs++;
00097 
00098             // check that one parent is created for each surface
00099             parents.clear();
00100             rval = mbi->get_parent_meshsets( *it, parents );CHECK_ERR( rval );
00101             CHECK_EQUAL( 1, (int)parents.size() );
00102 
00103             // check that sense of surface wrt parent is FORWARD = 1
00104             rval = myGeomTool->get_sense( *it, *parents.begin(), sense );CHECK_ERR( rval );
00105             CHECK_EQUAL( 1, sense );
00106         }
00107         else if( dim == 3 )
00108         {
00109             num_vols++;
00110 
00111             // check that one child is created for each volume
00112             children.clear();
00113             rval = mbi->get_child_meshsets( *it, children );CHECK_ERR( rval );
00114             CHECK_EQUAL( 1, (int)children.size() );
00115         }
00116     }
00117 
00118     // check that two surfaces and two volumes are created
00119     CHECK_EQUAL( 2, num_surfs );
00120     CHECK_EQUAL( 2, num_vols );
00121 
00122     delete myGeomTool;
00123 }
00124 
00125 void test_check_groups()
00126 {
00127     ErrorCode rval;
00128     Core core;
00129     Interface* mbi = &core;
00130     read_file( core, shuttle.c_str() );
00131 
00132     // check that number of tris created is 616
00133     //  170 tris + 223 quads split into 2 tris = 616
00134     Range tris;
00135     int tri_dim = 2;
00136     rval        = mbi->get_entities_by_dimension( 0, tri_dim, tris );CHECK_ERR( rval );
00137     CHECK_EQUAL( 616, (int)tris.size() );
00138 
00139     // check that 11 mesh sets are created
00140     // 1 for global vert set + 1 for each of 10 groups
00141     Range ent_sets, mesh_sets;
00142     id_tag = mbi->globalId_tag();
00143     rval   = mbi->get_entities_by_type_and_tag( 0, MBENTITYSET, &id_tag, NULL, 1, ent_sets );
00144 
00145     CHECK_EQUAL( 11, (int)ent_sets.size() );
00146 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines