testSmooth.cc 55.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/**
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 */
/**
 * \file testgeom.cc
 *
 * \brief testgeom, a unit test for the ITAPS geometry interface
 *
 */
14
#include "FBiGeom.h"
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <string.h>
#include <math.h>
#define CHECK( STR ) if (err != iBase_SUCCESS) return print_error( STR, err, geom, __FILE__, __LINE__ )

#define STRINGIFY(S) XSTRINGIFY(S)
#define XSTRINGIFY(S) #S

30
static bool print_error(const char* desc, int err, FBiGeom_Instance geom,
31 32
      const char* file, int line) {
   char buffer[1024];
33
   FBiGeom_getDescription(geom, buffer, sizeof(buffer));
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
   buffer[sizeof(buffer) - 1] = '\0';

   std::cerr << "ERROR: " << desc << std::endl << "  Error code: " << err
         << std::endl << "  Error desc: " << buffer << std::endl
         << "  At        : " << file << ':' << line << std::endl;

   return false; // must always return false or CHECK macro will break
}

typedef iBase_TagHandle TagHandle;
typedef iBase_EntityHandle GentityHandle;
typedef iBase_EntitySetHandle GentitysetHandle;

/* Frees allocated arrays for us */
template<typename T> class SimpleArray {
private:
   T* arr;
   int arrSize;
   int arrAllocated;

public:
   SimpleArray() :
      arr(0), arrSize(0), arrAllocated(0) {
   }
   SimpleArray(unsigned s) :
      arrSize(s), arrAllocated(s) {
      arr = (T*) malloc(s * sizeof(T));
      for (unsigned i = 0; i < s; ++i)
         new (arr + i) T();
   }

   ~SimpleArray() {
      for (int i = 0; i < size(); ++i)
         arr[i].~T();
      free(arr);
   }

   T** ptr() {
      return &arr;
   }
   int& size() {
      return arrSize;
   }
   int size() const {
      return arrSize;
   }
   int& capacity() {
      return arrAllocated;
   }
   int capacity() const {
      return arrAllocated;
   }

   typedef T* iterator;
   typedef const T* const_iterator;
   iterator begin() {
      return arr;
   }
   const_iterator begin() const {
      return arr;
   }
   iterator end() {
      return arr + arrSize;
   }
   const_iterator end() const {
      return arr + arrSize;
   }

   T& operator[](unsigned idx) {
      return arr[idx];
   }
   T operator[](unsigned idx) const {
      return arr[idx];
   }
};

#define ARRAY_INOUT( A ) A.ptr(), &A.capacity(), &A.size()
#define ARRAY_IN( A ) &A[0], A.size()

113
bool smooth_test(const std::string &filename, FBiGeom_Instance);
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

bool tags_test(FBiGeom_Instance geom);
bool tag_get_set_test(FBiGeom_Instance geom);
bool tag_info_test(FBiGeom_Instance geom);
bool gentityset_test(FBiGeom_Instance geom, bool /*multiset*/, bool /*ordered*/);
bool topology_adjacencies_test(FBiGeom_Instance geom);
bool geometry_evaluation_test(FBiGeom_Instance geom);
bool construct_test(FBiGeom_Instance geom);
bool primitives_test(FBiGeom_Instance geom);
bool transforms_test(FBiGeom_Instance geom);
bool booleans_test(FBiGeom_Instance geom);
bool shutdown_test(FBiGeom_Instance geom, std::string &engine_opt);
bool save_entset_test(FBiGeom_Instance geom);
bool mesh_size_test(FBiGeom_Instance geom);
bool normals_test(FBiGeom_Instance geom);

bool ray_test(FBiGeom_Instance geom);
131

132 133 134 135 136 137 138 139 140 141 142 143
void handle_error_code(const bool result, int &number_failed,
      int &/*number_not_implemented*/, int &number_successful) {
   if (result) {
      std::cout << "Success";
      number_successful++;
   } else {
      std::cout << "Failure";
      number_failed++;
   }
}

int main(int argc, char *argv[]) {
144
   std::string filename = STRINGIFY(MESHDIR) "/shell.h5m";
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
   std::string engine_opt;

   if (argc == 1) {
      std::cout << "Using default input file: " << filename << std::endl;
   } else if (argc == 2) {
      filename = argv[1];
   } else {
      std::cerr << "Usage: " << argv[0] << " [geom_filename]" << std::endl;
      return 1;
   }

   bool result;
   int number_tests = 0;
   int number_tests_successful = 0;
   int number_tests_not_implemented = 0;
   int number_tests_failed = 0;

   // initialize the Mesh
   int err;
164 165
   FBiGeom_Instance geom;
   FBiGeom_newGeom(engine_opt.c_str(), &geom, &err, engine_opt.length());
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
   CHECK( "Interface initialization didn't work properly." );

   // Print out Header information
   std::cout << "\n\nITAPS GEOMETRY INTERFACE TEST PROGRAM:\n\n";
   // gLoad test

   std::cout << "   Smooth faceting load and initialization: \n";
   result = smooth_test(filename, geom);
   handle_error_code(result, number_tests_failed, number_tests_not_implemented,
         number_tests_successful);

   number_tests++;
   std::cout << "\n";

   // tags test
   std::cout << "   tags: ";
   result = tags_test(geom);
   handle_error_code(result, number_tests_failed, number_tests_not_implemented,
         number_tests_successful);
   number_tests++;
   std::cout << "\n";
   /*
    // gentitysets test
    std::cout << "   gentity sets: ";
    result = gentityset_test(geom, false, false);
    handle_error_code(result, number_tests_failed,
    number_tests_not_implemented,
    number_tests_successful);
    number_tests++;
    std::cout << "\n";
    */
   // topology adjacencies test
   std::cout << "   topology adjacencies: ";
   result = topology_adjacencies_test(geom);
   handle_error_code(result, number_tests_failed, number_tests_not_implemented,
         number_tests_successful);
   number_tests++;
   std::cout << "\n";

   // geometry evaluation test
   std::cout << "   geometry evaluation: \n";
   result = geometry_evaluation_test(geom);
   handle_error_code(result, number_tests_failed, number_tests_not_implemented,
         number_tests_successful);
   number_tests++;
   std::cout << "\n";

   // normals evaluation test
   std::cout << "   normals geometry evaluation: \n";
   result = normals_test(geom);
   handle_error_code(result, number_tests_failed, number_tests_not_implemented,
         number_tests_successful);
   number_tests++;
   std::cout << "\n";
220 221 222 223 224 225 226 227

   // ray tracing test
   std::cout << "   ray intersection test: \n";
   result = ray_test(geom);
   handle_error_code(result, number_tests_failed, number_tests_not_implemented,
            number_tests_successful);
   number_tests++;
   std::cout << "\n";
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
   /*
    // construct test
    std::cout << "   construct: ";
    result = construct_test(geom);
    handle_error_code(result, number_tests_failed,
    number_tests_not_implemented,
    number_tests_successful);
    number_tests++;
    std::cout << "\n";

    // primitives test
    std::cout << "   primitives: ";
    result = primitives_test(geom);
    handle_error_code(result, number_tests_failed,
    number_tests_not_implemented,
    number_tests_successful);
    number_tests++;
    std::cout << "\n";

    // transforms test
    std::cout << "   transforms: ";
    result = transforms_test(geom);
    handle_error_code(result, number_tests_failed,
    number_tests_not_implemented,
    number_tests_successful);
    number_tests++;
    std::cout << "\n";

    // booleans test
    std::cout << "   booleans: ";
    result = booleans_test(geom);
    handle_error_code(result, number_tests_failed,
    number_tests_not_implemented,
    number_tests_successful);
    number_tests++;
    std::cout << "\n";

    #if defined(HAVE_ACIS) && !defined(FORCE_OCC)
    std::cout << "   mesh size: ";
    result = mesh_size_test(geom);
    handle_error_code(result, number_tests_failed,
    number_tests_not_implemented,
    number_tests_successful);
    number_tests++;
    std::cout << "\n";

    // save entset test
    std::cout << "   save entset: ";
    result = save_entset_test(geom);
    handle_error_code(result, number_tests_failed,
    number_tests_not_implemented,
    number_tests_successful);
    number_tests++;
    std::cout << "\n";
    #endif
    */
   // shutdown test
   std::cout << "   shutdown: ";
   result = shutdown_test(geom, engine_opt);
   handle_error_code(result, number_tests_failed, number_tests_not_implemented,
         number_tests_successful);
   number_tests++;
   std::cout << "\n";

   // summary

   std::cout << "\nTSTT TEST SUMMARY: \n" << "   Number Tests:           "
         << number_tests << "\n" << "   Number Successful:      "
         << number_tests_successful << "\n" << "   Number Not Implemented: "
         << number_tests_not_implemented << "\n"
         << "   Number Failed:          " << number_tests_failed << "\n\n"
         << std::endl;

   return number_tests_failed;
}

/*!
 @test
 Load Mesh
 @li Load a mesh file
 */

310
bool smooth_test(const std::string &filename, FBiGeom_Instance geom) {
311
   int err;
312
   char opts[] = "SMOOTH;";
313 314
   FBiGeom_load(geom, &filename[0], opts, &err, filename.length(), 8);
   //FBiGeom_load( geom, &filename[0], 0, &err, filename.length(), 0 );
315 316 317
   CHECK( "ERROR : can not load a geometry" );

   iBase_EntitySetHandle root_set;
318
   FBiGeom_getRootSet(geom, &root_set, &err);
319 320 321 322 323 324 325
   CHECK( "ERROR : getRootSet failed!" );

   // print out the number of entities
   std::cout << "Model contents: " << std::endl;
   const char *gtype[] = { "vertices: ", "edges: ", "faces: ", "regions: " };
   for (int i = 0; i <= 3; ++i) {
      int count;
326
      FBiGeom_getNumOfType(geom, root_set, i, &count, &err);
327 328 329 330 331 332 333 334 335 336 337
      CHECK( "Error: problem getting entities after gLoad." );
      std::cout << gtype[i] << count << std::endl;
   }

   return true;
}
/*!
 @test
 Test tag creating, reading, writing, deleting
 @li Load a mesh file
 */
338
bool tags_test(FBiGeom_Instance geom) {
339
   bool success = tag_info_test(geom);
340 341 342 343 344 345 346 347 348 349
   if (!success)
      return success;

   success = tag_get_set_test(geom);
   if (!success)
      return success;

   return true;
}

350
bool tag_info_test(FBiGeom_Instance geom) {
351 352 353
   int err;

   iBase_EntitySetHandle root_set;
354
   FBiGeom_getRootSet(geom, &root_set, &err);
355 356 357 358 359
   CHECK( "ERROR : getRootSet failed!" );

   // create an arbitrary tag, size 4
   iBase_TagHandle this_tag, tmp_handle;
   std::string tag_name("tag_info tag"), tmp_name;
360
   FBiGeom_createTag(geom, &tag_name[0], 4, iBase_BYTES, &this_tag, &err,
361 362 363 364 365 366
         tag_name.length());
   CHECK( "ERROR : can not create a tag." );

   // get information on the tag

   char name_buffer[256];
367
   FBiGeom_getTagName(geom, this_tag, name_buffer, &err, sizeof(name_buffer));
368 369 370 371 372 373 374
   CHECK( "ERROR : Couldn't get tag name." );
   if (tag_name != name_buffer) {
      std::cerr << "ERROR: getTagName returned '" << name_buffer
            << "' for tag created as '" << tag_name << "'" << std::endl;
      return false;
   }

375
   FBiGeom_getTagHandle(geom, &tag_name[0], &tmp_handle, &err, tag_name.length());
376 377 378 379 380 381 382 383
   CHECK( "ERROR : Couldn't get tag handle." );
   if (tmp_handle != this_tag) {
      std::cerr << "ERROR: getTagHandle didn't return consistent result."
            << std::endl;
      return false;
   }

   int tag_size;
384
   FBiGeom_getTagSizeBytes(geom, this_tag, &tag_size, &err);
385 386 387 388 389 390 391
   CHECK( "ERROR : Couldn't get tag size." );
   if (tag_size != 4) {
      std::cerr << "ERROR: getTagSizeBytes: expected 4, got " << tag_size
            << std::endl;
      return false;
   }

392
   FBiGeom_getTagSizeValues(geom, this_tag, &tag_size, &err);
393 394 395 396 397 398 399 400
   CHECK( "ERROR : Couldn't get tag size." );
   if (tag_size != 4) {
      std::cerr << "ERROR: getTagSizeValues: expected 4, got " << tag_size
            << std::endl;
      return false;
   }

   int tag_type;
401
   FBiGeom_getTagType(geom, this_tag, &tag_type, &err);
402 403 404 405 406 407 408
   CHECK( "ERROR : Couldn't get tag type." );
   if (tag_type != iBase_BYTES) {
      std::cerr << "ERROR: getTagType: expected " << iBase_BYTES << ", got "
            << tag_type << std::endl;
      return false;
   }

409
   FBiGeom_destroyTag(geom, this_tag, true, &err);
410 411 412 413 414 415
   CHECK( "ERROR : Couldn't delete a tag." );

   // print information about all the tags in the model

   std::set<iBase_TagHandle> tags;
   SimpleArray<iBase_EntityHandle> entities;
416
   FBiGeom_getEntities(geom, root_set, iBase_ALL_TYPES, ARRAY_INOUT(entities), &err );
417 418 419
   CHECK( "getEntities( ..., iBase_ALL_TYPES, ... ) failed." );
   for (int i = 0; i < entities.size(); ++i) {
      SimpleArray<iBase_TagHandle> tag_arr;
420
      FBiGeom_getAllTags( geom, entities[i], ARRAY_INOUT(tag_arr), &err);
421 422 423 424 425 426 427
      CHECK( "getAllTags failed." );
      std::copy( tag_arr.begin(), tag_arr.end(), std::inserter( tags, tags.begin() ) );
   }

   std::cout << "Tags defined on model: ";
   bool first = true;
   for (std::set<iBase_TagHandle>::iterator sit = tags.begin(); sit != tags.end(); ++sit) {
428
      FBiGeom_getTagName( geom, *sit, name_buffer, &err, sizeof(name_buffer) );
429 430 431 432 433 434 435 436 437 438 439 440 441
      name_buffer[sizeof(name_buffer)-1] = '\0'; // mnake sure of NUL termination
      CHECK( "getTagName failed." );

      if (!first) std::cout << ", ";
      std::cout << name_buffer;
      first = false;
   }
   if (first) std::cout << "<none>";
   std::cout << std::endl;

   return true;
}

