Branch data Line data Source code
1 : : /**
2 : : * This library is free software; you can redistribute it and/or
3 : : * modify it under the terms of the GNU Lesser General Public
4 : : * License as published by the Free Software Foundation; either
5 : : * version 2.1 of the License, or (at your option) any later version.
6 : : *
7 : : */
8 : : /**
9 : : * \file testgeom.cc
10 : : *
11 : : * \brief testgeom, a unit test for the ITAPS geometry interface
12 : : *
13 : : */
14 : : #include "FBiGeom.h"
15 : : #include <iostream>
16 : : #include <set>
17 : : #include <algorithm>
18 : : #include <vector>
19 : : #include <iterator>
20 : : #include <algorithm>
21 : : #include <iomanip>
22 : : #include <assert.h>
23 : : #include <string.h>
24 : : #include <math.h>
25 : : #define CHECK( STR ) \
26 : : if( err != iBase_SUCCESS ) return print_error( STR, err, geom, __FILE__, __LINE__ )
27 : :
28 : : #define STRINGIFY( S ) XSTRINGIFY( S )
29 : : #define XSTRINGIFY( S ) #S
30 : :
31 : 0 : static bool print_error( const char* desc, int err, FBiGeom_Instance geom, const char* file, int line )
32 : : {
33 : : char buffer[1024];
34 [ # # ]: 0 : FBiGeom_getDescription( geom, buffer, sizeof( buffer ) );
35 : 0 : buffer[sizeof( buffer ) - 1] = '\0';
36 : :
37 [ # # ][ # # ]: 0 : std::cerr << "ERROR: " << desc << std::endl
[ # # ]
38 [ # # ][ # # ]: 0 : << " Error code: " << err << std::endl
[ # # ]
39 [ # # ][ # # ]: 0 : << " Error desc: " << buffer << std::endl
[ # # ]
40 [ # # ][ # # ]: 0 : << " At : " << file << ':' << line << std::endl;
[ # # ][ # # ]
[ # # ]
41 : :
42 : 0 : return false; // must always return false or CHECK macro will break
43 : : }
44 : :
45 : : typedef iBase_TagHandle TagHandle;
46 : : typedef iBase_EntityHandle GentityHandle;
47 : : typedef iBase_EntitySetHandle GentitysetHandle;
48 : :
49 : : /* Frees allocated arrays for us */
50 : : template < typename T >
51 : : class SimpleArray
52 : : {
53 : : private:
54 : : T* arr;
55 : : int arrSize;
56 : : int arrAllocated;
57 : :
58 : : public:
59 : 77 : SimpleArray() : arr( 0 ), arrSize( 0 ), arrAllocated( 0 ) {}
60 : 0 : SimpleArray( unsigned s ) : arrSize( s ), arrAllocated( s )
61 : : {
62 : 0 : arr = (T*)malloc( s * sizeof( T ) );
63 [ # # ]: 0 : for( unsigned i = 0; i < s; ++i )
64 [ # # ]: 0 : new( arr + i ) T();
65 : 0 : }
66 : :
67 : 77 : ~SimpleArray()
68 : : {
69 [ # # ][ # # ]: 330 : for( int i = 0; i < size(); ++i )
[ + + ][ + + ]
[ + + ]
70 : 253 : arr[i].~T();
71 : 77 : free( arr );
72 : 77 : }
73 : :
74 : 77 : T** ptr()
75 : : {
76 : 77 : return &arr;
77 : : }
78 : 458 : int& size()
79 : : {
80 : 458 : return arrSize;
81 : : }
82 : : int size() const
83 : : {
84 : : return arrSize;
85 : : }
86 : 77 : int& capacity()
87 : : {
88 : 77 : return arrAllocated;
89 : : }
90 : : int capacity() const
91 : : {
92 : : return arrAllocated;
93 : : }
94 : :
95 : : typedef T* iterator;
96 : : typedef const T* const_iterator;
97 : 53 : iterator begin()
98 : : {
99 : 53 : return arr;
100 : : }
101 : : const_iterator begin() const
102 : : {
103 : : return arr;
104 : : }
105 : 83 : iterator end()
106 : : {
107 : 83 : return arr + arrSize;
108 : : }
109 : : const_iterator end() const
110 : : {
111 : : return arr + arrSize;
112 : : }
113 : :
114 : 57 : T& operator[]( unsigned idx )
115 : : {
116 : 57 : return arr[idx];
117 : : }
118 : : T operator[]( unsigned idx ) const
119 : : {
120 : : return arr[idx];
121 : : }
122 : : };
123 : :
124 : : #define ARRAY_INOUT( A ) A.ptr(), &A.capacity(), &A.size()
125 : : #define ARRAY_IN( A ) &A[0], A.size()
126 : :
127 : : bool gLoad_test( const std::string& filename, FBiGeom_Instance );
128 : :
129 : : bool tags_test( FBiGeom_Instance geom );
130 : : bool tag_get_set_test( FBiGeom_Instance geom );
131 : : bool tag_info_test( FBiGeom_Instance geom );
132 : : bool gentityset_test( FBiGeom_Instance geom, bool /*multiset*/, bool /*ordered*/ );
133 : : bool topology_adjacencies_test( FBiGeom_Instance geom );
134 : : bool geometry_evaluation_test( FBiGeom_Instance geom );
135 : : bool construct_test( FBiGeom_Instance geom );
136 : : bool primitives_test( FBiGeom_Instance geom );
137 : : bool transforms_test( FBiGeom_Instance geom );
138 : : bool booleans_test( FBiGeom_Instance geom );
139 : : bool shutdown_test( FBiGeom_Instance geom, std::string& engine_opt );
140 : : bool save_entset_test( FBiGeom_Instance geom );
141 : : bool mesh_size_test( FBiGeom_Instance geom );
142 : :
143 : 5 : void handle_error_code( const bool result, int& number_failed, int& /*number_not_implemented*/, int& number_successful )
144 : : {
145 [ + - ]: 5 : if( result )
146 : : {
147 : 5 : std::cout << "Success";
148 : 5 : number_successful++;
149 : : }
150 : : else
151 : : {
152 : 0 : std::cout << "Failure";
153 : 0 : number_failed++;
154 : : }
155 : 5 : }
156 : :
157 : 1 : int main( int argc, char* argv[] )
158 : : {
159 [ + - ]: 1 : std::string filename = STRINGIFY( MESHDIR ) "/shell.h5m";
160 [ + - ]: 2 : std::string engine_opt;
161 : :
162 [ + - ][ + - ]: 1 : if( argc == 1 ) { std::cout << "Using default input file: " << filename << std::endl; }
[ + - ][ + - ]
163 [ # # ]: 0 : else if( argc == 2 )
164 : : {
165 [ # # ]: 0 : filename = argv[1];
166 : : }
167 : : else
168 : : {
169 [ # # ][ # # ]: 0 : std::cerr << "Usage: " << argv[0] << " [geom_filename]" << std::endl;
[ # # ][ # # ]
170 : 0 : return 1;
171 : : }
172 : :
173 : : bool result;
174 : 1 : int number_tests = 0;
175 : 1 : int number_tests_successful = 0;
176 : 1 : int number_tests_not_implemented = 0;
177 : 1 : int number_tests_failed = 0;
178 : :
179 : : // initialize the Mesh
180 : : int err;
181 : : FBiGeom_Instance geom;
182 [ + - ]: 1 : FBiGeom_newGeom( engine_opt.c_str(), &geom, &err, engine_opt.length() );
183 : :
184 : : // Print out Header information
185 [ + - ]: 1 : std::cout << "\n\nITAPS GEOMETRY INTERFACE TEST PROGRAM:\n\n";
186 : : // gLoad test
187 [ + - ]: 1 : std::cout << " gLoad: ";
188 [ + - ]: 1 : result = gLoad_test( filename, geom );
189 [ + - ]: 1 : handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
190 : 1 : number_tests++;
191 [ + - ]: 1 : std::cout << "\n";
192 : :
193 : : // tags test
194 [ + - ]: 1 : std::cout << " tags: ";
195 [ + - ]: 1 : result = tags_test( geom );
196 [ + - ]: 1 : handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
197 : 1 : number_tests++;
198 [ + - ]: 1 : std::cout << "\n";
199 : : /*
200 : : // gentitysets test
201 : : std::cout << " gentity sets: ";
202 : : result = gentityset_test(geom, false, false);
203 : : handle_error_code(result, number_tests_failed,
204 : : number_tests_not_implemented,
205 : : number_tests_successful);
206 : : number_tests++;
207 : : std::cout << "\n";
208 : : */
209 : : // topology adjacencies test
210 [ + - ]: 1 : std::cout << " topology adjacencies: ";
211 [ + - ]: 1 : result = topology_adjacencies_test( geom );
212 [ + - ]: 1 : handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
213 : 1 : number_tests++;
214 [ + - ]: 1 : std::cout << "\n";
215 : :
216 : : // geometry evaluation test
217 [ + - ]: 1 : std::cout << " geometry evaluation: ";
218 [ + - ]: 1 : result = geometry_evaluation_test( geom );
219 [ + - ]: 1 : handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
220 : 1 : number_tests++;
221 [ + - ]: 1 : std::cout << "\n";
222 : : /*
223 : : // construct test
224 : : std::cout << " construct: ";
225 : : result = construct_test(geom);
226 : : handle_error_code(result, number_tests_failed,
227 : : number_tests_not_implemented,
228 : : number_tests_successful);
229 : : number_tests++;
230 : : std::cout << "\n";
231 : :
232 : : // primitives test
233 : : std::cout << " primitives: ";
234 : : result = primitives_test(geom);
235 : : handle_error_code(result, number_tests_failed,
236 : : number_tests_not_implemented,
237 : : number_tests_successful);
238 : : number_tests++;
239 : : std::cout << "\n";
240 : :
241 : : // transforms test
242 : : std::cout << " transforms: ";
243 : : result = transforms_test(geom);
244 : : handle_error_code(result, number_tests_failed,
245 : : number_tests_not_implemented,
246 : : number_tests_successful);
247 : : number_tests++;
248 : : std::cout << "\n";
249 : :
250 : : // booleans test
251 : : std::cout << " booleans: ";
252 : : result = booleans_test(geom);
253 : : handle_error_code(result, number_tests_failed,
254 : : number_tests_not_implemented,
255 : : number_tests_successful);
256 : : number_tests++;
257 : : std::cout << "\n";
258 : :
259 : : #if defined(HAVE_ACIS) && !defined(FORCE_OCC)
260 : : std::cout << " mesh size: ";
261 : : result = mesh_size_test(geom);
262 : : handle_error_code(result, number_tests_failed,
263 : : number_tests_not_implemented,
264 : : number_tests_successful);
265 : : number_tests++;
266 : : std::cout << "\n";
267 : :
268 : : // save entset test
269 : : std::cout << " save entset: ";
270 : : result = save_entset_test(geom);
271 : : handle_error_code(result, number_tests_failed,
272 : : number_tests_not_implemented,
273 : : number_tests_successful);
274 : : number_tests++;
275 : : std::cout << "\n";
276 : : #endif
277 : : */
278 : : // shutdown test
279 [ + - ]: 1 : std::cout << " shutdown: ";
280 [ + - ]: 1 : result = shutdown_test( geom, engine_opt );
281 [ + - ]: 1 : handle_error_code( result, number_tests_failed, number_tests_not_implemented, number_tests_successful );
282 : 1 : number_tests++;
283 [ + - ]: 1 : std::cout << "\n";
284 : :
285 : : // summary
286 : :
287 [ + - ]: 1 : std::cout << "\nTSTT TEST SUMMARY: \n"
288 [ + - ][ + - ]: 1 : << " Number Tests: " << number_tests << "\n"
[ + - ]
289 [ + - ][ + - ]: 1 : << " Number Successful: " << number_tests_successful << "\n"
[ + - ]
290 [ + - ][ + - ]: 1 : << " Number Not Implemented: " << number_tests_not_implemented << "\n"
[ + - ]
291 [ + - ][ + - ]: 1 : << " Number Failed: " << number_tests_failed << "\n\n"
[ + - ]
292 [ + - ]: 1 : << std::endl;
293 : :
294 : 2 : return number_tests_failed;
295 : : }
296 : :
297 : : /*!
298 : : @test
299 : : Load Mesh
300 : : @li Load a mesh file
301 : : */
302 : 1 : bool gLoad_test( const std::string& filename, FBiGeom_Instance geom )
303 : : {
304 : : int err;
305 [ + - ][ + - ]: 1 : FBiGeom_load( geom, &filename[0], 0, &err, filename.length(), 0 );
306 [ - + ][ # # ]: 1 : CHECK( "ERROR : can not load a geometry" );
307 : :
308 : : iBase_EntitySetHandle root_set;
309 [ + - ]: 1 : FBiGeom_getRootSet( geom, &root_set, &err );
310 [ - + ][ # # ]: 1 : CHECK( "ERROR : getRootSet failed!" );
311 : :
312 : : // print out the number of entities
313 [ + - ][ + - ]: 1 : std::cout << "Model contents: " << std::endl;
314 : 1 : const char* gtype[] = { "vertices: ", "edges: ", "faces: ", "regions: " };
315 [ + + ]: 5 : for( int i = 0; i <= 3; ++i )
316 : : {
317 : : int count;
318 [ + - ]: 4 : FBiGeom_getNumOfType( geom, root_set, i, &count, &err );
319 [ - + ][ # # ]: 4 : CHECK( "Error: problem getting entities after gLoad." );
320 [ + - ][ + - ]: 4 : std::cout << gtype[i] << count << std::endl;
[ + - ]
321 : : }
322 : :
323 : 1 : return true;
324 : : }
325 : :
326 : : /*!
327 : : @test
328 : : Test tag creating, reading, writing, deleting
329 : : @li Load a mesh file
330 : : */
331 : 1 : bool tags_test( FBiGeom_Instance geom )
332 : : {
333 : 1 : bool success = tag_info_test( geom );
334 [ - + ]: 1 : if( !success ) return success;
335 : :
336 : 1 : success = tag_get_set_test( geom );
337 [ - + ]: 1 : if( !success ) return success;
338 : :
339 : 1 : return true;
340 : : }
341 : :
342 : 1 : bool tag_info_test( FBiGeom_Instance geom )
343 : : {
344 : : int err;
345 : :
346 : : iBase_EntitySetHandle root_set;
347 [ + - ]: 1 : FBiGeom_getRootSet( geom, &root_set, &err );
348 [ - + ][ # # ]: 1 : CHECK( "ERROR : getRootSet failed!" );
349 : :
350 : : // create an arbitrary tag, size 4
351 : : iBase_TagHandle this_tag, tmp_handle;
352 [ + - ][ + - ]: 2 : std::string tag_name( "tag_info tag" ), tmp_name;
353 [ + - ][ + - ]: 1 : FBiGeom_createTag( geom, &tag_name[0], 4, iBase_BYTES, &this_tag, &err, tag_name.length() );
354 [ - + ][ # # ]: 1 : CHECK( "ERROR : can not create a tag." );
355 : :
356 : : // get information on the tag
357 : :
358 : : char name_buffer[256];
359 [ + - ]: 1 : FBiGeom_getTagName( geom, this_tag, name_buffer, &err, sizeof( name_buffer ) );
360 [ - + ][ # # ]: 1 : CHECK( "ERROR : Couldn't get tag name." );
361 [ + - ][ - + ]: 1 : if( tag_name != name_buffer )
362 : : {
363 [ # # ][ # # ]: 0 : std::cerr << "ERROR: getTagName returned '" << name_buffer << "' for tag created as '" << tag_name << "'"
[ # # ][ # # ]
[ # # ]
364 [ # # ]: 0 : << std::endl;
365 : 0 : return false;
366 : : }
367 : :
368 [ + - ][ + - ]: 1 : FBiGeom_getTagHandle( geom, &tag_name[0], &tmp_handle, &err, tag_name.length() );
369 [ - + ][ # # ]: 1 : CHECK( "ERROR : Couldn't get tag handle." );
370 [ - + ]: 1 : if( tmp_handle != this_tag )
371 : : {
372 [ # # ][ # # ]: 0 : std::cerr << "ERROR: getTagHandle didn't return consistent result." << std::endl;
373 : 0 : return false;
374 : : }
375 : :
376 : : int tag_size;
377 [ + - ]: 1 : FBiGeom_getTagSizeBytes( geom, this_tag, &tag_size, &err );
378 [ - + ][ # # ]: 1 : CHECK( "ERROR : Couldn't get tag size." );
379 [ - + ]: 1 : if( tag_size != 4 )
380 : : {
381 [ # # ][ # # ]: 0 : std::cerr << "ERROR: getTagSizeBytes: expected 4, got " << tag_size << std::endl;
[ # # ]
382 : 0 : return false;
383 : : }
384 : :
385 [ + - ]: 1 : FBiGeom_getTagSizeValues( geom, this_tag, &tag_size, &err );
386 [ - + ][ # # ]: 1 : CHECK( "ERROR : Couldn't get tag size." );
387 [ - + ]: 1 : if( tag_size != 4 )
388 : : {
389 [ # # ][ # # ]: 0 : std::cerr << "ERROR: getTagSizeValues: expected 4, got " << tag_size << std::endl;
[ # # ]
390 : 0 : return false;
391 : : }
392 : :
393 : : int tag_type;
394 [ + - ]: 1 : FBiGeom_getTagType( geom, this_tag, &tag_type, &err );
395 [ - + ][ # # ]: 1 : CHECK( "ERROR : Couldn't get tag type." );
396 [ - + ]: 1 : if( tag_type != iBase_BYTES )
397 : : {
398 [ # # ][ # # ]: 0 : std::cerr << "ERROR: getTagType: expected " << iBase_BYTES << ", got " << tag_type << std::endl;
[ # # ][ # # ]
[ # # ]
399 : 0 : return false;
400 : : }
401 : :
402 [ + - ]: 1 : FBiGeom_destroyTag( geom, this_tag, true, &err );
403 [ - + ][ # # ]: 1 : CHECK( "ERROR : Couldn't delete a tag." );
404 : :
405 : : // print information about all the tags in the model
406 : :
407 [ + - ]: 2 : std::set< iBase_TagHandle > tags;
408 [ + - ]: 2 : SimpleArray< iBase_EntityHandle > entities;
409 [ + - ][ + - ]: 1 : FBiGeom_getEntities( geom, root_set, iBase_ALL_TYPES, ARRAY_INOUT( entities ), &err );
[ + - ][ + - ]
410 [ - + ][ # # ]: 1 : CHECK( "getEntities( ..., iBase_ALL_TYPES, ... ) failed." );
411 [ + - ][ + + ]: 16 : for( int i = 0; i < entities.size(); ++i )
412 : : {
413 [ + - ]: 15 : SimpleArray< iBase_TagHandle > tag_arr;
414 [ + - ][ + - ]: 15 : FBiGeom_getAllTags( geom, entities[i], ARRAY_INOUT( tag_arr ), &err );
[ + - ][ + - ]
[ + - ]
415 [ - + ][ # # ]: 15 : CHECK( "getAllTags failed." );
416 [ + - ][ + - ]: 15 : std::copy( tag_arr.begin(), tag_arr.end(), std::inserter( tags, tags.begin() ) );
[ + - ][ + - ]
[ + - ]
417 : 15 : }
418 : :
419 [ + - ]: 1 : std::cout << "Tags defined on model: ";
420 : 1 : bool first = true;
421 [ + - ][ + - ]: 4 : for( std::set< iBase_TagHandle >::iterator sit = tags.begin(); sit != tags.end(); ++sit )
[ + + ]
422 : : {
423 [ + - ][ + - ]: 3 : FBiGeom_getTagName( geom, *sit, name_buffer, &err, sizeof( name_buffer ) );
424 : 3 : name_buffer[sizeof( name_buffer ) - 1] = '\0'; // mnake sure of NUL termination
425 [ - + ][ # # ]: 3 : CHECK( "getTagName failed." );
426 : :
427 [ + + ][ + - ]: 3 : if( !first ) std::cout << ", ";
428 [ + - ]: 3 : std::cout << name_buffer;
429 : 3 : first = false;
430 : : }
431 [ - + ][ # # ]: 1 : if( first ) std::cout << "<none>";
432 [ + - ]: 1 : std::cout << std::endl;
433 : :
434 : 2 : return true;
435 : : }
436 : :
437 : 1 : bool tag_get_set_test( FBiGeom_Instance geom )
438 : : {
439 : : int err;
440 : :
441 : : // create an arbitrary tag, size 4
442 : : iBase_TagHandle this_tag;
443 [ + - ]: 1 : std::string tag_name( "tag_get_set tag" );
444 [ + - ][ + - ]: 1 : FBiGeom_createTag( geom, &tag_name[0], sizeof( int ), iBase_BYTES, &this_tag, &err, tag_name.length() );
445 [ - + ][ # # ]: 1 : CHECK( "ERROR : can not create a tag for get_set test." );
446 : :
447 : : iBase_EntitySetHandle root_set;
448 [ + - ]: 1 : FBiGeom_getRootSet( geom, &root_set, &err );
449 [ - + ][ # # ]: 1 : CHECK( "ERROR : getRootSet failed!" );
450 : :
451 : : // set this tag to an integer on each entity; keep track of total sum
452 : 1 : int sum = 0, num = 0, dim;
453 [ + + ]: 5 : for( dim = 0; dim <= 3; dim++ )
454 : : {
455 [ + - ]: 4 : SimpleArray< iBase_EntityHandle > gentity_handles;
456 [ + - ][ + - ]: 4 : FBiGeom_getEntities( geom, root_set, dim, ARRAY_INOUT( gentity_handles ), &err );
[ + - ][ + - ]
457 [ + - ]: 4 : int num_ents = gentity_handles.size();
458 [ + - ][ + - ]: 8 : std::vector< int > tag_vals( num_ents );
459 [ + + ]: 19 : for( int i = 0; i < num_ents; ++i )
460 : : {
461 [ + - ]: 15 : tag_vals[i] = num;
462 : 15 : sum += num;
463 : 15 : ++num;
464 : : }
465 : :
466 [ + - ][ + - ]: 4 : FBiGeom_setArrData( geom, ARRAY_IN( gentity_handles ), this_tag, (char*)&tag_vals[0],
[ + - ]
467 [ + - ]: 8 : tag_vals.size() * sizeof( int ), &err );
468 [ - + ][ # # ]: 4 : CHECK( "ERROR : can't set tag on entities" );
[ + - ]
469 : 4 : }
470 : :
471 : : // check tag values for entities now
472 : 1 : int get_sum = 0;
473 [ + + ]: 5 : for( dim = 0; dim <= 3; dim++ )
474 : : {
475 [ + - ]: 4 : SimpleArray< iBase_EntityHandle > gentity_handles;
476 [ + - ][ + - ]: 4 : FBiGeom_getEntities( geom, root_set, dim, ARRAY_INOUT( gentity_handles ), &err );
[ + - ][ + - ]
477 [ + - ]: 4 : int num_ents = gentity_handles.size();
478 : :
479 [ + - ][ + - ]: 8 : SimpleArray< char > tag_vals;
480 [ + - ][ + - ]: 4 : FBiGeom_getArrData( geom, ARRAY_IN( gentity_handles ), this_tag, (void**)tag_vals.ptr(), &tag_vals.capacity(),
[ + - ][ + - ]
481 [ + - ][ + - ]: 8 : &tag_vals.size(), &err );
482 [ - + ][ # # ]: 4 : CHECK( "ERROR : can't get tag on entities" );
483 : :
484 [ + - ]: 4 : int* tag_ptr = (int*)( &tag_vals[0] );
485 [ + + ][ + - ]: 19 : for( int i = 0; i < num_ents; ++i )
486 : 15 : get_sum += tag_ptr[i];
487 : 4 : }
488 : :
489 [ - + ]: 1 : if( get_sum != sum )
490 : : {
491 [ # # ][ # # ]: 0 : std::cerr << "ERROR: getData didn't return consistent results." << std::endl;
492 : 0 : return false;
493 : : }
494 : :
495 [ + - ]: 1 : FBiGeom_destroyTag( geom, this_tag, true, &err );
496 [ - + ][ # # ]: 1 : CHECK( "ERROR : couldn't delete tag." );
497 : :
498 : 1 : return true;
499 : : }
500 : :
501 : : /*!
502 : : @test
503 : : TSTT gentity sets test (just implemented parts for now)
504 : : @li Check gentity sets
505 : : */
506 : 0 : bool gentityset_test( FBiGeom_Instance geom, bool /*multiset*/, bool /*ordered*/ )
507 : : {
508 : 0 : int num_type = 4;
509 : : iBase_EntitySetHandle ges_array[4];
510 : : int number_array[4];
511 : : // int num_all_gentities_super = 0;
512 : 0 : int ent_type = iBase_VERTEX;
513 : :
514 : : int err;
515 : : iBase_EntitySetHandle root_set;
516 [ # # ]: 0 : FBiGeom_getRootSet( geom, &root_set, &err );
517 [ # # ][ # # ]: 0 : CHECK( "ERROR : getRootSet failed!" );
518 : :
519 : : // get the number of sets in the whole model
520 : 0 : int all_sets = 0;
521 [ # # ]: 0 : FBiGeom_getNumEntSets( geom, root_set, 0, &all_sets, &err );
522 [ # # ][ # # ]: 0 : CHECK( "Problem getting the number of all gentity sets in whole model." );
523 : :
524 : : // add gentities to entitysets by type
525 [ # # ]: 0 : for( ; ent_type < num_type; ent_type++ )
526 : : {
527 : : // initialize the entityset
528 [ # # ]: 0 : FBiGeom_createEntSet( geom, true, &ges_array[ent_type], &err );
529 [ # # ][ # # ]: 0 : CHECK( "Problem creating entityset." );
530 : :
531 : : // get entities by type in total "mesh"
532 [ # # ]: 0 : SimpleArray< iBase_EntityHandle > gentities;
533 [ # # ][ # # ]: 0 : FBiGeom_getEntities( geom, root_set, ent_type, ARRAY_INOUT( gentities ), &err );
[ # # ][ # # ]
534 [ # # ][ # # ]: 0 : CHECK( "Failed to get gentities by type in gentityset_test." );
535 : :
536 : : // add gentities into gentity set
537 [ # # ][ # # ]: 0 : FBiGeom_addEntArrToSet( geom, ARRAY_IN( gentities ), ges_array[ent_type], &err );
[ # # ]
538 [ # # ][ # # ]: 0 : CHECK( "Failed to add gentities in entityset_test." );
539 : :
540 : : // Check to make sure entity set really has correct number of entities in it
541 [ # # ]: 0 : FBiGeom_getNumOfType( geom, ges_array[ent_type], ent_type, &number_array[ent_type], &err );
542 [ # # ][ # # ]: 0 : CHECK( "Failed to get number of gentities by type in entityset_test." );
543 : :
544 : : // compare the number of entities by type
545 [ # # ]: 0 : int num_type_gentity = gentities.size();
546 : :
547 [ # # ]: 0 : if( number_array[ent_type] != num_type_gentity )
548 : : {
549 [ # # ][ # # ]: 0 : std::cerr << "Number of gentities by type is not correct" << std::endl;
550 [ # # ]: 0 : return false;
551 : : }
552 : :
553 : : // add to number of all entities in super set
554 : : // num_all_gentities_super += num_type_gentity;
555 : 0 : }
556 : :
557 : : // make a super set having all entitysets
558 : : iBase_EntitySetHandle super_set;
559 [ # # ]: 0 : FBiGeom_createEntSet( geom, true, &super_set, &err );
560 [ # # ][ # # ]: 0 : CHECK( "Failed to create a super set in gentityset_test." );
561 : :
562 [ # # ]: 0 : for( int i = 0; i < num_type; i++ )
563 : : {
564 [ # # ]: 0 : FBiGeom_addEntSet( geom, ges_array[i], super_set, &err );
565 [ # # ][ # # ]: 0 : CHECK( "Failed to create a super set in gentityset_test." );
566 : : }
567 : :
568 : : //----------TEST BOOLEAN OPERATIONS----------------//
569 : :
570 : : iBase_EntitySetHandle temp_ges1;
571 [ # # ]: 0 : FBiGeom_createEntSet( geom, true, &temp_ges1, &err );
572 [ # # ][ # # ]: 0 : CHECK( "Failed to create a super set in gentityset_test." );
573 : :
574 : : // Subtract
575 : : // add all EDGEs and FACEs to temp_es1
576 : : // get all EDGE entities
577 [ # # ][ # # ]: 0 : SimpleArray< iBase_EntityHandle > gedges, gfaces, temp_gentities1;
[ # # ]
578 [ # # ][ # # ]: 0 : FBiGeom_getEntities( geom, ges_array[iBase_EDGE], iBase_EDGE, ARRAY_INOUT( gedges ), &err );
[ # # ][ # # ]
579 [ # # ][ # # ]: 0 : CHECK( "Failed to get gedge gentities in gentityset_test." );
580 : :
581 : : // add EDGEs to ges1
582 [ # # ][ # # ]: 0 : FBiGeom_addEntArrToSet( geom, ARRAY_IN( gedges ), temp_ges1, &err );
[ # # ]
583 [ # # ][ # # ]: 0 : CHECK( "Failed to add gedge gentities in gentityset_test." );
584 : :
585 : : // get all FACE gentities
586 [ # # ][ # # ]: 0 : FBiGeom_getEntities( geom, ges_array[iBase_FACE], iBase_FACE, ARRAY_INOUT( gfaces ), &err );
[ # # ][ # # ]
587 [ # # ][ # # ]: 0 : CHECK( "Failed to get gface gentities in gentityset_test." );
588 : :
589 : : // add FACEs to es1
590 [ # # ][ # # ]: 0 : FBiGeom_addEntArrToSet( geom, ARRAY_IN( gfaces ), temp_ges1, &err );
[ # # ]
591 [ # # ][ # # ]: 0 : CHECK( "Failed to add gface gentities in gentityset_test." );
592 : :
593 : : // subtract EDGEs
594 [ # # ]: 0 : FBiGeom_subtract( geom, temp_ges1, ges_array[iBase_EDGE], &temp_ges1, &err );
595 [ # # ][ # # ]: 0 : CHECK( "Failed to subtract gentitysets in gentityset_test." );
596 : :
597 [ # # ][ # # ]: 0 : FBiGeom_getEntities( geom, temp_ges1, iBase_FACE, ARRAY_INOUT( temp_gentities1 ), &err );
[ # # ][ # # ]
598 [ # # ][ # # ]: 0 : CHECK( "Failed to get gface gentities in gentityset_test." );
599 : :
600 [ # # ][ # # ]: 0 : if( gfaces.size() != temp_gentities1.size() )
[ # # ]
601 : : {
602 [ # # ]: 0 : std::cerr << "Number of entitysets after subtraction not correct \
603 : : in gentityset_test."
604 [ # # ]: 0 : << std::endl;
605 : 0 : return false;
606 : : }
607 : :
608 : : // check there's nothing but gfaces in temp_ges1
609 : : int num_gents;
610 [ # # ]: 0 : FBiGeom_getNumOfType( geom, temp_ges1, iBase_EDGE, &num_gents, &err );
611 [ # # ][ # # ]: 0 : CHECK( "Failed to get dimensions of gentities in gentityset_test." );
612 [ # # ]: 0 : if( 0 != num_gents )
613 : : {
614 [ # # ][ # # ]: 0 : std::cerr << "Subtraction failed to remove all edges" << std::endl;
615 : 0 : return false;
616 : : }
617 : :
618 : : //------------Intersect------------
619 : : //
620 : :
621 : : // clean out the temp_ges1
622 [ # # ][ # # ]: 0 : FBiGeom_rmvEntArrFromSet( geom, ARRAY_IN( gfaces ), temp_ges1, &err );
[ # # ]
623 [ # # ][ # # ]: 0 : CHECK( "Failed to remove gface gentities in gentityset_test." );
624 : :
625 : : // check if it is really cleaned out
626 [ # # ]: 0 : FBiGeom_getNumOfType( geom, temp_ges1, iBase_FACE, &num_gents, &err );
627 [ # # ][ # # ]: 0 : CHECK( "Failed to get number of gentities by type in gentityset_test." );
628 : :
629 [ # # ]: 0 : if( num_gents != 0 )
630 : : {
631 [ # # ][ # # ]: 0 : std::cerr << "failed to remove correctly." << std::endl;
632 : 0 : return false;
633 : : }
634 : :
635 : : // add EDGEs to temp ges1
636 [ # # ][ # # ]: 0 : FBiGeom_addEntArrToSet( geom, ARRAY_IN( gedges ), temp_ges1, &err );
[ # # ]
637 [ # # ][ # # ]: 0 : CHECK( "Failed to add gedge gentities in gentityset_test." );
638 : :
639 : : // add FACEs to temp ges1
640 [ # # ][ # # ]: 0 : FBiGeom_addEntArrToSet( geom, ARRAY_IN( gfaces ), temp_ges1, &err );
[ # # ]
641 [ # # ][ # # ]: 0 : CHECK( "Failed to add gface gentities in gentityset_test." );
642 : :
643 : : // intersect temp_ges1 with gedges set
644 : : // temp_ges1 entityset is altered
645 [ # # ]: 0 : FBiGeom_intersect( geom, temp_ges1, ges_array[iBase_EDGE], &temp_ges1, &err );
646 [ # # ][ # # ]: 0 : CHECK( "Failed to intersect in gentityset_test." );
647 : :
648 : : // try to get FACEs, but there should be nothing but EDGE
649 [ # # ]: 0 : FBiGeom_getNumOfType( geom, temp_ges1, iBase_FACE, &num_gents, &err );
650 [ # # ][ # # ]: 0 : CHECK( "Failed to get gface gentities in gentityset_test." );
651 : :
652 [ # # ]: 0 : if( num_gents != 0 )
653 : : {
654 [ # # ][ # # ]: 0 : std::cerr << "wrong number of gfaces." << std::endl;
655 : 0 : return false;
656 : : }
657 : :
658 : : //-------------Unite--------------
659 : :
660 : : // get all regions
661 : : iBase_EntitySetHandle temp_ges2;
662 [ # # ]: 0 : SimpleArray< iBase_EntityHandle > gregions;
663 : :
664 [ # # ]: 0 : FBiGeom_createEntSet( geom, true, &temp_ges2, &err );
665 [ # # ][ # # ]: 0 : CHECK( "Failed to create a temp gentityset in gentityset_test." );
666 : :
667 [ # # ][ # # ]: 0 : FBiGeom_getEntities( geom, ges_array[iBase_REGION], iBase_REGION, ARRAY_INOUT( gregions ), &err );
[ # # ][ # # ]
668 [ # # ][ # # ]: 0 : CHECK( "Failed to get gregion gentities in gentityset_test." );
669 : :
670 : : // add REGIONs to temp es2
671 [ # # ][ # # ]: 0 : FBiGeom_addEntArrToSet( geom, ARRAY_IN( gregions ), temp_ges2, &err );
[ # # ]
672 [ # # ][ # # ]: 0 : CHECK( "Failed to add gregion gentities in gentityset_test." );
673 : :
674 : : // unite temp_ges1 and temp_ges2
675 : : // temp_ges1 gentityset is altered
676 [ # # ]: 0 : FBiGeom_unite( geom, temp_ges1, temp_ges2, &temp_ges1, &err );
677 [ # # ][ # # ]: 0 : CHECK( "Failed to unite in gentityset_test." );
678 : :
679 : : // perform the check
680 [ # # ]: 0 : FBiGeom_getNumOfType( geom, temp_ges1, iBase_REGION, &num_gents, &err );
681 [ # # ][ # # ]: 0 : CHECK( "Failed to get number of gregion gentities by type in gentityset_test." );
682 : :
683 [ # # ]: 0 : if( num_gents != number_array[iBase_REGION] )
684 : : {
685 [ # # ][ # # ]: 0 : std::cerr << "different number of gregions in gentityset_test." << std::endl;
686 : 0 : return false;
687 : : }
688 : :
689 : : //--------Test parent/child stuff in entiysets-----------
690 : :
691 : : // Add 2 sets as children to another
692 : : iBase_EntitySetHandle parent_child;
693 [ # # ]: 0 : FBiGeom_createEntSet( geom, true, &parent_child, &err );
694 [ # # ][ # # ]: 0 : CHECK( "Problem creating gentityset in gentityset_test." );
695 : :
696 [ # # ]: 0 : FBiGeom_addPrntChld( geom, ges_array[iBase_VERTEX], parent_child, &err );
697 [ # # ][ # # ]: 0 : CHECK( "Problem add parent in gentityset_test." );
698 : :
699 : : // check if parent is really added
700 [ # # ]: 0 : SimpleArray< iBase_EntitySetHandle > parents;
701 [ # # ][ # # ]: 0 : FBiGeom_getPrnts( geom, parent_child, 1, ARRAY_INOUT( parents ), &err );
[ # # ][ # # ]
702 [ # # ][ # # ]: 0 : CHECK( "Problem getting parents in gentityset_test." );
703 : :
704 [ # # ][ # # ]: 0 : if( parents.size() != 1 )
705 : : {
706 [ # # ][ # # ]: 0 : std::cerr << "number of parents is not correct in gentityset_test." << std::endl;
707 : 0 : return false;
708 : : }
709 : :
710 : : // add parent and child
711 : : // sidl::array<void*> parent_child_array = sidl::array<void*>::create1d(1);
712 : : // int num_parent_child_array;
713 : : // sidl::array<void*> temp_gedge_array = sidl::array<void*>::create1d(1);
714 : : // int num_temp_gedge_array;
715 : : // parent_child_array.set(0, parent_child);
716 : : // temp_gedge_array.set(0, ges_array[TSTTG::EntityType_EDGE]);
717 [ # # ]: 0 : FBiGeom_addPrntChld( geom, ges_array[iBase_EDGE], parent_child, &err );
718 [ # # ][ # # ]: 0 : CHECK( "Problem adding parent and child in gentityset_test." );
719 : :
720 : : // sidl::array<void*> temp_gface_array = sidl::array<void*>::create1d(1);
721 : : // int num_temp_gface_array;
722 : : // temp_gface_array.set(0, ges_array[TSTTG::EntityType_FACE]);
723 [ # # ]: 0 : FBiGeom_addPrntChld( geom, parent_child, ges_array[iBase_FACE], &err );
724 [ # # ][ # # ]: 0 : CHECK( "Problem adding parent and child in gentityset_test." );
725 : :
726 : : // add child
727 [ # # ]: 0 : FBiGeom_addPrntChld( geom, parent_child, ges_array[iBase_REGION], &err );
728 [ # # ][ # # ]: 0 : CHECK( "Problem adding child in gentityset_test." );
729 : :
730 : : // get the number of parent gentitysets
731 : 0 : num_gents = -1;
732 [ # # ]: 0 : FBiGeom_getNumPrnt( geom, parent_child, 1, &num_gents, &err );
733 [ # # ][ # # ]: 0 : CHECK( "Problem getting number of parents in gentityset_test." );
734 : :
735 [ # # ]: 0 : if( num_gents != 2 )
736 : : {
737 [ # # ][ # # ]: 0 : std::cerr << "number of parents is not correct in gentityset_test." << std::endl;
738 : 0 : return false;
739 : : }
740 : :
741 : : // get the number of child gentitysets
742 : 0 : num_gents = -1;
743 [ # # ]: 0 : FBiGeom_getNumChld( geom, parent_child, 1, &num_gents, &err );
744 [ # # ][ # # ]: 0 : CHECK( "Problem getting number of children in gentityset_test." );
745 : :
746 [ # # ]: 0 : if( num_gents != 2 )
747 : : {
748 [ # # ][ # # ]: 0 : std::cerr << "number of children is not correct in gentityset_test." << std::endl;
749 : 0 : return false;
750 : : }
751 : :
752 [ # # ]: 0 : SimpleArray< iBase_EntitySetHandle > children;
753 [ # # ][ # # ]: 0 : FBiGeom_getChldn( geom, parent_child, 1, ARRAY_INOUT( children ), &err );
[ # # ][ # # ]
754 [ # # ][ # # ]: 0 : CHECK( "Problem getting children in gentityset_test." );
755 : :
756 [ # # ][ # # ]: 0 : if( children.size() != 2 )
757 : : {
758 [ # # ][ # # ]: 0 : std::cerr << "number of children is not correct in gentityset_test." << std::endl;
759 : 0 : return false;
760 : : }
761 : :
762 : : // remove children
763 [ # # ]: 0 : FBiGeom_rmvPrntChld( geom, parent_child, ges_array[iBase_FACE], &err );
764 [ # # ][ # # ]: 0 : CHECK( "Problem removing parent child in gentityset_test." );
765 : :
766 : : // get the number of child gentitysets
767 [ # # ]: 0 : FBiGeom_getNumChld( geom, parent_child, 1, &num_gents, &err );
768 [ # # ][ # # ]: 0 : CHECK( "Problem getting number of children in gentityset_test." );
769 : :
770 [ # # ]: 0 : if( num_gents != 1 )
771 : : {
772 [ # # ][ # # ]: 0 : std::cerr << "number of children is not correct in gentityset_test." << std::endl;
773 : 0 : return false;
774 : : }
775 : :
776 : : // parent_child and ges_array[TSTTG::EntityType_EDGE] should be related
777 : 0 : int result = 0;
778 [ # # ]: 0 : FBiGeom_isChildOf( geom, ges_array[iBase_EDGE], parent_child, &result, &err );
779 [ # # ][ # # ]: 0 : CHECK( "Problem checking relation in gentityset_test." );
780 [ # # ]: 0 : if( !result )
781 : : {
782 [ # # ][ # # ]: 0 : std::cerr << "parent_child and ges_array[TSTTG::EntityType_EDGE] should be related" << std::endl;
783 : 0 : return false;
784 : : }
785 : :
786 : : // ges_array[TSTTG::EntityType_FACE] and ges_array[TSTTG::REGION] are not related
787 : 0 : result = 2;
788 [ # # ]: 0 : FBiGeom_isChildOf( geom, ges_array[iBase_FACE], ges_array[iBase_REGION], &result, &err );
789 [ # # ]: 0 : if( result )
790 : : {
791 : : std::cerr << "ges_array[TSTTG::REGION] and ges_array[TSTTG::EntityType_FACE] should not be "
792 [ # # ]: 0 : "related"
793 [ # # ]: 0 : << std::endl;
794 : 0 : return false;
795 : : }
796 : :
797 : : //--------test modify and query functions-----------------------------
798 : :
799 : : // check the number of gentity sets in whole mesh
800 [ # # ]: 0 : SimpleArray< iBase_EntitySetHandle > gentity_sets;
801 [ # # ][ # # ]: 0 : FBiGeom_getEntSets( geom, root_set, 1, ARRAY_INOUT( gentity_sets ), &err );
[ # # ][ # # ]
802 [ # # ][ # # ]: 0 : CHECK( "Problem to get all gentity sets in mesh." );
803 : :
804 [ # # ][ # # ]: 0 : if( gentity_sets.size() != all_sets + 8 )
805 : : {
806 [ # # ][ # # ]: 0 : std::cerr << "the number of gentity sets in whole mesh should be 8 times of num_iter." << std::endl;
807 : 0 : return false;
808 : : }
809 : :
810 : : // get all gentity sets in super set
811 [ # # ]: 0 : SimpleArray< iBase_EntitySetHandle > ges_array1;
812 [ # # ][ # # ]: 0 : FBiGeom_getEntSets( geom, super_set, 1, ARRAY_INOUT( ges_array1 ), &err );
[ # # ][ # # ]
813 [ # # ][ # # ]: 0 : CHECK( "Problem to get gentity sets in super set." );
814 : :
815 : : // get the number of gentity sets in super set
816 : : int num_super;
817 [ # # ]: 0 : FBiGeom_getNumEntSets( geom, super_set, 1, &num_super, &err );
818 [ # # ][ # # ]: 0 : CHECK( "Problem to get the number of all gentity sets in super set." );
819 : :
820 : : // the number of gentity sets in super set should be same
821 [ # # ][ # # ]: 0 : if( num_super != ges_array1.size() )
822 : : {
823 [ # # ][ # # ]: 0 : std::cerr << "the number of gentity sets in super set should be same." << std::endl;
824 : 0 : return false;
825 : : }
826 : :
827 : : // get all entities in super set
828 [ # # ]: 0 : SimpleArray< iBase_EntitySetHandle > all_gentities;
829 [ # # ][ # # ]: 0 : FBiGeom_getEntSets( geom, super_set, 1, ARRAY_INOUT( all_gentities ), &err );
[ # # ][ # # ]
830 [ # # ][ # # ]: 0 : CHECK( "Problem to get all gentities in super set." );
831 : :
832 : : // compare the number of all gentities in super set
833 : : // HJK : num_hops is not implemented
834 : : // if (num_all_gentities_super != ARRAY_SIZE(all_gentities)) {
835 : : // std::cerr << "number of all gentities in super set should be same." << std::endl;
836 : : // success = false;
837 : : //}
838 : :
839 : : // test add, remove and get all entitiy sets using super set
840 : : // check GetAllGentitysets works recursively and dosen't return
841 : : // multi sets
842 [ # # ]: 0 : for( int k = 0; k < num_super; k++ )
843 : : {
844 : : // add gentity sets of super set to each gentity set of super set
845 : : // make multiple child super sets
846 [ # # ]: 0 : iBase_EntitySetHandle ges_k = ges_array1[k];
847 : :
848 [ # # ][ # # ]: 0 : for( int a = 0; a < ges_array1.size(); a++ )
849 : : {
850 [ # # ][ # # ]: 0 : FBiGeom_addEntSet( geom, ges_array1[a], ges_k, &err );
851 [ # # ][ # # ]: 0 : CHECK( "Problem to add entity set." );
852 : : }
853 : :
854 : : // add super set to each entity set
855 : : // sidl::array<GentitysetHandle> superset_array
856 : : //= sidl::array<GentitysetHandle>::create1d(1);
857 : : // superset_array.set(0, super_set);
858 : : // int num_superset_array;
859 : :
860 [ # # ]: 0 : FBiGeom_addEntSet( geom, super_set, ges_k, &err );
861 [ # # ][ # # ]: 0 : CHECK( "Problem to add super set to gentitysets." );
862 : :
863 : : // add one gentity sets multiple times
864 : : // HJK: ??? how to deal this case?
865 : : // sidl::array<GentitysetHandle> temp_array1
866 : : //= sidl::array<GentitysetHandle>::create1d(1);
867 : : // int num_temp_array1;
868 : : // temp_array1.set(0, temp_ges1);
869 : :
870 : : // for (int l = 0; l < 3; l++) {
871 [ # # ]: 0 : FBiGeom_addEntSet( geom, temp_ges1, ges_k, &err );
872 [ # # ][ # # ]: 0 : CHECK( "Problem to add temp set to gentitysets." );
873 : : //}
874 : : }
875 : :
876 : 0 : return true;
877 : : }
878 : :
879 : : /*!
880 : : @test
881 : : TSTTG topology adjacencies Test
882 : : @li Check topology information
883 : : @li Check adjacency
884 : : */
885 : : // make each topological entity vectors, check their topology
886 : : // types, get interior and exterior faces of model
887 : 1 : bool topology_adjacencies_test( FBiGeom_Instance geom )
888 : : {
889 : : int i, err;
890 : : iBase_EntitySetHandle root_set;
891 [ + - ]: 1 : FBiGeom_getRootSet( geom, &root_set, &err );
892 [ - + ][ # # ]: 1 : CHECK( "ERROR : getRootSet failed!" );
893 : :
894 : 1 : int top = iBase_VERTEX;
895 : 1 : int num_test_top = iBase_ALL_TYPES;
896 [ + - ]: 1 : std::vector< std::vector< iBase_EntityHandle > > gentity_vectors( num_test_top );
897 : :
898 : : // fill the vectors of each topology entities
899 : : // like lines vector, polygon vector, triangle vector,
900 : : // quadrilateral, polyhedrron, tet, hex, prism, pyramid,
901 : : // septahedron vectors
902 [ + + ]: 5 : for( i = top; i < num_test_top; i++ )
903 : : {
904 [ + - ]: 4 : SimpleArray< iBase_EntityHandle > gentities;
905 [ + - ][ + - ]: 4 : FBiGeom_getEntities( geom, root_set, i, ARRAY_INOUT( gentities ), &err );
[ + - ][ + - ]
906 [ - + ][ # # ]: 4 : CHECK( "Failed to get gentities in adjacencies_test." );
907 : :
908 [ + - ][ + - ]: 4 : gentity_vectors[i].resize( gentities.size() );
[ + - ]
909 [ + - ][ + - ]: 4 : std::copy( gentities.begin(), gentities.end(), gentity_vectors[i].begin() );
[ + - ][ + - ]
[ + - ]
910 : 4 : }
911 : :
912 : : // check number of entities for each topology
913 [ + + ]: 5 : for( i = top; i < num_test_top; i++ )
914 : : {
915 : 4 : int num_tops = 0;
916 [ + - ]: 4 : FBiGeom_getNumOfType( geom, root_set, i, &num_tops, &err );
917 [ - + ][ # # ]: 4 : CHECK( "Failed to get number of gentities in adjacencies_test." );
918 : :
919 [ + - ][ - + ]: 4 : if( static_cast< int >( gentity_vectors[i].size() ) != num_tops )
920 : : {
921 [ # # ][ # # ]: 0 : std::cerr << "Number of gentities doesn't agree with number returned for dimension " << i << std::endl;
[ # # ]
922 : 0 : return false;
923 : : }
924 : : }
925 : :
926 : : // check adjacencies in both directions
927 : 1 : std::vector< iBase_EntityHandle >::iterator vit;
928 [ + + ]: 5 : for( i = iBase_REGION; i >= iBase_VERTEX; i-- )
929 : : {
930 [ + - ][ + - ]: 19 : for( vit = gentity_vectors[i].begin(); vit != gentity_vectors[i].end(); ++vit )
[ + - ][ + - ]
[ + + ]
931 : : {
932 [ + - ]: 15 : iBase_EntityHandle this_gent = *vit;
933 : :
934 : : // check downward adjacencies
935 [ + + ]: 26 : for( int j = iBase_VERTEX; j < i; j++ )
936 : : {
937 : :
938 [ + - ]: 11 : SimpleArray< iBase_EntityHandle > lower_ents;
939 [ + - ][ + - ]: 11 : FBiGeom_getEntAdj( geom, this_gent, j, ARRAY_INOUT( lower_ents ), &err );
[ + - ][ + - ]
940 [ - + ][ # # ]: 11 : CHECK( "Bi-directional adjacencies test failed." );
941 : :
942 : : // for each of them, make sure they are adjacent to the upward ones
943 [ + - ]: 11 : int num_lower = lower_ents.size();
944 [ + + ][ + - ]: 41 : for( int k = 0; k < num_lower; k++ )
945 : : {
946 [ + - ]: 30 : SimpleArray< iBase_EntityHandle > upper_ents;
947 [ + - ][ + - ]: 30 : FBiGeom_getEntAdj( geom, lower_ents[k], i, ARRAY_INOUT( upper_ents ), &err );
[ + - ][ + - ]
[ + - ]
948 [ - + ][ # # ]: 30 : CHECK( "Bi-directional adjacencies test failed." );
949 [ + - ][ + - ]: 30 : if( std::find( upper_ents.begin(), upper_ents.end(), this_gent ) == upper_ents.end() )
[ + - ][ + - ]
[ - + ]
950 : : {
951 : : std::cerr << "Didn't find lower-upper adjacency which was supposed to be "
952 [ # # ]: 0 : "there, dims = "
953 [ # # ][ # # ]: 0 : << i << ", " << j << std::endl;
[ # # ][ # # ]
954 [ + - ]: 30 : return false;
955 : : }
956 : 30 : }
957 : 11 : }
958 : : }
959 : : }
960 : :
961 : 1 : return true;
962 : : }
963 : :
964 : : /*!
965 : : @test
966 : : FBiGeom_MOAB topology adjacencies Test
967 : : @li Check topology information
968 : : @li Check adjacency
969 : : */
970 : : // make each topological entity vectors, check their topology
971 : : // types, get interior and exterior faces of model
972 : 1 : bool geometry_evaluation_test( FBiGeom_Instance geom )
973 : : {
974 : : int i, err;
975 : : iBase_EntitySetHandle root_set;
976 [ + - ]: 1 : FBiGeom_getRootSet( geom, &root_set, &err );
977 [ - + ][ # # ]: 1 : CHECK( "ERROR : getRootSet failed!" );
978 : :
979 : 1 : int top = iBase_VERTEX;
980 : 1 : int num_test_top = iBase_ALL_TYPES;
981 [ + - ]: 1 : std::vector< std::vector< iBase_EntityHandle > > gentity_vectors( num_test_top );
982 : :
983 : : // fill the vectors of each topology entities
984 : : // like lines vector, polygon vector, triangle vector,
985 : : // quadrilateral, polyhedrron, tet, hex, prism, pyramid,
986 : : // septahedron vectors
987 [ + + ]: 5 : for( i = top; i < num_test_top; i++ )
988 : : {
989 [ + - ]: 4 : SimpleArray< iBase_EntityHandle > gentities;
990 [ + - ][ + - ]: 4 : FBiGeom_getEntities( geom, root_set, i, ARRAY_INOUT( gentities ), &err );
[ + - ][ + - ]
991 [ - + ][ # # ]: 4 : CHECK( "Failed to get gentities in adjacencies_test." );
992 : :
993 [ + - ][ + - ]: 4 : gentity_vectors[i].resize( gentities.size() );
[ + - ]
994 [ + - ][ + - ]: 4 : std::copy( gentities.begin(), gentities.end(), gentity_vectors[i].begin() );
[ + - ][ + - ]
[ + - ]
995 : 4 : }
996 : :
997 : : // check adjacencies in both directions
998 : : double min[3], max[3], on[3];
999 : 1 : double near[3] = { .0, .0, .0 };
1000 : 1 : std::vector< iBase_EntityHandle >::iterator vit;
1001 [ + + ]: 5 : for( i = iBase_REGION; i >= iBase_VERTEX; i-- )
1002 : : {
1003 [ + + ]: 4 : if( i != iBase_EDGE )
1004 : : {
1005 [ + - ][ + - ]: 11 : for( vit = gentity_vectors[i].begin(); vit != gentity_vectors[i].end(); ++vit )
[ + - ][ + - ]
[ + + ]
1006 : : {
1007 [ + - ]: 8 : iBase_EntityHandle this_gent = *vit;
1008 [ + - ]: 8 : FBiGeom_getEntBoundBox( geom, this_gent, &min[0], &min[1], &min[2], &max[0], &max[1], &max[2], &err );
1009 [ - + ][ # # ]: 8 : CHECK( "Failed to get bounding box of entity." );
1010 : :
1011 [ + - ]: 8 : FBiGeom_getEntClosestPt( geom, this_gent, near[0], near[1], near[2], &on[0], &on[1], &on[2], &err );
1012 [ - + ][ # # ]: 8 : CHECK( "Failed to get closest point on entity." );
1013 : : }
1014 : : }
1015 : : }
1016 : :
1017 : 1 : return true;
1018 : : }
1019 : :
1020 : : /*!
1021 : : @test
1022 : : TSTTG construct Test
1023 : : @li Check construction of geometry
1024 : : */
1025 : 0 : bool construct_test( FBiGeom_Instance geom )
1026 : : {
1027 : : int err;
1028 : 0 : iBase_EntityHandle new_body = 0;
1029 : :
1030 : : // construct a cylinder, sweep it about an axis, and delete the result
1031 : 0 : iBase_EntityHandle cyl = 0;
1032 [ # # ]: 0 : FBiGeom_createCylinder( geom, 1.0, 1.0, 0.0, &cyl, &err );
1033 : : // Is the minor radius really supposed to be zero??? - JK
1034 [ # # ][ # # ]: 0 : CHECK( "Creating cylinder failed." );
1035 : :
1036 : : // move it onto the y axis
1037 [ # # ]: 0 : FBiGeom_moveEnt( geom, cyl, 0.0, 1.0, -0.5, &err );
1038 [ # # ][ # # ]: 0 : CHECK( "Problems moving surface." );
1039 : :
1040 : : // get the surface with max z
1041 : 0 : iBase_EntityHandle max_surf = 0;
1042 [ # # ]: 0 : SimpleArray< iBase_EntityHandle > surfs;
1043 [ # # ][ # # ]: 0 : FBiGeom_getEntAdj( geom, cyl, iBase_FACE, ARRAY_INOUT( surfs ), &err );
[ # # ][ # # ]
1044 [ # # ][ # # ]: 0 : CHECK( "Problems getting max surf for rotation." );
1045 : :
1046 [ # # ][ # # ]: 0 : SimpleArray< double > max_corn, min_corn;
1047 [ # # ][ # # ]: 0 : FBiGeom_getArrBoundBox( geom, ARRAY_IN( surfs ), iBase_INTERLEAVED, ARRAY_INOUT( min_corn ),
[ # # ][ # # ]
1048 [ # # ][ # # ]: 0 : ARRAY_INOUT( max_corn ), &err );
[ # # ][ # # ]
[ # # ]
1049 [ # # ][ # # ]: 0 : CHECK( "Problems getting max surf for rotation." );
1050 : 0 : double dtol = 1.0e-6;
1051 [ # # ][ # # ]: 0 : for( int i = 0; i < surfs.size(); ++i )
1052 : : {
1053 [ # # ][ # # ]: 0 : if( ( max_corn[3 * i + 2] ) <= dtol && ( max_corn[3 * i + 2] ) >= -dtol && ( min_corn[3 * i + 2] ) <= dtol &&
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1054 [ # # ]: 0 : ( min_corn[3 * i + 2] ) >= -dtol )
1055 : : {
1056 [ # # ]: 0 : max_surf = surfs[i];
1057 : 0 : break;
1058 : : }
1059 : : }
1060 : :
1061 [ # # ]: 0 : if( 0 == max_surf )
1062 : : {
1063 [ # # ][ # # ]: 0 : std::cerr << "Couldn't find max surf for rotation." << std::endl;
1064 : 0 : return false;
1065 : : }
1066 : :
1067 : : // sweep it around the x axis
1068 [ # # ]: 0 : FBiGeom_moveEnt( geom, cyl, 0.0, 1.0, 0.0, &err );
1069 [ # # ][ # # ]: 0 : CHECK( "Problems moving surface." );
1070 : :
1071 [ # # ]: 0 : FBiGeom_sweepEntAboutAxis( geom, max_surf, 360.0, 1.0, 0.0, 0.0, &new_body, &err );
1072 [ # # ][ # # ]: 0 : CHECK( "Problems sweeping surface about axis." );
1073 : :
1074 : : // now delete
1075 [ # # ]: 0 : FBiGeom_deleteEnt( geom, new_body, &err );
1076 [ # # ][ # # ]: 0 : CHECK( "Problems deleting cylinder or swept surface body." );
1077 : :
1078 : : // if we got here, we were successful
1079 : 0 : return true;
1080 : : }
1081 : :
1082 : 0 : static bool compare_box( const double* expected_min, const double* expected_max, const double* actual_min,
1083 : : const double* actual_max )
1084 : : {
1085 : 0 : bool same = true;
1086 : 0 : double dtol = 1.0e-6;
1087 : :
1088 [ # # ]: 0 : for( int i = 0; i < 3; ++i )
1089 : : {
1090 [ # # ][ # # ]: 0 : if( expected_min[i] < actual_min[i] - dtol || expected_min[i] * 10 > actual_min[i] ||
[ # # ]
1091 [ # # ]: 0 : expected_max[i] > actual_max[i] + dtol || expected_max[i] * 10 < actual_max[i] )
1092 : 0 : same = false;
1093 : : }
1094 : 0 : return same;
1095 : : }
1096 : :
1097 : 0 : bool primitives_test( FBiGeom_Instance geom )
1098 : : {
1099 : : int err;
1100 [ # # ]: 0 : SimpleArray< iBase_EntityHandle > prims( 3 );
1101 : : iBase_EntityHandle prim;
1102 : :
1103 [ # # ]: 0 : FBiGeom_createBrick( geom, 1.0, 2.0, 3.0, &prim, &err );
1104 [ # # ][ # # ]: 0 : CHECK( "createBrick failed." );
1105 [ # # ]: 0 : prims[0] = prim;
1106 : :
1107 [ # # ]: 0 : FBiGeom_createCylinder( geom, 1.0, 4.0, 2.0, &prim, &err );
1108 [ # # ][ # # ]: 0 : CHECK( "createCylinder failed." );
1109 [ # # ]: 0 : prims[1] = prim;
1110 : :
1111 [ # # ]: 0 : FBiGeom_createTorus( geom, 2.0, 1.0, &prim, &err );
1112 [ # # ][ # # ]: 0 : CHECK( "createTorus failed." );
1113 [ # # ]: 0 : prims[2] = prim;
1114 : :
1115 : : // verify the bounding boxes for Acis based entities
1116 [ # # ][ # # ]: 0 : SimpleArray< double > max_corn, min_corn;
1117 [ # # ][ # # ]: 0 : FBiGeom_getArrBoundBox( geom, ARRAY_IN( prims ), iBase_INTERLEAVED, ARRAY_INOUT( min_corn ),
[ # # ][ # # ]
1118 [ # # ][ # # ]: 0 : ARRAY_INOUT( max_corn ), &err );
[ # # ][ # # ]
[ # # ]
1119 : :
1120 : : double preset_min_corn[] =
1121 : : // min brick corner xyz
1122 : : { -0.5, -1.0, -1.5,
1123 : : // min cyl corner xyz
1124 : : -4.0, -2.0, -0.5,
1125 : : // min torus corner xyz
1126 : 0 : -3.0, -3.0, -1.0 };
1127 : :
1128 : : double preset_max_corn[] =
1129 : : // max brick corner xyz
1130 : : { 0.5, 1.0, 1.5,
1131 : : // max cyl corner xyz
1132 : : 4.0, 2.0, 0.5,
1133 : : // max torus corner xyz
1134 : 0 : 3.0, 3.0, 1.0 };
1135 : :
1136 [ # # ][ # # ]: 0 : if( !compare_box( preset_min_corn, preset_max_corn, &min_corn[0], &max_corn[0] ) )
[ # # ]
1137 : : {
1138 [ # # ][ # # ]: 0 : std::cerr << "Box check failed for brick" << std::endl;
1139 : 0 : return false;
1140 : : }
1141 : :
1142 [ # # ][ # # ]: 0 : if( !compare_box( preset_min_corn + 3, preset_max_corn + 3, &min_corn[3], &max_corn[3] ) )
[ # # ]
1143 : : {
1144 [ # # ][ # # ]: 0 : std::cerr << "Box check failed for cylinder" << std::endl;
1145 : 0 : return false;
1146 : : }
1147 : :
1148 [ # # ][ # # ]: 0 : if( !compare_box( preset_min_corn + 6, preset_max_corn + 6, &min_corn[6], &max_corn[6] ) )
[ # # ]
1149 : : {
1150 [ # # ][ # # ]: 0 : std::cerr << "Box check failed for torus" << std::endl;
1151 : 0 : return false;
1152 : : }
1153 : : // must have worked; delete the entities then return
1154 [ # # ]: 0 : for( int i = 0; i < 3; ++i )
1155 : : {
1156 [ # # ][ # # ]: 0 : FBiGeom_deleteEnt( geom, prims[i], &err );
1157 [ # # ][ # # ]: 0 : CHECK( "Problems deleting primitive after boolean check." );
1158 : : }
1159 : :
1160 : 0 : return true;
1161 : : }
1162 : :
1163 : 0 : bool transforms_test( FBiGeom_Instance geom )
1164 : : {
1165 : : int err;
1166 : :
1167 : : // construct a brick
1168 : 0 : iBase_EntityHandle brick = 0;
1169 [ # # ]: 0 : FBiGeom_createBrick( geom, 1.0, 2.0, 3.0, &brick, &err );
1170 [ # # ][ # # ]: 0 : CHECK( "Problems creating brick for transforms test." );
1171 : :
1172 : : // move it, then test bounding box
1173 [ # # ]: 0 : FBiGeom_moveEnt( geom, brick, 0.5, 1.0, 1.5, &err );
1174 [ # # ][ # # ]: 0 : CHECK( "Problems moving brick for transforms test." );
1175 : :
1176 : : double bb_min[3], bb_max[3];
1177 [ # # ]: 0 : FBiGeom_getEntBoundBox( geom, brick, bb_min, bb_min + 1, bb_min + 2, bb_max, bb_max + 1, bb_max + 2, &err );
1178 [ # # ][ # # ]: 0 : CHECK( "Problems getting bounding box after move." );
1179 : :
1180 : 0 : double dtol = 1.0e-6;
1181 [ # # ][ # # ]: 0 : if( ( bb_min[0] ) >= dtol || ( bb_min[0] ) <= -dtol || ( bb_min[1] ) >= dtol || ( bb_min[1] ) <= -dtol ||
[ # # ][ # # ]
[ # # ]
1182 [ # # ][ # # ]: 0 : ( bb_min[2] ) >= dtol || ( bb_min[2] ) <= -dtol || ( bb_max[0] - 1 ) >= dtol || 1 - bb_max[0] >= dtol ||
[ # # ][ # # ]
1183 [ # # ][ # # ]: 0 : ( bb_max[1] - 2 ) >= dtol || 2 - bb_max[1] >= dtol || ( bb_max[2] - 3 ) >= dtol || 3 - bb_max[2] >= dtol )
[ # # ]
1184 : : {
1185 [ # # ][ # # ]: 0 : std::cerr << "Wrong bounding box after move." << std::endl;
1186 : 0 : return false;
1187 : : }
1188 : :
1189 : : // now rotate it about +x, then test bounding box
1190 [ # # ]: 0 : FBiGeom_rotateEnt( geom, brick, 90, 1.0, 0.0, 0.0, &err );
1191 [ # # ][ # # ]: 0 : CHECK( "Problems rotating brick for transforms test." );
1192 : :
1193 [ # # ]: 0 : FBiGeom_getEntBoundBox( geom, brick, bb_min, bb_min + 1, bb_min + 2, bb_max, bb_max + 1, bb_max + 2, &err );
1194 [ # # ][ # # ]: 0 : CHECK( "Problems getting bounding box after rotate." );
1195 : :
1196 [ # # ][ # # ]: 0 : if( ( bb_min[0] ) >= dtol || -bb_min[0] >= dtol || ( bb_min[1] + 3 ) >= dtol || -( bb_min[1] + 3 ) >= dtol ||
[ # # ][ # # ]
[ # # ]
1197 [ # # ][ # # ]: 0 : ( bb_min[2] ) >= dtol || -( bb_min[2] ) >= dtol || ( bb_max[0] - 1 ) >= dtol || 1 - bb_max[0] >= dtol ||
[ # # ][ # # ]
1198 [ # # ][ # # ]: 0 : ( bb_max[1] ) >= dtol || -( bb_max[1] ) >= dtol || ( bb_max[2] - 2 ) >= dtol || 2 - bb_max[2] >= dtol )
[ # # ]
1199 : : {
1200 [ # # ][ # # ]: 0 : std::cerr << "Wrong bounding box after rotate." << std::endl;
1201 : 0 : return false;
1202 : : }
1203 : :
1204 : : // now reflect through y plane; should recover original bb
1205 [ # # ]: 0 : FBiGeom_reflectEnt( geom, brick, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, &err );
1206 [ # # ][ # # ]: 0 : CHECK( "Problems reflecting brick for transforms test." );
1207 : :
1208 [ # # ]: 0 : FBiGeom_getEntBoundBox( geom, brick, bb_min, bb_min + 1, bb_min + 2, bb_max, bb_max + 1, bb_max + 2, &err );
1209 [ # # ][ # # ]: 0 : CHECK( "Problems getting bounding box after reflect." );
1210 : :
1211 [ # # ][ # # ]: 0 : if( ( bb_min[0] ) >= dtol || -( bb_min[0] ) >= dtol || ( bb_min[1] ) >= dtol || ( bb_min[2] ) >= dtol ||
[ # # ][ # # ]
[ # # ]
1212 [ # # ][ # # ]: 0 : -( bb_min[1] ) >= dtol || -( bb_min[2] ) >= dtol || ( bb_max[0] - 1 ) >= dtol || 1 - bb_max[0] >= dtol ||
[ # # ][ # # ]
1213 [ # # ][ # # ]: 0 : ( bb_max[1] - 3 ) >= dtol || 3 - bb_max[1] >= dtol || ( bb_max[2] - 2 ) >= dtol || 2 - bb_max[2] >= dtol )
[ # # ]
1214 : : {
1215 [ # # ][ # # ]: 0 : std::cerr << "Wrong bounding box after reflect." << std::endl;
1216 : 0 : return false;
1217 : : }
1218 : :
1219 : : // must have worked; delete the entities then return
1220 [ # # ]: 0 : FBiGeom_deleteEnt( geom, brick, &err );
1221 [ # # ][ # # ]: 0 : CHECK( "Problems deleting brick after transforms check." );
1222 : 0 : return true;
1223 : : }
1224 : :
1225 : 0 : bool booleans_test( FBiGeom_Instance geom )
1226 : : {
1227 : : int err;
1228 : :
1229 : : // construct a brick size 1, and a cylinder rad 0.25 height 2
1230 : 0 : iBase_EntityHandle brick = 0, cyl = 0;
1231 [ # # ]: 0 : FBiGeom_createBrick( geom, 1.0, 0.0, 0.0, &brick, &err );
1232 [ # # ][ # # ]: 0 : CHECK( "Problems creating brick for booleans test." );
1233 [ # # ]: 0 : FBiGeom_createCylinder( geom, 1.0, 0.25, 0.0, &cyl, &err );
1234 [ # # ][ # # ]: 0 : CHECK( "Problems creating cylinder for booleans test." );
1235 : :
1236 : : // subtract the cylinder from the brick
1237 : 0 : iBase_EntityHandle subtract_result = 0;
1238 [ # # ]: 0 : FBiGeom_subtractEnts( geom, brick, cyl, &subtract_result, &err );
1239 [ # # ][ # # ]: 0 : CHECK( "Problems subtracting for booleans subtract test." );
1240 : :
1241 : : // section the brick
1242 : 0 : iBase_EntityHandle section_result = 0;
1243 [ # # ]: 0 : FBiGeom_sectionEnt( geom, subtract_result, 1.0, 0.0, 0.0, 0.25, true, §ion_result, &err );
1244 [ # # ][ # # ]: 0 : CHECK( "Problems sectioning for booleans section test." );
1245 : :
1246 : : // unite the section result with a new cylinder
1247 [ # # ]: 0 : FBiGeom_createCylinder( geom, 1.0, 0.25, 0.0, &cyl, &err );
1248 [ # # ][ # # ]: 0 : CHECK( "Problems creating cylinder for unite test." );
1249 : : iBase_EntityHandle unite_results;
1250 : 0 : iBase_EntityHandle unite_input[] = { section_result, cyl };
1251 [ # # ]: 0 : FBiGeom_uniteEnts( geom, unite_input, 2, &unite_results, &err );
1252 [ # # ][ # # ]: 0 : CHECK( "Problems uniting for booleans unite test." );
1253 : :
1254 [ # # ]: 0 : FBiGeom_deleteEnt( geom, unite_results, &err );
1255 [ # # ][ # # ]: 0 : CHECK( "Problems deleting for booleans unite test." );
1256 : 0 : return true;
1257 : : }
1258 : :
1259 : 0 : static int get_entities( FBiGeom_Instance geom, int entity_type, std::vector< iBase_EntityHandle >& entities_out,
1260 : : iBase_TagHandle id_tag = 0, std::vector< int >* ids_out = 0 )
1261 : : {
1262 : : int err, num;
1263 : : iBase_EntitySetHandle root;
1264 [ # # ]: 0 : FBiGeom_getRootSet( geom, &root, &err );
1265 [ # # ]: 0 : if( iBase_SUCCESS != err ) return err;
1266 [ # # ]: 0 : FBiGeom_getNumOfType( geom, root, entity_type, &num, &err );
1267 [ # # ]: 0 : if( iBase_SUCCESS != err ) return err;
1268 : :
1269 [ # # ]: 0 : entities_out.resize( num );
1270 : 0 : int junk1 = entities_out.size(), junk2;
1271 [ # # ]: 0 : iBase_EntityHandle* junk_ptr = &entities_out[0];
1272 : : ;
1273 [ # # ]: 0 : FBiGeom_getEntities( geom, root, entity_type, &junk_ptr, &junk1, &junk2, &err );
1274 [ # # ]: 0 : if( iBase_SUCCESS != err ) return err;
1275 [ # # ][ # # ]: 0 : assert( num == junk1 && num == junk2 );
1276 : :
1277 [ # # ]: 0 : if( !ids_out ) return iBase_SUCCESS;
1278 : :
1279 [ # # ]: 0 : ids_out->resize( num );
1280 [ # # ]: 0 : int* int_ptr = &( *ids_out )[0];
1281 [ # # ][ # # ]: 0 : FBiGeom_getIntArrData( geom, &entities_out[0], num, id_tag, &int_ptr, &junk1, &junk2, &err );
1282 [ # # ]: 0 : if( iBase_SUCCESS != err ) return err;
1283 [ # # ][ # # ]: 0 : assert( num == junk1 && num == junk2 );
1284 : :
1285 : 0 : return iBase_SUCCESS;
1286 : : }
1287 : :
1288 : 0 : static int check_firmness( FBiGeom_Instance geom, const std::vector< iBase_EntityHandle >& entities,
1289 : : const std::vector< int >& ids, iBase_TagHandle firmness_tag, const char* expected_value,
1290 : : const char* ent_type_str )
1291 : : {
1292 : 0 : const int firmness_size = 4;
1293 [ # # ]: 0 : std::vector< char > firmness( firmness_size * entities.size() );
1294 : :
1295 [ # # ]: 0 : char* byte_ptr = &firmness[0];
1296 : 0 : int err, junk1 = firmness.size(), junk2 = entities.size() * firmness_size;
1297 [ # # ][ # # ]: 0 : FBiGeom_getArrData( geom, &entities[0], entities.size(), firmness_tag, (void**)&byte_ptr, &junk1, &junk2, &err );
1298 [ # # ]: 0 : if( iBase_SUCCESS != err ) return err;
1299 : :
1300 : 0 : bool all_correct = true;
1301 [ # # ]: 0 : for( unsigned i = 0; i < entities.size(); ++i )
1302 [ # # ][ # # ]: 0 : if( std::string( &firmness[firmness_size * i], firmness_size ) != expected_value ) all_correct = false;
[ # # ][ # # ]
1303 [ # # ]: 0 : if( !all_correct )
1304 : : {
1305 [ # # ][ # # ]: 0 : std::cout << "ERROR: Expected \"" << expected_value << "\" firmness "
[ # # ]
1306 [ # # ][ # # ]: 0 : << "for all " << ent_type_str << "." << std::endl;
[ # # ][ # # ]
1307 [ # # ][ # # ]: 0 : std::cout << "ID Actual " << std::endl;
1308 [ # # ]: 0 : for( unsigned i = 0; i < entities.size(); ++i )
1309 [ # # ][ # # ]: 0 : std::cout << std::setw( 2 ) << ids[i] << " " << std::string( &firmness[firmness_size * i], firmness_size )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1310 [ # # ]: 0 : << std::endl;
1311 : 0 : return iBase_FAILURE;
1312 : : }
1313 : :
1314 : 0 : return iBase_SUCCESS;
1315 : : }
1316 : :
1317 : 0 : static int count_num_with_tag( FBiGeom_Instance geom, const std::vector< iBase_EntityHandle >& ents,
1318 : : iBase_TagHandle tag )
1319 : : {
1320 : : int err, bytes;
1321 [ # # ]: 0 : FBiGeom_getTagSizeBytes( geom, tag, &bytes, &err );
1322 [ # # ]: 0 : if( iBase_SUCCESS != err ) return -1;
1323 [ # # ]: 0 : std::vector< char > data( bytes );
1324 : :
1325 : 0 : int success_count = 0;
1326 [ # # ]: 0 : for( size_t i = 0; i < ents.size(); ++i )
1327 : : {
1328 [ # # ]: 0 : char* ptr = &data[0];
1329 : 0 : int junk1 = bytes, junk2;
1330 [ # # ][ # # ]: 0 : FBiGeom_getData( geom, ents[i], tag, (void**)&ptr, &junk1, &junk2, &err );
1331 [ # # ]: 0 : if( iBase_TAG_NOT_FOUND == err ) continue;
1332 [ # # ]: 0 : if( iBase_SUCCESS != err ) return -1;
1333 : 0 : ++success_count;
1334 : : }
1335 : :
1336 : 0 : return success_count;
1337 : : }
1338 : :
1339 : 0 : bool mesh_size_test( FBiGeom_Instance geom )
1340 : : {
1341 : 0 : const char* filename = STRINGIFY( SRCDIR ) "/size.sat";
1342 : : int err, junk1, junk2;
1343 : 0 : bool result = true;
1344 : :
1345 [ # # ]: 0 : FBiGeom_deleteAll( geom, &err );
1346 [ # # ][ # # ]: 0 : CHECK( "" );
1347 [ # # ]: 0 : FBiGeom_load( geom, filename, 0, &err, strlen( filename ), 0 );
1348 [ # # ][ # # ]: 0 : CHECK( "Failed to load input file: 'size.sat'" );
1349 : :
1350 : : // get tag handles
1351 : : iBase_TagHandle interval, size, firmness, id;
1352 [ # # ]: 0 : FBiGeom_getTagHandle( geom, "MESH_INTERVAL", &interval, &err, strlen( "MESH_INTERVAL" ) );
1353 [ # # ][ # # ]: 0 : CHECK( "FBiGeom_getTagHandle(\"MESH_INTERVAL\")" );
1354 [ # # ]: 0 : FBiGeom_getTagHandle( geom, "MESH_SIZE", &size, &err, strlen( "MESH_SIZE" ) );
1355 [ # # ][ # # ]: 0 : CHECK( "FBiGeom_getTagHandle(\"MESH_SIZE\")" );
1356 [ # # ]: 0 : FBiGeom_getTagHandle( geom, "SIZE_FIRMNESS", &firmness, &err, strlen( "SIZE_FIRMNESS" ) );
1357 [ # # ][ # # ]: 0 : CHECK( "FBiGeom_getTagHandle(\"SIZE_FIRMNESS\")" );
1358 [ # # ]: 0 : FBiGeom_getTagHandle( geom, "GLOBAL_ID", &id, &err, strlen( "GLOBAL_ID" ) );
1359 [ # # ][ # # ]: 0 : CHECK( "FBiGeom_getTagHandle(\"GLOBAL_ID\")" );
1360 : :
1361 : : // get entity lists
1362 [ # # ][ # # ]: 0 : std::vector< iBase_EntityHandle > verts, curves, surfs, vols;
[ # # ][ # # ]
1363 [ # # ][ # # ]: 0 : std::vector< int > vert_ids, curve_ids, surf_ids, vol_ids;
[ # # ][ # # ]
1364 [ # # ]: 0 : err = get_entities( geom, iBase_VERTEX, verts, id, &vert_ids );
1365 [ # # ][ # # ]: 0 : CHECK( "" );
1366 [ # # ]: 0 : err = get_entities( geom, iBase_EDGE, curves, id, &curve_ids );
1367 [ # # ][ # # ]: 0 : CHECK( "" );
1368 [ # # ]: 0 : err = get_entities( geom, iBase_FACE, surfs, id, &surf_ids );
1369 [ # # ][ # # ]: 0 : CHECK( "" );
1370 [ # # ]: 0 : err = get_entities( geom, iBase_REGION, vols, id, &vol_ids );
1371 [ # # ][ # # ]: 0 : CHECK( "" );
1372 : :
1373 : : // expect interval count to be the same as ID for every curve
1374 [ # # ]: 0 : std::vector< int > intervals( curves.size() );
1375 [ # # ]: 0 : int* int_ptr = &intervals[0];
1376 : 0 : junk1 = junk2 = curves.size();
1377 [ # # ][ # # ]: 0 : FBiGeom_getIntArrData( geom, &curves[0], curves.size(), interval, &int_ptr, &junk1, &junk2, &err );
1378 [ # # ][ # # ]: 0 : CHECK( "Failed to get intervals for curves" );
1379 [ # # ][ # # ]: 0 : if( intervals != curve_ids )
1380 : : {
1381 [ # # ][ # # ]: 0 : std::cout << "ERROR: Incorrect curve intervals for one or more curves." << std::endl;
1382 [ # # ][ # # ]: 0 : std::cout << "ID Expected Actual" << std::endl;
1383 [ # # ]: 0 : for( unsigned i = 0; i < curves.size(); ++i )
1384 [ # # ][ # # ]: 0 : std::cout << std::setw( 2 ) << curve_ids[i] << " " << std::setw( 8 ) << curve_ids[i] << " "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1385 [ # # ][ # # ]: 0 : << std::setw( 6 ) << intervals[i] << std::endl;
[ # # ][ # # ]
[ # # ]
1386 : 0 : result = false;
1387 : : }
1388 : :
1389 : : // expect size to be the same as ID for every surface
1390 [ # # ]: 0 : std::vector< double > sizes( surfs.size() );
1391 [ # # ]: 0 : double* dbl_ptr = &sizes[0];
1392 : 0 : junk1 = junk2 = surfs.size();
1393 [ # # ][ # # ]: 0 : FBiGeom_getDblArrData( geom, &surfs[0], surfs.size(), size, &dbl_ptr, &junk1, &junk2, &err );
1394 [ # # ][ # # ]: 0 : CHECK( "Failed to get sizes for surfaces" );
1395 : 0 : bool all_correct = true;
1396 [ # # ]: 0 : for( unsigned i = 0; i < surfs.size(); ++i )
1397 [ # # ][ # # ]: 0 : if( fabs( sizes[i] - (double)surf_ids[i] ) > 1e-8 ) all_correct = false;
[ # # ]
1398 [ # # ]: 0 : if( !all_correct )
1399 : : {
1400 [ # # ][ # # ]: 0 : std::cout << "ERROR: Incorrect mesh size for one or more surfaces." << std::endl;
1401 [ # # ][ # # ]: 0 : std::cout << "ID Expected Actual " << std::endl;
1402 [ # # ]: 0 : for( unsigned i = 0; i < surfs.size(); ++i )
1403 [ # # ][ # # ]: 0 : std::cout << std::setw( 2 ) << surf_ids[i] << " " << std::setw( 8 ) << (double)surf_ids[i] << " "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1404 [ # # ][ # # ]: 0 : << std::setw( 8 ) << sizes[i] << std::endl;
[ # # ][ # # ]
[ # # ]
1405 : 0 : result = false;
1406 : : }
1407 : :
1408 [ # # ]: 0 : err = result ? iBase_SUCCESS : iBase_FAILURE;
1409 [ # # ][ # # ]: 0 : CHECK( "Invalid size or interval data" );
1410 : :
1411 : : // expect "HARD" firmness on all curves
1412 [ # # ]: 0 : err = check_firmness( geom, curves, curve_ids, firmness, "HARD", "curves" );
1413 [ # # ][ # # ]: 0 : CHECK( "Invalid curve firmness" );
1414 : : // expect "SOFT" firmness on all surfaces
1415 [ # # ]: 0 : err = check_firmness( geom, surfs, surf_ids, firmness, "SOFT", "surfaces" );
1416 [ # # ][ # # ]: 0 : CHECK( "Invalid surface firmness" );
1417 : :
1418 : : // expect no firmnes on other entities
1419 [ # # ][ # # ]: 0 : err = count_num_with_tag( geom, verts, firmness ) ? iBase_FAILURE : iBase_SUCCESS;
1420 [ # # ][ # # ]: 0 : CHECK( "Got firmness for vertex." );
1421 [ # # ][ # # ]: 0 : err = count_num_with_tag( geom, vols, firmness ) ? iBase_FAILURE : iBase_SUCCESS;
1422 [ # # ][ # # ]: 0 : CHECK( "Got firmness for volume." );
1423 : :
1424 : : // expect no interval tag on any entities except curves
1425 [ # # ][ # # ]: 0 : err = count_num_with_tag( geom, verts, interval ) ? iBase_FAILURE : iBase_SUCCESS;
1426 [ # # ][ # # ]: 0 : CHECK( "Got interval count for vertex." );
1427 [ # # ][ # # ]: 0 : err = count_num_with_tag( geom, vols, interval ) ? iBase_FAILURE : iBase_SUCCESS;
1428 [ # # ][ # # ]: 0 : CHECK( "Got interval count for volume." );
1429 : :
1430 : : // expect no size tag on any entities except surfaces
1431 : : // curves should have size of one of their parent surfaces
1432 [ # # ][ # # ]: 0 : err = count_num_with_tag( geom, verts, size ) ? iBase_FAILURE : iBase_SUCCESS;
1433 [ # # ][ # # ]: 0 : CHECK( "Got mesh size for vertex." );
1434 [ # # ][ # # ]: 0 : err = count_num_with_tag( geom, vols, size ) ? iBase_FAILURE : iBase_SUCCESS;
1435 [ # # ][ # # ]: 0 : CHECK( "Got mesh size for volume." );
1436 : :
1437 : 0 : return true;
1438 : : }
1439 : :
1440 : 1 : bool shutdown_test( FBiGeom_Instance geom, std::string& engine_opt )
1441 : : {
1442 : : int err;
1443 : :
1444 : : // test shutdown & startup of interface
1445 [ + - ]: 1 : FBiGeom_dtor( geom, &err );
1446 [ - + ][ # # ]: 1 : CHECK( "Interface destruction didn't work properly." );
1447 : :
1448 [ + - ]: 1 : FBiGeom_newGeom( engine_opt.c_str(), &geom, &err, engine_opt.length() );
1449 [ - + ][ # # ]: 1 : CHECK( "Interface re-construction didn't work properly." );
1450 : :
1451 [ + - ]: 1 : FBiGeom_dtor( geom, &err );
1452 [ - + ][ # # ]: 1 : CHECK( "2nd Interface destruction didn't work properly." );
1453 : :
1454 : 1 : return true;
1455 : : }
1456 : :
1457 : 0 : bool save_entset_test( FBiGeom_Instance geom )
1458 : : {
1459 : : int err;
1460 : :
1461 : : #ifdef FORCE_OCC
1462 : : std::string filename = "testout.brep";
1463 : : #elif defined( HAVE_ACIS )
1464 : : std::string filename = "testout.sat";
1465 : : #elif defined( HAVE_OCC )
1466 : : std::string filename = "testout.brep";
1467 : : #else
1468 [ # # ]: 0 : std::string filename = "testout.sat";
1469 : : #endif
1470 : :
1471 : : // initialize number of ents and sets to compare with later
1472 : : int num_ents_bef, num_sets_bef;
1473 : : iBase_EntitySetHandle root;
1474 [ # # ]: 0 : FBiGeom_getRootSet( geom, &root, &err );
1475 [ # # ][ # # ]: 0 : CHECK( "Failed to get root set." );
1476 [ # # ]: 0 : FBiGeom_getNumEntSets( geom, root, 1, &num_sets_bef, &err );
1477 [ # # ][ # # ]: 0 : CHECK( "Failed to get number of ent sets." );
1478 [ # # ]: 0 : FBiGeom_getNumOfType( geom, root, iBase_REGION, &num_ents_bef, &err );
1479 [ # # ][ # # ]: 0 : CHECK( "Failed to get number of entities." );
1480 : :
1481 : : // create set, and entity to add to set
1482 : : iBase_EntityHandle cyl;
1483 [ # # ]: 0 : FBiGeom_createCylinder( geom, 1.0, 0.25, 0.0, &cyl, &err );
1484 [ # # ][ # # ]: 0 : CHECK( "Problems creating cylinder for save entset test." );
1485 : : iBase_EntitySetHandle seth;
1486 [ # # ]: 0 : FBiGeom_createEntSet( geom, true, &seth, &err );
1487 [ # # ][ # # ]: 0 : CHECK( "Problems creating entity set for save entset test." );
1488 : :
1489 : : // add the entity
1490 [ # # ]: 0 : FBiGeom_addEntToSet( geom, cyl, seth, &err );
1491 [ # # ][ # # ]: 0 : CHECK( "Problems adding entity to set for save entset test." );
1492 : :
1493 : : // save/restore the model, and see if the entity is there
1494 [ # # ]: 0 : FBiGeom_save( geom, filename.c_str(), NULL, &err, filename.length(), 0 );
1495 [ # # ][ # # ]: 0 : CHECK( "Problems saving file for save entset test." );
1496 : :
1497 [ # # ]: 0 : FBiGeom_destroyEntSet( geom, seth, &err );
1498 [ # # ][ # # ]: 0 : CHECK( "Failed to destroy entity set." );
1499 [ # # ]: 0 : FBiGeom_deleteEnt( geom, cyl, &err );
1500 [ # # ][ # # ]: 0 : CHECK( "Failed to destroy entity." );
1501 : :
1502 : : // read the file back in
1503 [ # # ]: 0 : FBiGeom_load( geom, filename.c_str(), NULL, &err, filename.length(), 0 );
1504 [ # # ][ # # ]: 0 : CHECK( "Problems reading file for save entset test." );
1505 : :
1506 : : // check number of sets and entities
1507 : : int num_ents_aft, num_sets_aft;
1508 [ # # ]: 0 : FBiGeom_getNumEntSets( geom, root, 1, &num_sets_aft, &err );
1509 [ # # ][ # # ]: 0 : CHECK( "Failed to get number of ent sets." );
1510 [ # # ]: 0 : FBiGeom_getNumOfType( geom, root, iBase_REGION, &num_ents_aft, &err );
1511 [ # # ][ # # ]: 0 : CHECK( "Failed to get number of entities." );
1512 : 0 : bool success = true;
1513 [ # # ]: 0 : if( num_ents_aft != 2 * num_ents_bef + 1 )
1514 : : {
1515 [ # # ]: 0 : print_error( "Failed to get the right number of entities.", iBase_FAILURE, geom, __FILE__, __LINE__ );
1516 : 0 : success = false;
1517 : : }
1518 [ # # ]: 0 : else if( num_sets_aft != 2 * num_sets_bef + 1 )
1519 : : {
1520 [ # # ]: 0 : print_error( "Failed to get the right number of entity sets.", iBase_FAILURE, geom, __FILE__, __LINE__ );
1521 : 0 : success = false;
1522 : : }
1523 : :
1524 : : // otherwise, we succeeded
1525 : 0 : return success;
1526 [ + - ][ + - ]: 4 : }
|