SheafSystem  0.0.0.0
d_array_point_locator.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_ARRAY_POINT_LOCATOR_IMPL_H
22 #define D_ARRAY_POINT_LOCATOR_IMPL_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef D_ARRAY_POINT_LOCATOR_H
29 #include "SheafSystem/d_array_point_locator.h"
30 #endif
31 
32 #ifndef D_BIN_POINT_LOCATOR_IMPL_H
33 #include "SheafSystem/d_bin_point_locator.impl.h"
34 #endif
35 
36 namespace geometry
37 {
38 
39 // ===========================================================
40 // D_BIN_POINT_LOCATOR FACET
41 // ===========================================================
42 
43 // PUBLIC MEMBER FUNCTIONS
44 
45 template <int DC, int DB>
49 {
50  // Preconditions:
51 
52  require(xpt != 0);
53  require(xpt_ub >= this->dc());
54  require(this->domain_contains(xpt, xpt_ub));
55 
56  // Body:
57 
59  this->relative_position_pa(xpt, xpt_ub, lcoord);
60 
61  const box_list_type& result = _bins[bin_id(lcoord)];
62 
63  // Postconditions:
64 
65  // Exit:
66 
67  return result;
68 }
69 
70 template <int DC, int DB>
71 bool
74 {
75  bool result = true;
76 
77  // Preconditions:
78 
79  require(xbox != 0);
80 
81  // Body:
82 
83  // Xbox has been inserted in this if and only if it has bin inserted in
84  // every bin that it overlaps. So all we have to check is one bin;
85  // the one containg the lower bound is convenient.
86 
87  box_list_type& llist = _bins[bin_id(xbox->lb())];
88  typename box_list_type::const_iterator itr = llist.begin();
89  while((itr != llist.end()) && (*itr != xbox))
90  {
91  ++itr;
92  }
93 
94  result = (itr != llist.end());
95 
96  // Postconditions:
97 
98 
99  // Exit:
100 
101  return result;
102 }
103 
104 
105 
106 
107 template <int DC, int DB>
108 void
111 {
112  // Preconditions:
113 
114  // Body:
115 
116  for(size_type i=0; i<_bins.ct(); i++)
117  {
118  _bins[i].clear();
119  }
120 
121  this->_box_ct = 0;
122 
123  // Postconditions:
124 
125  ensure(this->is_empty());
126 
127  // Exit:
128 
129  return;
130 }
131 
132 // ===========================================================
133 // D_ARRAY_POINT_LOCATOR FACET
134 // ===========================================================
135 
136 template <int DC, int DB>
138 d_array_point_locator(sec_ed& xcoords, const block<size_type>& xbin_ub, bool xpopulate, size_type xeval_capacity)
139  : d_bin_point_locator<DC, DB>::d_bin_point_locator(xcoords)
140 {
141  // Preconditions:
142 
143  require(xcoords.state_is_read_accessible());
144  require(xcoords.schema().df() == DC);
145  require(xbin_ub.ct() >= DC);
146  require_for_all(i, 0, xbin_ub.ct(), xbin_ub[i] > 0);
147 
148  // Body:
149 
150  for(int i=0; i<DC; i++)
151  {
152  this->_bin_ub[i] = xbin_ub[i];
153  }
154 
155  this->update(xpopulate, xeval_capacity);
156 
157  // Postconditions:
158 
159 
160  // Exit:
161 
162  return;
163 }
164 
165 template <int DC, int DB>
167 d_array_point_locator(sec_ed& xcoords, bool xpopulate, size_type xeval_capacity)
168  : d_bin_point_locator<DC, DB>::d_bin_point_locator(xcoords)
169 {
170  // Preconditions:
171 
172  require(xcoords.state_is_read_accessible());
173  require(xcoords.schema().df() == DC);
174 
175  // Body:
176 
177  // Set _bin_ub to the dc()-th root of the number of evaluation members.
178 
179  double leval_ct = static_cast<double>(xcoords.schema().evaluation_ct());
180  size_type lbin_ub =
181  static_cast<size_type>(exp(log(leval_ct)/static_cast<double>(DC)));
182 
183  // Make sure ub is at least 1.
184 
185  lbin_ub = (lbin_ub > 1) ? lbin_ub : 1;
186 
187 
188  for(int i=0; i<DC; i++)
189  {
190  this->_bin_ub[i] = lbin_ub;
191  }
192 
193  this->update(xpopulate, xeval_capacity);
194 
195  // Postconditions:
196 
197 
198  // Exit:
199 
200  return;
201 }
202 
203 
204 template <int DC, int DB>
207 {
208  // Preconditions:
209 
210  // Body:
211 
212  // Nothing to do.
213 
214  // Postconditions:
215 
216  // Exit:
217 
218  return;
219 }
220 
221 template <int DC, int DB>
222 size_type
224 size() const
225 {
226  size_type result;
227 
228  // Preconditions:
229 
230 
231  // Body:
232 
233  result = _bins.ct();
234 
235  // Postconditions:
236 
237  ensure(result > 0);
238 
239  // Exit:
240 
241  return result;
242 }
243 
244 template <int DC, int DB>
245 size_type
247 capacity() const
248 {
249  size_type result;
250 
251  // Preconditions:
252 
253 
254  // Body:
255 
256  result = _bins.ub();
257 
258  // Postconditions:
259 
260  ensure(result > 0);
261 
262  // Exit:
263 
264  return result;
265 }
266 
267 
268 template <int DC, int DB>
269 void
271 to_stream(std::ostream& xos) const
272 {
273  // Preconditions:
274 
275  // Body:
276 
277  using namespace std;
278 
279  xos << "lb =";
280  for(int i=0; i<this->dc(); i++)
281  {
282  xos << " " << this->lb()[i];
283  }
284  xos << endl;
285 
286  xos << "ub =";
287  for(int i=0; i<this->dc(); i++)
288  {
289  xos << " " << this->ub()[i];
290  }
291  xos << endl;
292 
293  xos << "bin ct: " << this->_bins.ct() << endl;
294  xos << "bins: " << endl;
295  for(size_type i=0; i<this->_bins.ct(); ++i)
296  {
297  xos << "bin " << i << endl;
298  xos << this->_bins[i] << endl;
299  }
300 
301  // Postconditions:
302 
303  // Exit:
304 
305  return;
306 }
307 
308 
309 // PROTECTED MEMBER FUNCTIONS
310 
311 
312 template <int DC, int DB>
313 void
316 {
317  // Preconditions:
318 
319  require(this->is_empty());
320 
321  // Body:
322 
323  // Compute the bin size.
324 
325  for(int i=0; i<DC; i++)
326  {
327  this->_bin_size[i] = (this->_ub[i] - this->_lb[i])/this->_bin_ub[i];
328  }
329 
330  // Compute the reciprocal of the smallest bin size.
331  // Used for efficiency in relative_position_pa().
332 
334  for(int i=0; i<DC; i++)
335  {
336  this->_one_over_min_bin_size[i] = 1.0/this->_bin_size[i];
337  }
338 
339  // Reset the size of the bin array.
340 
341  size_type lbin_ct = 1;
342  for(int i=0; i<DC; i++)
343  {
344  lbin_ct *= this->_bin_ub[i];
345  }
346 
347  _bins.reserve(lbin_ct);
348  _bins.set_ct(lbin_ct);
349 
352 
354 
355  // Postconditions:
356 
357  // Exit:
358 
359  return;
360 }
361 
362 template <int DC, int DB>
363 size_type
366 {
367  return (xi*this->_bin_ub[1] + xj);
368 };
369 
370 template <int DC, int DB>
371 size_type
374 {
375  return (xi*this->_bin_ub[1] + xj)*this->_bin_ub[2] + xk;
376 };
377 
378 
379 // ===========================================================
380 // POINT_LOCATOR FACET
381 // ===========================================================
382 
383 // PUBLIC MEMBER FUNCTIONS
384 
385 template <int DC, int DB>
386 bool
388 invariant() const
389 {
390  bool result = true;
391 
392  invariance(size() > 0);
393  invariance(capacity() > 0);
394 
395 
396  return result;
397 }
398 
399 
400 // ===========================================================
401 // NON-MEMBER FUNCTIONS
402 // ===========================================================
403 
404 template <int DC, int DB>
405 std::ostream&
406 operator<<(std::ostream& xos, const d_array_point_locator<DC, DB>& xpl)
407 {
408  // Preconditions:
409 
410  // Body:
411 
412  xpl.to_stream(xos);
413 
414  // Postconditions:
415 
416  // Exit:
417 
418  return xos;
419 }
420 
421 template <int DC, int DB>
422 std::ostream&
423 operator<<(std::ostream& xos, const singly_linked_list<const d_bounding_box<DC, DB>*>& xbl)
424 {
425  // Preconditions:
426 
427  // Body:
428 
429  using namespace std;
430 
432 
433  for(typename list_type::const_iterator i = xbl.begin(); i != xbl.end(); ++i)
434  {
435  xos << **i << endl;
436  }
437 
438  // Postconditions:
439 
440  // Exit:
441 
442  return xos;
443 }
444 
445 } // namespace geometry
446 
447 #endif // D_ARRAY_POINT_LOCATOR_IMPL_H
virtual void update()
Updates the search structure to the current values of coordinates(); synonym for update(true);.
singly_linked_list< const d_bounding_box< DC, DB > * > box_list_type
The type of box list.
size_type size() const
The number of bins used by the search structure.
size_type ct() const
The number of items currently in use.
virtual bool invariant() const
Class invariant.
block< sec_vd_value_type > _one_over_min_bin_size
Reciprocal of the dimensions of the smallest bins.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
bool is_empty() const
True if this contains no bounding boxes.
STL namespace.
const block< sec_vd_value_type > & lb() const
The lower bound of the domain defined by coordinates().
iterator begin()
Returns an iterator to the first element of the container.
Fixed point relative coordinates for a tree domain.
block< box_list_type > _bins
The search structure; a d-dimensional array of bins.
static int_type ub()
The upper bound for components.
A section of a fiber bundle with a d-dimensional Euclidean vector space fiber.
Definition: sec_ed.h:47
d_array_point_locator()
Default constructor; disabled.
block< sec_vd_value_type > _lb
The lower bound of the domain.
block< size_type > _bin_ub
The upper bound for the bin index.
virtual bool contains_box(d_bounding_box< DC, DB > *xbox) const
True if xbox is in this.
const d_bin_coordinates< DC, DB > & lb() const
The lower bound; the lower, left, front corner.
size_type bin_id(const d_bin_coordinates< DC, DB > &xcoord) const
The single index (offset) associated with tree coordinates xcoord.
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.
iterator end()
Returns an iterator to the element following the last element of the container.
SHEAF_DLL_SPEC void log(const sec_at0 &x0, sec_at0 &xresult, bool xauto_access)
Compute log of x0 (log(x0)) (pre-allocated version).
Definition: sec_at0.cc:1434
virtual const box_list_type & box_list(sec_vd_value_type *xpt, size_type xpt_ub) const
The list of bounding boxes which may contain xpt.
void update_bins()
Resets this with bounds xlb, xub, and xbin_ub. If xbin_ub == 0; use default_bin_ub().
virtual section_space_schema_member & schema()
The restricted schema for this (mutable version).
int dc() const
The spatial dimension of the domain; the dimension of the global coordinates.
int evaluation_ct() const
The number of members in the intersection of the evaluation subposet and the down set of the base spa...
block< sec_vd_value_type > _ub
The upper bound of the domain.
virtual void clear()
Clear this of all bounding boxes.
const block< sec_vd_value_type > & ub() const
The upper bound of the domain defined by coordinates().
int df() const
The dimension of the fiber space component.
SHEAF_DLL_SPEC void exp(const sec_at0 &x0, sec_at0 &xresult, bool xauto_access)
Compute exp of x0 (exp(x0)) (pre-allocated version).
Definition: sec_at0.cc:1310
void to_stream(std::ostream &xos) const
Inserts this in ostream xos.
size_type capacity() const
The number of bins allocated for use by the search structure.
Namespace for geometry component of sheaf system.
Definition: field_vd.h:54
vd_value_type sec_vd_value_type
The type of component in the value of a section at a point.
Definition: fiber_bundle.h:73
An abstract point location query in domains with global coordinate dimension dc and local coordinate ...
block< sec_vd_value_type > _bin_size
The dimensions of the smallest bins.
Wrapper class for forward_list or slist depending on compiler. The class replicates the minimum subse...