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

Friends

std::ostream & operator<< (std::ostream &os, AABB const &aabb)
 

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

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

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

88 {
89 if (std::distance(first, last) <= 0)
90 {
92 "AABB::AABB(InputIterator first, InputIterator last): first > "
93 "last");
94 }
95 init(*first);
96 InputIterator it(first);
97 while (it != last)
98 {
100 it++;
101 }
102 enlarge();
103 }
#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 196 of file AABB.h.

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

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

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

References _max_pnt, and _min_pnt.

Referenced by containsAABB(), main(), and anonymous_namespace{AddFaultToVoxelGrid.cpp}::markFaults().

◆ containsPointXY()

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

Definition at line 161 of file AABB.h.

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

References _max_pnt, and _min_pnt.

Referenced by MeshToolsLib::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 226 of file AABB.h.

227 {
228 for (std::size_t k = 0; k < 3; ++k)
229 {
230 if (to_update[k])
231 {
232 _max_pnt[k] = std::nextafter(
233 _max_pnt[k], std::numeric_limits<double>::max());
234 }
235 }
236 }

References _max_pnt.

Referenced by AABB(), AABB(), and update().

◆ getMaxPoint()

◆ getMinMaxPoints()

◆ getMinPoint()

◆ init() [1/2]

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

Definition at line 247 of file AABB.h.

248 {
249 init(*pnt);
250 }

References init().

◆ init() [2/2]

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

Definition at line 239 of file AABB.h.

240 {
241 _min_pnt[0] = _max_pnt[0] = pnt[0];
242 _min_pnt[1] = _max_pnt[1] = pnt[1];
243 _min_pnt[2] = _max_pnt[2] = pnt[2];
244 }

References _max_pnt, and _min_pnt.

Referenced by AABB(), 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 108 of file AABB.h.

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

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

281 {
282 update(*pnt);
283 }
bool update(PNT_TYPE const &p)
Definition AABB.h:108

References update().

◆ updateWithoutEnlarge() [1/2]

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

Definition at line 274 of file AABB.h.

275 {
277 }

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

259 {
260 for (std::size_t k(0); k < 3; k++)
261 {
262 if (p[k] < _min_pnt[k])
263 {
264 _min_pnt[k] = p[k];
265 }
266 if (p[k] >= _max_pnt[k])
267 {
268 _max_pnt[k] = p[k];
269 }
270 }
271 }

References _max_pnt, and _min_pnt.

Referenced by AABB(), AABB(), and updateWithoutEnlarge().

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
AABB const & aabb )
friend

Definition at line 202 of file AABB.h.

203 {
204 auto const [min, max] = aabb.getMinMaxPoints();
205 os << "\tx [" << min[0] << ", " << max[0] << ") (extent "
206 << max[0] - min[0] << ")\n";
207 os << "\ty [" << min[1] << ", " << max[1] << ") (extent "
208 << max[1] - min[1] << ")\n";
209 os << "\tz [" << min[2] << ", " << max[2] << ") (extent "
210 << max[2] - min[2] << ")";
211 return os;
212 }

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

218 {std::numeric_limits<double>::lowest(),
219 std::numeric_limits<double>::lowest(),
220 std::numeric_limits<double>::lowest()};

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

215 {std::numeric_limits<double>::max(),
216 std::numeric_limits<double>::max(),
217 std::numeric_limits<double>::max()};

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


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