MOAB: Mesh Oriented datABase  (version 5.4.0)
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 <cassert>
00018 #include <cstring>
00019 #include <cstdio>
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 + "unittest/partBed.smf";
00070     filename2 = TestDir + "unittest/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 )
00136     {
00137         return number_tests_failed;
00138     }
00139     std::cout << "create shell test: ";
00140     rval = create_shell_test( mb );
00141     handle_error_code( rval, number_tests_failed, number_tests_successful );
00142     std::cout << "\n";
00143 
00144     std::cout << "duplicate model test: ";
00145     rval = duplicate_model_test( mb );
00146     handle_error_code( rval, number_tests_failed, number_tests_successful );
00147     std::cout << "\n";
00148 
00149     std::cout << "check_model test: ";
00150     rval = check_model_test( mb );
00151     handle_error_code( rval, number_tests_failed, number_tests_successful );
00152     std::cout << "\n";
00153 
00154     std::cout << "test_rootsets_resize: ";
00155     Interface* mb2 = new Core();
00156     rval           = test_root_sets_resize( mb2 );
00157     handle_error_code( rval, number_tests_failed, number_tests_successful );
00158     delete mb2;
00159     std::cout << "\n";
00160 
00161     std::cout << "test_delete_obb_tree: ";
00162     Interface* mb3 = new Core();
00163     rval           = test_delete_obb_tree( mb3 );
00164     handle_error_code( rval, number_tests_failed, number_tests_successful );
00165     delete mb3;
00166     std::cout << "\n";
00167 
00168     std::cout << "test_restore_obb_trees: ";
00169     Interface* mb4 = new Core();
00170     Interface* mb5 = new Core();
00171     Interface* mb6 = new Core();
00172     rval           = test_restore_obb_trees( mb4, mb5, mb6 );
00173     handle_error_code( rval, number_tests_failed, number_tests_successful );
00174     delete mb4;
00175     delete mb5;
00176     delete mb6;
00177     std::cout << "\n";
00178 
00179     return number_tests_failed;
00180 }
00181 ErrorCode geometrize_test( Interface* mb, EntityHandle inputSet )
00182 {
00183     GeomTopoTool gtt( mb );
00184     EntityHandle outSet;
00185     ErrorCode rval = gtt.geometrize_surface_set( inputSet, outSet );MB_CHK_SET_ERR( rval, "Can't geometrize the set\n" );
00186 
00187     std::cout << "writing output file: " << ofile.c_str() << " ";
00188     rval = mb->write_file( ofile.c_str(), 0, 0, &outSet, 1 );MB_CHK_SET_ERR( rval, "Can't write output file\n" );
00189     if( remove_output_file )
00190     {
00191         remove( ofile.c_str() );
00192     }
00193     return MB_SUCCESS;
00194 }
00195 
00196 ErrorCode create_shell_test( Interface* mb )
00197 {
00198     // we should be able to delete mesh and create a model from scratch
00199 
00200     ErrorCode rval = mb->delete_mesh();MB_CHK_SET_ERR( rval, "Can't delete existing mesh\n" );
00201 
00202     // create some vertices
00203     double coords[] = { 0, 0,   0,    1, 0,   0.1, 2, 0,   0,    3, 0,   -0.1, 0,   1,   0,    1,   1,   0,  2, 1, 0,
00204                         3, 1,   -0.1, 0, 2,   0,   1, 2,   -0.1, 2, 2,   -0.1, 3,   2,   -0.2, 0,   0,   1,  1, 0, 0.9,
00205                         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 };
00206 
00207     int nvert = 20;
00208     Range verts;
00209     rval = mb->create_vertices( coords, nvert, verts );MB_CHK_SET_ERR( rval, "Can't create vertices\n" );
00210 
00211     EntityHandle connec[] = {
00212         1,  2,  5,  5,  2,  6,  2,  3,  6,  6,  3,  7,  3,  4,  7,  7,  4,  8,
00213         5,  6,  9,  9,  6,  10, 6,  7,  10, 10, 7,  11, 7,  8,  11, 11, 8,  12,  // first face, 1-12
00214         13, 14, 1,  1,  14, 2,  14, 15, 2,  2,  15, 3,  15, 16, 3,  3,  16, 4,
00215         17, 18, 13, 13, 18, 14, 18, 19, 14, 14, 19, 15, 19, 20, 15, 15, 20, 16  // second face, 13-24
00216     };
00217     EntityHandle elem;
00218     int nbTri = sizeof( connec ) / 3 / sizeof( EntityHandle );
00219     int i     = 0;
00220     std::vector< EntityHandle > tris;
00221     for( i = 0; i < nbTri; i++ )
00222     {
00223         mb->create_element( MBTRI, &connec[3 * i], 3, elem );
00224         tris.push_back( elem );
00225     }
00226 
00227     // create some edges too
00228     EntityHandle edges[] = {
00229         1,  2,  2,  3,  3,  4,   // geo edge 1  1:3
00230         4,  8,  8,  12,          // geo 2         4:5
00231         12, 11, 11, 10, 10, 9,   // geo 3 6:8
00232         9,  5,  5,  1,           // geo 4  9:10
00233         1,  13, 13, 17,          // geo 5  11:12
00234         17, 18, 18, 19, 19, 20,  // geo 6  13:15
00235         20, 16, 16, 4            // geo 7  16:17
00236     };
00237     int nbEdges = sizeof( edges ) / 2 / sizeof( EntityHandle );
00238     std::vector< EntityHandle > edgs;
00239     for( i = 0; i < nbEdges; i++ )
00240     {
00241         mb->create_element( MBEDGE, &edges[2 * i], 2, elem );
00242         edgs.push_back( elem );
00243     }
00244     // create some sets, and create some ordered sets for edges
00245     EntityHandle face1, face2;
00246     rval = mb->create_meshset( MESHSET_SET, face1 );MB_CHK_ERR( rval );
00247     rval = mb->add_entities( face1, &tris[0], 12 );MB_CHK_ERR( rval );
00248 
00249     rval = mb->create_meshset( MESHSET_SET, face2 );MB_CHK_ERR( rval );
00250     // next 12 triangles
00251     rval = mb->add_entities( face2, &tris[12], 12 );MB_CHK_ERR( rval );
00252 
00253     // the orientation and senses need to be set for face edges
00254     moab::GeomTopoTool gTopoTool( mb, false );
00255 
00256     rval = gTopoTool.add_geo_set( face1, 2 );MB_CHK_ERR( rval );
00257 
00258     rval = gTopoTool.add_geo_set( face2, 2 );MB_CHK_ERR( rval );
00259 
00260     // create some edges
00261     EntityHandle edge[7];  // edge[0] has EH 1...
00262     ;
00263     for( i = 0; i < 7; i++ )
00264     {
00265         rval = mb->create_meshset( MESHSET_ORDERED, edge[i] );MB_CHK_ERR( rval );
00266         rval = gTopoTool.add_geo_set( edge[i], 1 );MB_CHK_ERR( rval );
00267     }
00268 
00269     // first 3 mesh edges...
00270     rval = mb->add_entities( edge[0], &edgs[0], 3 );MB_CHK_ERR( rval );
00271     rval = mb->add_entities( edge[1], &edgs[3], 2 );MB_CHK_ERR( rval );
00272     rval = mb->add_entities( edge[2], &edgs[5], 3 );MB_CHK_ERR( rval );
00273     rval = mb->add_entities( edge[3], &edgs[8], 2 );MB_CHK_ERR( rval );
00274     rval = mb->add_entities( edge[4], &edgs[10], 2 );MB_CHK_ERR( rval );
00275     rval = mb->add_entities( edge[5], &edgs[12], 3 );MB_CHK_ERR( rval );
00276     rval = mb->add_entities( edge[6], &edgs[15], 2 );MB_CHK_ERR( rval );
00277 
00278     // create some sets for vertices; also need to create some for parent/child relationships
00279     EntityHandle vertSets[6];  // start from 0
00280 
00281     for( i = 0; i < 6; i++ )
00282     {
00283         rval = mb->create_meshset( MESHSET_SET, vertSets[i] );MB_CHK_ERR( rval );
00284         rval = gTopoTool.add_geo_set( vertSets[i], 0 );MB_CHK_ERR( rval );
00285     }
00286 
00287     EntityHandle v( 1 );  // first vertex;
00288     rval = mb->add_entities( vertSets[0], &v, 1 );MB_CHK_ERR( rval );
00289     v    = EntityHandle( 4 );
00290     rval = mb->add_entities( vertSets[1], &v, 1 );MB_CHK_ERR( rval );
00291     v    = EntityHandle( 9 );
00292     rval = mb->add_entities( vertSets[2], &v, 1 );MB_CHK_ERR( rval );
00293     v    = EntityHandle( 12 );
00294     rval = mb->add_entities( vertSets[3], &v, 1 );MB_CHK_ERR( rval );
00295     v    = EntityHandle( 17 );
00296     rval = mb->add_entities( vertSets[4], &v, 1 );MB_CHK_ERR( rval );
00297     v    = EntityHandle( 20 );
00298     rval = mb->add_entities( vertSets[5], &v, 1 );MB_CHK_ERR( rval );
00299 
00300     // need to add parent-child relations between sets
00301     // edge 1 : 1-2
00302     rval = mb->add_parent_child( edge[0], vertSets[0] );MB_CHK_ERR( rval );
00303     rval = mb->add_parent_child( edge[0], vertSets[1] );MB_CHK_ERR( rval );
00304     // edge 2 : 2-4
00305     rval = mb->add_parent_child( edge[1], vertSets[1] );MB_CHK_ERR( rval );
00306     rval = mb->add_parent_child( edge[1], vertSets[3] );MB_CHK_ERR( rval );
00307 
00308     // edge 3 : 4-3
00309     rval = mb->add_parent_child( edge[2], vertSets[3] );MB_CHK_ERR( rval );
00310     rval = mb->add_parent_child( edge[2], vertSets[2] );MB_CHK_ERR( rval );
00311 
00312     // edge 4 : 4-1
00313     rval = mb->add_parent_child( edge[3], vertSets[2] );MB_CHK_ERR( rval );
00314     rval = mb->add_parent_child( edge[3], vertSets[0] );MB_CHK_ERR( rval );
00315 
00316     // edge 5 : 1-5
00317     rval = mb->add_parent_child( edge[4], vertSets[0] );MB_CHK_ERR( rval );
00318     rval = mb->add_parent_child( edge[4], vertSets[4] );MB_CHK_ERR( rval );
00319 
00320     // edge 6 : 5-6
00321     rval = mb->add_parent_child( edge[5], vertSets[4] );MB_CHK_ERR( rval );
00322     rval = mb->add_parent_child( edge[5], vertSets[5] );MB_CHK_ERR( rval );
00323 
00324     // edge 7 : 6-2
00325     rval = mb->add_parent_child( edge[6], vertSets[5] );MB_CHK_ERR( rval );
00326     rval = mb->add_parent_child( edge[6], vertSets[1] );MB_CHK_ERR( rval );
00327 
00328     // face 1: edges 1, 2, 3, 4
00329     rval = mb->add_parent_child( face1, edge[0] );MB_CHK_ERR( rval );
00330     rval = mb->add_parent_child( face1, edge[1] );MB_CHK_ERR( rval );
00331     rval = mb->add_parent_child( face1, edge[2] );MB_CHK_ERR( rval );
00332     rval = mb->add_parent_child( face1, edge[3] );MB_CHK_ERR( rval );
00333 
00334     // face 2: edges 1, 5, 6, 7
00335     rval = mb->add_parent_child( face2, edge[0] );MB_CHK_ERR( rval );
00336     rval = mb->add_parent_child( face2, edge[4] );MB_CHK_ERR( rval );
00337     rval = mb->add_parent_child( face2, edge[5] );MB_CHK_ERR( rval );
00338     rval = mb->add_parent_child( face2, edge[6] );MB_CHK_ERR( rval );
00339 
00340     // set senses !!
00341     std::vector< EntityHandle > faces;
00342     faces.push_back( face1 );  // the face1 has all edges oriented positively
00343     std::vector< int > senses;
00344     senses.push_back( moab::SENSE_FORWARD );  //
00345 
00346     // faces.push_back(face1);
00347     // faces.push_back(face2);
00348     gTopoTool.set_senses( edge[1], faces, senses );
00349     gTopoTool.set_senses( edge[2], faces, senses );
00350     gTopoTool.set_senses( edge[3], faces, senses );
00351 
00352     faces[0] = face2;  // set senses for edges for face2
00353     gTopoTool.set_senses( edge[4], faces, senses );
00354     gTopoTool.set_senses( edge[5], faces, senses );
00355     gTopoTool.set_senses( edge[6], faces, senses );
00356 
00357     // the only complication is edge1 (edge[0]), that has face1 forward and face 2 reverse
00358     faces[0] = face1;
00359     faces.push_back( face2 );
00360     senses.push_back( moab::SENSE_REVERSE );  // -1 is reverse; face 2 is reverse for edge1 (0)
00361     // forward == 0, reverse ==1
00362     gTopoTool.set_senses( edge[0], faces, senses );
00363 
00364     rval = mb->write_mesh( ofile2.c_str() );MB_CHK_ERR( rval );
00365 
00366     rval = mb->delete_mesh();MB_CHK_ERR( rval );
00367 
00368     // now test loading it up
00369     rval = mb->load_file( ofile2.c_str() );MB_CHK_ERR( rval );
00370 
00371     if( remove_output_file )
00372     {
00373         remove( ofile2.c_str() );
00374     }
00375     // do some tests on geometry
00376 
00377     // it would be good to have a method on updating the geom topo tool
00378     // so we do not have to create another one
00379     moab::GeomTopoTool gTopoTool2( mb, true );  // to find the geomsets
00380     Range ranges[5];
00381     rval = gTopoTool2.find_geomsets( ranges );
00382 
00383     assert( MB_SUCCESS == rval );
00384     assert( ranges[0].size() == 6 );
00385     assert( ranges[1].size() == 7 );
00386     assert( ranges[2].size() == 2 );
00387     assert( ranges[3].size() == 0 );
00388     assert( ranges[4].size() == 0 );
00389 
00390     return MB_SUCCESS;
00391 }
00392 
00393 ErrorCode duplicate_model_test( Interface* mb )
00394 {
00395     moab::GeomTopoTool gTopoTool2( mb, true );  // to find the geomsets
00396 
00397     GeomTopoTool* newModel = NULL;
00398     ErrorCode rval         = gTopoTool2.duplicate_model( newModel );
00399     if( NULL == newModel || rval != MB_SUCCESS ) return MB_FAILURE;
00400 
00401     Range ranges[5];
00402     rval = newModel->find_geomsets( ranges );MB_CHK_ERR( rval );
00403 
00404     assert( ranges[0].size() == 6 );
00405     assert( ranges[1].size() == 7 );
00406     assert( ranges[2].size() == 2 );
00407     assert( ranges[3].size() == 0 );
00408 
00409     // write the model to a test file
00410     EntityHandle rootModelSet = newModel->get_root_model_set();
00411     std::cout << "writing duplicated model file: " << ofile3.c_str() << " ";
00412     rval = mb->write_file( ofile3.c_str(), 0, 0, &rootModelSet, 1 );MB_CHK_SET_ERR( rval, "Can't write output files\n" );
00413 
00414     delete newModel;  // we are done with the new geom topo tool
00415     // do not delete yet the output file, delay after the next test
00416     /*if (remove_output_file)
00417     {
00418       remove(ofile3.c_str());
00419     }*/
00420 
00421     return MB_SUCCESS;
00422 }
00423 
00424 ErrorCode check_model_test( Interface* mb )
00425 {
00426     ErrorCode rval = mb->delete_mesh();MB_CHK_SET_ERR( rval, "Can't delete existing mesh\n" );
00427 
00428     rval = mb->load_file( ofile3.c_str() );MB_CHK_ERR( rval );
00429 
00430     // do some tests on geometry
00431     // it would be good to have a method on updating the geom topo tool
00432     // so we do not have to create another one
00433     if( remove_output_file )
00434     {
00435         remove( ofile3.c_str() );
00436     }
00437     moab::GeomTopoTool gTopoTool( mb, true );
00438 
00439     if( !gTopoTool.check_model() ) return MB_FAILURE;
00440 
00441     return MB_SUCCESS;
00442 }
00443 
00444 ErrorCode test_root_sets_resize( Interface* mb )
00445 {
00446 
00447     // load the test file
00448     ErrorCode rval = mb->load_file( filename2.c_str() );MB_CHK_SET_ERR( rval, "Failed to load input file" );
00449 
00450     // create a GTT with all default settings
00451     moab::GeomTopoTool* gTopoTool = new GeomTopoTool( mb );
00452 
00453     Tag geomTag;
00454 
00455     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" );
00456 
00457     Range surfs;
00458 
00459     const int dim               = 2;
00460     const void* const dim_val[] = { &dim };
00461     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" );
00462 
00463     // in reverse order, add surfaces and construct their trees
00464     for( Range::reverse_iterator rit = surfs.rbegin(); rit != surfs.rend(); rit++ )
00465     {
00466 
00467         rval = gTopoTool->add_geo_set( *rit, 2 );MB_CHK_SET_ERR( rval, "Failed to add geometry set to GTT" );
00468 
00469         rval = gTopoTool->construct_obb_tree( *rit );MB_CHK_SET_ERR( rval, "Failed to construct obb tree for surf " << *rit );
00470     }
00471 
00472     for( Range::iterator it = surfs.begin(); it != surfs.end(); it++ )
00473     {
00474         EntityHandle obb_root_set;
00475         rval = gTopoTool->get_root( *it, obb_root_set );MB_CHK_SET_ERR( rval, "Failed to get obb tree root from GTT" );
00476 
00477         // make sure the returned root is valid
00478         CHECK( obb_root_set );
00479     }
00480 
00481     // clean up GTT
00482     delete gTopoTool;
00483 
00484     // create a GTT with all default settings
00485     gTopoTool = new moab::GeomTopoTool( mb, false, 0, false );
00486 
00487     // in reverse order, add surfaces and construct their trees
00488     for( Range::reverse_iterator rit = surfs.rbegin(); rit != surfs.rend(); rit++ )
00489     {
00490 
00491         rval = gTopoTool->add_geo_set( *rit, 2 );MB_CHK_SET_ERR( rval, "Failed to add geometry set to GTT" );
00492 
00493         rval = gTopoTool->construct_obb_tree( *rit );MB_CHK_SET_ERR( rval, "Failed to construct obb tree for surf " << *rit );
00494     }
00495 
00496     for( Range::iterator it = surfs.begin(); it != surfs.end(); it++ )
00497     {
00498         EntityHandle obb_root_set;
00499         rval = gTopoTool->get_root( *it, obb_root_set );MB_CHK_SET_ERR( rval, "Failed to get obb tree root from GTT" );
00500 
00501         // make sure the returned root is valid
00502         CHECK( obb_root_set );
00503     }
00504 
00505     delete gTopoTool;
00506 
00507     rval = mb->delete_mesh();MB_CHK_SET_ERR( rval, "Failed to delete mesh in MOAB instance." );
00508 
00509     return MB_SUCCESS;
00510 }
00511 
00512 ErrorCode test_delete_obb_tree( Interface* mb )
00513 {
00514 
00515     // Load the test file
00516     ErrorCode rval = mb->load_file( filename2.c_str() );MB_CHK_SET_ERR( rval, "Failed to load input file" );
00517 
00518     // Create a GTT with all default settings
00519     moab::GeomTopoTool* gTopoTool = new GeomTopoTool( mb );
00520 
00521     // Get all volumes and surfaces
00522     Range vols, surfs;
00523     rval = gTopoTool->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00524     rval = gTopoTool->get_gsets_by_dimension( 2, surfs );MB_CHK_SET_ERR( rval, "Failed to get surface gsets" );
00525 
00526     // Build obb tree for volume
00527     EntityHandle test_vol = vols.front();
00528     rval                  = gTopoTool->construct_obb_tree( test_vol );MB_CHK_SET_ERR( rval, "Error constructing all trees." );
00529 
00530     // Get the obbRootTag for vol
00531     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" );
00532     EntityHandle gbroot;
00533     rval = mb->tag_get_data( obbRootTag, &test_vol, 1, &gbroot );MB_CHK_SET_ERR( rval, "Failed to get the obb root tag" );
00534 
00535     // Test if obb tree in ModelSet
00536     EntityHandle test_vol_root;
00537     rval = gTopoTool->get_root( test_vol, test_vol_root );MB_CHK_SET_ERR( rval, "Obb root not in ModelSet" );
00538 
00539     // CASE 1: Delete vol obb tree including all child surface trees
00540     rval = gTopoTool->delete_obb_tree( test_vol, false );MB_CHK_SET_ERR( rval, "Error deleting volume tree." );
00541 
00542     // Make sure vol tree is gone
00543     EntityHandle newroot;
00544     rval = mb->tag_get_data( obbRootTag, &test_vol, 1, &newroot );
00545     if( MB_SUCCESS == rval )
00546     {
00547         return MB_FAILURE;
00548     }
00549 
00550     // Make sure its child surf trees also gone
00551     Range::iterator surf_it;
00552     for( surf_it = surfs.begin(); surf_it != surfs.end(); ++surf_it )
00553     {
00554         EntityHandle test_surf_root_gone;
00555         rval = mb->tag_get_data( obbRootTag, &( *surf_it ), 1, &test_surf_root_gone );
00556         if( MB_SUCCESS == rval )
00557         {
00558             return MB_FAILURE;
00559         }
00560     }
00561 
00562     // Rebuild vol tree
00563     rval = gTopoTool->construct_obb_tree( test_vol );MB_CHK_SET_ERR( rval, "Error constructing all trees." );
00564 
00565     // CASE 2: Delete just vol, not surf trees
00566     rval = gTopoTool->delete_obb_tree( test_vol, true );MB_CHK_SET_ERR( rval, "Error deleting volume tree." );
00567 
00568     // Make sure vol tree is gone
00569     rval = mb->tag_get_data( obbRootTag, &test_vol, 1, &gbroot );
00570     if( MB_SUCCESS == rval )
00571     {
00572         return MB_FAILURE;
00573     }
00574 
00575     // Make sure its child surf trees remain
00576     for( surf_it = surfs.begin(); surf_it != surfs.end(); ++surf_it )
00577     {
00578         EntityHandle test_surf_root;
00579         rval = mb->tag_get_data( obbRootTag, &( *surf_it ), 1, &test_surf_root );MB_CHK_SET_ERR( rval, "Problem getting obb root of surface." );
00580     }
00581 
00582     // CASE 3: Delete surf tree
00583     EntityHandle test_surf = surfs.front();
00584     rval                   = gTopoTool->delete_obb_tree( test_surf, false );MB_CHK_SET_ERR( rval, "Error deleting surface tree." );
00585 
00586     // Make sure surf tree is gone
00587     rval = mb->tag_get_data( obbRootTag, &test_surf, 1, &gbroot );
00588     if( MB_SUCCESS == rval )
00589     {
00590         return MB_FAILURE;
00591     }
00592 
00593     delete gTopoTool;
00594 
00595     return MB_SUCCESS;
00596 }
00597 
00598 ErrorCode test_restore_obb_trees( Interface* mb, Interface* mb2, Interface* mb3 )
00599 {
00600 
00601     // Load the test file
00602     ErrorCode rval = mb->load_file( filename2.c_str() );MB_CHK_SET_ERR( rval, "Failed to load input file" );
00603 
00604     // Create a GTT with all default settings
00605     moab::GeomTopoTool* gTopoTool = new GeomTopoTool( mb );
00606 
00607     // Build all obb trees
00608     rval = gTopoTool->construct_obb_trees();MB_CHK_SET_ERR( rval, "Error constructing all trees" );
00609     // Write the file with all obbs
00610     rval = mb->write_file( ofile4.c_str() );MB_CHK_SET_ERR( rval, "Can't write output file" );
00611 
00612     // Delete a vol obb tree
00613     Range vols;
00614     rval = gTopoTool->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00615     EntityHandle test_vol = vols.front();
00616     rval                  = gTopoTool->delete_obb_tree( test_vol, false );MB_CHK_SET_ERR( rval, "Error deleting volume tree" );
00617     // Write the file missing an obb
00618     rval = mb->write_file( ofile5.c_str() );MB_CHK_SET_ERR( rval, "Can't write output file" );
00619 
00620     // Load file containing obbs
00621     rval = mb2->load_file( ofile4.c_str() );MB_CHK_SET_ERR( rval, "Failed to load file containing obbs" );
00622 
00623     // 1) Check that roots are NOT restored by default GTT settings
00624     // GeomTopoTool(Interface *impl, bool find_geoments = false, EntityHandle modelRootSet = 0,
00625     //             bool p_rootSets_vector = true, bool restore_rootSets = true);
00626     moab::GeomTopoTool* gTopoTool2 = new GeomTopoTool( mb2, false, 0, true, true );
00627 
00628     vols.clear();
00629     Range surfs;
00630     rval = gTopoTool2->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00631     rval = gTopoTool2->get_gsets_by_dimension( 2, surfs );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00632 
00633     Range gsets;
00634     gsets.insert_list( surfs.begin(), surfs.end() );
00635     gsets.insert_list( vols.begin(), vols.end() );
00636     EntityHandle test_root2;
00637     for( Range::iterator rit = gsets.begin(); rit != gsets.end(); ++rit )
00638     {
00639         rval = gTopoTool2->get_root( *rit, test_root2 );
00640         if( MB_SUCCESS == rval )
00641         {
00642             return MB_FAILURE;
00643         }
00644     }
00645 
00646     // 2) Check that roots ARE restored by setting find_geoments and restore_rootSets to true
00647     moab::GeomTopoTool* gTopoTool3 = new GeomTopoTool( mb2, true, 0, true, true );
00648 
00649     vols.clear();
00650     rval = gTopoTool3->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00651     surfs.clear();
00652     rval = gTopoTool3->get_gsets_by_dimension( 2, surfs );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00653 
00654     gsets.clear();
00655     gsets.insert_list( surfs.begin(), surfs.end() );
00656     gsets.insert_list( vols.begin(), vols.end() );
00657     EntityHandle test_root3;
00658     for( Range::iterator rit = gsets.begin(); rit != gsets.end(); ++rit )
00659     {
00660         rval = gTopoTool3->get_root( *rit, test_root3 );MB_CHK_SET_ERR( rval, "Failed to get obb tree root from GTT" );
00661         CHECK( test_root3 );
00662     }
00663 
00664     // 3) Check that roots are deleted and then rebuilt if an obb tree is missing
00665 
00666     // Load file missing obb
00667     rval = mb3->load_file( ofile5.c_str() );MB_CHK_SET_ERR( rval, "Failed to load file containing obbs" );
00668 
00669     // Create GTT and try to restore OBBs
00670     moab::GeomTopoTool* gTopoTool4 = new GeomTopoTool( mb3, true, 0, true, true );
00671 
00672     // Check that roots still exist
00673     vols.clear();
00674     rval = gTopoTool4->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00675     surfs.clear();
00676     rval = gTopoTool4->get_gsets_by_dimension( 2, surfs );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00677 
00678     gsets.clear();
00679     gsets.insert_list( surfs.begin(), surfs.end() );
00680     gsets.insert_list( vols.begin(), vols.end() );
00681     EntityHandle test_root4;
00682     for( Range::iterator rit = gsets.begin(); rit != gsets.end(); ++rit )
00683     {
00684         rval = gTopoTool4->get_root( *rit, test_root4 );MB_CHK_SET_ERR( rval, "Failed to get obb tree root from GTT" );
00685         CHECK( test_root4 );
00686     }
00687 
00688     // 4) Check that roots exist but rootSets is NOT repopulated when find_geoments = true and
00689     // restore_rootSets = false
00690     moab::GeomTopoTool* gTopoTool5 = new GeomTopoTool( mb2, true, 0, true, false );
00691 
00692     // Get the obbRootTag for vol
00693     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" );
00694 
00695     vols.clear();
00696     rval = gTopoTool5->get_gsets_by_dimension( 3, vols );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00697     surfs.clear();
00698     rval = gTopoTool5->get_gsets_by_dimension( 2, surfs );MB_CHK_SET_ERR( rval, "Failed to get volume gsets" );
00699 
00700     gsets.clear();
00701     gsets.insert_list( surfs.begin(), surfs.end() );
00702     gsets.insert_list( vols.begin(), vols.end() );
00703     EntityHandle test_root5, tagged_root;
00704     for( Range::iterator rit = gsets.begin(); rit != gsets.end(); ++rit )
00705     {
00706         // Check that root still exits, but not in rootSet
00707         rval = mb2->tag_get_data( obbRootTag, &( *rit ), 1, &tagged_root );MB_CHK_SET_ERR( rval, "Failed to get root from tag" );
00708         CHECK( tagged_root );
00709         rval = gTopoTool5->get_root( *rit, test_root5 );
00710         if( MB_SUCCESS == rval ) return MB_FAILURE;
00711     }
00712 
00713     delete gTopoTool;
00714     delete gTopoTool2;
00715     delete gTopoTool3;
00716     delete gTopoTool4;
00717     delete gTopoTool5;
00718 
00719     return MB_SUCCESS;
00720 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines