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)
 
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
 

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 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:219
void updateWithoutEnlarge(PNT_TYPE const &p)
Definition: AABB.h:238
void enlarge(std::bitset< 3 > to_update=7)
Definition: AABB.h:206

References enlarge(), 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 80 of file AABB.h.

81 {
82 if (std::distance(first, last) <= 0)
83 {
85 "AABB::AABB(InputIterator first, InputIterator last): first > "
86 "last");
87 }
88 init(*first);
89 InputIterator it(first);
90 while (it != last)
91 {
93 it++;
94 }
95 enlarge();
96 }
#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 188 of file AABB.h.

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

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

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

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

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

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

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

References _max_pnt.

Referenced by AABB(), and update().

◆ getMaxPoint()

◆ getMinPoint()

◆ init() [1/2]

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

Definition at line 227 of file AABB.h.

228 {
229 init(*pnt);
230 }

References init().

◆ init() [2/2]

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

Definition at line 219 of file AABB.h.

220 {
221 _min_pnt[0] = _max_pnt[0] = pnt[0];
222 _min_pnt[1] = _max_pnt[1] = pnt[1];
223 _min_pnt[2] = _max_pnt[2] = pnt[2];
224 }

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

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

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

261 {
262 update(*pnt);
263 }
bool update(PNT_TYPE const &p)
Definition: AABB.h:101

References update().

◆ updateWithoutEnlarge() [1/2]

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

Definition at line 254 of file AABB.h.

255 {
257 }

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

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

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

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


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