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