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