MOAB: Mesh Oriented datABase  (version 5.5.0)
gqt_rayfire_test.cpp File Reference
#include <iostream>
#include "moab/Interface.hpp"
#include "TestUtil.hpp"
#include "Internals.hpp"
#include "moab/Core.hpp"
#include "moab/GeomQueryTool.hpp"
#include "moab/GeomTopoTool.hpp"
+ Include dependency graph for gqt_rayfire_test.cpp:

Go to the source code of this file.

Macros

#define IS_BUILDING_MB
 
#define CHKERR(A)
 

Functions

void gqt_setup_test ()
 
void gqt_origin_face_rayfire ()
 
void gqt_outside_face_rayfire ()
 
void gqt_outside_face_rayfire_orient_exit ()
 
void gqt_outside_face_rayfire_orient_entrance ()
 
void gqt_outside_face_rayfire_history_fail ()
 
void gqt_outside_face_rayfire_history ()
 
int main (int, char **)
 

Variables

InterfaceMBI
 
GeomTopoToolGTT
 
GeomQueryToolGQT
 
const std::string input_file = TestDir + "unittest/test_geom.h5m"
 
double eps = 1.0e-6
 

Macro Definition Documentation

◆ CHKERR

#define CHKERR (   A)
Value:
do \
{ \
if( MB_SUCCESS != ( A ) ) \
{ \
std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
return A; \
} \
} while( false )

Definition at line 20 of file gqt_rayfire_test.cpp.

◆ IS_BUILDING_MB

#define IS_BUILDING_MB

Definition at line 4 of file gqt_rayfire_test.cpp.

Function Documentation

◆ gqt_origin_face_rayfire()

void gqt_origin_face_rayfire ( )

Definition at line 43 of file gqt_rayfire_test.cpp.

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 }

References CHECK_REAL_EQUAL, moab::GeomTopoTool::entity_by_id(), eps, GQT, moab::GeomQueryTool::gttool(), origin, and moab::GeomQueryTool::ray_fire().

Referenced by main().

◆ gqt_outside_face_rayfire()

void gqt_outside_face_rayfire ( )

Definition at line 56 of file gqt_rayfire_test.cpp.

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 }

References CHECK_REAL_EQUAL, moab::GeomTopoTool::entity_by_id(), eps, GQT, moab::GeomQueryTool::gttool(), origin, and moab::GeomQueryTool::ray_fire().

Referenced by main().

◆ gqt_outside_face_rayfire_history()

void gqt_outside_face_rayfire_history ( )

Definition at line 128 of file gqt_rayfire_test.cpp.

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 }

References CHECK_EQUAL, moab::GeomTopoTool::entity_by_id(), GQT, moab::GeomQueryTool::gttool(), origin, moab::GeomQueryTool::ray_fire(), moab::GeomQueryTool::RayHistory::reset(), and moab::GeomQueryTool::RayHistory::size().

Referenced by main().

◆ gqt_outside_face_rayfire_history_fail()

void gqt_outside_face_rayfire_history_fail ( )

Definition at line 100 of file gqt_rayfire_test.cpp.

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 }

References CHECK_EQUAL, moab::GeomTopoTool::entity_by_id(), GQT, moab::GeomQueryTool::gttool(), origin, moab::GeomQueryTool::ray_fire(), and moab::GeomQueryTool::RayHistory::reset().

Referenced by main().

◆ gqt_outside_face_rayfire_orient_entrance()

void gqt_outside_face_rayfire_orient_entrance ( )

Definition at line 85 of file gqt_rayfire_test.cpp.

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 }

References CHECK_REAL_EQUAL, moab::GeomTopoTool::entity_by_id(), eps, GQT, moab::GeomQueryTool::gttool(), origin, and moab::GeomQueryTool::ray_fire().

Referenced by main().

◆ gqt_outside_face_rayfire_orient_exit()

void gqt_outside_face_rayfire_orient_exit ( )

Definition at line 70 of file gqt_rayfire_test.cpp.

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 }

References CHECK_REAL_EQUAL, moab::GeomTopoTool::entity_by_id(), eps, GQT, moab::GeomQueryTool::gttool(), origin, and moab::GeomQueryTool::ray_fire().

Referenced by main().

◆ gqt_setup_test()

void gqt_setup_test ( )

Definition at line 34 of file gqt_rayfire_test.cpp.

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 }

References CHECK_ERR, ErrorCode, GQT, GTT, moab::GeomQueryTool::initialize(), input_file, moab::Interface::load_file(), and MBI.

Referenced by main().

◆ main()

int main ( int  ,
char **   
)

Definition at line 160 of file gqt_rayfire_test.cpp.

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 }

References GQT, gqt_origin_face_rayfire(), gqt_outside_face_rayfire(), gqt_outside_face_rayfire_history(), gqt_outside_face_rayfire_history_fail(), gqt_outside_face_rayfire_orient_entrance(), gqt_outside_face_rayfire_orient_exit(), gqt_setup_test(), GTT, MBI, and RUN_TEST.

Variable Documentation

◆ eps

◆ GQT

◆ GTT

Definition at line 17 of file gqt_rayfire_test.cpp.

Referenced by gqt_setup_test(), and main().

◆ input_file

const std::string input_file = TestDir + "unittest/test_geom.h5m"

Definition at line 30 of file gqt_rayfire_test.cpp.

Referenced by gqt_setup_test().

◆ MBI

Interface* MBI

Definition at line 16 of file gqt_rayfire_test.cpp.

Referenced by gqt_setup_test(), and main().