SheafSystem  0.0.0.0
d_tree_point_locator_path.impl.h
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #ifndef D_TREE_POINT_LOCATOR_PATH_IMPL_H
22 #define D_TREE_POINT_LOCATOR_PATH_IMPL_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef D_TREE_POINT_LOCATOR_PATH_H
29 #include "SheafSystem/d_tree_point_locator_path.h"
30 #endif
31 
32 #ifndef ASSERT_CONTRACT_H
33 #include "SheafSystem/assert_contract.h"
34 #endif
35 
36 #ifndef D_BOUNDING_BOX_H
37 #include "SheafSystem/d_bounding_box.h"
38 #endif
39 
40 #ifndef STD_BITSET_H
41 #include "SheafSystem/std_bitset.h"
42 #endif
43 
44 #ifndef STD_LIMITS_H
45 #include "SheafSystem/std_limits.h"
46 #endif
47 
48 //#undef DIAGNOSTIC_OUTPUT
49 //#define DIAGNOSTIC_OUTPUT
50 
51 namespace geometry
52 {
53 
54 // ============================================================================
55 // D_TREE_POINT_LOCATOR_PATH FACET
56 // ============================================================================
57 
58 // PUBLIC MEMBER FUNCTIONS
59 
60 template <int DC, int DB>
61 d_tree_point_locator_path<DC, DB>&
64 {
65  if(&xother != this)
66  {
67  _height = xother._height;
68  _path = xother._path;
69  }
70  return *this;
71 }
72 
73 template <int DC, int DB>
74 bool
76 invariant() const
77 {
78  invariance(height() <= max_height());
79  invariance(depth() == max_height() - height());
80  invariance(max_depth() == max_height());
81 
82  return true;
83 }
84 
85 template <int DC, int DB>
88 {
89  *this = xother;
90 }
91 
92 
93 template <int DC, int DB>
96 {}
97 
98 
99 template <int DC, int DB>
102  const d_tree_point_locator<DC, DB>* xtree)
103 {
104  // Preconditions:
105 
106  // Body:
107 
108  _path = xpt;
109  _tree = xtree;
110 
111  reset();
112 
113  // Postconditions:
114 
115  ensure(depth() == 0);
116  ensure(tree() == xtree);
117 
118  // Exit:
119 
120  return;
121 }
122 
123 template <int DC, int DB>
126 {
127  // Preconditions:
128 
129  // Body:
130 
131  // _path initialized by default.
132 
133  _tree = xtree;
134 
135  reset();
136 
137  // Postconditions:
138 
139  ensure(depth() == 0);
140  ensure(tree() == xtree);
141 
142  // Exit:
143 
144  return;
145 }
146 
147 template <int DC, int DB>
150 depth() const
151 {
152  size_type result = max_height() - _height;
153 
154  // Postconditions:
155 
156  ensure(result <= max_depth());
157 
158  return result;
159 }
160 
161 template <int DC, int DB>
164 height() const
165 {
166  size_type result = _height;
167 
168  // Postconditions:
169 
170  ensure(result <= max_height());
171 
172  return result;
173 }
174 
175 template <int DC, int DB>
179 {
181  return result;
182 }
183 
184 template <int DC, int DB>
188 {
189  return max_height();
190 }
191 
192 template <int DC, int DB>
195 tree() const
196 {
197  return const_cast<d_tree_point_locator<DC, DB>*>(_tree);
198 }
199 
200 template <int DC, int DB>
203 head() const
204 {
205  size_type result;
206 
207  // Preconditions:
208 
209  // Body:
210 
211  result = _path.branch(_height);
212 
213  // Postconditions:
214 
215  ensure(result < DEGREE);
216 
217  // Exit:
218 
219  return result;
220 }
221 
222 template <int DC, int DB>
223 void
226 {
227  // Preconditions:
228 
229  require(depth() > 0);
230 
231  // Body:
232 
233  define_old_variable(size_type old_depth = depth());
234 
235  _height++;
236 
237  // Postconditions:
238 
239  ensure(depth() == old_depth - 1);
240 
241  // Exit:
242 
243  return;
244 }
245 
246 template <int DC, int DB>
247 void
250 {
251  // Preconditions:
252 
253  require(depth() < max_depth());
254 
255  // Body:
256 
257  define_old_variable(size_type old_depth = depth());
258 
259  _height--;
260 
261  // Postocnditions:
262 
263  ensure(depth() == old_depth + 1);
264 
265  // Exit:
266 
267  return;
268 }
269 
270 template <int DC, int DB>
271 void
274 {
275  // Preconditions:
276 
277  require(xhead < DEGREE);
278 
279  // Body:
280 
281  _path.put_branch(_height, xhead);
282 
283  // Postconditions:
284 
285  ensure(head() == xhead);
286 
287  // Exit:
288 
289  return;
290 }
291 
292 template <int DC, int DB>
293 void
296 {
297  // Preconditions:
298 
299  // Body:
300 
301  _height = max_height();
302 
303  // Postconditions:
304 
305  ensure(depth() == 0);
306 
307  // Exit:
308 
309  return;
310 }
311 
312 template <int DC, int DB>
313 bool
316 {
317  bool result;
318 
319  // Preconditions:
320 
321  require(xbox != 0);
322 
323  // This intersects xbox iff for i in [0, DC):
324  // (xbox->lb() <= _path) && (xbox->ub() >= _path),
325  // where the comparisons are done using only the bits in the
326  // current path, that is, the bits at height >= the current height.
327  // This is implemented by right shifting the tree coordinates by _height
328  // and then doing the usual numerical comparisons.
329 
330  // The path to the root should intersect all boxes, but this comparison
331  // will only return true if the leftmost bit of all box bounds is 0.
332  // So using this comparison relies on the invariant that the tree coordinates
333  // in _path and in the box lb and ub are always < d_bin_coordinates::ub().
334 
335  d_bin_coordinates<DC, DB> lbox_lb(xbox->lb());
336  lbox_lb >>= _height;
337 
338  d_bin_coordinates<DC, DB> lbox_ub(xbox->ub());
339  lbox_ub >>= _height;
340 
341  d_bin_coordinates<DC, DB> lpath(_path);
342  lpath >>= _height;
343 
344  result = (lbox_lb <= lpath) && (lpath <= lbox_ub);
345 
346 #ifdef DIAGNOSTIC_OUTPUT
347 
348  cout << "height= " << _height << endl;
349  cout << "unshifted:" << endl;
350  cout << xbox->lb() << endl;
351  cout << _path << endl;
352  cout << xbox->ub() << endl;
353  cout << "shifted:" << endl;
354  cout << lbox_lb << endl;
355  cout << lpath << endl;
356  cout << lbox_ub << endl;
357  cout << "result= " << boolalpha << result << noboolalpha << endl;
358  cout << endl;
359 #endif
360 
361  // Postconditions:
362 
363  // Exit:
364 
365  return result;
366 }
367 
368 template <int DC, int DB>
371 path() const
372 {
373  return _path;
374 }
375 
376 template <int DC, int DB>
380 {
381  return DEGREE;
382 }
383 
384 template <int DC, int DB>
387 {}
388 
389 
390 // ===========================================================
391 // NON-MEMBER FUNCTIONS
392 // ===========================================================
393 
394 template <int DC, int DB>
395 std::ostream&
396 operator<<(std::ostream &os, const d_tree_point_locator_path<DC, DB>& xpath)
397 {
398  os << "height = " << xpath.height()
399  << ", max_height = " << xpath.max_height()
400  << ", head = " << xpath.head()
401  << ", path = " << xpath.path()
402  << std::endl;
403 
404  return os;
405 }
406 
407 } // namespace geometry
408 
409 #endif // ifndef D_TREE_POINT_LOCATOR_PATH_IMPL_H
static size_type max_depth()
The depth of the head of the longest representable path.
size_type depth() const
The current depth.
void ascend()
Ascend one level in the path.
size_type head() const
The branch index of the head of the path.
d_tree_point_locator_path< DC, DB > & operator=(const d_tree_point_locator_path< DC, DB > &xother)
Assignment operator.
static size_type leftmost_bit_id()
The index of the leftmost bit.
const d_bin_coordinates< DC, DB > & ub() const
The upper bound; the upper, right, rear corner.
Fixed point relative coordinates for a tree domain.
size_type height() const
The current height.
A point location query in domains with global coordinate dimension dc and local coordinate dimension ...
const d_bin_coordinates< DC, DB > & lb() const
The lower bound; the lower, left, front corner.
bool intersects(const d_bounding_box< DC, DB > *xbox) const
True if the tree box represented by the current head intersects the box with lower bound xlb and uppe...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
A bounding box that can be strung together into a list.
static size_type degree()
The degree of the tree this is a path for.
const d_bin_coordinates< DC, DB > & path() const
The representation of the path.
virtual bool invariant() const
Class invariant.
static size_type max_height()
The height of the root of the longest representable path.
A path in an d_tree_point_locator search structure.
void descend()
Descend one level in the path.
void put_head(size_type xhead)
Set the current head to xhead.
d_tree_point_locator< DC, DB > * tree() const
The tree this is a path in.
sheaf::size_type size_type
An unsigned integral type used to represent sizes and capacities.
Namespace for geometry component of sheaf system.
Definition: field_vd.h:54