MOAB: Mesh Oriented datABase  (version 5.4.1)
gqt_rayfire_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 #include "moab/GeomQueryTool.hpp"
00010 
00011 #include "moab/GeomTopoTool.hpp"
00012 #include "moab/GeomQueryTool.hpp"
00013 
00014 using namespace moab;
00015 
00016 Interface* MBI;
00017 GeomTopoTool* GTT;
00018 GeomQueryTool* GQT;
00019 
00020 #define CHKERR( A )                                                                                        \
00021     do                                                                                                     \
00022     {                                                                                                      \
00023         if( MB_SUCCESS != ( A ) )                                                                          \
00024         {                                                                                                  \
00025             std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
00026             return A;                                                                                      \
00027         }                                                                                                  \
00028     } while( false )
00029 
00030 const std::string input_file = TestDir + "unittest/test_geom.h5m";
00031 
00032 double eps = 1.0e-6;
00033 
00034 void gqt_setup_test()
00035 {
00036     MBI            = new Core();
00037     ErrorCode rval = MBI->load_file( input_file.c_str() );CHECK_ERR( rval );
00038     GTT  = new GeomTopoTool( MBI );
00039     GQT  = new GeomQueryTool( GTT );
00040     rval = GQT->initialize();CHECK_ERR( rval );
00041 }
00042 
00043 void gqt_origin_face_rayfire()
00044 {
00045     int vol_idx        = 1;
00046     EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
00047     double dir[3]      = { -1.0, 0.0, 0.0 };
00048     double origin[3]   = { 0.0, 0.0, 0.0 };
00049     double next_surf_dist;
00050     EntityHandle next_surf;
00051     GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist );
00052     double expected_next_surf_dist = 5.0;
00053     CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
00054 }
00055 
00056 void gqt_outside_face_rayfire()
00057 {
00058     int vol_idx        = 1;
00059     EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
00060     double dir[3]      = { 1.0, 0.0, 0.0 };    // ray along x direction
00061     double origin[3]   = { -10.0, 0.0, 0.0 };  // origin at -10 0 0
00062     double next_surf_dist;
00063     EntityHandle next_surf;
00064     GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist );
00065     std::cout << next_surf_dist << std::endl;
00066     double expected_next_surf_dist = 15.0;
00067     CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
00068 }
00069 
00070 void gqt_outside_face_rayfire_orient_exit()
00071 {
00072     GeomQueryTool::RayHistory history;
00073     int vol_idx        = 1;
00074     EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
00075     double dir[3]      = { 1.0, 0.0, 0.0 };    // ray along x direction
00076     double origin[3]   = { -10.0, 0.0, 0.0 };  // origin at -10 0 0
00077     double next_surf_dist;
00078     EntityHandle next_surf;
00079     GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 );
00080     std::cout << next_surf_dist << std::endl;
00081     double expected_next_surf_dist = 15.0;
00082     CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
00083 }
00084 
00085 void gqt_outside_face_rayfire_orient_entrance()
00086 {
00087     GeomQueryTool::RayHistory history;
00088     int vol_idx        = 1;
00089     EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
00090     double dir[3]      = { 1.0, 0.0, 0.0 };    // ray along x direction
00091     double origin[3]   = { -10.0, 0.0, 0.0 };  // origin at -10 0 0
00092     double next_surf_dist;
00093     EntityHandle next_surf;
00094     GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0.0, -1 );
00095     std::cout << next_surf_dist << std::endl;
00096     double expected_next_surf_dist = 5.0;
00097     CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
00098 }
00099 
00100 void gqt_outside_face_rayfire_history_fail()
00101 {
00102     GeomQueryTool::RayHistory history;
00103     int vol_idx        = 1;
00104     EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
00105     double dir[3]      = { 1.0, 0.0, 0.0 };    // ray along x direction
00106     double origin[3]   = { -10.0, 0.0, 0.0 };  // origin at -10 0 0
00107     double xyz[3];
00108     double next_surf_dist;
00109     EntityHandle next_surf;
00110 
00111     history.reset();
00112 
00113     // ray fired exactly along boundary shared by 2 facets on a single surface,
00114     // needs two ray_fires to cross, this is expected and ok
00115 
00116     // first ray fire with history
00117     GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 );
00118     // second ray fire with history
00119     GQT->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
00120     // this fire should hit graveyard, i.e. next_surf = 0
00121     GQT->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
00122 
00123     // using history with this geom, there should be no next surface, i.e. 0
00124     EntityHandle ZERO = 0;
00125     CHECK_EQUAL( ZERO, next_surf );
00126 }
00127 
00128 void gqt_outside_face_rayfire_history()
00129 {
00130     GeomQueryTool::RayHistory history;
00131     int vol_idx        = 1;
00132     EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
00133     double dir[3]      = { 1.0, 0.0, 0.0 };    // ray along x direction
00134     double origin[3]   = { -10.0, 0.0, 0.0 };  // origin at -10 0 0
00135     double xyz[3];
00136     double next_surf_dist;
00137     EntityHandle next_surf;
00138 
00139     history.reset();
00140     // first ray fire with history
00141     GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 );
00142     std::cout << next_surf << " " << history.size() << std::endl;
00143     // second ray fire with history
00144 
00145     xyz[0] = origin[0] + ( next_surf_dist * dir[0] );
00146     xyz[1] = origin[1] + ( next_surf_dist * dir[1] );
00147     xyz[2] = origin[2] + ( next_surf_dist * dir[2] );
00148 
00149     // ray fired execacyl
00150 
00151     GQT->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
00152 
00153     GQT->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
00154 
00155     // using history with this geom, there should be no next surface, i.e. 0
00156     EntityHandle ZERO = 0;
00157     CHECK_EQUAL( ZERO, next_surf );
00158 }
00159 
00160 int main( int /* argc */, char** /* argv */ )
00161 {
00162     int result = 0;
00163 
00164     result += RUN_TEST( gqt_setup_test );  // setup problem
00165     // rays fired along cardinal directions
00166     result += RUN_TEST( gqt_origin_face_rayfire );  // point in centre
00167     result += RUN_TEST( gqt_outside_face_rayfire );
00168     result += RUN_TEST( gqt_outside_face_rayfire_orient_exit );      // fire ray from point outside volume
00169                                                                      // looking for exit intersections
00170     result += RUN_TEST( gqt_outside_face_rayfire_orient_entrance );  // fire ray from point outside volume
00171                                                                      // looking for entrance intersection
00172     result += RUN_TEST( gqt_outside_face_rayfire_history_fail );     // fire ray from point outside
00173                                                                      // geometry using ray history
00174     result += RUN_TEST( gqt_outside_face_rayfire_history );          // fire ray from point outside geometry
00175                                                                      // using ray history
00176 
00177     delete GQT;
00178     delete GTT;
00179     delete MBI;
00180 
00181     return result;
00182 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines