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