442
bool tag_get_set_test(FBiGeom_Instance geom) {
443 444 445 446 447
   int err;

   // create an arbitrary tag, size 4
   iBase_TagHandle this_tag;
   std::string tag_name("tag_get_set tag");
448
   FBiGeom_createTag(geom, &tag_name[0], sizeof(int), iBase_BYTES, &this_tag,
449 450 451 452
         &err, tag_name.length());
   CHECK( "ERROR : can not create a tag for get_set test." );

   iBase_EntitySetHandle root_set;
453
   FBiGeom_getRootSet(geom, &root_set, &err);
454 455 456 457 458 459
   CHECK( "ERROR : getRootSet failed!" );

   // set this tag to an integer on each entity; keep track of total sum
   int sum = 0, num = 0, dim;
   for (dim = 0; dim <= 3; dim++) {
      SimpleArray<iBase_EntityHandle> gentity_handles;
460
      FBiGeom_getEntities(geom, root_set, dim, ARRAY_INOUT( gentity_handles ), &err );
461 462 463 464 465 466 467 468
      int num_ents = gentity_handles.size();
      std::vector<int> tag_vals( num_ents );
      for (int i = 0; i < num_ents; ++i) {
         tag_vals[i] = num;
         sum += num;
         ++num;
      }

469
      FBiGeom_setArrData( geom, ARRAY_IN( gentity_handles ),
470 471 472 473 474 475 476 477 478 479
            this_tag,
            (char*)&tag_vals[0], tag_vals.size()*sizeof(int),
            &err );
      CHECK( "ERROR : can't set tag on entities" );
   }

   // check tag values for entities now
   int get_sum = 0;
   for (dim = 0; dim <= 3; dim++) {
      SimpleArray<iBase_EntityHandle> gentity_handles;
480
      FBiGeom_getEntities( geom, root_set, dim, ARRAY_INOUT( gentity_handles ), &err );
481 482 483
      int num_ents = gentity_handles.size();

      SimpleArray<char> tag_vals;
484
      FBiGeom_getArrData( geom, ARRAY_IN( gentity_handles ), this_tag,
485
          (void**)tag_vals.ptr(), &tag_vals.capacity(), &tag_vals.size(), &err );
486 487 488 489 490 491 492 493 494 495 496 497
      CHECK( "ERROR : can't get tag on entities" );

      int* tag_ptr = (int*)(&tag_vals[0]);
      for (int i = 0; i < num_ents; ++i)
      get_sum += tag_ptr[i];
   }

   if (get_sum != sum) {
      std::cerr << "ERROR: getData didn't return consistent results." << std::endl;
      return false;
   }

498
   FBiGeom_destroyTag( geom, this_tag, true, &err );
499 500 501 502 503 504 505 506 507 508
   CHECK( "ERROR : couldn't delete tag." );

   return true;
}

/*!
 @test
 TSTT gentity sets test (just implemented parts for now)
 @li Check gentity sets
 */
509
bool gentityset_test(FBiGeom_Instance geom, bool /*multiset*/, bool /*ordered*/) {
510 511 512
   int num_type = 4;
   iBase_EntitySetHandle ges_array[4];
   int number_array[4];
513
   //int num_all_gentities_super = 0;
514 515 516 517
   int ent_type = iBase_VERTEX;

   int err;
   iBase_EntitySetHandle root_set;
518
   FBiGeom_getRootSet(geom, &root_set, &err);
519 520 521 522
   CHECK( "ERROR : getRootSet failed!" );

   // get the number of sets in the whole model
   int all_sets = 0;
523
   FBiGeom_getNumEntSets(geom, root_set, 0, &all_sets, &err);
524 525 526 527 528
   CHECK( "Problem getting the number of all gentity sets in whole model." );

   // add gentities to entitysets by type
   for (; ent_type < num_type; ent_type++) {
      // initialize the entityset
529
      FBiGeom_createEntSet(geom, true, &ges_array[ent_type], &err);
530 531 532 533
      CHECK( "Problem creating entityset." );

      // get entities by type in total "mesh"
      SimpleArray<iBase_EntityHandle> gentities;
534
      FBiGeom_getEntities(geom, root_set, ent_type, ARRAY_INOUT(gentities), &err );
535 536 537
      CHECK( "Failed to get gentities by type in gentityset_test." );

      // add gentities into gentity set
538
      FBiGeom_addEntArrToSet( geom, ARRAY_IN( gentities ), ges_array[ent_type], &err );
539 540 541
      CHECK( "Failed to add gentities in entityset_test." );

      // Check to make sure entity set really has correct number of entities in it
542
      FBiGeom_getNumOfType( geom, ges_array[ent_type], ent_type, &number_array[ent_type], &err );
543 544 545 546 547 548 549 550 551 552 553 554 555
      CHECK( "Failed to get number of gentities by type in entityset_test." );

      // compare the number of entities by type
      int num_type_gentity = gentities.size();

      if (number_array[ent_type] != num_type_gentity)
      {
         std::cerr << "Number of gentities by type is not correct"
         << std::endl;
         return false;
      }

      // add to number of all entities in super set
556
      //num_all_gentities_super += num_type_gentity;
557 558 559 560
   }

   // make a super set having all entitysets
   iBase_EntitySetHandle super_set;
561
   FBiGeom_createEntSet( geom, true, &super_set, &err );
562 563 564
   CHECK( "Failed to create a super set in gentityset_test." );

   for (int i = 0; i < num_type; i++) {
565
      FBiGeom_addEntSet( geom, ges_array[i], super_set, &err );
566 567 568 569 570 571
      CHECK( "Failed to create a super set in gentityset_test." );
   }

   //----------TEST BOOLEAN OPERATIONS----------------//

   iBase_EntitySetHandle temp_ges1;
572
   FBiGeom_createEntSet( geom, true, &temp_ges1, &err );
573 574 575 576 577 578
   CHECK( "Failed to create a super set in gentityset_test." );

   // Subtract
   // add all EDGEs and FACEs to temp_es1
   // get all EDGE entities
   SimpleArray<iBase_EntityHandle> gedges, gfaces, temp_gentities1;
579
   FBiGeom_getEntities( geom, ges_array[iBase_EDGE], iBase_EDGE, ARRAY_INOUT(gedges), &err );
580 581 582
   CHECK( "Failed to get gedge gentities in gentityset_test." );

   // add EDGEs to ges1
583
   FBiGeom_addEntArrToSet( geom, ARRAY_IN(gedges), temp_ges1, &err );
584 585 586
   CHECK( "Failed to add gedge gentities in gentityset_test." );

   // get all FACE gentities
587
   FBiGeom_getEntities( geom, ges_array[iBase_FACE], iBase_FACE, ARRAY_INOUT(gfaces), &err );
588 589 590
   CHECK( "Failed to get gface gentities in gentityset_test." );

   // add FACEs to es1
591
   FBiGeom_addEntArrToSet( geom, ARRAY_IN(gfaces), temp_ges1, &err );
592 593 594
   CHECK( "Failed to add gface gentities in gentityset_test." );

   // subtract EDGEs
595
   FBiGeom_subtract( geom, temp_ges1, ges_array[iBase_EDGE], &temp_ges1, &err );
596 597
   CHECK( "Failed to subtract gentitysets in gentityset_test." );

598
   FBiGeom_getEntities( geom, temp_ges1, iBase_FACE, ARRAY_INOUT(temp_gentities1), &err );
599 600 601 602 603 604 605 606 607 608
   CHECK( "Failed to get gface gentities in gentityset_test." );

   if (gfaces.size() != temp_gentities1.size()) {
      std::cerr << "Number of entitysets after subtraction not correct \
             in gentityset_test." << std::endl;
      return false;
   }

   // check there's nothing but gfaces in temp_ges1
   int num_gents;
609
   FBiGeom_getNumOfType( geom, temp_ges1, iBase_EDGE, &num_gents, &err );
610 611 612 613 614 615 616 617 618 619
   CHECK( "Failed to get dimensions of gentities in gentityset_test." );
   if (0 != num_gents) {
      std::cerr << "Subtraction failed to remove all edges" << std::endl;
      return false;
   }

   //------------Intersect------------
   //

   // clean out the temp_ges1
620
   FBiGeom_rmvEntArrFromSet( geom, ARRAY_IN(gfaces), temp_ges1, &err );
621 622 623
   CHECK( "Failed to remove gface gentities in gentityset_test." );

   // check if it is really cleaned out
624
   FBiGeom_getNumOfType( geom, temp_ges1, iBase_FACE, &num_gents, &err );
625 626 627 628 629 630 631 632
   CHECK( "Failed to get number of gentities by type in gentityset_test." );

   if (num_gents != 0) {
      std::cerr << "failed to remove correctly." << std::endl;
      return false;
   }

   // add EDGEs to temp ges1
633
   FBiGeom_addEntArrToSet( geom, ARRAY_IN(gedges), temp_ges1, &err );
634 635 636
   CHECK( "Failed to add gedge gentities in gentityset_test." );

   // add FACEs to temp ges1
637
   FBiGeom_addEntArrToSet( geom, ARRAY_IN(gfaces), temp_ges1, &err );
638 639 640 641
   CHECK( "Failed to add gface gentities in gentityset_test." );

   // intersect temp_ges1 with gedges set
   // temp_ges1 entityset is altered
642
   FBiGeom_intersect( geom, temp_ges1, ges_array[iBase_EDGE], &temp_ges1, &err );
643 644 645
   CHECK( "Failed to intersect in gentityset_test." );

   // try to get FACEs, but there should be nothing but EDGE
646
   FBiGeom_getNumOfType( geom, temp_ges1, iBase_FACE, &num_gents, &err );
647 648 649 650 651 652 653 654 655 656 657 658 659
   CHECK( "Failed to get gface gentities in gentityset_test." );

   if (num_gents != 0) {
      std::cerr << "wrong number of gfaces." << std::endl;
      return false;
   }

   //-------------Unite--------------

   // get all regions
   iBase_EntitySetHandle temp_ges2;
   SimpleArray<iBase_EntityHandle> gregions;

660
   FBiGeom_createEntSet( geom, true, &temp_ges2, &err );
661 662
   CHECK( "Failed to create a temp gentityset in gentityset_test." );

663
   FBiGeom_getEntities( geom, ges_array[iBase_REGION], iBase_REGION, ARRAY_INOUT(gregions), &err );
664 665 666
   CHECK( "Failed to get gregion gentities in gentityset_test." );

   // add REGIONs to temp es2
667
   FBiGeom_addEntArrToSet( geom, ARRAY_IN(gregions), temp_ges2, &err );
668 669 670 671
   CHECK( "Failed to add gregion gentities in gentityset_test." );

   // unite temp_ges1 and temp_ges2
   // temp_ges1 gentityset is altered
672
   FBiGeom_unite( geom, temp_ges1, temp_ges2, &temp_ges1, &err );
673 674 675
   CHECK( "Failed to unite in gentityset_test." );

   // perform the check
676
   FBiGeom_getNumOfType( geom, temp_ges1, iBase_REGION, &num_gents, &err );
677 678 679 680 681 682 683 684 685 686 687
   CHECK( "Failed to get number of gregion gentities by type in gentityset_test." );

   if (num_gents != number_array[iBase_REGION]) {
      std::cerr << "different number of gregions in gentityset_test." << std::endl;
      return false;
   }

   //--------Test parent/child stuff in entiysets-----------

   // Add 2 sets as children to another
   iBase_EntitySetHandle parent_child;
688
   FBiGeom_createEntSet( geom, true, &parent_child, &err );
689 690
   CHECK( "Problem creating gentityset in gentityset_test." );

691
   FBiGeom_addPrntChld( geom, ges_array[iBase_VERTEX], parent_child, &err );
692 693 694 695
   CHECK( "Problem add parent in gentityset_test." );

   // check if parent is really added
   SimpleArray<iBase_EntitySetHandle> parents;
696
   FBiGeom_getPrnts( geom, parent_child, 1, ARRAY_INOUT(parents), &err );
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
   CHECK( "Problem getting parents in gentityset_test." );

   if (parents.size() != 1) {
      std::cerr << "number of parents is not correct in gentityset_test."
      << std::endl;
      return false;
   }

   // add parent and child
   //sidl::array<void*> parent_child_array = sidl::array<void*>::create1d(1);
   //int num_parent_child_array;
   //sidl::array<void*> temp_gedge_array = sidl::array<void*>::create1d(1);
   //int num_temp_gedge_array;
   //parent_child_array.set(0, parent_child);
   //temp_gedge_array.set(0, ges_array[TSTTG::EntityType_EDGE]);
712
   FBiGeom_addPrntChld( geom, ges_array[iBase_EDGE], parent_child, &err );
713 714 715 716 717
   CHECK( "Problem adding parent and child in gentityset_test." );

   //sidl::array<void*> temp_gface_array = sidl::array<void*>::create1d(1);
   //int num_temp_gface_array;
   //temp_gface_array.set(0, ges_array[TSTTG::EntityType_FACE]);
718
   FBiGeom_addPrntChld( geom, parent_child, ges_array[iBase_FACE], &err );
719 720 721
   CHECK( "Problem adding parent and child in gentityset_test." );

   // add child
722
   FBiGeom_addPrntChld( geom, parent_child, ges_array[iBase_REGION], &err );
723 724 725 726
   CHECK( "Problem adding child in gentityset_test." );

   // get the number of parent gentitysets
   num_gents = -1;
727
   FBiGeom_getNumPrnt( geom, parent_child, 1, &num_gents, &err );
728 729 730 731 732 733 734 735 736 737
   CHECK( "Problem getting number of parents in gentityset_test." );

   if (num_gents != 2) {
      std::cerr << "number of parents is not correct in gentityset_test."
      << std::endl;
      return false;
   }

   // get the number of child gentitysets
   num_gents = -1;
738
   FBiGeom_getNumChld( geom, parent_child, 1, &num_gents, &err );
739 740 741 742 743 744 745 746 747
   CHECK( "Problem getting number of children in gentityset_test." );

   if (num_gents != 2) {
      std::cerr << "number of children is not correct in gentityset_test."
      << std::endl;
      return false;
   }

   SimpleArray<iBase_EntitySetHandle> children;
748
   FBiGeom_getChldn( geom, parent_child, 1, ARRAY_INOUT(children), &err );
749 750 751 752 753 754 755 756 757
   CHECK( "Problem getting children in gentityset_test." );

   if (children.size() != 2) {
      std::cerr << "number of children is not correct in gentityset_test."
      << std::endl;
      return false;
   }

   // remove children
758
   FBiGeom_rmvPrntChld( geom, parent_child, ges_array[iBase_FACE], &err );
759 760 761
   CHECK( "Problem removing parent child in gentityset_test." );

   // get the number of child gentitysets
762
   FBiGeom_getNumChld( geom, parent_child, 1, &num_gents, &err );
763 764 765 766 767 768 769 770 771 772
   CHECK( "Problem getting number of children in gentityset_test." );

   if (num_gents != 1) {
      std::cerr << "number of children is not correct in gentityset_test."
      << std::endl;
      return false;
   }

   // parent_child and ges_array[TSTTG::EntityType_EDGE] should be related
   int result = 0;
773
   FBiGeom_isChildOf( geom, ges_array[iBase_EDGE], parent_child, &result, &err );
774 775 776 777 778 779 780 781
   CHECK( "Problem checking relation in gentityset_test." );
   if (!result) {
      std::cerr << "parent_child and ges_array[TSTTG::EntityType_EDGE] should be related" << std::endl;
      return false;
   }

   // ges_array[TSTTG::EntityType_FACE] and ges_array[TSTTG::REGION] are not related
   result = 2;
782
   FBiGeom_isChildOf( geom, ges_array[iBase_FACE], ges_array[iBase_REGION], &result, &err );
783 784 785 786 787 788 789 790 791
   if (result) {
      std::cerr << "ges_array[TSTTG::REGION] and ges_array[TSTTG::EntityType_FACE] should not be related" << std::endl;
      return false;
   }

   //--------test modify and query functions-----------------------------

   // check the number of gentity sets in whole mesh
   SimpleArray<iBase_EntitySetHandle> gentity_sets;
792
   FBiGeom_getEntSets( geom, root_set, 1, ARRAY_INOUT( gentity_sets ), &err );
793 794 795 796 797 798 799 800 801 802
   CHECK( "Problem to get all gentity sets in mesh." );

   if (gentity_sets.size() != all_sets + 8) {
      std::cerr << "the number of gentity sets in whole mesh should be 8 times of num_iter."
      << std::endl;
      return false;
   }

   // get all gentity sets in super set
   SimpleArray<iBase_EntitySetHandle> ges_array1;
803
   FBiGeom_getEntSets( geom, super_set, 1, ARRAY_INOUT( ges_array1 ), &err );
804 805 806 807
   CHECK( "Problem to get gentity sets in super set." );

   // get the number of gentity sets in super set
   int num_super;
808
   FBiGeom_getNumEntSets( geom, super_set, 1, &num_super, &err );
809 810 811 812 813 814 815 816 817 818
   CHECK( "Problem to get the number of all gentity sets in super set." );

   // the number of gentity sets in super set should be same
   if (num_super != ges_array1.size()) {
      std::cerr << "the number of gentity sets in super set should be same." << std::endl;
      return false;
   }

   // get all entities in super set
   SimpleArray<iBase_EntitySetHandle> all_gentities;
819
   FBiGeom_getEntSets( geom, super_set, 1, ARRAY_INOUT( all_gentities ), &err );
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
   CHECK( "Problem to get all gentities in super set." );

   // compare the number of all gentities in super set
   // HJK : num_hops is not implemented
   //if (num_all_gentities_super != ARRAY_SIZE(all_gentities)) {
   //std::cerr << "number of all gentities in super set should be same." << std::endl;
   //success = false;
   //}

   // test add, remove and get all entitiy sets using super set
   // check GetAllGentitysets works recursively and dosen't return
   // multi sets
   for (int k = 0; k < num_super; k++) {
      // add gentity sets of super set to each gentity set of super set
      // make multiple child super sets
      iBase_EntitySetHandle ges_k = ges_array1[k];

      for (int a = 0; a < ges_array1.size(); a++) {
838
         FBiGeom_addEntSet( geom, ges_array1[a], ges_k, &err );
839 840 841 842 843 844 845 846 847
         CHECK( "Problem to add entity set." );
      }

      // add super set to each entity set
      //    sidl::array<GentitysetHandle> superset_array
      //= sidl::array<GentitysetHandle>::create1d(1);
      //superset_array.set(0, super_set);
      //int num_superset_array;

848
      FBiGeom_addEntSet( geom, super_set, ges_k, &err );
849 850 851 852 853 854 855 856 857 858
      CHECK( "Problem to add super set to gentitysets." );

      // add one gentity sets multiple times
      // HJK: ??? how to deal this case?
      //sidl::array<GentitysetHandle> temp_array1
      //= sidl::array<GentitysetHandle>::create1d(1);
      //int num_temp_array1;
      //temp_array1.set(0, temp_ges1);

      //for (int l = 0; l < 3; l++) {
859
      FBiGeom_addEntSet( geom, temp_ges1, ges_k, &err );
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874
      CHECK( "Problem to add temp set to gentitysets." );
      //}
   }

   return true;
}

/*!
 @test
 TSTTG topology adjacencies Test
 @li Check topology information
 @li Check adjacency
 */
// make each topological entity vectors, check their topology
// types, get interior and exterior faces of model
875
bool topology_adjacencies_test(FBiGeom_Instance geom) {
876 877
   int i, err;
   iBase_EntitySetHandle root_set;
878
   FBiGeom_getRootSet(geom, &root_set, &err);
879 880 881 882 883 884 885 886 887 888 889 890
   CHECK( "ERROR : getRootSet failed!" );

   int top = iBase_VERTEX;
   int num_test_top = iBase_ALL_TYPES;
   std::vector<std::vector<iBase_EntityHandle> > gentity_vectors(num_test_top);

   // fill the vectors of each topology entities
   // like lines vector, polygon vector, triangle vector,
   // quadrilateral, polyhedrron, tet, hex, prism, pyramid,
   // septahedron vectors
   for (i = top; i < num_test_top; i++) {
      SimpleArray<iBase_EntityHandle> gentities;
891
      FBiGeom_getEntities(geom, root_set, i, ARRAY_INOUT( gentities ), &err );
892 893 894 895 896 897 898 899 900
      CHECK("Failed to get gentities in adjacencies_test.");

      gentity_vectors[i].resize( gentities.size() );
      std::copy( gentities.begin(), gentities.end(), gentity_vectors[i].begin() );
   }

   // check number of entities for each topology
   for (i = top; i < num_test_top; i++) {
      int num_tops = 0;
901
      FBiGeom_getNumOfType( geom, root_set, i, &num_tops, &err );
902 903 904 905 906 907 908 909 910 911 912 913
      CHECK( "Failed to get number of gentities in adjacencies_test." );

      if (static_cast<int>(gentity_vectors[i].size()) != num_tops) {
         std::cerr << "Number of gentities doesn't agree with number returned for dimension "
         << i << std::endl;
         return false;
      }
   }

   // check adjacencies in both directions
   std::vector<iBase_EntityHandle>::iterator vit;
   for (i = iBase_REGION; i >= iBase_VERTEX; i--) {
914
      for (vit = gentity_vectors[i].begin(); vit != gentity_vectors[i].end(); ++vit) {
915 916 917 918 919 920
         iBase_EntityHandle this_gent = *vit;

         // check downward adjacencies
         for (int j = iBase_VERTEX; j < i; j++) {

            SimpleArray<iBase_EntityHandle> lower_ents;
921
            FBiGeom_getEntAdj( geom, this_gent, j, ARRAY_INOUT(lower_ents), &err );
922 923 924 925 926 927
            CHECK( "Bi-directional adjacencies test failed." );

            // for each of them, make sure they are adjacent to the upward ones
            int num_lower = lower_ents.size();
            for (int k = 0; k < num_lower; k++) {
               SimpleArray<iBase_EntityHandle> upper_ents;
928
               FBiGeom_getEntAdj( geom, lower_ents[k], i, ARRAY_INOUT(upper_ents), &err );
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945
               CHECK( "Bi-directional adjacencies test failed." );
               if (std::find(upper_ents.begin(),upper_ents.end(), this_gent) ==
               upper_ents.end()) {
                  std::cerr << "Didn't find lower-upper adjacency which was supposed to be there, dims = "
                  << i << ", " << j << std::endl;
                  return false;
               }
            }
         }
      }
   }

   return true;
}

/*!
 @test
946
 FBiGeom_MOAB topology adjacencies Test
947 948 949 950 951
 @li Check topology information
 @li Check adjacency
 */
// make each topological entity vectors, check their topology
// types, get interior and exterior faces of model
952
bool geometry_evaluation_test(FBiGeom_Instance geom) {
953 954
   int i, err;
   iBase_EntitySetHandle root_set;
955
   FBiGeom_getRootSet(geom, &root_set, &err);
956 957 958 959 960 961 962 963 964 965 966 967
   CHECK( "ERROR : getRootSet failed!" );

   int top = iBase_VERTEX;
   int num_test_top = iBase_ALL_TYPES;
   std::vector<std::vector<iBase_EntityHandle> > gentity_vectors(num_test_top);

   // fill the vectors of each topology entities
   // like lines vector, polygon vector, triangle vector,
   // quadrilateral, polyhedrron, tet, hex, prism, pyramid,
   // septahedron vectors
   for (i = top; i < num_test_top; i++) {
      SimpleArray<iBase_EntityHandle> gentities;
968
      FBiGeom_getEntities(geom, root_set, i, ARRAY_INOUT( gentities ), &err );
969 970 971 972 973 974 975 976 977 978 979 980
      CHECK("Failed to get gentities in adjacencies_test.");

      gentity_vectors[i].resize( gentities.size() );
      std::copy( gentities.begin(), gentities.end(), gentity_vectors[i].begin() );
   }

   // check adjacencies in both directions
   double min[3], max[3], on[3];
   double near[3] = {.0, .0, .0};
   std::vector<iBase_EntityHandle>::iterator vit;
   for (i = iBase_REGION; i >= iBase_VERTEX; i--) {
      if (i != iBase_EDGE) {
981
         for (vit = gentity_vectors[i].begin(); vit != gentity_vectors[i].end(); ++vit) {
982
            iBase_EntityHandle this_gent = *vit;
983
            FBiGeom_getEntBoundBox(geom, this_gent, &min[0], &min[1], &min[2],
984 985 986 987 988
            &max[0], &max[1], &max[2], &err);
            CHECK("Failed to get bounding box of entity.");

            for (int j=0; j<3; j++)
            near[j] = (min[j]+max[j])/2;
989
            FBiGeom_getEntClosestPt(geom, this_gent, near[0], near[1], near[2],
990 991 992 993 994 995 996 997 998 999 1000 1001
            &on[0], &on[1], &on[2], &err);
            CHECK("Failed to get closest point on entity.");
            std::cout<<" entity of type " << i << " closest point to \n  " <<
            near[0] << " " << near[1] << " " << near[2] << "\n  is " << on[0] << " " << on[1] << " " << on[2] << "\n";
         }
      }
   }

   return true;
}
// 
//  test normals evaluations on the surface only
1002
bool normals_test(FBiGeom_Instance geom) {
1003 1004
   int i, err;
   iBase_EntitySetHandle root_set;
1005
   FBiGeom_getRootSet(geom, &root_set, &err);
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
   CHECK( "ERROR : getRootSet failed!" );

   int top = iBase_VERTEX;
   int num_test_top = iBase_ALL_TYPES;
   std::vector<std::vector<iBase_EntityHandle> > gentity_vectors(num_test_top);

   // fill the vectors of each topology entities
   // like lines vector, polygon vector, triangle vector,
   // quadrilateral, polyhedrron, tet, hex, prism, pyramid,
   // septahedron vectors
   for (i = top; i < num_test_top; i++) {
      SimpleArray<iBase_EntityHandle> gentities;
1018
      FBiGeom_getEntities(geom, root_set, i, ARRAY_INOUT( gentities ), &err );
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
      CHECK("Failed to get gentities in adjacencies_test.");

      gentity_vectors[i].resize( gentities.size() );
      std::copy( gentities.begin(), gentities.end(), gentity_vectors[i].begin() );
   }

   // check adjacencies in both directions
   double min[3], max[3];
   double normal[3] = {.0, .0, .0};
   std::vector<iBase_EntityHandle>::iterator vit;
   for (i = iBase_REGION; i > iBase_EDGE; i--) {
1030
      for (vit = gentity_vectors[i].begin(); vit != gentity_vectors[i].end(); ++vit) {
1031
         iBase_EntityHandle this_gent = *vit;
1032
         FBiGeom_getEntBoundBox(geom, this_gent, &min[0], &min[1], &min[2],
1033 1034 1035
         &max[0], &max[1], &max[2], &err);
         CHECK("Failed to get bounding box of entity.");

1036
         FBiGeom_getEntNrmlXYZ( geom, this_gent,
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
         (max[0]+min[0])/2,
         (max[1]+min[1])/2,
         (max[2]+min[2])/2,
         &normal[0],
         &normal[1],
         &normal[2],
         &err );

         CHECK("Failed to get normal to the closest point.");
         std::cout<<" entity of type " << i << " closest normal to center:\n  " <<
         normal[0] << " " << normal[1] << " " << normal[2] << "\n";
      }
   }

   return true;
}

1054
//  test normals evaluations on the surface only
1055
bool ray_test(FBiGeom_Instance geom) {
1056 1057
   int  err;
   iBase_EntitySetHandle root_set;
1058
   FBiGeom_getRootSet(geom, &root_set, &err);
1059 1060 1061 1062 1063
   CHECK( "ERROR : getRootSet failed!" );

   int top = iBase_FACE;

   SimpleArray<iBase_EntityHandle> faces;
1064
   FBiGeom_getEntities(geom, root_set, top, ARRAY_INOUT( faces ), &err );
1065 1066 1067 1068 1069 1070 1071 1072 1073
   CHECK("Failed to get gentities in adjacencies_test.");

   // check only the first face

   // check adjacencies in both directions
   double min[3], max[3];

   iBase_EntityHandle first_face = faces[0];

1074
   FBiGeom_getEntBoundBox(geom, first_face, &min[0], &min[1], &min[2],
1075 1076 1077 1078 1079 1080 1081 1082 1083
   &max[0], &max[1], &max[2], &err);
   CHECK("Failed to get bounding box of entity.");

   // assume that the ray shot from the bottom of the box (middle) is a pretty good candidate
   // in z direction
   double x = (min[0]+max[0])/2, y = (min[1]+max[1])/2, z = min[2];
   SimpleArray<iBase_EntityHandle> intersect_entity_handles;
   SimpleArray<double> intersect_coords;
   SimpleArray<double> param_coords;
1084
   FBiGeom_getPntRayIntsct( geom,  x,  y,  z, // shot from
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
                                       0., 0., 1., // direction
                                       ARRAY_INOUT(intersect_entity_handles),
                                       iBase_INTERLEAVED,
                                       ARRAY_INOUT(intersect_coords),
                                       ARRAY_INOUT(param_coords),
                                       &err );

   CHECK("Failed to find ray intersections points ");
   for(int i=0; i<intersect_entity_handles.size(); i++)
   {
      int j;
1096
      FBiGeom_getEntType( geom, intersect_entity_handles[i],
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
                               &j,&err);
      CHECK("Failed to get type of entity.");

      std::cout<<" entity of type " << j << " n: " << intersect_entity_handles[i]<< "\n"<<
            intersect_coords[3*i] << " " << intersect_coords[3*i+1] << " "
            << intersect_coords[3*i+2] << "\n" <<
            " distance: " << param_coords[i] << "\n";
   }

   return true;
}

