MOAB: Mesh Oriented datABase  (version 5.4.1)
gqt_pointinvol_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 #define CHKERR( A )                                                                                        \
00020     do                                                                                                     \
00021     {                                                                                                      \
00022         if( MB_SUCCESS != ( A ) )                                                                          \
00023         {                                                                                                  \
00024             std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
00025             return A;                                                                                      \
00026         }                                                                                                  \
00027     } while( false )
00028 
00029 const std::string input_file = TestDir + "unittest/test_geom.h5m";
00030 
00031 void gqt_setup_test()
00032 {
00033     MBI            = new Core();
00034     ErrorCode rval = MBI->load_file( input_file.c_str() );CHECK_ERR( rval );
00035 
00036     GTT  = new GeomTopoTool( MBI );
00037     GQT  = new GeomQueryTool( GTT );
00038     rval = GQT->initialize();CHECK_ERR( rval );
00039 }
00040 
00041 void gqt_point_in()
00042 {
00043     int result          = 0;
00044     int expected_result = 1;
00045     double xyz[3]       = { 0.0, 0.0, 0.0 };
00046     int vol_idx         = 1;
00047     EntityHandle vol_h  = GQT->gttool()->entity_by_id( 3, vol_idx );
00048     ErrorCode rval      = GQT->point_in_volume( vol_h, xyz, result );CHECK_ERR( rval );
00049     CHECK_EQUAL( expected_result, result );
00050 }
00051 
00052 int gqt_point_in_vol_dir( double origin[3], double dir[3], int vol_idx )
00053 {
00054     int result         = 0;
00055     EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
00056     double xyz[3];
00057     double next_surf_dist;
00058     EntityHandle next_surf;
00059 
00060     // normalise the vector
00061     double dir_norm = ( dir[0] * dir[0] ) + ( dir[1] * dir[1] ) + ( dir[2] * dir[2] );
00062 
00063     dir[0] = dir[0] / sqrt( dir_norm );
00064     dir[1] = dir[1] / sqrt( dir_norm );
00065     dir[2] = dir[2] / sqrt( dir_norm );
00066 
00067     ErrorCode rval = GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist );CHECK_ERR( rval );
00068 
00069     xyz[0] = origin[0] + ( next_surf_dist * dir[0] );
00070     xyz[1] = origin[1] + ( next_surf_dist * dir[1] );
00071     xyz[2] = origin[2] + ( next_surf_dist * dir[2] );
00072 
00073     std::cout << xyz[0] << " " << xyz[1] << " " << xyz[2] << std::endl;
00074 
00075     rval = GQT->point_in_volume( vol_h, xyz, result, dir );CHECK_ERR( rval );
00076     return result;
00077 }
00078 
00079 void gqt_point_in_vol_1()
00080 {
00081     double dir[3]       = { -1.0, 0.0, 0.0 };
00082     double origin[3]    = { 0.0, 0.0, 0.0 };
00083     int vol_idx         = 1;
00084     int expected_result = 1;
00085 
00086     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00087     CHECK_EQUAL( expected_result, result );
00088 }
00089 
00090 void gqt_point_in_vol_2()
00091 {
00092     int expected_result = 1;
00093     int vol_idx         = 1;
00094     double dir[3]       = { 1.0, 0.0, 0.0 };
00095     double origin[3]    = { 0.0, 0.0, 0.0 };
00096 
00097     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00098 
00099     CHECK_EQUAL( expected_result, result );
00100 }
00101 
00102 void gqt_point_in_vol_3()
00103 {
00104     int expected_result = 1;
00105     int vol_idx         = 1;
00106     double dir[3]       = { 0.0, -1.0, 0.0 };
00107     double origin[3]    = { 0.0, 0.0, 0.0 };
00108 
00109     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00110 
00111     CHECK_EQUAL( expected_result, result );
00112 }
00113 
00114 void gqt_point_in_vol_4()
00115 {
00116     int expected_result = 1;
00117     int vol_idx         = 1;
00118     double dir[3]       = { 0.0, 1.0, 0.0 };
00119     double origin[3]    = { 0.0, 0.0, 0.0 };
00120 
00121     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00122 
00123     CHECK_EQUAL( expected_result, result );
00124 }
00125 
00126 void gqt_point_in_vol_5()
00127 {
00128     int expected_result = 1;
00129     int vol_idx         = 1;
00130     double dir[3]       = { 0.0, 0.0, -1.0 };
00131     double origin[3]    = { 0.0, 0.0, 0.0 };
00132 
00133     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00134 
00135     CHECK_EQUAL( expected_result, result );
00136 }
00137 
00138 void gqt_point_in_vol_6()
00139 {
00140     int expected_result = 1;
00141     int vol_idx         = 1;
00142     double dir[3]       = { 0.0, 0.0, 1.0 };
00143     double origin[3]    = { 0.0, 0.0, 0.0 };
00144 
00145     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00146 
00147     CHECK_EQUAL( expected_result, result );
00148 }
00149 
00150 void gqt_point_on_corner_1()
00151 {
00152     int expected_result = 1;
00153     int vol_idx         = 1;
00154     double dir[3]       = { 1.0, 1.0, 1.0 };
00155     double origin[3]    = { 0.0, 0.0, 0.0 };
00156 
00157     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00158 
00159     CHECK_EQUAL( expected_result, result );
00160 }
00161 
00162 void gqt_point_on_corner_2()
00163 {
00164     int expected_result = 1;
00165     int vol_idx         = 1;
00166     double dir[3]       = { -1.0, 1.0, 1.0 };
00167     double origin[3]    = { 0.0, 0.0, 0.0 };
00168 
00169     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00170 
00171     CHECK_EQUAL( expected_result, result );
00172 }
00173 
00174 void gqt_point_on_corner_3()
00175 {
00176     int expected_result = 1;
00177     int vol_idx         = 1;
00178     double dir[3]       = { 1.0, 1.0, -1.0 };
00179     double origin[3]    = { 0.0, 0.0, 0.0 };
00180 
00181     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00182 
00183     CHECK_EQUAL( expected_result, result );
00184 }
00185 
00186 void gqt_point_on_corner_4()
00187 {
00188     int expected_result = 1;
00189     int vol_idx         = 1;
00190     double dir[3]       = { -1.0, 1.0, -1.0 };
00191     double origin[3]    = { 0.0, 0.0, 0.0 };
00192 
00193     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00194 
00195     CHECK_EQUAL( expected_result, result );
00196 }
00197 
00198 void gqt_point_on_corner_5()
00199 {
00200     int expected_result = 1;
00201     int vol_idx         = 1;
00202     double dir[3]       = { 1.0, -1.0, 1.0 };
00203     double origin[3]    = { 0.0, 0.0, 0.0 };
00204 
00205     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00206 
00207     CHECK_EQUAL( expected_result, result );
00208 }
00209 
00210 void gqt_point_on_corner_6()
00211 {
00212     int expected_result = 1;
00213     int vol_idx         = 1;
00214     double dir[3]       = { -1.0, -1.0, 1.0 };
00215     double origin[3]    = { 0.0, 0.0, 0.0 };
00216 
00217     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00218 
00219     CHECK_EQUAL( expected_result, result );
00220 }
00221 
00222 void gqt_point_on_corner_7()
00223 {
00224     int expected_result = 1;
00225     int vol_idx         = 1;
00226     double dir[3]       = { 1.0, -1.0, -1.0 };
00227     double origin[3]    = { 0.0, 0.0, 0.0 };
00228 
00229     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00230 
00231     CHECK_EQUAL( expected_result, result );
00232 }
00233 
00234 void gqt_point_on_corner_8()
00235 {
00236     int expected_result = 1;
00237     int vol_idx         = 1;
00238     double dir[3]       = { -1.0, -1.0, -1.0 };
00239     double origin[3]    = { 0.0, 0.0, 0.0 };
00240 
00241     int result = gqt_point_in_vol_dir( origin, dir, vol_idx );
00242 
00243     CHECK_EQUAL( expected_result, result );
00244 }
00245 
00246 int main( int /* argc */, char** /* argv */ )
00247 {
00248     int result = 0;
00249 
00250     result += RUN_TEST( gqt_setup_test );  // setup problem
00251     result += RUN_TEST( gqt_point_in );    // point in centre
00252     // rays fired along cardinal directions
00253     result += RUN_TEST( gqt_point_in_vol_1 );  // point in centre
00254     result += RUN_TEST( gqt_point_in_vol_2 );  // point in centre
00255     result += RUN_TEST( gqt_point_in_vol_3 );  // point in centre
00256     result += RUN_TEST( gqt_point_in_vol_4 );  // point in centre
00257     result += RUN_TEST( gqt_point_in_vol_5 );  // point in centre
00258     result += RUN_TEST( gqt_point_in_vol_6 );  // point in centre
00259     // rays fired at nodes
00260     result += RUN_TEST( gqt_point_on_corner_1 );
00261     result += RUN_TEST( gqt_point_on_corner_2 );
00262     result += RUN_TEST( gqt_point_on_corner_3 );
00263     result += RUN_TEST( gqt_point_on_corner_4 );
00264 
00265     // result += RUN_TEST(dagmc_point_in({0.0, 0.0, 5.0}); // point in centre
00266     // result += RUN_TEST(dagmc_point_in({0.0, 0.0, -5.0}); // point in centre
00267     // result += RUN_TEST(dagmc_point_in({0.0, 5.0, 0.0}); // point in centre
00268     // result += RUN_TEST(dagmc_point_in({0.0, -5.0, 0.0}); // point in centre
00269     // result += RUN_TEST(dagmc_point_in({5.0, 0.0, 0.0}); // point in centre
00270     // result += RUN_TEST(dagmc_point_in({-5.0, 0.0, 0.0}); // point in centre
00271 
00272     delete GQT;
00273     delete GTT;
00274     delete MBI;
00275 
00276     return result;
00277 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines