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

55 {
56 assert(!ids.empty());
57 init(pnts[ids[0]]);
58 for (std::size_t i = 1; i < ids.size(); ++i)
59 {
60 updateWithoutEnlarge(*(pnts[ids[i]]));
61 }
62 enlarge();
63 }
void init(PNT_TYPE const &pnt)
Definition AABB.h:228
void updateWithoutEnlarge(PNT_TYPE const &p)
Definition AABB.h:247
void enlarge(std::bitset< 3 > to_update=7)
Definition AABB.h:215
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:216

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

Referenced by GeoLib::Grid< POINT >::Grid(), GeoLib::SurfaceGrid::SurfaceGrid(), containsAABB(), and operator<<.

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

77 {
78 if (std::distance(first, last) <= 0)
79 {
81 "AABB::AABB(InputIterator first, InputIterator last): first > "
82 "last");
83 }
84 init(*first);
85 InputIterator it(first);
86 while (it != last)
87 {
89 it++;
90 }
91 enlarge();
92 }
#define OGS_FATAL(...)
Definition Error.h:19

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

186 {
187 return containsPoint(other_aabb.getMinPoint(), 0) &&
188 containsPoint(other_aabb.getMaxPoint(), 0);
189 }
bool containsPoint(T const &pnt, double eps) const
Definition AABB.h:132

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

133 {
134 if (pnt[0] < _min_pnt[0] - eps || _max_pnt[0] + eps <= pnt[0])
135 {
136 return false;
137 }
138 if (pnt[1] < _min_pnt[1] - eps || _max_pnt[1] + eps <= pnt[1])
139 {
140 return false;
141 }
142 if (pnt[2] < _min_pnt[2] - eps || _max_pnt[2] + eps <= pnt[2])
143 {
144 return false;
145 }
146 return true;
147 }
Eigen::Vector3d _min_pnt
Definition AABB.h:204
Eigen::Vector3d _max_pnt
Definition AABB.h:207

References _max_pnt, and _min_pnt.

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

◆ containsPointXY()

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

Definition at line 150 of file AABB.h.

151 {
152 if (pnt[0] < _min_pnt[0] || _max_pnt[0] <= pnt[0])
153 {
154 return false;
155 }
156 if (pnt[1] < _min_pnt[1] || _max_pnt[1] <= pnt[1])
157 {
158 return false;
159 }
160 return true;
161 }

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

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

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

237 {
238 init(*pnt);
239 }

References init().

◆ init() [2/2]

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

Definition at line 228 of file AABB.h.

229 {
230 _min_pnt[0] = _max_pnt[0] = pnt[0];
231 _min_pnt[1] = _max_pnt[1] = pnt[1];
232 _min_pnt[2] = _max_pnt[2] = pnt[2];
233 }

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

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

References _max_pnt, _min_pnt, and enlarge().

Referenced by update().

◆ update() [2/2]

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

Definition at line 269 of file AABB.h.

270 {
271 update(*pnt);
272 }
bool update(PNT_TYPE const &p)
Definition AABB.h:97

References update().

◆ updateWithoutEnlarge() [1/2]

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

Definition at line 263 of file AABB.h.

264 {
266 }

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

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

References _max_pnt, and _min_pnt.

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

◆ operator<<

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

Definition at line 191 of file AABB.h.

192 {
193 auto const [min, max] = aabb.getMinMaxPoints();
194 os << "\tx [" << min[0] << ", " << max[0] << ") (extent "
195 << max[0] - min[0] << ")\n";
196 os << "\ty [" << min[1] << ", " << max[1] << ") (extent "
197 << max[1] - min[1] << ")\n";
198 os << "\tz [" << min[2] << ", " << max[2] << ") (extent "
199 << max[2] - min[2] << ")";
200 return os;
201 }

References AABB(), and getMinMaxPoints().

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

207 {std::numeric_limits<double>::lowest(),
208 std::numeric_limits<double>::lowest(),
209 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 204 of file AABB.h.

204 {std::numeric_limits<double>::max(),
205 std::numeric_limits<double>::max(),
206 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: