1
2 #include <iostream>
3 #include "moab/Interface.hpp"
4 #ifndef IS_BUILDING_MB
5 #define IS_BUILDING_MB
6 #endif
7 #include "TestUtil.hpp"
8 #include "Internals.hpp"
9 #include "moab/Core.hpp"
10 #include "MBTagConventions.hpp"
11 #include "InitCGMA.hpp"
12 #include "GeometryQueryTool.hpp"
13
14 using namespace moab;
15
16 #define CHKERR(A) do { if (MB_SUCCESS != (A)) { \
17 std::cerr << "Failure (error code " << (A) << ") at " __FILE__ ":" \
18 << __LINE__ << std::endl; \
19 return A; } } while(false)
20
21
22 #ifdef HAVE_OCC_STEP
23 const std::string input_cube = TestDir + "/io/cube.stp";
24 #else
25 const std::string input_cube = TestDir + "/io/cube.sat";
26 #endif
27
28 // Function used to load the test file
29 void read_file( Interface* moab, const char* input_file );
30
31 // List of tests in this file
32 void read_cube_verts_test();
33 void read_cube_curves_test();
34 void read_cube_tris_test();
35 void read_cube_surfs_test();
36 void read_cube_vols_test();
37 void read_cube_vertex_pos_test();
38 //void delete_mesh_test();
39
40
main(int,char **)41 int main(int /* argc */, char** /* argv */)
42 {
43 int result = 0;
44
45 result += RUN_TEST(read_cube_verts_test);
46 result += RUN_TEST(read_cube_curves_test);
47 result += RUN_TEST(read_cube_tris_test);
48 result += RUN_TEST(read_cube_surfs_test);
49 result += RUN_TEST(read_cube_vols_test);
50 result += RUN_TEST(read_cube_vertex_pos_test);
51
52 return result;
53 }
54
55
56
read_file(Interface * moab,const char * input_file)57 void read_file( Interface* moab, const char* input_file )
58 {
59 InitCGMA::initialize_cgma();
60 GeometryQueryTool::instance()->delete_geometry();
61
62 ErrorCode rval = moab->load_file( input_file );
63 CHECK_ERR(rval);
64 }
65
66 // Gets the vertex entities from a simple cube file load and checks that the
67 // correct number of them exist.
read_cube_verts_test()68 void read_cube_verts_test()
69 {
70 ErrorCode rval;
71 //Open the test file
72 Core moab;
73 Interface* mb = &moab;
74 read_file( mb, input_cube.c_str() );
75
76 int number_of_vertices;
77 rval = mb->get_number_entities_by_type( 0, MBVERTEX, number_of_vertices );
78 CHECK_ERR(rval);
79 //For a cube there should be exactly 8 vertices
80 CHECK_EQUAL( 8, number_of_vertices );
81 }
82
83 // Gets the triangle entities from a simple cube file load and checks that the
84 // correct number of them exist.
read_cube_tris_test()85 void read_cube_tris_test()
86 {
87 ErrorCode rval;
88 //Open the test file
89 Core moab;
90 Interface* mb = &moab;
91 read_file( mb, input_cube.c_str() );
92
93 int number_of_tris;
94
95 rval = mb->get_number_entities_by_type( 0, MBTRI , number_of_tris );
96 std::cout << "Number of Triangles = " << number_of_tris << std::endl;
97 CHECK_ERR(rval);
98 //For a cube, there should be exactly 2 triangles per face
99 CHECK_EQUAL( 12, number_of_tris );
100 }
101
102 // Gets the curve entities from a simple cube file load and checks that the
103 // correct number of them exist.
read_cube_curves_test()104 void read_cube_curves_test()
105 {
106 ErrorCode rval;
107 //Open the test file
108 Core moab;
109 Interface* mb = &moab;
110 read_file( mb, input_cube.c_str() );
111 //Get the geometry tag handle from the mesh
112 Tag geom_tag;
113 rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1,
114 MB_TYPE_INTEGER, geom_tag, moab::MB_TAG_DENSE|moab::MB_TAG_CREAT );
115 CHECK_ERR(rval);
116 //Get the curves from the mesh
117 int dim = 1;
118 void *val[] = {&dim};
119 int number_of_curves;
120 rval = mb->get_number_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag,
121 val, 1, number_of_curves );
122 CHECK_ERR(rval);
123 //For a cube, there should be exactly 12 curves loaded from the file
124 CHECK_EQUAL( 12, number_of_curves );
125
126 }
127
128 // Gets the surface entities from a simple cube file load and checks that the
129 // correct number of them exist.
read_cube_surfs_test()130 void read_cube_surfs_test()
131 {
132 ErrorCode rval;
133 //Open the test file
134 Core moab;
135 Interface* mb = &moab;
136 read_file( mb, input_cube.c_str() );
137
138 //Get geometry tag for pulling curve data from the mesh
139 Tag geom_tag;
140 rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER,
141 geom_tag, moab::MB_TAG_DENSE|moab::MB_TAG_CREAT );
142 CHECK_ERR(rval);
143
144 //Get the number of surface from the mesh geometry data
145 int dim = 2;
146 void *val[] = {&dim};
147 int number_of_surfs;
148 rval = mb->get_number_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag,
149 val, 1, number_of_surfs );
150 CHECK_ERR(rval);
151 //For a cube, there should be exactly 6 surfaces
152 CHECK_EQUAL( 6, number_of_surfs );
153
154 }
155
read_cube_vols_test()156 void read_cube_vols_test()
157 {
158 ErrorCode rval;
159 //Open the test file
160 Core moab;
161 Interface* mb = &moab;
162 read_file( mb, input_cube.c_str() );
163
164 //Get geometry tag for pulling curve data from the mesh
165 Tag geom_tag;
166 rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER,
167 geom_tag, moab::MB_TAG_DENSE|moab::MB_TAG_CREAT );
168 CHECK_ERR(rval);
169
170 //Get the number of volumes from the mesh geometry data
171 int dim = 3;
172 void *val[] = {&dim};
173 int number_of_vols;
174 rval = mb->get_number_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag,
175 val, 1, number_of_vols );
176 CHECK_ERR(rval);
177 CHECK_EQUAL( 1, number_of_vols );
178 }
179
180 // Gets the vertex eitities from a simple cube file load and checks that
181 // they are in the correct locations.
read_cube_vertex_pos_test()182 void read_cube_vertex_pos_test()
183 {
184
185 ErrorCode rval;
186 //Open the test file
187 Core moab;
188 Interface* mb = &moab;
189 read_file( mb, input_cube.c_str() );
190
191 //Retrieve all vertex handles from the mesh
192 Range verts;
193 rval = mb->get_entities_by_type( 0, MBVERTEX, verts );
194 CHECK_ERR( rval );
195
196 int number_of_verts = verts.size();
197 CHECK_EQUAL( 8, number_of_verts );
198 //Get the vertex coordinates
199 double x[8];
200 double y[8];
201 double z[8];
202 rval = mb-> get_coords( verts, &x[0], &y[0], &z[0] );
203 CHECK_ERR(rval);
204
205 //Check against known locations of the vertices
206
207 std::vector<double> x_ref;
208 std::vector<double> y_ref;
209 std::vector<double> z_ref;
210
211 // Vertex 1
212 x_ref.push_back( 5 );
213 y_ref.push_back( -5 );
214 z_ref.push_back( 5 );
215
216 // Vertex 2
217 x_ref.push_back( 5 );
218 y_ref.push_back( 5 );
219 z_ref.push_back( 5 );
220
221 // Vertex 3
222 x_ref.push_back( -5 );
223 y_ref.push_back( 5 );
224 z_ref.push_back( 5 );
225
226 // Vertex 4
227 x_ref.push_back( -5 );
228 y_ref.push_back( -5 );
229 z_ref.push_back( 5 );
230
231 // Vertex 5
232 x_ref.push_back( 5 );
233 y_ref.push_back( 5 );
234 z_ref.push_back( -5 );
235
236 // Vertex 6
237 x_ref.push_back( 5 );
238 y_ref.push_back( -5 );
239 z_ref.push_back( -5 );
240
241 // Vertex 7
242 x_ref.push_back( -5 );
243 y_ref.push_back( -5 );
244 z_ref.push_back( -5 );
245
246 // Vertex 8
247 x_ref.push_back( -5 );
248 y_ref.push_back( 5 );
249 z_ref.push_back( -5 );
250
251 std::cout << verts.size() << std::endl;
252 std::cout << x_ref.size() << std::endl;
253
254 for(unsigned int i=0; i<verts.size(); i++)
255 {
256 for(unsigned int j=0; j<x_ref.size(); j++)
257 {
258 if( x[i]==x_ref[j] && y[i]==y_ref[j] && z[i]==z_ref[j] )
259 {
260 x_ref.erase( x_ref.begin()+j );
261 y_ref.erase( y_ref.begin()+j );
262 z_ref.erase( z_ref.begin()+j );
263 }
264 }
265 }
266
267 //After looping through each vertex loaded from the mesh
268 //there should be no entities left in the reference vector
269 int leftovers = x_ref.size();
270 CHECK_EQUAL( 0, leftovers );
271
272 }
273
274 //Superfluous test for ReadCGM, but perhaps better
275 //than the test in place for moab::delete_geometry()
276
277
278 /*
279 void delete_mesh_test()
280 {
281 Core moab;
282 Interface* mb = &moab;
283 read_file( mb, input_cube );
284
285 ErrorCode rval;
286
287 //Get geometry tag for pulling curve data from the mesh
288 Tag geom_tag;
289 rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER,
290 geom_tag, moab::MB_TAG_DENSE|moab::MB_TAG_CREAT );
291 CHECK_ERR(rval);
292
293 Range geom_sets[4];
294
295 for(unsigned dim=0; dim<4; dim++)
296 {
297 void *val[] = {&dim};
298 rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag,
299 val, 1, geom_sets[dim] );
300 CHECK_ERR(rval);
301
302 if( geom_sets[dim].size() == 0 ) std::cout << "Warning: No geom sets to begin with" << std::endl;
303
304 }
305
306 mb->delete_mesh();
307
308 Range geom_sets_after[4];
309 for(unsigned dim=0; dim<4; dim++)
310 {
311 void *val_after[] = {&dim};
312 rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &geom_tag,
313 val_after, 1, geom_sets_after[dim] );
314 CHECK_ERR(rval);
315
316 if( 0 != geom_sets_after[dim].size() ) rval = MB_FAILURE;
317
318 CHECK_ERR(rval);
319 }
320
321 }
322
323 */
324