MOAB: Mesh Oriented datABase  (version 5.5.0)
gqt_findvol_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_findvol_test.cpp:

Go to the source code of this file.

Classes

struct  FindVolTestResult
 

Macros

#define IS_BUILDING_MB
 

Functions

void find_volume_tests ()
 
int main ()
 
ErrorCode id_lookup (EntityHandle eh, int &id)
 

Variables

CoreMBI
 
GeomTopoToolGTT
 
GeomQueryToolGQT
 
Tag id_tag = 0
 
const std::string input_file = TestDir + "unittest/find_vol_test_geom.h5m"
 

Macro Definition Documentation

◆ IS_BUILDING_MB

#define IS_BUILDING_MB

Definition at line 4 of file gqt_findvol_test.cpp.

Function Documentation

◆ find_volume_tests()

void find_volume_tests ( )

Definition at line 101 of file gqt_findvol_test.cpp.

102 {
103 
104  ErrorCode rval;
105 
106  const struct FindVolTestResult tests[] = {
107  // one point unambiguously placed in each volume
108  // and the implicit complement
109  { { -0.1, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 2, 4 }, // 1
110  { { 0.6, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 3, 4 }, // 2
111  { { 3.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 1, -1 }, // 3
112  { { -5.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 0, -1 }, // 4
113  // Point on the negative side of the geometry
114  { { -5.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 0, -1 }, // 5
115  { { -5.0, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 0, -1 }, // 6
116  // Point on the positive side of the geometry
117  { { 10.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 0, -1 }, // 7
118  { { 10.0, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 0, -1 }, // 8
119  { { 10.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 0, -1 }, // 9
120  // Point between the volumes
121  { { 1.5, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 0, 4 }, // 10
122  { { 1.5, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 4, -1 }, // 11
123  { { 1.5, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 4, -1 }, // 12
124  { { 1.5, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, 0, -1 }, // 13
125  // Point in the overlap of vols 2 & 3
126  { { 0.4, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 2, 3 }, // 14
127  { { 0.4, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 2, 3 }, // 15
128  { { 0.4, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 2, 3 }, // 16
129  // Point in Vol 3 w/ different directions applied
130  { { 0.6, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, 3, 4 }, // 17
131  { { 0.6, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, 3, 4 }, // 18
132  { { 0.6, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, 3, 4 }, // 19
133  // Point on surface of volume 1 w/ tangent direction
134  { { 3.0, 0.5, 0.0 }, { 1.0, 0.0, 0.0 }, 1, -1 }, // 20
135  { { 3.0, 0.5, 0.0 }, { -1.0, 0.0, 0.0 }, 1, -1 }, // 21
136  // Point on surface of volume 1 w/ non-tangent direction
137  { { 3.0, 0.5, 0.0 }, { 0.0, 1.0, 0.0 }, 1, -1 }, // 22
138  { { 3.0, 0.5, 0.0 }, { 0.0, -1.0, 0.0 }, 4, -1 }, // 23
139  // Checks that the neg ray distance doesn't affect results
140  // Location: Positive Y Surface of Volume 2
141  { { 0.6, 0.25000000000001, 0.0 }, { 0.0, 1.0, 0.0 }, 4, 0 }, // 24
142  { { 0.6, 0.25000000000001, 0.0 }, { 0.0, -1.0, 0.0 }, 4, -1 }, // 25
143  // ON-SURFACE POINT TESTS (not checked using PIV loop)
144  // Point on surface of volume 1 w/ random directions
145  { { 3.0, 0.5, 0.0 }, { 0.0, 0.0, 0.0 }, 1, 4 }, // 26
146  // Point on surface of volume 2 w/ random directions
147  { { 0.6, 0.23, 0.0 }, { 0.0, 0.0, 0.0 }, 3, 4 } // 27
148  };
149 
150  int num_tests = sizeof( tests ) / sizeof( FindVolTestResult );
151 
152  EntityHandle volume_found;
153  int vol_id;
154 
155  bool using_find_volume_slow = GTT->get_one_vol_root() == 0;
156 
157  // Skip the last two tests
158  if( using_find_volume_slow )
159  {
160  std::cout << "Skipping last two tests when"
161  << "using find_volume_slow (PIV loop)" << std::endl;
162  num_tests -= 2;
163  }
164 
165  for( int i = 1; i < num_tests + 1; i++ )
166  {
167  const FindVolTestResult& test = tests[i - 1];
168 
169  const double* direction = NULL;
170  if( test.dir[0] != 0.0 || test.dir[1] != 0.0 || test.dir[2] != 0.0 )
171  {
172  direction = test.dir;
173  }
174 
175  // if we're testing a random direction, run the test many times
176  int num_repeats = direction ? 1 : 100;
177  for( int j = 0; j < num_repeats; j++ )
178  {
179  rval = GQT->find_volume( test.pnt, volume_found, direction );
180  // if not found, we will check later
181  if( rval != MB_ENTITY_NOT_FOUND )
182  {
183  MB_CHK_SET_ERR_CONT( rval, "Failed in find_volume" );
184  }
185 
186  rval = id_lookup( volume_found, vol_id );MB_CHK_SET_ERR_CONT( rval, "Failed in id lookup" );
187 
188  std::cout << "Test " << i << ". Volume found id: " << vol_id << "\n";
189  // make sure at least one of these checks passed
190  CHECK( vol_id == test.resultA || vol_id == test.resultB );
191 
192  // reset result and id for safety
193  volume_found = 0;
194  vol_id = -1;
195  } // repeat loop
196  } // test loop
197 }

References CHECK, ErrorCode, moab::GeomQueryTool::find_volume(), moab::GeomTopoTool::get_one_vol_root(), GQT, GTT, id_lookup(), MB_CHK_SET_ERR_CONT, MB_ENTITY_NOT_FOUND, num_tests, and test.

Referenced by main().

◆ id_lookup()

ErrorCode id_lookup ( EntityHandle  eh,
int &  id 
)

Definition at line 51 of file gqt_findvol_test.cpp.

52 {
53  ErrorCode rval;
54  if( !id_tag )
55  {
56  id_tag = MBI->globalId_tag();
57  }
58 
59  rval = MBI->tag_get_data( id_tag, &eh, 1, (void*)&id );MB_CHK_SET_ERR( rval, "Failed to lookup volume id" );
60 
61  return MB_SUCCESS;
62 }

References ErrorCode, moab::Core::globalId_tag(), id_tag, MB_CHK_SET_ERR, MB_SUCCESS, MBI, and moab::Core::tag_get_data().

Referenced by find_volume_tests().

◆ main()

int main ( )

Definition at line 25 of file gqt_findvol_test.cpp.

26 {
27 
28  MBI = new Core();
29  ErrorCode rval = MBI->load_file( input_file.c_str() );MB_CHK_SET_ERR( rval, "Failed to load test file" );
30 
31  GTT = new GeomTopoTool( MBI );
32  GQT = new GeomQueryTool( GTT );
33 
34  // initialize the rest of the GQT
35  GQT->initialize();
36 
37  int result = 0;
38 
39  // with no global OBB tree (will defer to find_volume_slow)
40  result += RUN_TEST( find_volume_tests );
41 
42  // build OBBs with one-vol tree
43  GTT->construct_obb_trees( true );
44 
45  // using the global OBB tree
46  result += RUN_TEST( find_volume_tests );
47 
48  return result;
49 }

References moab::GeomTopoTool::construct_obb_trees(), ErrorCode, find_volume_tests(), GQT, GTT, moab::GeomQueryTool::initialize(), input_file, moab::Core::load_file(), MB_CHK_SET_ERR, MBI, and RUN_TEST.

Variable Documentation

◆ GQT

◆ GTT

Definition at line 16 of file gqt_findvol_test.cpp.

Referenced by build_cube(), check_tree(), find_volume_tests(), heappermute(), and main().

◆ id_tag

◆ input_file

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

Definition at line 21 of file gqt_findvol_test.cpp.

Referenced by main().

◆ MBI

Core* MBI

Definition at line 15 of file gqt_findvol_test.cpp.

Referenced by id_lookup(), and main().