MOAB: Mesh Oriented datABase  (version 5.5.0)
read_cgm_basic_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_basic_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)
 
void read_cube_verts_test ()
 
void read_cube_curves_test ()
 
void read_cube_tris_test ()
 
void read_cube_surfs_test ()
 
void read_cube_vols_test ()
 
void read_cube_vertex_pos_test ()
 
int main (int, char **)
 

Variables

const std::string input_cube = TestDir + "unittest/io/cube.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_basic_test.cpp.

◆ IS_BUILDING_MB

#define IS_BUILDING_MB

Definition at line 4 of file read_cgm_basic_test.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 43 of file read_cgm_basic_test.cpp.

44 {
45  int result = 0;
46 
47  result += RUN_TEST( read_cube_verts_test );
48  result += RUN_TEST( read_cube_curves_test );
49  result += RUN_TEST( read_cube_tris_test );
50  result += RUN_TEST( read_cube_surfs_test );
51  result += RUN_TEST( read_cube_vols_test );
53 
54  return result;
55 }

References read_cube_curves_test(), read_cube_surfs_test(), read_cube_tris_test(), read_cube_vertex_pos_test(), read_cube_verts_test(), read_cube_vols_test(), and RUN_TEST.

◆ read_cube_curves_test()

void read_cube_curves_test ( )

Definition at line 101 of file read_cgm_basic_test.cpp.

102 {
103  ErrorCode rval;
104  // Open the test file
105  Core moab;
106  Interface* mb = &moab;
107  read_file( mb, input_cube.c_str() );
108  // Get the geometry tag handle from the mesh
109  Tag geom_tag;
112  // Get the curves from the mesh
113  int dim = 1;
114  void* val[] = { &dim };
115  int number_of_curves;
116  rval = mb->get_number_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, val, 1, number_of_curves );CHECK_ERR( rval );
117  // For a cube, there should be exactly 12 curves loaded from the file
118  CHECK_EQUAL( 12, number_of_curves );
119 }

References CHECK_EQUAL, CHECK_ERR, dim, ErrorCode, GEOM_DIMENSION_TAG_NAME, geom_tag, moab::Core::get_number_entities_by_type_and_tag(), input_cube, mb, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, MBENTITYSET, read_file(), and moab::Core::tag_get_handle().

Referenced by main().

◆ read_cube_surfs_test()

void read_cube_surfs_test ( )

Definition at line 123 of file read_cgm_basic_test.cpp.

124 {
125  ErrorCode rval;
126  // Open the test file
127  Core moab;
128  Interface* mb = &moab;
129  read_file( mb, input_cube.c_str() );
130 
131  // Get geometry tag for pulling curve data from the mesh
132  Tag geom_tag;
135 
136  // Get the number of surface from the mesh geometry data
137  int dim = 2;
138  void* val[] = { &dim };
139  int number_of_surfs;
140  rval = mb->get_number_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, val, 1, number_of_surfs );CHECK_ERR( rval );
141  // For a cube, there should be exactly 6 surfaces
142  CHECK_EQUAL( 6, number_of_surfs );
143 }

References CHECK_EQUAL, CHECK_ERR, dim, ErrorCode, GEOM_DIMENSION_TAG_NAME, geom_tag, moab::Core::get_number_entities_by_type_and_tag(), input_cube, mb, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, MBENTITYSET, read_file(), and moab::Core::tag_get_handle().

Referenced by main().

◆ read_cube_tris_test()

void read_cube_tris_test ( )

Definition at line 83 of file read_cgm_basic_test.cpp.

84 {
85  ErrorCode rval;
86  // Open the test file
87  Core moab;
88  Interface* mb = &moab;
89  read_file( mb, input_cube.c_str() );
90 
91  int number_of_tris;
92 
93  rval = mb->get_number_entities_by_type( 0, MBTRI, number_of_tris );
94  std::cout << "Number of Triangles = " << number_of_tris << std::endl;CHECK_ERR( rval );
95  // For a cube, there should be exactly 2 triangles per face
96  CHECK_EQUAL( 12, number_of_tris );
97 }

References CHECK_EQUAL, CHECK_ERR, ErrorCode, moab::Core::get_number_entities_by_type(), input_cube, mb, MBTRI, and read_file().

Referenced by main().

◆ read_cube_vertex_pos_test()

void read_cube_vertex_pos_test ( )

Definition at line 168 of file read_cgm_basic_test.cpp.

169 {
170 
171  ErrorCode rval;
172  // Open the test file
173  Core moab;
174  Interface* mb = &moab;
175  read_file( mb, input_cube.c_str() );
176 
177  // Retrieve all vertex handles from the mesh
178  Range verts;
179  rval = mb->get_entities_by_type( 0, MBVERTEX, verts );CHECK_ERR( rval );
180 
181  int number_of_verts = verts.size();
182  CHECK_EQUAL( 8, number_of_verts );
183  // Get the vertex coordinates
184  double x[8];
185  double y[8];
186  double z[8];
187  rval = mb->get_coords( verts, &x[0], &y[0], &z[0] );CHECK_ERR( rval );
188 
189  // Check against known locations of the vertices
190 
191  std::vector< double > x_ref;
192  std::vector< double > y_ref;
193  std::vector< double > z_ref;
194 
195  // Vertex 1
196  x_ref.push_back( 5 );
197  y_ref.push_back( -5 );
198  z_ref.push_back( 5 );
199 
200  // Vertex 2
201  x_ref.push_back( 5 );
202  y_ref.push_back( 5 );
203  z_ref.push_back( 5 );
204 
205  // Vertex 3
206  x_ref.push_back( -5 );
207  y_ref.push_back( 5 );
208  z_ref.push_back( 5 );
209 
210  // Vertex 4
211  x_ref.push_back( -5 );
212  y_ref.push_back( -5 );
213  z_ref.push_back( 5 );
214 
215  // Vertex 5
216  x_ref.push_back( 5 );
217  y_ref.push_back( 5 );
218  z_ref.push_back( -5 );
219 
220  // Vertex 6
221  x_ref.push_back( 5 );
222  y_ref.push_back( -5 );
223  z_ref.push_back( -5 );
224 
225  // Vertex 7
226  x_ref.push_back( -5 );
227  y_ref.push_back( -5 );
228  z_ref.push_back( -5 );
229 
230  // Vertex 8
231  x_ref.push_back( -5 );
232  y_ref.push_back( 5 );
233  z_ref.push_back( -5 );
234 
235  std::cout << verts.size() << std::endl;
236  std::cout << x_ref.size() << std::endl;
237 
238  for( unsigned int i = 0; i < verts.size(); i++ )
239  {
240  for( unsigned int j = 0; j < x_ref.size(); j++ )
241  {
242  if( x[i] == x_ref[j] && y[i] == y_ref[j] && z[i] == z_ref[j] )
243  {
244  x_ref.erase( x_ref.begin() + j );
245  y_ref.erase( y_ref.begin() + j );
246  z_ref.erase( z_ref.begin() + j );
247  }
248  }
249  }
250 
251  // After looping through each vertex loaded from the mesh
252  // there should be no entities left in the reference vector
253  int leftovers = x_ref.size();
254  CHECK_EQUAL( 0, leftovers );
255 }

References CHECK_EQUAL, CHECK_ERR, ErrorCode, moab::Core::get_coords(), moab::Core::get_entities_by_type(), input_cube, mb, MBVERTEX, read_file(), and moab::Range::size().

Referenced by main().

◆ read_cube_verts_test()

void read_cube_verts_test ( )

Definition at line 67 of file read_cgm_basic_test.cpp.

68 {
69  ErrorCode rval;
70  // Open the test file
71  Core moab;
72  Interface* mb = &moab;
73  read_file( mb, input_cube.c_str() );
74 
75  int number_of_vertices;
76  rval = mb->get_number_entities_by_type( 0, MBVERTEX, number_of_vertices );CHECK_ERR( rval );
77  // For a cube there should be exactly 8 vertices
78  CHECK_EQUAL( 8, number_of_vertices );
79 }

References CHECK_EQUAL, CHECK_ERR, ErrorCode, moab::Core::get_number_entities_by_type(), input_cube, mb, MBVERTEX, and read_file().

Referenced by main().

◆ read_cube_vols_test()

void read_cube_vols_test ( )

Definition at line 145 of file read_cgm_basic_test.cpp.

146 {
147  ErrorCode rval;
148  // Open the test file
149  Core moab;
150  Interface* mb = &moab;
151  read_file( mb, input_cube.c_str() );
152 
153  // Get geometry tag for pulling curve data from the mesh
154  Tag geom_tag;
157 
158  // Get the number of volumes from the mesh geometry data
159  int dim = 3;
160  void* val[] = { &dim };
161  int number_of_vols;
162  rval = mb->get_number_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag, val, 1, number_of_vols );CHECK_ERR( rval );
163  CHECK_EQUAL( 1, number_of_vols );
164 }

References CHECK_EQUAL, CHECK_ERR, dim, ErrorCode, GEOM_DIMENSION_TAG_NAME, geom_tag, moab::Core::get_number_entities_by_type_and_tag(), input_cube, mb, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, MBENTITYSET, read_file(), and moab::Core::tag_get_handle().

Referenced by main().

◆ read_file()

bool read_file ( Interface moab,
const char *  input_file 
)

Definition at line 57 of file read_cgm_basic_test.cpp.

58 {
59  InitCGMA::initialize_cgma();
60  GeometryQueryTool::instance()->delete_geometry();
61 
62  ErrorCode rval = moab->load_file( input_file );CHECK_ERR( rval );
63 }

References CHECK_ERR, ErrorCode, and input_file.

Referenced by read_cube_curves_test(), read_cube_surfs_test(), read_cube_tris_test(), read_cube_vertex_pos_test(), read_cube_verts_test(), and read_cube_vols_test().

Variable Documentation

◆ input_cube

const std::string input_cube = TestDir + "unittest/io/cube.sat"