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