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 54 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)
 
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
 
MinMaxPoints getMinMaxPoints () 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
 

Constructor & Destructor Documentation

◆ AABB() [1/2]

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_TYPEa point type supporting accessing the coordinates via operator[]

Definition at line 63 of file AABB.h.

65 {
66 assert(!ids.empty());
67 init(pnts[ids[0]]);
68 for (std::size_t i = 1; i < ids.size(); ++i)
69 {
70 updateWithoutEnlarge(*(pnts[ids[i]]));
71 }
72 enlarge();
73 }
void init(PNT_TYPE const &pnt)
Definition: AABB.h:226
void updateWithoutEnlarge(PNT_TYPE const &p)
Definition: AABB.h:245
void enlarge(std::bitset< 3 > to_update=7)
Definition: AABB.h:213
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition: Mesh.h:313

References enlarge(), MeshLib::views::ids, init(), and updateWithoutEnlarge().

◆ AABB() [2/2]

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
firstthe input iterator to the initial position in the sequence
lastthe 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 86 of file AABB.h.

87 {
88 if (std::distance(first, last) <= 0)
89 {
91 "AABB::AABB(InputIterator first, InputIterator last): first > "
92 "last");
93 }
94 init(*first);
95 InputIterator it(first);
96 while (it != last)
97 {
99 it++;
100 }
101 enlarge();
102 }
#define OGS_FATAL(...)
Definition: Error.h:26

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

Member Function Documentation

◆ 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_aabbthe AABB to test with
Returns
true if the other AABB is contained in the AABB represented by this object

Definition at line 195 of file AABB.h.

196 {
197 return containsPoint(other_aabb.getMinPoint(), 0) &&
198 containsPoint(other_aabb.getMaxPoint(), 0);
199 }
bool containsPoint(T const &pnt, double eps) const
Definition: AABB.h:142

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 142 of file AABB.h.

143 {
144 if (pnt[0] < _min_pnt[0] - eps || _max_pnt[0] + eps <= pnt[0])
145 {
146 return false;
147 }
148 if (pnt[1] < _min_pnt[1] - eps || _max_pnt[1] + eps <= pnt[1])
149 {
150 return false;
151 }
152 if (pnt[2] < _min_pnt[2] - eps || _max_pnt[2] + eps <= pnt[2])
153 {
154 return false;
155 }
156 return true;
157 }
Eigen::Vector3d _min_pnt
Definition: AABB.h:202
Eigen::Vector3d _max_pnt
Definition: AABB.h:205

References _max_pnt, and _min_pnt.

Referenced by containsAABB(), main(), and markFaults().

◆ containsPointXY()

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

Definition at line 160 of file AABB.h.

161 {
162 if (pnt[0] < _min_pnt[0] || _max_pnt[0] <= pnt[0])
163 {
164 return false;
165 }
166 if (pnt[1] < _min_pnt[1] || _max_pnt[1] <= pnt[1])
167 {
168 return false;
169 }
170 return true;
171 }

References _max_pnt, and _min_pnt.

Referenced by MeshLib::Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh().

◆ 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 213 of file AABB.h.

214 {
215 for (std::size_t k = 0; k < 3; ++k)
216 {
217 if (to_update[k])
218 {
219 _max_pnt[k] = std::nextafter(
220 _max_pnt[k], std::numeric_limits<double>::max());
221 }
222 }
223 }

References _max_pnt.

Referenced by AABB(), and update().

◆ getMaxPoint()

◆ getMinMaxPoints()

MinMaxPoints GeoLib::AABB::getMinMaxPoints ( ) const
inline

Definition at line 173 of file AABB.h.

173{ return {_min_pnt, _max_pnt}; }

References _max_pnt, and _min_pnt.

◆ getMinPoint()

◆ init() [1/2]

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

Definition at line 234 of file AABB.h.

235 {
236 init(*pnt);
237 }

References init().

◆ init() [2/2]

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

Definition at line 226 of file AABB.h.

227 {
228 _min_pnt[0] = _max_pnt[0] = pnt[0];
229 _min_pnt[1] = _max_pnt[1] = pnt[1];
230 _min_pnt[2] = _max_pnt[2] = pnt[2];
231 }

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 107 of file AABB.h.

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

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 267 of file AABB.h.

268 {
269 update(*pnt);
270 }
bool update(PNT_TYPE const &p)
Definition: AABB.h:107

References update().

◆ updateWithoutEnlarge() [1/2]

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

Definition at line 261 of file AABB.h.

262 {
264 }

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
ppoint that will possibly change the bounding box points

Definition at line 245 of file AABB.h.

246 {
247 for (std::size_t k(0); k < 3; k++)
248 {
249 if (p[k] < _min_pnt[k])
250 {
251 _min_pnt[k] = p[k];
252 }
253 if (p[k] >= _max_pnt[k])
254 {
255 _max_pnt[k] = p[k];
256 }
257 }
258 }

References _max_pnt, and _min_pnt.

Referenced by AABB(), and updateWithoutEnlarge().

Member Data Documentation

◆ _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 205 of file AABB.h.

Referenced by containsPoint(), containsPointXY(), enlarge(), getMaxPoint(), getMinMaxPoints(), 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 202 of file AABB.h.

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


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