MOAB: Mesh Oriented datABase  (version 5.5.0)
read_cgm_connectivity_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 "moab/MeshTopoUtil.hpp"
+ Include dependency graph for read_cgm_connectivity_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 cube_verts_connectivity_test ()
 
void cube_tris_connectivity_test ()
 
void cube_tri_curve_coincidence_test ()
 
void cube_edge_adjacencies_test ()
 
void cube_tri_vertex_test ()
 
void match_tri_edges_w_curve (const Range &tri_edges, const Range &curves)
 
int main (int, char **)
 

Variables

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_connectivity_test.cpp.

◆ IS_BUILDING_MB

#define IS_BUILDING_MB

Definition at line 4 of file read_cgm_connectivity_test.cpp.

Function Documentation

◆ cube_edge_adjacencies_test()

void cube_edge_adjacencies_test ( )

Definition at line 176 of file read_cgm_connectivity_test.cpp.

177 {
178  ErrorCode rval;
179  // Open the test file
180  Core moab;
181  Interface* mb = &moab;
182  read_file( mb, input_cube.c_str() );
183 
184  // Get the curves
185  Range curves;
186  rval = mb->get_entities_by_type( 0, MBEDGE, curves );CHECK_ERR( rval );
187 
188  for( Range::const_iterator i = curves.begin(); i != curves.end(); ++i )
189  {
190  // Get triangle adjacent to each edge
191  Range adj_tris;
192  rval = mb->get_adjacencies( &( *i ), 1, 2, false, adj_tris );CHECK_ERR( rval );
193 
194  int num_adj_tris = adj_tris.size();
195  // Ensure that no edge is adjacent to more than two triangles
196  CHECK( num_adj_tris <= 2 );
197  }
198 }

References moab::Range::begin(), CHECK, CHECK_ERR, moab::Range::end(), ErrorCode, moab::Core::get_adjacencies(), moab::Core::get_entities_by_type(), input_cube, mb, MBEDGE, read_file(), and moab::Range::size().

◆ cube_tri_curve_coincidence_test()

void cube_tri_curve_coincidence_test ( )

Definition at line 123 of file read_cgm_connectivity_test.cpp.

124 {
125 
126  ErrorCode rval;
127  // Open the test file
128  Core moab;
129  Interface* mb = &moab;
130  read_file( mb, input_cube.c_str() );
131 
132  // Get curves from the mesh
133  Range curves;
134  rval = mb->get_entities_by_type( 0, MBEDGE, curves );CHECK_ERR( rval );
135  curves.print();
136 
137  // Get triangles from the mesh
138  Range tris;
139  rval = mb->get_entities_by_type( 0, MBTRI, tris );CHECK_ERR( rval );
140 
141  for( Range::const_iterator i = tris.begin(); i != tris.end(); ++i )
142  {
143  // Get the any curve edges that are a part of the triangle
144  Range tri_edges;
145  rval = mb->get_adjacencies( &( *i ), 1, 1, false, tri_edges );CHECK_ERR( rval );
146  // Check that we've retrieved two edges from get_adjacencies
147  // For a this file (cube), each triangle should have two curve
148  // edges
149  int num_of_tri_edges = tri_edges.size();
150  CHECK_EQUAL( 2, num_of_tri_edges );
151  match_tri_edges_w_curve( tri_edges, curves );CHECK_ERR( rval );
152  }
153 }

References moab::Range::begin(), CHECK_EQUAL, CHECK_ERR, moab::Range::end(), ErrorCode, moab::Core::get_adjacencies(), moab::Core::get_entities_by_type(), input_cube, match_tri_edges_w_curve(), mb, MBEDGE, MBTRI, moab::Range::print(), read_file(), and moab::Range::size().

Referenced by main().

◆ cube_tri_vertex_test()

void cube_tri_vertex_test ( )

Definition at line 201 of file read_cgm_connectivity_test.cpp.

202 {
203  ErrorCode rval;
204  // Open the test file
205  Core moab;
206  Interface* mb = &moab;
207  read_file( mb, input_cube.c_str() );
208 
209  // Get all triangles
210  Range tris;
211  rval = mb->get_entities_by_type( 0, MBTRI, tris );CHECK_ERR( rval );
212 
213  for( Range::const_iterator i = tris.begin(); i != tris.end(); ++i )
214  {
215  // Get all triangle vertices
216  Range verts;
217  rval = mb->get_connectivity( &( *i ), 1, verts );CHECK_ERR( rval );
218  // Make sure that each vertex making up
219  // the triangle is different
220  int number_of_verts = verts.size();
221  CHECK( 3 == number_of_verts );
222  CHECK( verts[0] != verts[1] );
223  CHECK( verts[1] != verts[2] );
224  CHECK( verts[2] != verts[0] );
225  }
226 }

References moab::Range::begin(), CHECK, CHECK_ERR, moab::Range::end(), ErrorCode, moab::Core::get_connectivity(), moab::Core::get_entities_by_type(), input_cube, mb, MBTRI, read_file(), and moab::Range::size().

Referenced by main().

◆ cube_tris_connectivity_test()

void cube_tris_connectivity_test ( )

Definition at line 92 of file read_cgm_connectivity_test.cpp.

93 {
94  ErrorCode rval;
95  // Open the test file
96  Core moab;
97  Interface* mb = &moab;
98  read_file( mb, input_cube.c_str() );
99 
100  // Get triangles from the mesh
101  Range tris;
102  rval = mb->get_entities_by_type( 0, MBTRI, tris );CHECK_ERR( rval );
103 
104  int expected_num_of_adj_tris = 3;
105 
106  for( Range::const_iterator i = tris.begin() + 1; i != tris.end(); ++i )
107  {
108  Range adj_tris;
109  moab::MeshTopoUtil mu( mb );
110  // Use Triangle edges to get all adjacent triangles
111  rval = mu.get_bridge_adjacencies( *i, 1, 2, adj_tris );CHECK_ERR( rval );
112  CHECK_EQUAL( expected_num_of_adj_tris, (int)adj_tris.size() );
113 
114  // Check that the entities we found from bridge_adjacencies
115  // are triangles
116  Range adj_tri_test = adj_tris.subset_by_type( MBTRI );
117  CHECK_EQUAL( (int)adj_tris.size(), (int)adj_tri_test.size() );
118  }
119 }

References moab::Range::begin(), CHECK_EQUAL, CHECK_ERR, moab::Range::end(), ErrorCode, moab::MeshTopoUtil::get_bridge_adjacencies(), moab::Core::get_entities_by_type(), input_cube, mb, MBTRI, read_file(), moab::Range::size(), and moab::Range::subset_by_type().

Referenced by main().

◆ cube_verts_connectivity_test()

void cube_verts_connectivity_test ( )

Definition at line 66 of file read_cgm_connectivity_test.cpp.

67 {
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  // Get all vertex handles from the mesh
76  Range verts;
77  rval = mb->get_entities_by_type( 0, MBVERTEX, verts );CHECK_ERR( rval );
78 
79  // Check that each vertex connects to at least 4 and no more than 6 triangles
80  for( Range::const_iterator i = verts.begin(); i != verts.end(); ++i )
81  {
82  std::vector< EntityHandle > adj_tris;
83  rval = mb->get_adjacencies( &( *i ), 1, 2, false, adj_tris );CHECK_ERR( rval );
84 
85  int adj_size = adj_tris.size();
86  CHECK( adj_size >= 4 && adj_size <= 6 );
87  }
88 }

References moab::Range::begin(), CHECK, CHECK_ERR, moab::Range::end(), ErrorCode, moab::Core::get_adjacencies(), moab::Core::get_entities_by_type(), input_cube, mb, MBVERTEX, and read_file().

Referenced by main().

◆ main()

int main ( int  ,
char **   
)

Definition at line 44 of file read_cgm_connectivity_test.cpp.

45 {
46  int result = 0;
47 
51  result += RUN_TEST( cube_tri_vertex_test );
52 
53  return result;
54 }

References cube_tri_curve_coincidence_test(), cube_tri_vertex_test(), cube_tris_connectivity_test(), cube_verts_connectivity_test(), and RUN_TEST.

◆ match_tri_edges_w_curve()

void match_tri_edges_w_curve ( const Range tri_edges,
const Range curves 
)

Definition at line 155 of file read_cgm_connectivity_test.cpp.

156 {
157  int match_counter = 0;
158  int num_of_tri_edges = tri_edges.size();
159  CHECK( num_of_tri_edges );
160  for( Range::const_iterator i = tri_edges.begin(); i != tri_edges.end(); ++i )
161  {
162  for( Range::const_iterator j = curves.begin(); j != curves.end(); ++j )
163  {
164  // If the edge handle matches a curve handle, increment the number
165  // matches
166  if( *i == *j ) match_counter++;
167  }
168  }
169  // Make sure that each edge returned from triangle edges
170  // has been matched to a curve
171  CHECK_EQUAL( num_of_tri_edges, match_counter );
172 }

References moab::Range::begin(), CHECK, CHECK_EQUAL, moab::Range::end(), and moab::Range::size().

Referenced by cube_tri_curve_coincidence_test().

◆ read_file()

void read_file ( Interface moab,
const char *  input_file 
)

Definition at line 56 of file read_cgm_connectivity_test.cpp.

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

References CHECK_ERR, ErrorCode, and input_file.

Referenced by cube_edge_adjacencies_test(), cube_tri_curve_coincidence_test(), cube_tri_vertex_test(), cube_tris_connectivity_test(), and cube_verts_connectivity_test().

Variable Documentation

◆ input_cube

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