MOAB: Mesh Oriented datABase  (version 5.5.0)
gqt_rayfire_test.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include "moab/Interface.hpp"
3 #ifndef IS_BUILDING_MB
4 #define IS_BUILDING_MB
5 #endif
6 #include "TestUtil.hpp"
7 #include "Internals.hpp"
8 #include "moab/Core.hpp"
9 #include "moab/GeomQueryTool.hpp"
10 
11 #include "moab/GeomTopoTool.hpp"
12 #include "moab/GeomQueryTool.hpp"
13 
14 using namespace moab;
15 
19 
20 #define CHKERR( A ) \
21  do \
22  { \
23  if( MB_SUCCESS != ( A ) ) \
24  { \
25  std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
26  return A; \
27  } \
28  } while( false )
29 
30 const std::string input_file = TestDir + "unittest/test_geom.h5m";
31 
32 double eps = 1.0e-6;
33 
35 {
36  MBI = new Core();
37  ErrorCode rval = MBI->load_file( input_file.c_str() );CHECK_ERR( rval );
38  GTT = new GeomTopoTool( MBI );
39  GQT = new GeomQueryTool( GTT );
40  rval = GQT->initialize();CHECK_ERR( rval );
41 }
42 
44 {
45  int vol_idx = 1;
46  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
47  double dir[3] = { -1.0, 0.0, 0.0 };
48  double origin[3] = { 0.0, 0.0, 0.0 };
49  double next_surf_dist;
50  EntityHandle next_surf;
51  GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist );
52  double expected_next_surf_dist = 5.0;
53  CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
54 }
55 
57 {
58  int vol_idx = 1;
59  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
60  double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction
61  double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0
62  double next_surf_dist;
63  EntityHandle next_surf;
64  GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist );
65  std::cout << next_surf_dist << std::endl;
66  double expected_next_surf_dist = 15.0;
67  CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
68 }
69 
71 {
73  int vol_idx = 1;
74  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
75  double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction
76  double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0
77  double next_surf_dist;
78  EntityHandle next_surf;
79  GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 );
80  std::cout << next_surf_dist << std::endl;
81  double expected_next_surf_dist = 15.0;
82  CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
83 }
84 
86 {
88  int vol_idx = 1;
89  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
90  double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction
91  double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0
92  double next_surf_dist;
93  EntityHandle next_surf;
94  GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0.0, -1 );
95  std::cout << next_surf_dist << std::endl;
96  double expected_next_surf_dist = 5.0;
97  CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
98 }
99 
101 {
103  int vol_idx = 1;
104  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
105  double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction
106  double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0
107  double xyz[3];
108  double next_surf_dist;
109  EntityHandle next_surf;
110 
111  history.reset();
112 
113  // ray fired exactly along boundary shared by 2 facets on a single surface,
114  // needs two ray_fires to cross, this is expected and ok
115 
116  // first ray fire with history
117  GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 );
118  // second ray fire with history
119  GQT->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
120  // this fire should hit graveyard, i.e. next_surf = 0
121  GQT->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
122 
123  // using history with this geom, there should be no next surface, i.e. 0
124  EntityHandle ZERO = 0;
125  CHECK_EQUAL( ZERO, next_surf );
126 }
127 
129 {
131  int vol_idx = 1;
132  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
133  double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction
134  double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0
135  double xyz[3];
136  double next_surf_dist;
137  EntityHandle next_surf;
138 
139  history.reset();
140  // first ray fire with history
141  GQT->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 );
142  std::cout << next_surf << " " << history.size() << std::endl;
143  // second ray fire with history
144 
145  xyz[0] = origin[0] + ( next_surf_dist * dir[0] );
146  xyz[1] = origin[1] + ( next_surf_dist * dir[1] );
147  xyz[2] = origin[2] + ( next_surf_dist * dir[2] );
148 
149  // ray fired execacyl
150 
151  GQT->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
152 
153  GQT->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
154 
155  // using history with this geom, there should be no next surface, i.e. 0
156  EntityHandle ZERO = 0;
157  CHECK_EQUAL( ZERO, next_surf );
158 }
159 
160 int main( int /* argc */, char** /* argv */ )
161 {
162  int result = 0;
163 
164  result += RUN_TEST( gqt_setup_test ); // setup problem
165  // rays fired along cardinal directions
166  result += RUN_TEST( gqt_origin_face_rayfire ); // point in centre
167  result += RUN_TEST( gqt_outside_face_rayfire );
168  result += RUN_TEST( gqt_outside_face_rayfire_orient_exit ); // fire ray from point outside volume
169  // looking for exit intersections
170  result += RUN_TEST( gqt_outside_face_rayfire_orient_entrance ); // fire ray from point outside volume
171  // looking for entrance intersection
172  result += RUN_TEST( gqt_outside_face_rayfire_history_fail ); // fire ray from point outside
173  // geometry using ray history
174  result += RUN_TEST( gqt_outside_face_rayfire_history ); // fire ray from point outside geometry
175  // using ray history
176 
177  delete GQT;
178  delete GTT;
179  delete MBI;
180 
181  return result;
182 }