MOAB: Mesh Oriented datABase  (version 5.5.0)
gqt_findvol_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 
10 #include "moab/GeomQueryTool.hpp"
11 #include "moab/GeomTopoTool.hpp"
12 
13 using namespace moab;
14 
18 
19 Tag id_tag = 0;
20 
21 const std::string input_file = TestDir + "unittest/find_vol_test_geom.h5m";
22 
23 void find_volume_tests();
24 
25 int main()
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 }
50 
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 }
63 
64 // Test case structure
65 // It is possible in some cases
66 // to have 2 correct answers (overlaps)
67 // A result of zero means no volume should be found
68 
70 {
71  double pnt[3];
72  double dir[3];
73  int resultA;
74  int resultB;
75 };
76 
77 // Test Geometry
78 
79 // The test geometry consists of 3 cubes, one of which
80 // overlaps another. Volumes 1 and 2 have edges with
81 // length 1. Volume 3 has an edge length of 0.5.
82 // Volume 1 is centered at (3, 0, 0). Volume 2 is
83 // centered on the origin. Volume 3 is centered on (0.5, 0, 0).
84 // Volume 4 is the implicit complement.
85 //
86 // XY slice of geometry:
87 //
88 // ########################### #############################
89 // # # # #
90 // # # # #
91 // # #################### # #
92 // # # # # # #
93 // # Vol 2 # # Vol 3 # # Vol 1 #
94 // # # # # # #
95 // # # # # # #
96 // # #################### # #
97 // # # # #
98 // # # Vol 4 (IC) # #
99 // ########################### #############################
100 
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 }