MOAB: Mesh Oriented datABase  (version 5.4.1)
gqt_findvol_test.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include "moab/Interface.hpp"
00003 #ifndef IS_BUILDING_MB
00004 #define IS_BUILDING_MB
00005 #endif
00006 #include "TestUtil.hpp"
00007 #include "Internals.hpp"
00008 #include "moab/Core.hpp"
00009 
00010 #include "moab/GeomQueryTool.hpp"
00011 #include "moab/GeomTopoTool.hpp"
00012 
00013 using namespace moab;
00014 
00015 Core* MBI;
00016 GeomTopoTool* GTT;
00017 GeomQueryTool* GQT;
00018 
00019 Tag id_tag = 0;
00020 
00021 const std::string input_file = TestDir + "unittest/find_vol_test_geom.h5m";
00022 
00023 void find_volume_tests();
00024 
00025 int main()
00026 {
00027 
00028     MBI            = new Core();
00029     ErrorCode rval = MBI->load_file( input_file.c_str() );MB_CHK_SET_ERR( rval, "Failed to load test file" );
00030 
00031     GTT = new GeomTopoTool( MBI );
00032     GQT = new GeomQueryTool( GTT );
00033 
00034     // initialize the rest of the GQT
00035     GQT->initialize();
00036 
00037     int result = 0;
00038 
00039     // with no global OBB tree (will defer to find_volume_slow)
00040     result += RUN_TEST( find_volume_tests );
00041 
00042     // build OBBs with one-vol tree
00043     GTT->construct_obb_trees( true );
00044 
00045     // using the global OBB tree
00046     result += RUN_TEST( find_volume_tests );
00047 
00048     return result;
00049 }
00050 
00051 ErrorCode id_lookup( EntityHandle eh, int& id )
00052 {
00053     ErrorCode rval;
00054     if( !id_tag )
00055     {
00056         id_tag = MBI->globalId_tag();
00057     }
00058 
00059     rval = MBI->tag_get_data( id_tag, &eh, 1, (void*)&id );MB_CHK_SET_ERR( rval, "Failed to lookup volume id" );
00060 
00061     return MB_SUCCESS;
00062 }
00063 
00064 // Test case structure
00065 // It is possible in some cases
00066 // to have 2 correct answers (overlaps)
00067 // A result of zero means no volume should be found
00068 
00069 struct FindVolTestResult
00070 {
00071     double pnt[3];
00072     double dir[3];
00073     int resultA;
00074     int resultB;
00075 };
00076 
00077 // Test Geometry
00078 
00079 // The test geometry consists of 3 cubes, one of which
00080 // overlaps another. Volumes 1 and 2 have edges with
00081 // length 1. Volume 3 has an edge length of 0.5.
00082 // Volume 1 is centered at (3, 0, 0). Volume 2 is
00083 // centered on the origin. Volume 3 is centered on (0.5, 0, 0).
00084 // Volume 4 is the implicit complement.
00085 //
00086 // XY slice of geometry:
00087 //
00088 // ###########################                   #############################
00089 // #                         #                   #                           #
00090 // #                         #                   #                           #
00091 // #                ####################         #                           #
00092 // #                #        #         #         #                           #
00093 // #      Vol 2     #        #  Vol 3  #         #           Vol 1           #
00094 // #                #        #         #         #                           #
00095 // #                #        #         #         #                           #
00096 // #                ####################         #                           #
00097 // #                         #                   #                           #
00098 // #                         #     Vol 4 (IC)    #                           #
00099 // ###########################                   #############################
00100 
00101 void find_volume_tests()
00102 {
00103 
00104     ErrorCode rval;
00105 
00106     const struct FindVolTestResult tests[] = {
00107         // one point unambiguously placed in each volume
00108         // and the implicit complement
00109         { { -0.1, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 2, 4 },   // 1
00110         { { 0.6, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 3, 4 },    // 2
00111         { { 3.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 1, -1 },   // 3
00112         { { -5.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 0, -1 },  // 4
00113         // Point on the negative side of the geometry
00114         { { -5.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 0, -1 },   // 5
00115         { { -5.0, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 0, -1 },  // 6
00116         // Point on the positive side of the geometry
00117         { { 10.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 0, -1 },   // 7
00118         { { 10.0, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 0, -1 },  // 8
00119         { { 10.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 0, -1 },   // 9
00120         // Point between the volumes
00121         { { 1.5, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 0, 4 },    // 10
00122         { { 1.5, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 4, -1 },  // 11
00123         { { 1.5, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 4, -1 },   // 12
00124         { { 1.5, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, 0, -1 },   // 13
00125         // Point in the overlap of vols 2 & 3
00126         { { 0.4, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 2, 3 },   // 14
00127         { { 0.4, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 2, 3 },  // 15
00128         { { 0.4, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 2, 3 },   // 16
00129         // Point in Vol 3 w/ different directions applied
00130         { { 0.6, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 3, 4 },   // 17
00131         { { 0.6, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 3, 4 },  // 18
00132         { { 0.6, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 3, 4 },   // 19
00133         // Point on surface of volume 1 w/ tangent direction
00134         { { 3.0, 0.5, 0.0 }, { 1.0, 0.0, 0.0 }, 1, -1 },   // 20
00135         { { 3.0, 0.5, 0.0 }, { -1.0, 0.0, 0.0 }, 1, -1 },  // 21
00136         // Point on surface of volume 1 w/ non-tangent direction
00137         { { 3.0, 0.5, 0.0 }, { 0.0, 1.0, 0.0 }, 1, -1 },   // 22
00138         { { 3.0, 0.5, 0.0 }, { 0.0, -1.0, 0.0 }, 4, -1 },  // 23
00139         // Checks that the neg ray distance doesn't affect results
00140         // Location: Positive Y Surface of Volume 2
00141         { { 0.6, 0.25000000000001, 0.0 }, { 0.0, 1.0, 0.0 }, 4, 0 },    // 24
00142         { { 0.6, 0.25000000000001, 0.0 }, { 0.0, -1.0, 0.0 }, 4, -1 },  // 25
00143         // ON-SURFACE POINT TESTS (not checked using PIV loop)
00144         // Point on surface of volume 1 w/ random directions
00145         { { 3.0, 0.5, 0.0 }, { 0.0, 0.0, 0.0 }, 1, 4 },  // 26
00146         // Point on surface of volume 2 w/ random directions
00147         { { 0.6, 0.23, 0.0 }, { 0.0, 0.0, 0.0 }, 3, 4 }  // 27
00148     };
00149 
00150     int num_tests = sizeof( tests ) / sizeof( FindVolTestResult );
00151 
00152     EntityHandle volume_found;
00153     int vol_id;
00154 
00155     bool using_find_volume_slow = GTT->get_one_vol_root() == 0;
00156 
00157     // Skip the last two tests
00158     if( using_find_volume_slow )
00159     {
00160         std::cout << "Skipping last two tests when"
00161                   << "using find_volume_slow (PIV loop)" << std::endl;
00162         num_tests -= 2;
00163     }
00164 
00165     for( int i = 1; i < num_tests + 1; i++ )
00166     {
00167         const FindVolTestResult& test = tests[i - 1];
00168 
00169         const double* direction = NULL;
00170         if( test.dir[0] != 0.0 || test.dir[1] != 0.0 || test.dir[2] != 0.0 )
00171         {
00172             direction = test.dir;
00173         }
00174 
00175         // if we're testing a random direction, run the test many times
00176         int num_repeats = direction ? 1 : 100;
00177         for( int j = 0; j < num_repeats; j++ )
00178         {
00179             rval = GQT->find_volume( test.pnt, volume_found, direction );
00180             // if not found, we will check later
00181             if( rval != MB_ENTITY_NOT_FOUND )
00182             {
00183                 MB_CHK_SET_ERR_CONT( rval, "Failed in find_volume" );
00184             }
00185 
00186             rval = id_lookup( volume_found, vol_id );MB_CHK_SET_ERR_CONT( rval, "Failed in id lookup" );
00187 
00188             std::cout << "Test " << i << ". Volume found id: " << vol_id << "\n";
00189             // make sure at least one of these checks passed
00190             CHECK( vol_id == test.resultA || vol_id == test.resultB );
00191 
00192             // reset result and id for safety
00193             volume_found = 0;
00194             vol_id       = -1;
00195         }  // repeat loop
00196     }      // test loop
00197 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines