MOAB: Mesh Oriented datABase
(version 5.4.1)
|
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 std::string input_cylcube = TestDir + "unittest/io/cylcube.stp"; 00027 #else 00028 std::string input_cylcube = TestDir + "unittest/io/cylcube.sat"; 00029 #endif 00030 00031 // Function used to load the test file 00032 void read_file( Interface* moab, const char* input_file ); 00033 00034 // Function for getting entity ids 00035 int geom_id_by_handle( Interface* moab, const EntityHandle set ); 00036 00037 // Function for checking retrieved group data 00038 void check_group_data( std::vector< int >& group_ids, 00039 std::vector< std::string >& group_names, 00040 #ifdef HAVE_OCC_STEP 00041 std::vector< int >& ); 00042 #else 00043 std::vector< int >& group_ent_ids ); 00044 #endif 00045 00046 // Function for loading all reference data 00047 void load_group_references( std::vector< int >& ids, std::vector< std::string >& names, std::vector< int >& ent_ids ); 00048 00049 // List of tests in this file 00050 void read_cylcube_groups_test(); 00051 00052 int main( int /* argc */, char** /* argv */ ) 00053 { 00054 int result = 0; 00055 00056 result += RUN_TEST( read_cylcube_groups_test ); 00057 00058 return result; 00059 } 00060 00061 void read_file( Interface* moab, const char* input_file ) 00062 { 00063 InitCGMA::initialize_cgma(); 00064 GeometryQueryTool::instance()->delete_geometry(); 00065 00066 ErrorCode rval = moab->load_file( input_file );CHECK_ERR( rval ); 00067 } 00068 00069 // Checks that group information is being read correctly if MOAB is 00070 // being build with CGM. If MOAB is built with OCC, it makes sure 00071 // no erroneous group data is loaded as STEP files do not hold 00072 // information about groups. 00073 void read_cylcube_groups_test() 00074 { 00075 00076 ErrorCode rval; 00077 // Open the test file 00078 Core moab; 00079 Interface* mb = &moab; 00080 read_file( mb, input_cylcube.c_str() ); 00081 00082 // Get (or create) the name and category tags 00083 Tag name_tag, category_tag; 00084 00085 rval = mb->tag_get_handle( NAME_TAG_NAME, NAME_TAG_SIZE, MB_TYPE_OPAQUE, name_tag, 00086 moab::MB_TAG_SPARSE | moab::MB_TAG_CREAT );CHECK_ERR( rval ); 00087 00088 rval = mb->tag_get_handle( CATEGORY_TAG_NAME, CATEGORY_TAG_SIZE, MB_TYPE_OPAQUE, category_tag, 00089 moab::MB_TAG_SPARSE | moab::MB_TAG_CREAT );CHECK_ERR( rval ); 00090 00091 // Get the group entity handles 00092 Range group_sets; 00093 char query[CATEGORY_TAG_SIZE] = "Group\0"; 00094 // Has to be this way because of the way tags are created 00095 void* val[] = { &query }; 00096 rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &category_tag, val, 1, group_sets );CHECK_ERR( rval ); 00097 // Get group names and IDs 00098 std::vector< int > g_ids; 00099 std::vector< std::string > g_names; 00100 std::vector< int > g_ent_ids; 00101 00102 for( Range::iterator i = group_sets.begin(); i != group_sets.end(); ++i ) 00103 { 00104 int group_id = geom_id_by_handle( mb, *i ); 00105 g_ids.push_back( group_id ); 00106 // Get the group name 00107 char group_name[NAME_TAG_SIZE + 1]; 00108 rval = mb->tag_get_data( name_tag, &( *i ), 1, &group_name );CHECK_ERR( rval ); 00109 // Store group name 00110 std::string temp( group_name ); 00111 g_names.push_back( temp ); 00112 // Get all entities in the group 00113 Range group_ents; 00114 rval = mb->get_entities_by_type( *i, MBENTITYSET, group_ents, false );CHECK_ERR( rval ); 00115 if( group_ents.size() != 1 ) CHECK( false ); 00116 int grp_ent_id = geom_id_by_handle( mb, group_ents[0] ); 00117 g_ent_ids.push_back( grp_ent_id ); 00118 } 00119 check_group_data( g_ids, g_names, g_ent_ids ); 00120 } 00121 00122 void check_group_data( std::vector< int >& group_ids, 00123 std::vector< std::string >& group_names, 00124 #ifdef HAVE_OCC_STEP 00125 std::vector< int >& /*group_ent_ids*/ ) 00126 #else 00127 std::vector< int >& group_ent_ids ) 00128 #endif 00129 { 00130 // Step files do not contain group data, MOAB shouldn't return errors when trying to access 00131 // this data but there shouldn't be any found. 00132 #ifdef HAVE_OCC_STEP 00133 int num_g_ids = group_ids.size(); 00134 int num_g_names = group_names.size(); 00135 00136 CHECK_EQUAL( 0, num_g_ids ); 00137 CHECK_EQUAL( 0, num_g_names ); 00138 #else 00139 00140 // Initialize reference data 00141 std::vector< int > group_ref_ids; 00142 std::vector< std::string > group_ref_names; 00143 std::vector< int > group_ref_ent_ids; 00144 load_group_references( group_ref_ids, group_ref_names, group_ref_ent_ids ); 00145 00146 // check that the correct number of entities were found 00147 CHECK_EQUAL( group_ref_ids.size(), group_ids.size() ); 00148 CHECK_EQUAL( group_ref_names.size(), group_names.size() ); 00149 CHECK_EQUAL( group_ref_ent_ids.size(), group_ent_ids.size() ); 00150 00151 // now make sure that each group has a matching group 00152 for( unsigned int i = 0; i < group_ids.size(); i++ ) 00153 { 00154 for( unsigned int j = 0; j < group_ref_ids.size(); j++ ) 00155 { 00156 if( group_ids[i] == group_ref_ids[j] && group_names[i] == group_ref_names[j] && 00157 group_ent_ids[i] == group_ref_ent_ids[j] ) 00158 { 00159 group_ref_ids.erase( group_ref_ids.begin() + j ); 00160 group_ref_names.erase( group_ref_names.begin() + j ); 00161 group_ref_ent_ids.erase( group_ref_ent_ids.begin() + j ); 00162 continue; 00163 } 00164 } 00165 } 00166 00167 // Check sizes of reference vectors after matching 00168 // (all should be zero) 00169 int leftovers = group_ref_ids.size(); 00170 CHECK_EQUAL( 0, leftovers ); 00171 leftovers = group_ref_names.size(); 00172 CHECK_EQUAL( 0, leftovers ); 00173 leftovers = group_ref_ent_ids.size(); 00174 CHECK_EQUAL( 0, leftovers ); 00175 #endif 00176 } 00177 00178 void load_group_references( std::vector< int >& ids, std::vector< std::string >& names, std::vector< int >& ent_ids ) 00179 { 00180 // First set of group info 00181 names.push_back( "Group 3" ); 00182 ids.push_back( 3 ); 00183 ent_ids.push_back( 2 ); 00184 00185 // Second set of group info 00186 names.push_back( "Group 2" ); 00187 ids.push_back( 2 ); 00188 ent_ids.push_back( 1 ); 00189 } 00190 00191 int geom_id_by_handle( Interface* moab, const EntityHandle set ) 00192 { 00193 ErrorCode rval; 00194 // Get the id_tag handle 00195 Tag id_tag = moab->globalId_tag(); 00196 // Load the ID for the EntHandle given to the function 00197 int id; 00198 rval = moab->tag_get_data( id_tag, &set, 1, &id );CHECK_ERR( rval ); 00199 return id; 00200 }