MOAB: Mesh Oriented datABase  (version 5.2.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 + "/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 ) { id_tag = MBI->globalId_tag(); }
00055 
00056     rval = MBI->tag_get_data( id_tag, &eh, 1, (void*)&id );MB_CHK_SET_ERR( rval, "Failed to lookup volume id" );
00057 
00058     return MB_SUCCESS;
00059 }
00060 
00061 // Test case structure
00062 // It is possible in some cases
00063 // to have 2 correct answers (overlaps)
00064 // A result of zero means no volume should be found
00065 
00066 struct FindVolTestResult
00067 {
00068     double pnt[3];
00069     double dir[3];
00070     int resultA;
00071     int resultB;
00072 };
00073 
00074 // Test Geometry \\
00075 
00076 // The test geometry consists of 3 cubes, one of which
00077 // overlaps another. Volumes 1 and 2 have edges with
00078 // length 1. Volume 3 has an edge length of 0.5.
00079 // Volume 1 is centered at (3, 0, 0). Volume 2 is
00080 // centered on the origin. Volume 3 is centered on (0.5, 0, 0).
00081 // Volume 4 is the implicit complement.
00082 
00083 // XY slice of geometry:
00084 
00085 // ###########################                   #############################
00086 // #                         #                   #                           #
00087 // #                         #                   #                           #
00088 // #                ####################         #                           #
00089 // #                #        #         #         #                           #
00090 // #      Vol 2     #        #  Vol 3  #         #           Vol 1           #
00091 // #                #        #         #         #                           #
00092 // #                #        #         #         #                           #
00093 // #                ####################         #                           #
00094 // #                         #                   #                           #
00095 // #                         #     Vol 4 (IC)    #                           #
00096 // ###########################                   #############################
00097 
00098 void find_volume_tests()
00099 {
00100 
00101     ErrorCode rval;
00102 
00103     const struct FindVolTestResult tests[] = {
00104         // one point unambiguously placed in each volume
00105         // and the implicit complement
00106         { { -0.1, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 2, 4 },   // 1
00107         { { 0.6, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 3, 4 },    // 2
00108         { { 3.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 1, -1 },   // 3
00109         { { -5.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 0, -1 },  // 4
00110         // Point on the negative side of the geometry
00111         { { -5.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 0, -1 },   // 5
00112         { { -5.0, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 0, -1 },  // 6
00113         // Point on the positive side of the geometry
00114         { { 10.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 0, -1 },   // 7
00115         { { 10.0, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 0, -1 },  // 8
00116         { { 10.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 0, -1 },   // 9
00117         // Point between the volumes
00118         { { 1.5, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 0, 4 },    // 10
00119         { { 1.5, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 4, -1 },  // 11
00120         { { 1.5, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 4, -1 },   // 12
00121         { { 1.5, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, 0, -1 },   // 13
00122         // Point in the overlap of vols 2 & 3
00123         { { 0.4, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 2, 3 },   // 14
00124         { { 0.4, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 2, 3 },  // 15
00125         { { 0.4, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 2, 3 },   // 16
00126         // Point in Vol 3 w/ different directions applied
00127         { { 0.6, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 3, 4 },   // 17
00128         { { 0.6, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 3, 4 },  // 18
00129         { { 0.6, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 3, 4 },   // 19
00130         // Point on surface of volume 1 w/ tangent direction
00131         { { 3.0, 0.5, 0.0 }, { 1.0, 0.0, 0.0 }, 1, -1 },   // 20
00132         { { 3.0, 0.5, 0.0 }, { -1.0, 0.0, 0.0 }, 1, -1 },  // 21
00133         // Point on surface of volume 1 w/ non-tangent direction
00134         { { 3.0, 0.5, 0.0 }, { 0.0, 1.0, 0.0 }, 1, -1 },   // 22
00135         { { 3.0, 0.5, 0.0 }, { 0.0, -1.0, 0.0 }, 4, -1 },  // 23
00136         // Checks that the neg ray distance doesn't affect results
00137         // Location: Positive Y Surface of Volume 2
00138         { { 0.6, 0.25000000000001, 0.0 }, { 0.0, 1.0, 0.0 }, 4, 0 },    // 24
00139         { { 0.6, 0.25000000000001, 0.0 }, { 0.0, -1.0, 0.0 }, 4, -1 },  // 25
00140         /// ON-SURFACE POINT TESTS (not checked using PIV loop) \\\
00141     // Point on surface of volume 1 w/ random directions
00142         { { 3.0, 0.5, 0.0 }, { 0.0, 0.0, 0.0 }, 1, 4 },  // 26
00143         // Point on surface of volume 2 w/ random directions
00144         { { 0.6, 0.23, 0.0 }, { 0.0, 0.0, 0.0 }, 3, 4 }  // 27
00145     };
00146 
00147     int num_tests = sizeof( tests ) / sizeof( FindVolTestResult );
00148 
00149     EntityHandle volume_found;
00150     int vol_id;
00151 
00152     bool using_find_volume_slow = GTT->get_one_vol_root() == 0;
00153 
00154     // Skip the last two tests
00155     if( using_find_volume_slow )
00156     {
00157         std::cout << "Skipping last two tests when"
00158                   << "using find_volume_slow (PIV loop)" << std::endl;
00159         num_tests -= 2;
00160     }
00161 
00162     for( int i = 1; i < num_tests + 1; i++ )
00163     {
00164 
00165         const FindVolTestResult& test = tests[i - 1];
00166 
00167         const double* direction = NULL;
00168         if( test.dir[0] != 0.0 || test.dir[1] != 0.0 || test.dir[2] != 0.0 ) { direction = test.dir; }
00169 
00170         // if we're testing a random direction, run the test many times
00171         int num_repeats = direction ? 1 : 100;
00172         for( int j = 0; j < num_repeats; j++ )
00173         {
00174             rval = GQT->find_volume( test.pnt, volume_found, direction );
00175             // if not found, we will check later
00176             if( rval != MB_ENTITY_NOT_FOUND ) { MB_CHK_SET_ERR_CONT( rval, "Failed in find_volume" ); }
00177 
00178             rval = id_lookup( volume_found, vol_id );MB_CHK_SET_ERR_CONT( rval, "Failed in id lookup" );
00179 
00180             std::cout << "Test " << i << ". Volume found id: " << vol_id << "\n";
00181             // make sure at least one of these checks passed
00182             CHECK( vol_id == test.resultA || vol_id == test.resultB );
00183 
00184             // reset result and id for safety
00185             volume_found = 0;
00186             vol_id       = -1;
00187         }  // repeat loop
00188     }      // test loop
00189 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines