MOAB: Mesh Oriented datABase  (version 5.2.1)
gttool_test.cpp
Go to the documentation of this file.
00001 /**
00002  * This library is free software; you can redistribute it and/or
00003  * modify it under the terms of the GNU Lesser General Public
00004  * License as published by the Free Software Foundation; either
00005  * version 2.1 of the License, or (at your option) any later version.
00006  *
00007  */
00008 /**
00009  * \file gttool_test.cpp
00010  *
00011  * \brief test geometrize method from GeomTopoTool
00012  *
00013  */
00014 #include "moab/Core.hpp"
00015 #include <iostream>
00016 
00017 #include <assert.h>
00018 #include <string.h>
00019 #include <stdio.h>
00020 
00021 #include "TestUtil.hpp"
00022 #include "moab/GeomTopoTool.hpp"
00023 #include "MBTagConventions.hpp"
00024 
00025 using namespace moab;
00026 
00027 std::string filename;
00028 std::string filename2;
00029 std::string ofile;
00030 std::string ofile2;
00031 std::string ofile3;
00032 std::string ofile4;
00033 std::string ofile5;
00034 
00035 const char OBB_ROOT_TAG_NAME[] = "OBB_ROOT";
00036 Tag obbRootTag;
00037 
00038 bool remove_output_file;
00039 ErrorCode geometrize_test( Interface* mb, EntityHandle inputSet );
00040 
00041 ErrorCode create_shell_test( Interface* mb );
00042 
00043 ErrorCode duplicate_model_test( Interface* mb );
00044 
00045 ErrorCode check_model_test( Interface* mb );
00046 
00047 ErrorCode test_root_sets_resize( Interface* mb );
00048 
00049 ErrorCode test_delete_obb_tree( Interface* mb );
00050 
00051 ErrorCode test_restore_obb_trees( Interface* mb, Interface* mb2, Interface* mb3 );
00052 
00053 void handle_error_code( ErrorCode rv, int& number_failed, int& number_successful )
00054 {
00055     if( rv == MB_SUCCESS )
00056     {
00057         std::cout << "Success";
00058         number_successful++;
00059     }
00060     else
00061     {
00062         std::cout << "Failure";
00063         number_failed++;
00064     }
00065 }
00066 
00067 int main( int argc, char* argv[] )
00068 {
00069     filename  = TestDir + "/partBed.smf";
00070     filename2 = TestDir + "/test_geom.h5m";
00071     ofile     = "output.h5m";
00072     ofile2    = "shell.h5m";
00073     ofile3    = "shellCopy.h5m";
00074     ofile4    = "geom_w_obbs.h5m";
00075     ofile5    = "geom_missing_obb.h5m";
00076 
00077     remove_output_file   = true;
00078     bool only_check      = false;
00079     bool only_geometrize = false;
00080 
00081     if( argc == 1 )
00082     {
00083         std::cout << "Using default input file and output files " << filename << " " << ofile << " " << ofile2 << " "
00084                   << ofile3 << std::endl;
00085     }
00086     else if( argc == 5 )
00087     {
00088         filename           = argv[1];
00089         ofile              = argv[2];
00090         ofile2             = argv[3];
00091         ofile3             = argv[4];
00092         remove_output_file = false;
00093     }
00094     else if( argc == 2 )
00095     {
00096         ofile3             = argv[1];  // check model only from file
00097         only_check         = true;
00098         remove_output_file = false;  // this is input now, do not delete it
00099     }
00100     else if( argc == 3 )
00101     {
00102         filename           = argv[1];
00103         ofile              = argv[2];
00104         only_geometrize    = true;
00105         remove_output_file = false;
00106     }
00107     else
00108     {
00109         std::cerr << "Usage: " << argv[0] << " [surface_mesh] [mbgeo_file] [shellfile] [copyshellfile] " << std::endl;
00110         return 1;
00111     }
00112 
00113     int number_tests_successful = 0;
00114     int number_tests_failed     = 0;
00115 
00116     Core mbcore;
00117     Interface* mb = &mbcore;
00118 
00119     // use this as a tool to check a model
00120     if( only_check )
00121     {
00122         if( MB_SUCCESS == check_model_test( mb ) ) std::cout << ofile3 << " passed gtt check\n";
00123         return 0;
00124     }
00125 
00126     mb->load_file( filename.c_str() );
00127 
00128     //   FBEngine * pFacet = new FBEngine(mb, NULL, true);// smooth facetting, no OBB tree passed
00129 
00130     std::cout << "geometrize test: ";
00131     ErrorCode rval = geometrize_test( mb, 0 );  // just pass the root set
00132     handle_error_code( rval, number_tests_failed, number_tests_successful );
00133     std::cout << "\n";
00134 
00135     if( only_geometrize ) { return number_tests_failed; }
00136     std::cout << "create shell test: ";
00137     rval = create_shell_test( mb );
00138     handle_error_code( rval, number_tests_failed, number_tests_successful );
00139     std::cout << "\n";
00140 
00141     std::cout << "duplicate model test: ";
00142     rval = duplicate_model_test( mb );
00143     handle_error_code( rval, number_tests_failed, number_tests_successful );
00144     std::cout << "\n";
00145 
00146     std::cout << "check_model test: ";
00147     rval = check_model_test( mb );
00148     handle_error_code( rval, number_tests_failed, number_tests_successful );
00149     std::cout << "\n";
00150 
00151     std::cout << "test_rootsets_resize: ";
00152     Interface* mb2 = new Core();
00153     rval           = test_root_sets_resize( mb2 );
00154     handle_error_code( rval, number_tests_failed, number_tests_successful );
00155     delete mb2;
00156     std::cout << "\n";
00157 
00158     std::cout << "test_delete_obb_tree: ";
00159     Interface* mb3 = new Core();
00160     rval           = test_delete_obb_tree( mb3 );
00161     handle_error_code( rval, number_tests_failed, number_tests_successful );
00162     delete mb3;
00163     std::cout << "\n";
00164 
00165     std::cout << "test_restore_obb_trees: ";
00166     Interface* mb4 = new Core();
00167     Interface* mb5 = new Core();
00168     Interface* mb6 = new Core();
00169     rval           = test_restore_obb_trees( mb4, mb5, mb6 );
00170     handle_error_code( rval, number_tests_failed, number_tests_successful );
00171     delete mb4;
00172     delete mb5;
00173     delete mb6;
00174     std::cout << "\n";
00175 
00176     return number_tests_failed;
00177 }
00178 ErrorCode geometrize_test( Interface* mb, EntityHandle inputSet )
00179 {
00180     GeomTopoTool gtt( mb );
00181     EntityHandle outSet;
00182     ErrorCode rval = gtt.geometrize_surface_set( inputSet, outSet );MB_CHK_SET_ERR( rval, "Can't geometrize the set\n" );
00183 
00184     std::cout << "writing output file: " << ofile.c_str() << " ";
00185     rval = mb->write_file( ofile.c_str(), 0, 0, &outSet, 1 );MB_CHK_SET_ERR( rval, "Can't write output file\n" );
00186     if( remove_output_file ) { remove( ofile.c_str() ); }
00187     return MB_SUCCESS;
00188 }
00189 
00190 ErrorCode create_shell_test( Interface* mb )
00191 {
00192     // we should be able to delete mesh and create a model from scratch
00193 
00194     ErrorCode rval = mb->delete_mesh();MB_CHK_SET_ERR( rval, "Can't delete existing mesh\n" );
00195 
00196     // create some vertices
00197     double coords[] = {
00198         0, 0,   0, 1,    0,    0.1, 2,   0,   0, 3,    0, -0.1, 0,    1, 0,   1,    1,   0,   2,   1,
00199         0, 3,   1, -0.1, 0,    2,   0,   1,   2, -0.1, 2, 2,    -0.1, 3, 2,   -0.2, 0,   0,   1,   1,
00200         0, 0.9, 2, 0.1,  0.85, 3,   0.2, 0.8, 0, 0.1,  2, 1,    0.1,  2, 2.1, 0.2,  2.1, 3.1, 0.2, 2.1
00201     };
00202 
00203     int nvert = 20;
00204     Range verts;
00205     rval = mb->create_vertices( coords, nvert, verts );MB_CHK_SET_ERR( rval, "Can't create vertices\n" );
00206 
00207     EntityHandle connec[] = {
00208         1,  2,  5,  5,  2,  6,  2,  3,  6,  6,  3,  7,  3,  4,  7,  7,  4,  8,
00209         5,  6,  9,  9,  6,  10, 6,  7,  10, 10, 7,  11, 7,  8,  11, 11, 8,  12,  // first face, 1-12
00210         13, 14, 1,  1,  14, 2,  14, 15, 2,  2,  15, 3,  15, 16, 3,  3,  16, 4,
00211         17, 18, 13, 13, 18, 14, 18, 19, 14, 14, 19, 15, 19, 20, 15, 15, 20, 16  // second face, 13-24
00212     };
00213     EntityHandle elem;
00214     int nbTri = sizeof( connec ) / 3 / sizeof( EntityHandle );
00215     int i     = 0;
00216     std::vector< EntityHandle > tris;
00217     for( i = 0; i < nbTri; i++ )
00218     {
00219         mb->create_element( MBTRI, &connec[3 * i], 3, elem );
00220         tris.push_back( elem );
00221     }
00222 
00223     // create some edges too
00224     EntityHandle edges[] = {
00225         1,  2,  2,  3,  3,  4,   // geo edge 1  1:3
00226         4,  8,  8,  12,          // geo 2         4:5
00227         12, 11, 11, 10, 10, 9,   // geo 3 6:8
00228         9,  5,  5,  1,           // geo 4  9:10
00229         1,  13, 13, 17,          // geo 5  11:12
00230         17, 18, 18, 19, 19, 20,  // geo 6  13:15
00231         20, 16, 16, 4            // geo 7  16:17
00232     };
00233     int nbEdges = sizeof( edges ) / 2 / sizeof( EntityHandle );
00234     std::vector< EntityHandle > edgs;
00235     for( i = 0; i < nbEdges; i++ )
00236     {
00237         mb->create_element( MBEDGE, &edges[2 * i], 2, elem );
00238         edgs.push_back( elem );
00239     }
00240     // create some sets, and create some ordered sets for edges
00241     EntityHandle face1, face2;
00242     rval = mb->create_meshset( MESHSET_SET, face1 );MB_CHK_ERR( rval );
00243     rval = mb->add_entities( face1, &tris[0], 12 );MB_CHK_ERR( rval );
00244 
00245     rval = mb->create_meshset( MESHSET_SET, face2 );MB_CHK_ERR( rval );
00246     // next 12 triangles
00247     rval = mb->add_entities( face2, &tris[12], 12 );MB_CHK_ERR( rval );
00248 
00249     // the orientation and senses need to be set for face edges
00250     moab::GeomTopoTool gTopoTool( mb, false );
00251 
00252     rval = gTopoTool.add_geo_set( face1, 2 );MB_CHK_ERR( rval );
00253 
00254     rval = gTopoTool.add_geo_set( face2, 2 );MB_CHK_ERR( rval );
00255 
00256     // create some edges
00257     EntityHandle edge[7];  // edge[0] has EH 1...
00258     ;
00259     for( i = 0; i < 7; i++ )
00260     {
00261         rval = mb->create_meshset( MESHSET_ORDERED, edge[i] );MB_CHK_ERR( rval );
00262         rval = gTopoTool.add_geo_set( edge[i], 1 );MB_CHK_ERR( rval );
00263     }
00264 
00265     // first 3 mesh edges...
00266     rval = mb->add_entities( edge[0], &edgs[0], 3 );MB_CHK_ERR( rval );
00267     rval = mb->add_entities( edge[1], &edgs[3], 2 );MB_CHK_ERR( rval );
00268     rval = mb->add_entities( edge[2], &edgs[5], 3 );MB_CHK_ERR( rval );
00269     rval = mb->add_entities( edge[3], &edgs[8], 2 );MB_CHK_ERR( rval );
00270     rval = mb->add_entities( edge[4], &edgs[10], 2 );MB_CHK_ERR( rval );
00271     rval = mb->add_entities( edge[5], &edgs[12], 3 );MB_CHK_ERR( rval );
00272     rval = mb->add_entities( edge[6], &edgs[15], 2 );MB_CHK_ERR( rval );
00273 
00274     // create some sets for vertices; also need to create some for parent/child relationships
00275     EntityHandle vertSets[6];  // start from 0
00276 
00277     for( i = 0; i < 6; i++ )
00278     {
00279         rval = mb->create_meshset( MESHSET_SET, vertSets[i] );MB_CHK_ERR( rval );
00280         rval = gTopoTool.add_geo_set( vertSets[i], 0 );MB_CHK_ERR( rval );
00281     }
00282 
00283     EntityHandle v( 1 );  // first vertex;
00284     rval = mb->add_entities( vertSets[0], &v, 1 );MB_CHK_ERR( rval );
00285     v    = EntityHandle( 4 );
00286     rval = mb->add_entities( vertSets[1], &v, 1 );MB_CHK_ERR( rval );
00287     v    = EntityHandle( 9 );
00288     rval = mb->add_entities( vertSets[2], &v, 1 );MB_CHK_ERR( rval );
00289     v    = EntityHandle( 12 );
00290     rval = mb->add_entities( vertSets[3], &v, 1 );MB_CHK_ERR( rval );
00291     v    = EntityHandle( 17 );
00292     rval = mb->add_entities( vertSets[4], &v, 1 );MB_CHK_ERR( rval );
00293     v    = EntityHandle( 20 );
00294     rval = mb->add_entities( vertSets[5], &v, 1 );MB_CHK_ERR( rval );
00295 
00296     // need to add parent-child relations between sets
00297     // edge 1 : 1-2
00298     rval = mb->add_parent_child( edge[0], vertSets[0] );MB_CHK_ERR( rval );
00299     rval = mb->add_parent_child( edge[0], vertSets[1] );MB_CHK_ERR( rval );
00300     // edge 2 : 2-4
00301     rval = mb->add_parent_child( edge[1], vertSets[1] );MB_CHK_ERR( rval );
00302     rval = mb->add_parent_child( edge[1], vertSets[3] );MB_CHK_ERR( rval );
00303 
00304     // edge 3 : 4-3
00305     rval = mb->add_parent_child( edge[2], vertSets[3] );MB_CHK_ERR( rval );
00306     rval = mb->add_parent_child( edge[2], vertSets[2] );MB_CHK_ERR( rval );
00307 
00308     // edge 4 : 4-1
00309     rval = mb->add_parent_child( edge[3], vertSets[2] );MB_CHK_ERR( rval );
00310     rval = mb->add_parent_child( edge[3], vertSets[0] );MB_CHK_ERR( rval );
00311 
00312     // edge 5 : 1-5
00313     rval = mb->add_parent_child( edge[4], vertSets[0] );MB_CHK_ERR( rval );
00314     rval = mb->add_parent_child( edge[4], vertSets[4] );MB_CHK_ERR( rval );
00315 
00316     // edge 6 : 5-6
00317     rval = mb->add_parent_child( edge[5], vertSets[4] );MB_CHK_ERR( rval );
00318     rval = mb->add_parent_child( edge[5], vertSets[5] );MB_CHK_ERR( rval );
00319 
00320     // edge 7 : 6-2
00321     rval = mb->add_parent_child( edge[6], vertSets[5] );MB_CHK_ERR( rval );
00322     rval = mb->add_parent_child( edge[6], vertSets[1] );MB_CHK_ERR( rval );
00323 
00324     // face 1: edges 1, 2, 3, 4
00325     rval = mb->add_parent_child( face1, edge[0] );MB_CHK_ERR( rval );
00326     rval = mb->add_parent_child( face1, edge[1] );MB_CHK_ERR( rval );
00327     rval = mb->add_parent_child( face1, edge[2] );MB_CHK_ERR( rval );
00328     rval = mb->add_parent_child( face1, edge[3] );MB_CHK_ERR( rval );
00329 
00330     // face 2: edges 1, 5, 6, 7
00331     rval = mb->add_parent_child( face2, edge[0] );MB_CHK_ERR( rval );
00332     rval = mb->add_parent_child( face2, edge[4] );MB_CHK_ERR( rval );
00333     rval = mb->add_parent_child( face2, edge[5] );MB_CHK_ERR( rval );
00334     rval = mb->add_parent_child( face2, edge[6] );MB_CHK_ERR( rval );
00335 
00336     // set senses !!
00337     std::vector< EntityHandle > faces;
00338     faces.push_back( face1 );  // the face1 has all edges oriented positively
00339     std::vector< int > senses;
00340     senses.push_back( moab::SENSE_FORWARD );  //
00341 
00342     // faces.push_back(face1);
00343     // faces.push_back(face2);
00344     gTopoTool.set_senses( edge[1], faces, senses );
00345     gTopoTool.set_senses( edge[2], faces, senses );
00346     gTopoTool.set_senses( edge[3], faces, senses );
00347 
00348     faces[0] = face2;  // set senses for edges for face2
00349     gTopoTool.set_senses( edge[4], faces, senses );
00350     gTopoTool.set_senses( edge[5], faces, senses );
00351     gTopoTool.set_senses( edge[6], faces, senses );
00352 
00353     // the only complication is edge1 (edge[0]), that has face1 forward and face 2 reverse
00354     faces[0] = face1;
00355     faces.push_back( face2 );
00356     senses.push_back( moab::SENSE_REVERSE );  // -1 is reverse; face 2 is reverse for edge1 (0)
00357     // forward == 0, reverse ==1
00358     gTopoTool.set_senses( edge[0], faces, senses );
00359 
00360     rval = mb->write_mesh( ofile2.c_str() );MB_CHK_ERR( rval );
00361 
00362     rval = mb->delete_mesh();MB_CHK_ERR( rval );
00363 
00364     // now test loading it up
00365     rval = mb->load_file( ofile2.c_str() );MB_CHK_ERR( rval );
00366 
00367     if( remove_output_file ) { remove( ofile2.c_str() ); }
00368     // do some tests on geometry
00369 
00370     // it would be good to have a method on updating the geom topo tool
00371     // so we do not have to create another one
00372     moab::GeomTopoTool gTopoTool2( mb, true );  // to find the geomsets
00373     Range ranges[5];
00374     rval = gTopoTool2.find_geomsets( ranges );
00375 
00376     assert( MB_SUCCESS == rval );
00377     assert( ranges[0].size() == 6 );
00378     assert( ranges[1].size() == 7 );
00379     assert( ranges[2].size() == 2 );
00380     assert( ranges[3].size() == 0 );
00381     assert( ranges[4].size() == 0 );
00382 
00383     return MB_SUCCESS;
00384 }
00385 
00386 ErrorCode duplicate_model_test( Interface* mb )
00387 {
00388     moab::GeomTopoTool gTopoTool2( mb, true );  // to find the geomsets
00389 
00390     GeomTopoTool* newModel = NULL;
00391     ErrorCode rval         = gTopoTool2.duplicate_model( newModel );
00392     if( NULL == newModel || rval != MB_SUCCESS ) return MB_FAILURE;
00393 
00394     Range ranges[5];
00395     rval = newModel->find_geomsets( ranges );MB_CHK_ERR( rval );
00396 
00397     assert( ranges[0].size() == 6 );
00398     assert( ranges[1].size() == 7 );
00399     assert( ranges[2].size() == 2 );
00400     assert( ranges[3].size() == 0 );
00401 
00402     // write the model to a test file
00403     EntityHandle rootModelSet = newModel->get_root_model_set();
00404     std::cout << "writing duplicated model file: " << ofile3.c_str() << " ";
00405     rval = mb->write_file( ofile3.c_str(), 0, 0, &rootModelSet, 1 );MB_CHK_SET_ERR( rval, "Can't write output files\n" );
00406 
00407     delete newModel;  // we are done with the new geom topo tool
00408     // do not delete yet the output file, delay after the next test
00409     /*if (remove_output_file)
00410     {
00411       remove(ofile3.c_str());
00412     }*/
00413 
00414     return MB_SUCCESS;
00415 }
00416 
00417 ErrorCode check_model_test( Interface* mb )
00418 {
00419     ErrorCode rval = mb->delete_mesh();MB_CHK_SET_ERR( rval, "Can't delete existing mesh\n" );
00420 
00421     rval = mb->load_file( ofile3.c_str() );MB_CHK_ERR( rval );
00422 
00423     // do some tests on geometry
00424     // it would be good to have a method on updating the geom topo tool
00425     // so we do not have to create another one
00426     if( remove_output_file ) { remove( ofile3.c_str() ); }
00427     moab::GeomTopoTool gTopoTool( mb, true );
00428 
00429     if( !gTopoTool.check_model() ) return MB_FAILURE;
00430 
00431     return MB_SUCCESS;
00432 }
00433 
00434 ErrorCode test_root_sets_resize( Interface* mb )
00435 {
00436 
00437     // load the test file
00438     ErrorCode rval = mb->load_file( filename2.c_str() );MB_CHK_SET_ERR( rval, "Failed to load input file" );
00439 
00440     // create a GTT with all default settings
00441     moab::GeomTopoTool* gTopoTool = new GeomTopoTool( mb );
00442 
00443     Tag geomTag;
00444 
00445     rval = mb->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, geomTag, MB_TAG_CREAT | MB_TAG_SPARSE );MB_CHK_SET_ERR( rval, "Error: Failed to create geometry dimension tag" );
00446 
00447     Range surfs;
00448 
00449     const int dim               = 2;
00450     const void* const dim_val[] = { &dim };
00451     rval                        = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &geomTag, dim_val, 1, surfs );MB_CHK_SET_ERR( rval, "Failed to get entity sets by type and tag" );
00452 
00453     // in reverse order, add surfaces and construct their trees
00454     for( Range::reverse_iterator rit = surfs.rbegin(); rit != surfs.rend(); rit++ )
00455     {
00456 
00457         rval = gTopoTool->add_geo_set( *rit, 2 );MB_CHK_SET_ERR( rval, "Failed to add geometry set to GTT" );
00458 
00459         rval = gTopoTool->construct_obb_tree( *rit );MB_CHK_SET_ERR( rval, "Failed to construct obb tree for surf " << *rit );
00460     }
00461 
00462     for( Range::iterator it = surfs.begin(); it != surfs.end(); it++ )
00463     {
00464         EntityHandle obb_root_set;
00465         rval = gTopoTool->get_root( *it, obb_root_set );MB_CHK_SET_ERR( rval, "Failed to get obb tree root from GTT" );
00466 
00467         // make sure the returned root is valid
00468         CHECK( obb_root_set );
00469     }
00470 
00471     // clean up GTT
00472     delete gTopoTool;
00473 
00474     // create a GTT with all default settings
00475     gTopoTool = new moab::GeomTopoTool( mb, false, 0, false );
00476 
00477     // in reverse order, add surfaces and construct their trees
00478     for( Range::reverse_iterator rit = surfs.rbegin(); rit != surfs.rend(); rit++ )
00479     {
00480 
00481         rval = gTopoTool->add_geo_set( *rit, 2 );MB_CHK_SET_ERR( rval, "Failed to add geometry set to GTT" );
00482 
00483         rval = gTopoTool->construct_obb_tree( *rit );MB_CHK_SET_ERR( rval, "Failed to construct obb tree for surf " << *rit );
00484     }
00485 
00486     for( Range::iterator it = surfs.begin(); it != surfs.end(); it++ )
00487     {
00488         EntityHandle obb_root_set;
00489         rval = gTopoTool->get_root( *it, obb_root_set );MB_CHK_SET_ERR( rval, "Failed to get obb tree root from GTT" );
00490 
00491         // make sure the returned root is valid
00492         CHECK( obb_root_set );
00493     }
00494 
00495     delete gTopoTool;
00496 
00497     rval = mb->delete_mesh();MB_CHK_SET_ERR( rval, "Failed to delete mesh in MOAB instance." );
00498 
00499     return MB_SUCCESS;
00500 }
00501 
00502 ErrorCode test_delete_obb_tree( Interface* mb )
00503 {
00504 
00505     // Load the test file
00506     ErrorCode rval = mb->load_file( filename2.c_str() );MB_CHK_SET_ERR( rval, "Failed to load input file" );
00507 
00508     // Create a GTT with all default settings
00509     moab::GeomTopoTool* gTopoTool = new GeomTopoTool( mb );
00510 
00511     // Get all volumes and surfaces
00512     Range vols, surfs;
00513     rval = gTopoTool->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00514     rval = gTopoTool->get_gsets_by_dimension( 2, surfs );MB_CHK_SET_ERR( rval, "Failed to get surface gsets" );
00515 
00516     // Build obb tree for volume
00517     EntityHandle test_vol = vols.front();
00518     rval                  = gTopoTool->construct_obb_tree( test_vol );MB_CHK_SET_ERR( rval, "Error constructing all trees." );
00519 
00520     // Get the obbRootTag for vol
00521     rval = mb->tag_get_handle( OBB_ROOT_TAG_NAME, 1, MB_TYPE_HANDLE, obbRootTag, MB_TAG_CREAT | MB_TAG_SPARSE );MB_CHK_SET_ERR_CONT( rval, "Error: Failed to create obb root tag" );
00522     EntityHandle gbroot;
00523     rval = mb->tag_get_data( obbRootTag, &test_vol, 1, &gbroot );MB_CHK_SET_ERR( rval, "Failed to get the obb root tag" );
00524 
00525     // Test if obb tree in ModelSet
00526     EntityHandle test_vol_root;
00527     rval = gTopoTool->get_root( test_vol, test_vol_root );MB_CHK_SET_ERR( rval, "Obb root not in ModelSet" );
00528 
00529     // CASE 1: Delete vol obb tree including all child surface trees
00530     rval = gTopoTool->delete_obb_tree( test_vol, false );MB_CHK_SET_ERR( rval, "Error deleting volume tree." );
00531 
00532     // Make sure vol tree is gone
00533     EntityHandle newroot;
00534     rval = mb->tag_get_data( obbRootTag, &test_vol, 1, &newroot );
00535     if( MB_SUCCESS == rval ) { return MB_FAILURE; }
00536 
00537     // Make sure its child surf trees also gone
00538     Range::iterator surf_it;
00539     for( surf_it = surfs.begin(); surf_it != surfs.end(); ++surf_it )
00540     {
00541         EntityHandle test_surf_root_gone;
00542         rval = mb->tag_get_data( obbRootTag, &( *surf_it ), 1, &test_surf_root_gone );
00543         if( MB_SUCCESS == rval ) { return MB_FAILURE; }
00544     }
00545 
00546     // Rebuild vol tree
00547     rval = gTopoTool->construct_obb_tree( test_vol );MB_CHK_SET_ERR( rval, "Error constructing all trees." );
00548 
00549     // CASE 2: Delete just vol, not surf trees
00550     rval = gTopoTool->delete_obb_tree( test_vol, true );MB_CHK_SET_ERR( rval, "Error deleting volume tree." );
00551 
00552     // Make sure vol tree is gone
00553     rval = mb->tag_get_data( obbRootTag, &test_vol, 1, &gbroot );
00554     if( MB_SUCCESS == rval ) { return MB_FAILURE; }
00555 
00556     // Make sure its child surf trees remain
00557     for( surf_it = surfs.begin(); surf_it != surfs.end(); ++surf_it )
00558     {
00559         EntityHandle test_surf_root;
00560         rval = mb->tag_get_data( obbRootTag, &( *surf_it ), 1, &test_surf_root );MB_CHK_SET_ERR( rval, "Problem getting obb root of surface." );
00561     }
00562 
00563     // CASE 3: Delete surf tree
00564     EntityHandle test_surf = surfs.front();
00565     rval                   = gTopoTool->delete_obb_tree( test_surf, false );MB_CHK_SET_ERR( rval, "Error deleting surface tree." );
00566 
00567     // Make sure surf tree is gone
00568     rval = mb->tag_get_data( obbRootTag, &test_surf, 1, &gbroot );
00569     if( MB_SUCCESS == rval ) { return MB_FAILURE; }
00570 
00571     delete gTopoTool;
00572 
00573     return MB_SUCCESS;
00574 }
00575 
00576 ErrorCode test_restore_obb_trees( Interface* mb, Interface* mb2, Interface* mb3 )
00577 {
00578 
00579     // Load the test file
00580     ErrorCode rval = mb->load_file( filename2.c_str() );MB_CHK_SET_ERR( rval, "Failed to load input file" );
00581 
00582     // Create a GTT with all default settings
00583     moab::GeomTopoTool* gTopoTool = new GeomTopoTool( mb );
00584 
00585     // Build all obb trees
00586     rval = gTopoTool->construct_obb_trees();MB_CHK_SET_ERR( rval, "Error constructing all trees" );
00587     // Write the file with all obbs
00588     rval = mb->write_file( ofile4.c_str() );MB_CHK_SET_ERR( rval, "Can't write output file" );
00589 
00590     // Delete a vol obb tree
00591     Range vols;
00592     rval = gTopoTool->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00593     EntityHandle test_vol = vols.front();
00594     rval                  = gTopoTool->delete_obb_tree( test_vol, false );MB_CHK_SET_ERR( rval, "Error deleting volume tree" );
00595     // Write the file missing an obb
00596     rval = mb->write_file( ofile5.c_str() );MB_CHK_SET_ERR( rval, "Can't write output file" );
00597 
00598     // Load file containing obbs
00599     rval = mb2->load_file( ofile4.c_str() );MB_CHK_SET_ERR( rval, "Failed to load file containing obbs" );
00600 
00601     // 1) Check that roots are NOT restored by default GTT settings
00602     // GeomTopoTool(Interface *impl, bool find_geoments = false, EntityHandle modelRootSet = 0,
00603     //             bool p_rootSets_vector = true, bool restore_rootSets = true);
00604     moab::GeomTopoTool* gTopoTool2 = new GeomTopoTool( mb2, false, 0, true, true );
00605 
00606     vols.clear();
00607     Range surfs;
00608     rval = gTopoTool2->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00609     rval = gTopoTool2->get_gsets_by_dimension( 2, surfs );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00610 
00611     Range gsets;
00612     gsets.insert_list( surfs.begin(), surfs.end() );
00613     gsets.insert_list( vols.begin(), vols.end() );
00614     EntityHandle test_root2;
00615     for( Range::iterator rit = gsets.begin(); rit != gsets.end(); ++rit )
00616     {
00617         rval = gTopoTool2->get_root( *rit, test_root2 );
00618         if( MB_SUCCESS == rval ) { return MB_FAILURE; }
00619     }
00620 
00621     // 2) Check that roots ARE restored by setting find_geoments and restore_rootSets to true
00622     moab::GeomTopoTool* gTopoTool3 = new GeomTopoTool( mb2, true, 0, true, true );
00623 
00624     vols.clear();
00625     rval = gTopoTool3->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00626     surfs.clear();
00627     rval = gTopoTool3->get_gsets_by_dimension( 2, surfs );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00628 
00629     gsets.clear();
00630     gsets.insert_list( surfs.begin(), surfs.end() );
00631     gsets.insert_list( vols.begin(), vols.end() );
00632     EntityHandle test_root3;
00633     for( Range::iterator rit = gsets.begin(); rit != gsets.end(); ++rit )
00634     {
00635         rval = gTopoTool3->get_root( *rit, test_root3 );MB_CHK_SET_ERR( rval, "Failed to get obb tree root from GTT" );
00636         CHECK( test_root3 );
00637     }
00638 
00639     // 3) Check that roots are deleted and then rebuilt if an obb tree is missing
00640 
00641     // Load file missing obb
00642     rval = mb3->load_file( ofile5.c_str() );MB_CHK_SET_ERR( rval, "Failed to load file containing obbs" );
00643 
00644     // Create GTT and try to restore OBBs
00645     moab::GeomTopoTool* gTopoTool4 = new GeomTopoTool( mb3, true, 0, true, true );
00646 
00647     // Check that roots still exist
00648     vols.clear();
00649     rval = gTopoTool4->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00650     surfs.clear();
00651     rval = gTopoTool4->get_gsets_by_dimension( 2, surfs );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00652 
00653     gsets.clear();
00654     gsets.insert_list( surfs.begin(), surfs.end() );
00655     gsets.insert_list( vols.begin(), vols.end() );
00656     EntityHandle test_root4;
00657     for( Range::iterator rit = gsets.begin(); rit != gsets.end(); ++rit )
00658     {
00659         rval = gTopoTool4->get_root( *rit, test_root4 );MB_CHK_SET_ERR( rval, "Failed to get obb tree root from GTT" );
00660         CHECK( test_root4 );
00661     }
00662 
00663     // 4) Check that roots exist but rootSets is NOT repopulated when find_geoments = true and
00664     // restore_rootSets = false
00665     moab::GeomTopoTool* gTopoTool5 = new GeomTopoTool( mb2, true, 0, true, false );
00666 
00667     // Get the obbRootTag for vol
00668     rval = mb2->tag_get_handle( OBB_ROOT_TAG_NAME, 1, MB_TYPE_HANDLE, obbRootTag, MB_TAG_CREAT | MB_TAG_SPARSE );MB_CHK_SET_ERR_CONT( rval, "Error: Failed to create obb root tag" );
00669 
00670     vols.clear();
00671     rval = gTopoTool5->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00672     surfs.clear();
00673     rval = gTopoTool5->get_gsets_by_dimension( 2, surfs );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00674 
00675     gsets.clear();
00676     gsets.insert_list( surfs.begin(), surfs.end() );
00677     gsets.insert_list( vols.begin(), vols.end() );
00678     EntityHandle test_root5, tagged_root;
00679     for( Range::iterator rit = gsets.begin(); rit != gsets.end(); ++rit )
00680     {
00681         // Check that root still exits, but not in rootSet
00682         rval = mb2->tag_get_data( obbRootTag, &( *rit ), 1, &tagged_root );MB_CHK_SET_ERR( rval, "Failed to get root from tag" );
00683         CHECK( tagged_root );
00684         rval = gTopoTool5->get_root( *rit, test_root5 );
00685         if( MB_SUCCESS == rval ) return MB_FAILURE;
00686     }
00687 
00688     delete gTopoTool;
00689     delete gTopoTool2;
00690     delete gTopoTool3;
00691     delete gTopoTool4;
00692     delete gTopoTool5;
00693 
00694     return MB_SUCCESS;
00695 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines