OGS
GeoLib::AABB Class Reference

## Detailed Description

Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type PNT_TYPE.

Let $$P = \{p_k \in \mathbb{R}^3, \ k=1, \dotsc, n\}$$ a set of 3d points. The bounding volume is described by its lower, left, front point $$\ell$$ and the upper, right, back point $$u$$, i.e. the coordinates of $$\ell$$ and $$u$$ are computed as follows $$\ell_i = \min \limits_{p \in P} p_i$$, $$u_i = \max \limits_{p \in P} p_i$$, respectively. The bounding box consists of half-open intervals $$[\ell_x, u_x) \times [\ell_y, u_y) \times [\ell_z, u_z).$$ The bounding box is enlarged up to the next available floating point number such that all input points are contained in the bounding box.

Definition at line 48 of file AABB.h.

#include <AABB.h>

Inheritance diagram for GeoLib::AABB:
[legend]

## Public Member Functions

template<typename PNT_TYPE >
AABB (std::vector< PNT_TYPE * > const &pnts, std::vector< std::size_t > const &ids)

AABB (AABB const &)=default

template<typename InputIterator >
AABB (InputIterator first, InputIterator last)

template<typename PNT_TYPE >
bool update (PNT_TYPE const &p)

template<typename T >
bool containsPoint (T const &pnt, double eps) const

template<typename T >
bool containsPointXY (T const &pnt) const

Eigen::Vector3d const & getMinPoint () const

Eigen::Vector3d const & getMaxPoint () const

bool containsAABB (AABB const &other_aabb) const

## Private Member Functions

void enlarge (std::bitset< 3 > to_update=7)

template<typename PNT_TYPE >
void init (PNT_TYPE const &pnt)

template<typename PNT_TYPE >
void init (PNT_TYPE *const &pnt)

template<typename PNT_TYPE >
void updateWithoutEnlarge (PNT_TYPE const &p)

template<typename PNT_TYPE >
void updateWithoutEnlarge (PNT_TYPE *const &pnt)

template<typename PNT_TYPE >
void update (PNT_TYPE const *pnt)

## Private Attributes

Eigen::Vector3d _min_pnt

Eigen::Vector3d _max_pnt

## ◆ AABB() [1/3]

template<typename PNT_TYPE >
 GeoLib::AABB::AABB ( std::vector< PNT_TYPE * > const & pnts, std::vector< std::size_t > const & ids )
inline

construction of object, initialization the axis aligned bounding box

Template Parameters
 PNT_TYPE a point type supporting accessing the coordinates via operator[]

Definition at line 57 of file AABB.h.

59  {
60  assert(!ids.empty());
61  init(pnts[ids[0]]);
62  for (std::size_t i = 1; i < ids.size(); ++i)
63  {
64  updateWithoutEnlarge(*(pnts[ids[i]]));
65  }
66  enlarge();
67  }
void init(PNT_TYPE const &pnt)
Definition: AABB.h:221
void updateWithoutEnlarge(PNT_TYPE const &p)
Definition: AABB.h:240
void enlarge(std::bitset< 3 > to_update=7)
Definition: AABB.h:208

References enlarge(), init(), and updateWithoutEnlarge().

## ◆ AABB() [2/3]

 GeoLib::AABB::AABB ( AABB const & )
default

## ◆ AABB() [3/3]

template<typename InputIterator >
 GeoLib::AABB::AABB ( InputIterator first, InputIterator last )
inline

Construction of object using input iterators. In contrast to give a vector this approach is more generic. You can use every (stl) container and C arrays as input for constructing the object.

Attention
{The constructor requires that std::distance(first, last) > 0.}
Parameters
 first the input iterator to the initial position in the sequence last the input iterator to the final position in a container, i.e. [first, last).
Attention
{The iterator last must be reachable from first.}

Definition at line 82 of file AABB.h.

83  {
84  if (std::distance(first, last) <= 0)
85  {
86  OGS_FATAL(
87  "AABB::AABB(InputIterator first, InputIterator last): first > "
88  "last");
89  }
90  init(*first);
91  InputIterator it(first);
92  while (it != last)
93  {
95  it++;
96  }
97  enlarge();
98  }
#define OGS_FATAL(...)
Definition: Error.h:26

References enlarge(), init(), OGS_FATAL, and updateWithoutEnlarge().

## ◆ containsAABB()

 bool GeoLib::AABB::containsAABB ( AABB const & other_aabb ) const
inline

Method checks if the given AABB object is contained within the AABB represented by this object.

Parameters
 other_aabb the AABB to test with
Returns
true if the other AABB is contained in the AABB represented by this object

Definition at line 190 of file AABB.h.

191  {
192  return containsPoint(other_aabb.getMinPoint(), 0) &&
193  containsPoint(other_aabb.getMaxPoint(), 0);
194  }
bool containsPoint(T const &pnt, double eps) const
Definition: AABB.h:138

References containsPoint(), getMaxPoint(), and getMinPoint().

## ◆ containsPoint()

template<typename T >
 bool GeoLib::AABB::containsPoint ( T const & pnt, double eps ) const
inline

check if point is in the axis aligned bounding box

Definition at line 138 of file AABB.h.

139  {
140  if (pnt[0] < _min_pnt[0] - eps || _max_pnt[0] + eps <= pnt[0])
141  {
142  return false;
143  }
144  if (pnt[1] < _min_pnt[1] - eps || _max_pnt[1] + eps <= pnt[1])
145  {
146  return false;
147  }
148  if (pnt[2] < _min_pnt[2] - eps || _max_pnt[2] + eps <= pnt[2])
149  {
150  return false;
151  }
152  return true;
153  }
Eigen::Vector3d _min_pnt
Definition: AABB.h:197
Eigen::Vector3d _max_pnt
Definition: AABB.h:200

References _max_pnt, and _min_pnt.

Referenced by containsAABB(), and markFaults().

## ◆ containsPointXY()

template<typename T >
 bool GeoLib::AABB::containsPointXY ( T const & pnt ) const
inline

Definition at line 156 of file AABB.h.

157  {
158  if (pnt[0] < _min_pnt[0] || _max_pnt[0] <= pnt[0])
159  {
160  return false;
161  }
162  if (pnt[1] < _min_pnt[1] || _max_pnt[1] <= pnt[1])
163  {
164  return false;
165  }
166  return true;
167  }

References _max_pnt, and _min_pnt.

## ◆ enlarge()

 void GeoLib::AABB::enlarge ( std::bitset< 3 > to_update = 7 )
inlineprivate

Enlarge the bounding box the smallest possible amount (modifying the unit in the last place). Only the coordinates of the maximum point are changed such that the half-open property will be preserved.

Definition at line 208 of file AABB.h.

209  {
210  for (std::size_t k = 0; k < 3; ++k)
211  {
212  if (to_update[k])
213  {
214  _max_pnt[k] = std::nextafter(
215  _max_pnt[k], std::numeric_limits<double>::max());
216  }
217  }
218  }

References _max_pnt.

Referenced by AABB(), and update().

## ◆ getMaxPoint()

 Eigen::Vector3d const& GeoLib::AABB::getMaxPoint ( ) const
inline

returns a point that coordinates are maximal for each dimension within the given point set

Returns
a point

Definition at line 181 of file AABB.h.

181 { return _max_pnt; }

References _max_pnt.

## ◆ getMinPoint()

 Eigen::Vector3d const& GeoLib::AABB::getMinPoint ( ) const
inline

returns a point that coordinates are minimal for each dimension for the given point set

Returns
a point

Definition at line 174 of file AABB.h.

174 { return _min_pnt; }

References _min_pnt.

## ◆ init() [1/2]

template<typename PNT_TYPE >
 void GeoLib::AABB::init ( PNT_TYPE *const & pnt )
inlineprivate

Definition at line 229 of file AABB.h.

230  {
231  init(*pnt);
232  }

References init().

## ◆ init() [2/2]

template<typename PNT_TYPE >
 void GeoLib::AABB::init ( PNT_TYPE const & pnt )
inlineprivate

Definition at line 221 of file AABB.h.

222  {
223  _min_pnt[0] = _max_pnt[0] = pnt[0];
224  _min_pnt[1] = _max_pnt[1] = pnt[1];
225  _min_pnt[2] = _max_pnt[2] = pnt[2];
226  }

References _max_pnt, and _min_pnt.

Referenced by AABB(), and init().

## ◆ update() [1/2]

template<typename PNT_TYPE >
 bool GeoLib::AABB::update ( PNT_TYPE const & p )
inline

Checks if the bounding box has to be updated.

Returns
true if AABB is updated.

Definition at line 103 of file AABB.h.

104  {
105  // First component of the pair signals if the minimum point is changed
106  // Second component signals not only if the max point is changed.
107  // Furthermore it is signaled what coordinate (0,1,2) is changed.
108  std::pair<bool, std::bitset<3>> updated(false, 0);
109  for (std::size_t k(0); k < 3; k++)
110  {
111  // if the minimum point is updated pair.first==true
112  if (p[k] < _min_pnt[k])
113  {
114  _min_pnt[k] = p[k];
115  updated.first = true;
116  }
117  // if the kth coordinate of the maximum point is updated
118  // pair.second[k]==true
119  if (p[k] >= _max_pnt[k])
120  {
121  _max_pnt[k] = p[k];
122  updated.second[k] = true;
123  }
124  }
125
126  if (updated.second.any())
127  {
128  enlarge(updated.second);
129  return true;
130  }
131  return updated.first;
132  }

References _max_pnt, _min_pnt, and enlarge().

Referenced by GeoLib::PointVec::uniqueInsert(), and update().

## ◆ update() [2/2]

template<typename PNT_TYPE >
 void GeoLib::AABB::update ( PNT_TYPE const * pnt )
inlineprivate

Definition at line 262 of file AABB.h.

263  {
264  update(*pnt);
265  }
bool update(PNT_TYPE const &p)
Definition: AABB.h:103

References update().

## ◆ updateWithoutEnlarge() [1/2]

template<typename PNT_TYPE >
 void GeoLib::AABB::updateWithoutEnlarge ( PNT_TYPE *const & pnt )
inlineprivate

Definition at line 256 of file AABB.h.

257  {
258  updateWithoutEnlarge(*pnt);
259  }

References updateWithoutEnlarge().

## ◆ updateWithoutEnlarge() [2/2]

template<typename PNT_TYPE >
 void GeoLib::AABB::updateWithoutEnlarge ( PNT_TYPE const & p )
inlineprivate

Private method that is used internally to update the min and max point of the bounding box using point $$p$$ without enlarging the bounding box. Using this method the bounding box of the initial point set is enlarged only once.

Parameters
 p point that will possibly change the bounding box points

Definition at line 240 of file AABB.h.

241  {
242  for (std::size_t k(0); k < 3; k++)
243  {
244  if (p[k] < _min_pnt[k])
245  {
246  _min_pnt[k] = p[k];
247  }
248  if (p[k] >= _max_pnt[k])
249  {
250  _max_pnt[k] = p[k];
251  }
252  }
253  }

References _max_pnt, and _min_pnt.

Referenced by AABB(), and updateWithoutEnlarge().

## ◆ _max_pnt

 Eigen::Vector3d GeoLib::AABB::_max_pnt
private
Initial value:
{std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest()}

Definition at line 200 of file AABB.h.

Referenced by containsPoint(), containsPointXY(), enlarge(), getMaxPoint(), init(), update(), and updateWithoutEnlarge().

## ◆ _min_pnt

 Eigen::Vector3d GeoLib::AABB::_min_pnt
private
Initial value:
{std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(),
std::numeric_limits<double>::max()}

Definition at line 197 of file AABB.h.

Referenced by containsPoint(), containsPointXY(), getMinPoint(), init(), update(), and updateWithoutEnlarge().

The documentation for this class was generated from the following file: