EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_BoundingVolumes.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
11#ifndef EBGEOMETRY_BOUNDINGVOLUMES_HPP
12#define EBGEOMETRY_BOUNDINGVOLUMES_HPP
13
14// Std includes
15#include <ostream>
16#include <type_traits>
17#include <vector>
18
19// Our includes
20#include "EBGeometry_Macros.hpp"
21#include "EBGeometry_Vec.hpp"
22
23namespace EBGeometry {
24
28namespace BoundingVolumes {
29
34template <class T>
36{
37 static_assert(std::is_floating_point_v<T>, "SphereT<T>: T must be a floating-point type.");
38
39public:
46 friend std::ostream&
47 operator<<(std::ostream& os, const SphereT<T>& sphere)
48 {
49 os << '(' << sphere.getCentroid() << ", " << sphere.getRadius() << ')';
50
51 return os;
52 }
53
57 enum class BuildAlgorithm
58 {
59 Ritter,
60 };
61
65 using Vec3 = Vec3T<T>;
66
74
81
87
93
103
108
114 SphereT&
116
122
128 SphereT&
130
139 inline void
141
147 [[nodiscard]] inline bool
149
154 inline T&
156
161 [[nodiscard]] inline const T&
163
168 inline Vec3&
170
177
183 [[nodiscard]] inline T
185
191 [[nodiscard]] inline T
193
203 [[nodiscard]] inline T
205
210 [[nodiscard]] inline T
212
217 [[nodiscard]] inline T
219
224 T m_radius = T(-1);
225
229 Vec3 m_center = Vec3::zeros();
230
237 inline void
239};
240
245template <class T>
247{
248 static_assert(std::is_floating_point_v<T>, "AABBT<T>: T must be a floating-point type.");
249
250public:
257 friend std::ostream&
258 operator<<(std::ostream& os, const AABBT<T>& aabb)
259 {
260 os << '(' << aabb.getLowCorner() << ", " << aabb.getHighCorner() << ')';
261
262 return os;
263 }
264
268 using Vec3 = Vec3T<T>;
269
278
285
291
297
306
311
317 AABBT&
319
325
331 AABBT&
333
341 inline void
343
349 [[nodiscard]] inline bool
351
356 inline Vec3T<T>&
357 getLowCorner() noexcept;
358
364 getLowCorner() const noexcept;
365
370 inline Vec3T<T>&
371 getHighCorner() noexcept;
372
378 getHighCorner() const noexcept;
379
386
392 [[nodiscard]] inline T
394
400 [[nodiscard]] inline T
402
410 [[nodiscard]] inline T
412
417 [[nodiscard]] inline T
419
424 [[nodiscard]] inline T
426
431 Vec3 m_loCorner = Vec3::infinity();
432
436 Vec3 m_hiCorner = -Vec3::infinity();
437};
438
446template <class T>
447[[nodiscard]] bool
449
457template <class T>
458[[nodiscard]] bool
460
468template <class T>
469[[nodiscard]] T
471
479template <class T>
480[[nodiscard]] T
482} // namespace BoundingVolumes
483
484} // namespace EBGeometry
485
486#include "EBGeometry_BoundingVolumesImplem.hpp"
487
488#endif
Utility macros for EBGeometry.
Declaration of 2D and 3D point/vector classes with templated precision. Used with DCEL tools.
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:247
AABBT() noexcept=default
Default constructor. Sets lo = +∞, hi = −∞ (inverted sentinel).
Bounding sphere — an approximation to the smallest sphere enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:36
bool intersects(const SphereT &a_other) const noexcept
Test whether this bounding sphere intersects a_other.
SphereT() noexcept=default
Default constructor. Sets radius to -1 (invalid sentinel).
friend std::ostream & operator<<(std::ostream &os, const SphereT< T > &sphere)
Output a bounding sphere to a stream in the form "(centroid, radius)".
Definition EBGeometry_BoundingVolumes.hpp:47
Vec3 m_center
Sphere centre. Initialised to the origin.
Definition EBGeometry_BoundingVolumes.hpp:229
void define(const std::vector< Vec3T< P > > &a_points, const BuildAlgorithm &a_alg) noexcept
Fit this sphere to a set of 3D points using the specified algorithm.
T getArea() const noexcept
Compute the sphere surface area (4 * pi * r^2).
Vec3 & getCentroid() noexcept
Get a modifiable reference to the sphere centroid.
T getVolume() const noexcept
Compute the sphere volume (4/3 * pi * r^3).
T getOverlappingVolume(const SphereT< T > &a_other) const noexcept
Compute the overlapping volume between this sphere and a_other.
T m_radius
Sphere radius. Initialised to -1 (invalid sentinel).
Definition EBGeometry_BoundingVolumes.hpp:224
T getDistance(const Vec3 &a_x0) const noexcept
Compute the unsigned distance from a_x0 to this sphere.
void buildRitter(const std::vector< Vec3T< P > > &a_points) noexcept
Fit a bounding sphere to a_points using Ritter's algorithm.
T getDistance2(const Vec3 &a_x0) const noexcept
Compute the squared unsigned distance from a_x0 to this sphere.
BuildAlgorithm
Algorithm used to compute a bounding sphere for a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:58
@ Ritter
Ritter's simple two-pass approximation. Fast but may overestimate the radius slightly.
T & getRadius() noexcept
Get a modifiable reference to the sphere radius.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:225
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:31