MOAB: Mesh Oriented datABase  (version 5.5.0)
read_cgm_group_test.cpp File Reference
#include <iostream>
#include "moab/Interface.hpp"
#include "TestUtil.hpp"
#include "Internals.hpp"
#include "moab/Core.hpp"
#include "MBTagConventions.hpp"
#include "InitCGMA.hpp"
#include "GeometryQueryTool.hpp"
+ Include dependency graph for read_cgm_group_test.cpp:

Go to the source code of this file.

Macros

#define IS_BUILDING_MB
 
#define CHKERR(A)
 

Functions

void read_file (Interface *moab, const char *input_file)
 
int geom_id_by_handle (Interface *moab, const EntityHandle set)
 
void check_group_data (std::vector< int > &group_ids, std::vector< std::string > &group_names, std::vector< int > &group_ent_ids)
 
void load_group_references (std::vector< int > &ids, std::vector< std::string > &names, std::vector< int > &ent_ids)
 
void read_cylcube_groups_test ()
 
int main (int, char **)
 

Variables

std::string input_cylcube = TestDir + "unittest/io/cylcube.sat"
 

Macro Definition Documentation

◆ CHKERR

#define CHKERR (   A)
Value:
do \
{ \
if( MB_SUCCESS != ( A ) ) \
{ \
std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
return A; \
} \
} while( false )

Definition at line 15 of file read_cgm_group_test.cpp.

◆ IS_BUILDING_MB

#define IS_BUILDING_MB

Definition at line 4 of file read_cgm_group_test.cpp.

Function Documentation

◆ check_group_data()

void check_group_data ( std::vector< int > &  group_ids,
std::vector< std::string > &  group_names,
std::vector< int > &  group_ent_ids 
)

Definition at line 122 of file read_cgm_group_test.cpp.

129 {
130  // Step files do not contain group data, MOAB shouldn't return errors when trying to access
131  // this data but there shouldn't be any found.
132 #ifdef HAVE_OCC_STEP
133  int num_g_ids = group_ids.size();
134  int num_g_names = group_names.size();
135 
136  CHECK_EQUAL( 0, num_g_ids );
137  CHECK_EQUAL( 0, num_g_names );
138 #else
139 
140  // Initialize reference data
141  std::vector< int > group_ref_ids;
142  std::vector< std::string > group_ref_names;
143  std::vector< int > group_ref_ent_ids;
144  load_group_references( group_ref_ids, group_ref_names, group_ref_ent_ids );
145 
146  // check that the correct number of entities were found
147  CHECK_EQUAL( group_ref_ids.size(), group_ids.size() );
148  CHECK_EQUAL( group_ref_names.size(), group_names.size() );
149  CHECK_EQUAL( group_ref_ent_ids.size(), group_ent_ids.size() );
150 
151  // now make sure that each group has a matching group
152  for( unsigned int i = 0; i < group_ids.size(); i++ )
153  {
154  for( unsigned int j = 0; j < group_ref_ids.size(); j++ )
155  {
156  if( group_ids[i] == group_ref_ids[j] && group_names[i] == group_ref_names[j] &&
157  group_ent_ids[i] == group_ref_ent_ids[j] )
158  {
159  group_ref_ids.erase( group_ref_ids.begin() + j );
160  group_ref_names.erase( group_ref_names.begin() + j );
161  group_ref_ent_ids.erase( group_ref_ent_ids.begin() + j );
162  continue;
163  }
164  }
165  }
166 
167  // Check sizes of reference vectors after matching
168  // (all should be zero)
169  int leftovers = group_ref_ids.size();
170  CHECK_EQUAL( 0, leftovers );
171  leftovers = group_ref_names.size();
172  CHECK_EQUAL( 0, leftovers );
173  leftovers = group_ref_ent_ids.size();
174  CHECK_EQUAL( 0, leftovers );
175 #endif
176 }

References CHECK_EQUAL, and load_group_references().

Referenced by read_cylcube_groups_test().

◆ geom_id_by_handle()

int geom_id_by_handle ( Interface moab,
const EntityHandle  set 
)

Definition at line 191 of file read_cgm_group_test.cpp.

192 {
193  ErrorCode rval;
194  // Get the id_tag handle
195  Tag id_tag = moab->globalId_tag();
196  // Load the ID for the EntHandle given to the function
197  int id;
198  rval = moab->tag_get_data( id_tag, &set, 1, &id );CHECK_ERR( rval );
199  return id;
200 }

References CHECK_ERR, ErrorCode, and id_tag.

Referenced by read_cylcube_groups_test().

◆ load_group_references()

void load_group_references ( std::vector< int > &  ids,
std::vector< std::string > &  names,
std::vector< int > &  ent_ids 
)

Definition at line 178 of file read_cgm_group_test.cpp.

179 {
180  // First set of group info
181  names.push_back( "Group 3" );
182  ids.push_back( 3 );
183  ent_ids.push_back( 2 );
184 
185  // Second set of group info
186  names.push_back( "Group 2" );
187  ids.push_back( 2 );
188  ent_ids.push_back( 1 );
189 }

Referenced by check_group_data().

◆ main()

int main ( int  ,
char **   
)

Definition at line 52 of file read_cgm_group_test.cpp.

53 {
54  int result = 0;
55 
57 
58  return result;
59 }

References read_cylcube_groups_test(), and RUN_TEST.

◆ read_cylcube_groups_test()

void read_cylcube_groups_test ( )

Definition at line 73 of file read_cgm_group_test.cpp.

74 {
75 
76  ErrorCode rval;
77  // Open the test file
78  Core moab;
79  Interface* mb = &moab;
80  read_file( mb, input_cylcube.c_str() );
81 
82  // Get (or create) the name and category tags
84 
87 
90 
91  // Get the group entity handles
92  Range group_sets;
93  char query[CATEGORY_TAG_SIZE] = "Group\0";
94  // Has to be this way because of the way tags are created
95  void* val[] = { &query };
96  rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &category_tag, val, 1, group_sets );CHECK_ERR( rval );
97  // Get group names and IDs
98  std::vector< int > g_ids;
99  std::vector< std::string > g_names;
100  std::vector< int > g_ent_ids;
101 
102  for( Range::iterator i = group_sets.begin(); i != group_sets.end(); ++i )
103  {
104  int group_id = geom_id_by_handle( mb, *i );
105  g_ids.push_back( group_id );
106  // Get the group name
107  char group_name[NAME_TAG_SIZE + 1];
108  rval = mb->tag_get_data( name_tag, &( *i ), 1, &group_name );CHECK_ERR( rval );
109  // Store group name
110  std::string temp( group_name );
111  g_names.push_back( temp );
112  // Get all entities in the group
113  Range group_ents;
114  rval = mb->get_entities_by_type( *i, MBENTITYSET, group_ents, false );CHECK_ERR( rval );
115  if( group_ents.size() != 1 ) CHECK( false );
116  int grp_ent_id = geom_id_by_handle( mb, group_ents[0] );
117  g_ent_ids.push_back( grp_ent_id );
118  }
119  check_group_data( g_ids, g_names, g_ent_ids );
120 }

References moab::Range::begin(), category_tag, CATEGORY_TAG_NAME, CATEGORY_TAG_SIZE, CHECK, CHECK_ERR, check_group_data(), moab::Range::end(), ErrorCode, geom_id_by_handle(), moab::Core::get_entities_by_type(), moab::Core::get_entities_by_type_and_tag(), input_cylcube, mb, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_OPAQUE, MBENTITYSET, name_tag, NAME_TAG_NAME, NAME_TAG_SIZE, read_file(), moab::Range::size(), moab::Core::tag_get_data(), and moab::Core::tag_get_handle().

Referenced by main().

◆ read_file()

void read_file ( Interface moab,
const char *  input_file 
)

Definition at line 61 of file read_cgm_group_test.cpp.

62 {
63  InitCGMA::initialize_cgma();
64  GeometryQueryTool::instance()->delete_geometry();
65 
66  ErrorCode rval = moab->load_file( input_file );CHECK_ERR( rval );
67 }

References CHECK_ERR, ErrorCode, and input_file.

Referenced by read_cylcube_groups_test().

Variable Documentation

◆ input_cylcube

std::string input_cylcube = TestDir + "unittest/io/cylcube.sat"

Definition at line 28 of file read_cgm_group_test.cpp.

Referenced by read_cylcube_groups_test().