EBGeometry  1.0
EBGeometry_BoundingVolumes.hpp
Go to the documentation of this file.
1 /* EBGeometry
2  * Copyright © 2022 Robert Marskar
3  * Please refer to Copyright.txt and LICENSE in the EBGeometry root directory.
4  */
5 
13 #ifndef EBGeometry_BoundingVolumes_H
14 #define EBGeometry_BoundingVolumes_H
15 
16 // Std includes
17 #include <vector>
18 #include <iostream>
19 
20 // Our includes
21 #include "EBGeometry_Vec.hpp"
23 
28 namespace BoundingVolumes {
29 
35  template <class T>
37  {
38  public:
42  friend std::ostream&
43  operator<<(std::ostream& os, const BoundingSphereT<T>& sphere)
44  {
45  os << '(' << sphere.getCentroid() << ", " << sphere.getRadius() << ')';
46 
47  return os;
48  }
49 
55  {
56  Ritter,
57  };
58 
62  using Vec3 = Vec3T<T>;
63 
67  inline BoundingSphereT() noexcept;
68 
74  inline BoundingSphereT(const Vec3T<T>& a_center, const T& a_radius) noexcept;
75 
81  inline BoundingSphereT(const std::vector<BoundingSphereT<T>>& a_otherSpheres) noexcept;
82 
87  inline BoundingSphereT(const BoundingSphereT& a_other) noexcept;
88 
97  template <class P>
98  inline BoundingSphereT(const std::vector<Vec3T<P>>& a_points,
99  const BoundingVolumeAlgorithm& a_alg = BoundingVolumeAlgorithm::Ritter) noexcept;
100 
104  virtual ~BoundingSphereT() noexcept;
105 
111  operator=(const BoundingSphereT& a_other) = default;
112 
120  template <class P>
121  inline void
122  define(const std::vector<Vec3T<P>>& a_points, const BoundingVolumeAlgorithm& a_alg) noexcept;
123 
129  inline bool
130  intersects(const BoundingSphereT& a_other) const noexcept;
131 
135  inline T&
136  getRadius() noexcept;
137 
141  inline const T&
142  getRadius() const noexcept;
143 
147  inline Vec3&
148  getCentroid() noexcept;
149 
153  inline const Vec3&
154  getCentroid() const noexcept;
155 
162  inline T
163  getOverlappingVolume(const BoundingSphereT<T>& a_other) const noexcept;
164 
172  inline T
173  getDistance(const Vec3& a_x0) const noexcept;
174 
179  inline T
180  getVolume() const noexcept;
181 
186  inline T
187  getArea() const noexcept;
188 
189  protected:
194 
199 
204  template <class P>
205  inline void
206  buildRitter(const std::vector<Vec3T<P>>& a_points) noexcept;
207  };
208 
215  template <class T>
216  class AABBT
217  {
218  public:
222  friend std::ostream&
223  operator<<(std::ostream& os, const AABBT<T>& aabb)
224  {
225  os << '(' << aabb.getLowCorner() << ", " << aabb.getHighCorner() << ')';
226 
227  return os;
228  }
229 
233  using Vec3 = Vec3T<T>;
234 
238  inline AABBT() noexcept;
239 
245  inline AABBT(const Vec3T<T>& a_lo, const Vec3T<T>& a_hi) noexcept;
246 
251  inline AABBT(const AABBT& a_other) noexcept;
252 
258  inline AABBT(const std::vector<AABBT<T>>& a_others) noexcept;
259 
266  template <class P>
267  inline AABBT(const std::vector<Vec3T<P>>& a_points) noexcept;
268 
272  virtual ~AABBT() noexcept;
273 
278  AABBT&
279  operator=(const AABBT<T>& a_other) = default;
280 
286  template <class P>
287  inline void
288  define(const std::vector<Vec3T<P>>& a_points) noexcept;
289 
295  inline bool
296  intersects(const AABBT& a_other) const noexcept;
297 
301  inline Vec3T<T>&
302  getLowCorner() noexcept;
303 
307  inline const Vec3T<T>&
308  getLowCorner() const noexcept;
309 
313  inline Vec3T<T>&
314  getHighCorner() noexcept;
315 
319  inline const Vec3T<T>&
320  getHighCorner() const noexcept;
321 
325  inline Vec3
326  getCentroid() const noexcept;
327 
333  inline T
334  getOverlappingVolume(const AABBT<T>& a_other) const noexcept;
335 
343  inline T
344  getDistance(const Vec3& a_x0) const noexcept;
345 
349  inline T
350  getVolume() const noexcept;
351 
355  inline T
356  getArea() const noexcept;
357 
358  protected:
362  Vec3 m_loCorner;
363 
367  Vec3 m_hiCorner;
368  };
369 
375  template <class T>
376  bool
377  intersects(const BoundingSphereT<T>& a_u, const BoundingSphereT<T>& a_v) noexcept;
378 
384  template <class T>
385  bool
386  intersects(const AABBT<T>& a_u, const AABBT<T>& a_v) noexcept;
387 
393  template <class T>
394  T
395  getOverlappingVolume(const BoundingSphereT<T>& a_u, const BoundingSphereT<T>& a_v) noexcept;
396 
402  template <class T>
403  T
404  getOverlappingVolume(const AABBT<T>& a_u, const AABBT<T>& a_v) noexcept;
405 } // namespace BoundingVolumes
406 
407 #include "EBGeometry_NamespaceFooter.hpp"
408 
409 #include "EBGeometry_BoundingVolumesImplem.hpp"
410 
411 #endif
Declaration of 2D and 3D point/vector classes with templated precision. Used with DCEL tools.
Axis-aligned bounding box as bounding volume.
Definition: EBGeometry_BoundingVolumes.hpp:217
Vec3T< T > & getHighCorner() noexcept
Get the modifiable upper-right corner of the AABB.
AABBT() noexcept
Default constructor (does nothing)
Vec3T< T > & getLowCorner() noexcept
Get the modifiable lower-left corner of the AABB.
Class which encloses a set of points using a bounding sphere.
Definition: EBGeometry_BoundingVolumes.hpp:37
T getDistance(const Vec3 &a_x0) const noexcept
Get the distance to this bounding sphere (points inside the sphere have a zero distance)
void buildRitter(const std::vector< Vec3T< P >> &a_points) noexcept
Template function which computes the bounding sphere for a set of points (mixed precision allowed) us...
T getArea() const noexcept
Get the sphere area.
T getVolume() const noexcept
Get the sphere volume.
T getOverlappingVolume(const BoundingSphereT< T > &a_other) const noexcept
Compute the overlapping volume between this bounding sphere and another.
friend std::ostream & operator<<(std::ostream &os, const BoundingSphereT< T > &sphere)
For outputting a vector to an output stream.
Definition: EBGeometry_BoundingVolumes.hpp:43
Vec3 & getCentroid() noexcept
Get modifiable center for this sphere.
T & getRadius() noexcept
Get modifiable radius for this sphere.
BoundingSphereT() noexcept
Default constructor. Leaves object in undefined state.
bool intersects(const BoundingSphereT &a_other) const noexcept
Check if this bounding sphere intersect another bounding sphere.
void define(const std::vector< Vec3T< P >> &a_points, const BoundingVolumeAlgorithm &a_alg) noexcept
Template define function which takes a set of 3D points (mixed precision allowed).
Vec3 m_center
Sphere center.
Definition: EBGeometry_BoundingVolumes.hpp:198
T m_radius
Sphere radius.
Definition: EBGeometry_BoundingVolumes.hpp:193
BoundingVolumeAlgorithm
Typename for possible algorithms that support the computation of a bounding sphere for a set of 3D po...
Definition: EBGeometry_BoundingVolumes.hpp:55
Three-dimensional vector class with arithmetic operators.
Definition: EBGeometry_Vec.hpp:218
Namespace for encapsulating various bounding volumes for usage with BVHs.
Definition: EBGeometry_BoundingVolumes.hpp:28