EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
EBGeometry::BoundingVolumes::SphereT< T > Class Template Reference

Bounding sphere — an approximation to the smallest sphere enclosing a set of 3D points. More...

#include <EBGeometry_BoundingVolumes.hpp>

Public Types

enum class  BuildAlgorithm { Ritter }
 Algorithm used to compute a bounding sphere for a set of 3D points. More...
 
using Vec3 = Vec3T< T >
 Alias to cut down on typing.
 

Public Member Functions

 SphereT () noexcept=default
 Default constructor. Sets radius to -1 (invalid sentinel).
 
 SphereT (const Vec3T< T > &a_center, const T &a_radius) noexcept
 Construct a sphere with an explicit centre and radius.
 
 SphereT (const std::vector< SphereT< T > > &a_otherSpheres) noexcept
 Construct the smallest sphere enclosing all a_otherSpheres.
 
 SphereT (const SphereT &a_other) noexcept
 Copy constructor.
 
template<class P >
 SphereT (const std::vector< Vec3T< P > > &a_points, const BuildAlgorithm &a_alg=BuildAlgorithm::Ritter) noexcept
 Construct a bounding sphere enclosing a set of 3D points.
 
 ~SphereT () noexcept
 Destructor.
 
SphereToperator= (const SphereT &a_other)=default
 Copy assignment operator.
 
 SphereT (SphereT &&a_other) noexcept=default
 Move constructor.
 
SphereToperator= (SphereT &&a_other) noexcept=default
 Move assignment operator.
 
template<class P >
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.
 
bool intersects (const SphereT &a_other) const noexcept
 Test whether this bounding sphere intersects a_other.
 
T & getRadius () noexcept
 Get a modifiable reference to the sphere radius.
 
const T & getRadius () const noexcept
 Get the sphere radius.
 
Vec3getCentroid () noexcept
 Get a modifiable reference to the sphere centroid.
 
const Vec3getCentroid () const noexcept
 Get the sphere centroid.
 
getOverlappingVolume (const SphereT< T > &a_other) const noexcept
 Compute the overlapping volume between this sphere and a_other.
 
getDistance (const Vec3 &a_x0) const noexcept
 Compute the unsigned distance from a_x0 to this sphere.
 
getDistance2 (const Vec3 &a_x0) const noexcept
 Compute the squared unsigned distance from a_x0 to this sphere.
 
getVolume () const noexcept
 Compute the sphere volume (4/3 * pi * r^3).
 
getArea () const noexcept
 Compute the sphere surface area (4 * pi * r^2).
 

Protected Member Functions

template<class P >
void buildRitter (const std::vector< Vec3T< P > > &a_points) noexcept
 Fit a bounding sphere to a_points using Ritter's algorithm.
 

Protected Attributes

m_radius = T(-1)
 Sphere radius. Initialised to -1 (invalid sentinel).
 
Vec3 m_center = Vec3::zeros()
 Sphere centre. Initialised to the origin.
 

Friends

std::ostream & operator<< (std::ostream &os, const SphereT< T > &sphere)
 Output a bounding sphere to a stream in the form "(centroid, radius)".
 

Detailed Description

template<class T>
class EBGeometry::BoundingVolumes::SphereT< T >

Bounding sphere — an approximation to the smallest sphere enclosing a set of 3D points.

Template Parameters
TFloating-point precision (e.g., float or double).

Member Enumeration Documentation

◆ BuildAlgorithm

Algorithm used to compute a bounding sphere for a set of 3D points.

Enumerator
Ritter 

Ritter's simple two-pass approximation. Fast but may overestimate the radius slightly.

Constructor & Destructor Documentation

◆ SphereT() [1/6]

template<class T >
EBGeometry::BoundingVolumes::SphereT< T >::SphereT ( )
defaultnoexcept

Default constructor. Sets radius to -1 (invalid sentinel).

Any geometric method called on a default-constructed sphere will fire an EBGEOMETRY_EXPECT assertion. Call define() or use the explicit constructor before use.

◆ SphereT() [2/6]

template<class T >
EBGeometry::BoundingVolumes::SphereT< T >::SphereT ( const Vec3T< T > &  a_center,
const T &  a_radius 
)
inlinenoexcept

Construct a sphere with an explicit centre and radius.

Parameters
[in]a_centerSphere centre.
[in]a_radiusSphere radius.

◆ SphereT() [3/6]

template<class T >
EBGeometry::BoundingVolumes::SphereT< T >::SphereT ( const std::vector< SphereT< T > > &  a_otherSpheres)
inlinenoexcept

Construct the smallest sphere enclosing all a_otherSpheres.

Parameters
[in]a_otherSpheresSpheres to enclose.

◆ SphereT() [4/6]

template<class T >
EBGeometry::BoundingVolumes::SphereT< T >::SphereT ( const SphereT< T > &  a_other)
inlinenoexcept

Copy constructor.

Parameters
[in]a_otherSphere to copy.

◆ SphereT() [5/6]

template<class T >
template<class P >
EBGeometry::BoundingVolumes::SphereT< T >::SphereT ( const std::vector< Vec3T< P > > &  a_points,
const BuildAlgorithm a_alg = BuildAlgorithm::Ritter 
)
inlinenoexcept

Construct a bounding sphere enclosing a set of 3D points.

Mixed floating-point precision is allowed: P may differ from T.

