SheafSystem  0.0.0.0
point_locator.cc
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 
22 #include "SheafSystem/point_locator.h"
23 
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/chart_point_3d.h"
26 #include "SheafSystem/error_message.h"
27 #include "SheafSystem/preorder_iterator.h"
28 #include "SheafSystem/sec_at1_space.h"
29 #include "SheafSystem/sec_ed.h"
30 #include "SheafSystem/std_iostream.h"
31 
32 using namespace std;
33 using namespace geometry; // Workaround for MS C++ bug.
34 using namespace fiber_bundle::sec_vd_algebra;
35 
36 //#define DIAGNOSTIC_OUTPUT 1
37 
38 
39 // ===========================================================
40 // CANONICAL FACET
41 // ===========================================================
42 
43 // PUBLIC MEMBER FUNCTIONS
44 
45 bool
47 invariant() const
48 {
49  bool result = true;
50 
51  invariance(dc() == coordinates().schema().df());
52 
53  return result;
54 }
55 
56 
59 {
60  // Preconditions:
61 
62  // Body:
63 
64  // Nothing to do.
65 
66  // Postconditions:
67 
68  // Exit:
69 
70  return;
71 }
72 
73 
74 // ===========================================================
75 // POINT_LOCATOR FACET
76 // ===========================================================
77 
78 // PUBLIC MEMBER FUNCTIONS
79 
82 coordinates() const
83 {
84  // Preconditions:
85 
86 
87  // Body:
88 
89  sec_ed& result = _coordinates;
90 
91  // Postconditions:
92 
93 
94  // Exit:
95 
96  return result;
97 }
98 
101 lb() const
102 {
103  // Preconditions:
104 
105 
106  // Body:
107 
108  const block<sec_vd_value_type>& result = _lb;
109 
110  // Postconditions:
111 
112  // Exit:
113 
114  return result;
115 }
116 
117 
120 ub() const
121 {
122  // Preconditions:
123 
124 
125  // Body:
126 
127  const block<sec_vd_value_type>& result = _ub;
128 
129  // Postconditions:
130 
131  // Exit:
132 
133  return result;
134 }
135 
136 int
138 dc() const
139 {
140  int result;
141 
142  // Preconditions:
143 
144  // Body:
145 
146  result = _dc;
147 
148  // Postconditions:
149 
150 
151  // Exit:
152 
153  return result;
154 }
155 
156 int
158 db() const
159 {
160  int result;
161 
162  // Preconditions:
163 
164  // Body:
165 
166  result = _db;
167 
168  // Postconditions:
169 
170 
171  // Exit:
172 
173  return result;
174 }
175 
176 bool
179 {
180  bool result = true;
181 
182  // Preconditions:
183 
184  require(xpt != 0);
185  require(xpt_ub >= dc());
186 
187  // Body:
188 
189  for(int i=0; i<dc(); i++)
190  {
191  result = result && ((_lb[i] <= xpt[i]) && (xpt[i] <= _ub[i]));
192  }
193 
194  // Postconditions:
195 
196  ensure_for_all(i, 0, dc(),
197  result ? ((lb()[i] <= xpt[i]) && (xpt[i] <= ub()[i])) : true);
198 
199  // Exit:
200 
201  return result;
202 }
203 
204 
205 void
208 {
209  // Preconditions:
210 
211  require(coordinates().state_is_read_accessible());
212 
213  // Body:
214 
215  is_abstract();
216 
217  // Postconditions:
218 
219 
220  // Exit:
221 
222  return;
223 }
224 
225 void
228  size_type xvalue_ub,
229  chart_point& xresult)
230 {
231  // Preconditions:
232 
233 
234  // Body:
235 
236  is_abstract();
237 
238  // Postconditions:
239 
240 
241  // Exit:
242 
243  return;
244 }
245 
246 void
249  size_type xvalue_ub,
250  block<chart_point_3d>& xresult)
251 {
252  // Preconditions:
253 
254 
255  // Body:
256 
257  is_abstract();
258 
259  // Postconditions:
260 
261  ensure_for_all(i, 0, xresult.ct(), xresult[i].is_valid());
262 
263  // Exit:
264 
265  return;
266 }
267 
268 void
271  size_type xvalue_ub,
272  block<branch_point_pair>& xresult)
273 {
274  // Preconditions:
275 
276 
277  // Body:
278 
279  define_old_variable(int old_xresult_ct = xresult.ct());
280 
281  is_abstract();
282 
283  // Postconditions:
284 
285  ensure(xresult.ct() >= old_xresult_ct);
286  ensure_for_all(i, old_xresult_ct, xresult.ct(),
287  coordinates().host()->contains_member(xresult[i].first, false));
288  ensure_for_all(i, old_xresult_ct, xresult.ct(), xresult[i].second.is_valid());
289 
290  // Exit:
291 
292  return;
293 }
294 
295 
296 // PROTECTED MEMBER FUNCTIONS
297 
300  : _coordinates(*(new sec_ed())) // Should never be called.
301 {
302  // Preconditions:
303 
304  // Body:
305 
306  not_implemented();
307 
308  // Postconditions:
309 
310  ensure(invariant());
311 
312  // Exit:
313 
314  return;
315 
316 }
317 
318 
321  : _coordinates(xcoords)
322 {
323  // Preconditions:
324 
325  require(xcoords.state_is_read_accessible());
326  require(xcoords.schema().db() <= xcoords.schema().df());
327 
328  // Body:
329 
330  // Set the dimension.
331 
332  _dc = coordinates().schema().df();
333  _db = coordinates().schema().db();
334 
335  _lb.reserve(_dc);
336  _lb.set_ct(_dc);
338 
339 
340  _ub.reserve(_dc);
341  _ub.set_ct(_dc);
343 
344  // Postconditions:
345 
346  ensure(invariant());
347 
348  // Exit:
349 
350  return;
351 }
352 
356 {
357  sec_vd_value_type result;
358 
359  // Preconditions:
360 
361 
362  // Body:
363 
364  sec_vd_value_type a_little =
365  static_cast<sec_vd_value_type>(10.0)*numeric_limits<sec_vd_value_type>::epsilon();
366 
367  if(x == static_cast<sec_vd_value_type>(0.0))
368  {
369  result = a_little;
370  }
371  else if(x < static_cast<sec_vd_value_type>(0.0))
372  {
373  result = x*(static_cast<sec_vd_value_type>(1.0) - a_little);
374  }
375  else
376  {
377  result = x*(static_cast<sec_vd_value_type>(1.0) + a_little);
378  }
379 
380  // Postconditions:
381 
382  ensure(result > x);
383 
384  // Exit:
385 
386  return result;
387 }
388 
392 {
393  sec_vd_value_type result;
394 
395  // Preconditions:
396 
397 
398  // Body:
399 
400  sec_vd_value_type a_little =
401  static_cast<sec_vd_value_type>(10.0)*numeric_limits<sec_vd_value_type>::epsilon();
402 
403  if(x == static_cast<sec_vd_value_type>(0.0))
404  {
405  result = -a_little;
406  }
407  else if(x < static_cast<sec_vd_value_type>(0.0))
408  {
409  result = x*(static_cast<sec_vd_value_type>(1.0) + a_little);
410  }
411  else
412  {
413  result = x*(static_cast<sec_vd_value_type>(1.0) - a_little);
414  }
415 
416  // Postconditions:
417 
418  ensure(result < x);
419 
420  // Exit:
421 
422  return result;
423 }
424 
425 void
428 {
429 #ifdef DIAGNOSTIC_OUTPUT
430  post_information_message("entering update_domain");
431 #endif
432 
433  // Preconditions:
434 
435  require(coordinates().state_is_read_accessible());
436 
437  // Body:
438 
439  // Get the minimum and maximum values of the coordinates.
440 
443 
446 
447  sec_vd lbranch;
448  preorder_iterator lbranch_itr(_coordinates, "jims", DOWN, NOT_STRICT);
449  while(!lbranch_itr.is_done())
450  {
451  lbranch.attach_to_state(_coordinates.host(), lbranch_itr.index());
452 
453  //lbranch.extrema_pa(llb.base(), llb.ub(), lub.base(), lub.ub());
454  extrema(lbranch, llb.base(), llb.ub(), lub.base(), lub.ub());
455 
456  lbranch.detach_from_state();
457 
458  for(int i=0; i<_dc; ++i)
459  {
460  if(llb[i] < _lb[i])
461  {
462  _lb[i] = llb[i];
463  }
464 
465  if(lub[i] > _ub[i])
466  {
467  _ub[i] = lub[i];
468  }
469  }
470 
471  // Move on to the next branch.
472 
473  lbranch_itr.truncate();
474  }
475 
476  // Ensure that domain strictly contains the data bounds.
477  // This avoids numerical precision problems near the boundaries.
478 
479  for(int i=0; i<_dc; ++i)
480  {
481  _lb[i] = slightly_less_than(_lb[i]);
482  _ub[i] = slightly_greater_than(_ub[i]);
483  }
484 
485 
486 #ifdef DIAGNOSTIC_OUTPUT
487  cout << "_lb: " << _lb << endl;
488  cout << "_ub: " << _ub << endl;
489  post_information_message("leaving update_domain");
490 #endif
491 
492  // Postconditions:
493 
494  // Exit:
495 
496  return;
497 }
498 
499 
500 // PRIVATE MEMBER FUNCTIONS
501 
503 point_locator(const point_locator& xother)
504  : _coordinates(xother._coordinates)
505 {
506  // Preconditions:
507 
508 
509  // Body:
510 
511  not_implemented();
512 
513  // Postconditions:
514 
515 
516  // Exit:
517 
518  return;
519 }
520 
522 geometry::point_locator::
523 operator=(const point_locator& xother)
524 {
525 
526  // Preconditions:
527 
528 
529  // Body:
530 
531  not_implemented();
532 
533  // Postconditions:
534 
535 
536  // Exit:
537 
538  return *this;
539 }
540 
541 // ===========================================================
542 // NON-MEMBER FUNCTIONS
543 // ===========================================================
virtual void update()=0
Updates the search structure to the current values of coordinates().
virtual void point_at_value(const sec_vd_value_type *xvalue, size_type xvalue_ub, chart_point &xresult)=0
Finds a chart point at which coordinates() has value xvalue.
void truncate()
Makes this the next member of the subset which is not less than old this, i.e. the depth-first descen...
int _dc
The spatial dimension of the domain; the dimension of the global coordinates.
index_type ub() const
The upper bound on the storage array. The number of items current allocated in the storage array...
size_type ct() const
The number of items currently in use.
sec_ed & coordinates() const
The coordinate section this inverts.
virtual ~point_locator()
Destructor.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
virtual void all_points_at_value(const sec_vd_value_type *xvalue, size_type xvalue_ub, block< chart_point_3d > &xresult)=0
Finds all chart points at which coordinates() has value xvalue and appends them to xresult...
STL namespace.
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
point_locator()
Default constructor.
A point in chart space.
Definition: chart_point.h:52
void update_domain()
Initializes the domain bounds and dimension.
host_type * host() const
The poset this is a member of.
Definition: sec_at1.cc:525
static sec_vd_value_type slightly_less_than(sec_vd_value_type x)
A value slightly less then x.
const block< sec_vd_value_type > & lb() const
The lower bound of the domain defined by coordinates().
static sec_vd_value_type slightly_greater_than(sec_vd_value_type x)
A value slightly greater then x.
A section of a fiber bundle with a d-dimensional Euclidean vector space fiber.
Definition: sec_ed.h:47
const bool NOT_STRICT
Iteration strictness control.
Definition: sheaf.h:102
const bool DOWN
Iteration directions.
Definition: sheaf.h:77
block< sec_vd_value_type > _lb
The lower bound of the domain.
void assign(const_reference_type xitem)
Sets the values of all items to xitem.
pointer_type base() const
The underlying storage array.
void set_ct(size_type xct)
Sets ct() == xct.
int _db
The intrinsic dimension of the domain; the dimension of the local coordinates.
virtual bool invariant() const
Class invariant.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
SHEAF_DLL_SPEC void max(const vd &x0, vd_value_type &xresult, bool xauto_access)
Maximum component of x0, pre-allocated version.
Definition: vd.cc:2097
A section of a fiber bundle with a d-dimensional vector space fiber.
Definition: sec_vd.h:54
bool is_done() const
True if iteration finished.
void detach_from_state()
Detaches field from state it is currently attached to.
Definition: sec_tuple.cc:603
int db() const
The intrinsic dimension of the domain; the dimension of the local coordinates.
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.
block< sec_vd_value_type > _ub
The upper bound of the domain.
SHEAF_DLL_SPEC void extrema(const sec_vd &x0, vd_lite &xmin, vd_lite &xmax, bool xauto_access)
Extrema (pre-allocated version).
Definition: sec_vd.cc:2137
const block< sec_vd_value_type > & ub() const
The upper bound of the domain defined by coordinates().
Namespace containing the algrebra functions for a a section of a fiber bundle with a d-dimensional ve...
Definition: sec_vd.h:691
int db() const
The dimension of the base space component.
int df() const
The dimension of the fiber space component.
void attach_to_state(const namespace_poset *xns, const poset_path &xpath, bool xauto_access=true)
Attach to the state specified by path xpath in the namespace xns.
virtual void branch_points_at_value(const sec_vd_value_type *xvalue, size_type xvalue_ub, block< branch_point_pair > &xresult)=0
Finds one chart point in each branch at which coordinates() has value xvalue and appends them to xres...
An auto_block with a no-initialization initialization policy.
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
bool domain_contains(sec_vd_value_type *xpt, size_type xpt_ub) const
True if the domain contains xpt.
An abstract point location query in domains with global coordinate dimension dc and local coordinate ...
Definition: point_locator.h:52
const scoped_index & index() const
The index of the current member of the iteration.