1109 1110 1111 1112 1113
/*!
 @test
 TSTTG construct Test
 @li Check construction of geometry
 */
1114
bool construct_test(FBiGeom_Instance geom) {
1115 1116 1117 1118 1119
   int err;
   iBase_EntityHandle new_body = 0;

   // construct a cylinder, sweep it about an axis, and delete the result
   iBase_EntityHandle cyl = 0;
1120
   FBiGeom_createCylinder(geom, 1.0, 1.0, 0.0, &cyl, &err);
1121 1122 1123 1124
   // Is the minor radius really supposed to be zero??? - JK
   CHECK( "Creating cylinder failed." );

   // move it onto the y axis
1125
   FBiGeom_moveEnt(geom, cyl, 0.0, 1.0, -0.5, &err);
1126 1127 1128 1129 1130
   CHECK( "Problems moving surface." );

   // get the surface with max z
   iBase_EntityHandle max_surf = 0;
   SimpleArray<iBase_EntityHandle> surfs;
1131
   FBiGeom_getEntAdj(geom, cyl, iBase_FACE, ARRAY_INOUT(surfs), &err );
1132 1133 1134
   CHECK( "Problems getting max surf for rotation." );

   SimpleArray<double> max_corn, min_corn;
1135
   FBiGeom_getArrBoundBox( geom, ARRAY_IN(surfs), iBase_INTERLEAVED,
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
   ARRAY_INOUT( min_corn ),
   ARRAY_INOUT( max_corn ),
   &err );
   CHECK( "Problems getting max surf for rotation." );
   double dtol = 1.0e-6;
   for (int i = 0; i < surfs.size(); ++i) {
      if ((max_corn[3*i+2]) <= dtol && (max_corn[3*i+2]) >= -dtol &&
      (min_corn[3*i+2]) <= dtol && (min_corn[3*i+2]) >= -dtol) {
         max_surf = surfs[i];
         break;
      }
   }

   if (0 == max_surf) {
      std::cerr << "Couldn't find max surf for rotation." << std::endl;
      return false;
   }

   // sweep it around the x axis
1155
   FBiGeom_moveEnt( geom, cyl, 0.0, 1.0, 0.0, &err );
1156 1157
   CHECK( "Problems moving surface." );

1158
   FBiGeom_sweepEntAboutAxis( geom, max_surf, 360.0, 1.0, 0.0, 0.0, &new_body, &err );
1159 1160 1161
   CHECK( "Problems sweeping surface about axis." );

   // now delete
1162
   FBiGeom_deleteEnt( geom, new_body, &err );
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
   CHECK( "Problems deleting cylinder or swept surface body." );

   // if we got here, we were successful
   return true;
}

static bool compare_box(const double* expected_min, const double* expected_max,
      const double* actual_min, const double* actual_max) {
   bool same = true;
   double dtol = 1.0e-6;

   for (int i = 0; i < 3; ++i) {
      if (expected_min[i] < actual_min[i] - dtol || expected_min[i] * 10
            > actual_min[i] || expected_max[i] > actual_max[i] + dtol
            || expected_max[i] * 10 < actual_max[i])
         same = false;
   }
   return same;
}

1183
bool primitives_test(FBiGeom_Instance geom) {
1184 1185 1186 1187
   int err;
   SimpleArray<iBase_EntityHandle> prims(3);
   iBase_EntityHandle prim;

1188
   FBiGeom_createBrick(geom, 1.0, 2.0, 3.0, &prim, &err);
1189 1190 1191
   CHECK( "createBrick failed." );
   prims[0] = prim;

1192
   FBiGeom_createCylinder(geom, 1.0, 4.0, 2.0, &prim, &err);
1193 1194 1195
   CHECK( "createCylinder failed." );
   prims[1] = prim;

1196
   FBiGeom_createTorus(geom, 2.0, 1.0, &prim, &err);
1197 1198 1199 1200 1201
   CHECK( "createTorus failed." );
   prims[2] = prim;

   // verify the bounding boxes for Acis based entities
   SimpleArray<double> max_corn, min_corn;
1202
   FBiGeom_getArrBoundBox(geom, ARRAY_IN(prims),iBase_INTERLEAVED,  ARRAY_INOUT(min_corn),
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
         ARRAY_INOUT(max_corn), &err );

         double preset_min_corn[] =
         // min brick corner xyz
         {  -0.5, -1.0, -1.5,
            // min cyl corner xyz
         -4.0, -2.0, -0.5,
         // min torus corner xyz
         -3.0, -3.0, -1.0
      };

      double preset_max_corn[] =
      // max brick corner xyz
         {  0.5, 1.0, 1.5,
            // max cyl corner xyz
         4.0, 2.0, 0.5,
         // max torus corner xyz
         3.0, 3.0, 1.0
      };

      if (!compare_box( preset_min_corn, preset_max_corn,
                  &min_corn[0], &max_corn[0] )) {
         std::cerr << "Box check failed for brick" << std::endl;
         return false;
      }

      if (!compare_box( preset_min_corn+3, preset_max_corn+3,
                  &min_corn[3], &max_corn[3] )) {
         std::cerr << "Box check failed for cylinder" << std::endl;
         return false;
      }

      if (!compare_box( preset_min_corn+6, preset_max_corn+6,
                  &min_corn[6], &max_corn[6] )) {
         std::cerr << "Box check failed for torus" << std::endl;
         return false;
      }
      // must have worked; delete the entities then return
         for (int i = 0; i < 3; ++i) {
1242
            FBiGeom_deleteEnt( geom, prims[i], &err );
1243 1244