Template Parameters
PFloating-point precision of the input points.
Parameters
[in]a_pointsSet of 3D points.
[in]a_algAlgorithm to use (default: Ritter).

◆ SphereT() [6/6]

template<class T >
EBGeometry::BoundingVolumes::SphereT< T >::SphereT ( SphereT< T > &&  a_other)
defaultnoexcept

Move constructor.

Parameters
[in]a_otherSphere to move from.

Member Function Documentation

◆ buildRitter()

template<class T >
template<class P >
void EBGeometry::BoundingVolumes::SphereT< T >::buildRitter ( const std::vector< Vec3T< P > > &  a_points)
inlineprotectednoexcept

Fit a bounding sphere to a_points using Ritter's algorithm.

Template Parameters
PFloating-point precision of the input points.
Parameters
[in]a_pointsSet of 3D points to enclose.

◆ define()

template<class T >
template<class P >
void EBGeometry::BoundingVolumes::SphereT< T >::define ( const std::vector< Vec3T< P > > &  a_points,
const BuildAlgorithm a_alg 
)
inlinenoexcept

Fit this sphere to a set of 3D points using the specified algorithm.

Mixed floating-point precision is allowed: P may differ from T.

Template Parameters
PFloating-point precision of the input points.
Parameters
[in]a_pointsSet of 3D points.
[in]a_algAlgorithm to use.

◆ getArea()

template<class T >
T EBGeometry::BoundingVolumes::SphereT< T >::getArea ( ) const
inlinenoexcept

Compute the sphere surface area (4 * pi * r^2).

Returns
Sphere surface area.

◆ getCentroid() [1/2]

template<class T >
const Vec3 & EBGeometry::BoundingVolumes::SphereT< T >::getCentroid ( ) const
inlinenoexcept

Get the sphere centroid.

Returns
Const reference to the sphere centroid.

◆ getCentroid() [2/2]

template<class T >
Vec3 & EBGeometry::BoundingVolumes::SphereT< T >::getCentroid ( )
inlinenoexcept

Get a modifiable reference to the sphere centroid.

Returns
Reference to the sphere centroid.

◆ getDistance()

template<class T >
T EBGeometry::BoundingVolumes::SphereT< T >::getDistance ( const Vec3 a_x0) const
inlinenoexcept

Compute the unsigned distance from a_x0 to this sphere.

Parameters
[in]a_x03D query point.
Returns
Distance from a_x0 to the sphere surface; zero if a_x0 is inside.

◆ getDistance2()

template<class T >
T EBGeometry::BoundingVolumes::SphereT< T >::getDistance2 ( const Vec3 a_x0) const
inlinenoexcept

Compute the squared unsigned distance from a_x0 to this sphere.

Mirrors AABBT::getDistance2(), giving both bounding volumes a uniform squared-distance query (e.g. for a BVH's sqrt-free pruning). Unlike the box, a sphere's surface distance is inherently radial, so this cannot avoid the square root the way AABBT::getDistance2() does – it is simply getDistance() squared.

Parameters
[in]a_x03D query point.
Returns
Squared distance from a_x0 to the sphere surface; zero if a_x0 is inside.

◆ getOverlappingVolume()

template<class T >
T EBGeometry::BoundingVolumes::SphereT< T >::getOverlappingVolume ( const SphereT< T > &  a_other) const
inlinenoexcept

Compute the overlapping volume between this sphere and a_other.

Parameters
[in]a_otherOther bounding sphere.
Returns
Overlap volume; zero if the spheres do not intersect.

◆ getRadius() [1/2]

template<class T >
const T & EBGeometry::BoundingVolumes::SphereT< T >::getRadius ( ) const
inlinenoexcept

Get the sphere radius.

Returns
Const reference to the sphere radius.

◆ getRadius() [2/2]

template<class T >
T & EBGeometry::BoundingVolumes::SphereT< T >::getRadius ( )
inlinenoexcept

Get a modifiable reference to the sphere radius.

Returns
Reference to the sphere radius.

◆ getVolume()

template<class T >
T EBGeometry::BoundingVolumes::SphereT< T >::getVolume ( ) const
inlinenoexcept

Compute the sphere volume (4/3 * pi * r^3).

Returns
Sphere volume.

◆ intersects()

template<class T >
bool EBGeometry::BoundingVolumes::SphereT< T >::intersects ( const SphereT< T > &  a_other) const
inlinenoexcept

Test whether this bounding sphere intersects a_other.

Parameters
[in]a_otherOther bounding sphere.
Returns
True if the two spheres overlap, false otherwise.

◆ operator=() [1/2]

template<class T >
SphereT & EBGeometry::BoundingVolumes::SphereT< T >::operator= ( const SphereT< T > &  a_other)
default

Copy assignment operator.

Parameters
[in]a_otherSphere to copy.
Returns
Reference to (*this).

◆ operator=() [2/2]

template<class T >
SphereT & EBGeometry::BoundingVolumes::SphereT< T >::operator= ( SphereT< T > &&  a_other)
defaultnoexcept

Move assignment operator.

Parameters
[in]a_otherSphere to move from.
Returns
Reference to (*this).

Friends And Related Symbol Documentation

◆ operator<<

template<class T >
std::ostream & operator<< ( std::ostream &  os,
const SphereT< T > &  sphere 
)
friend

Output a bounding sphere to a stream in the form "(centroid, radius)".

Parameters
[in,out]osOutput stream.
[in]sphereBounding sphere to print.
Returns
Reference to os to allow chaining.

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