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

Signed distance function for a pure triangle mesh using SoA-grouped primitives in a compact (linearized) BVH. More...

#include <EBGeometry_MeshDistanceFunctions.hpp>

Inheritance diagram for EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >:
Inheritance graph
[legend]
Collaboration diagram for EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >:
Collaboration graph
[legend]

Public Types

using Mesh = EBGeometry::DCEL::MeshT< T, Meta >
 Alias for DCEL mesh type.
 
using Tri = typename EBGeometry::Triangle< T, Meta >
 Alias for DCEL face type.
 
using TriSoA = TriangleSoAT< T, W >
 Alias for the SoA triangle group type.
 
using Root = typename EBGeometry::BVH::PackedBVH< T, TriSoA, K, StoragePolicy >
 Alias for which BVH root node.
 

Public Member Functions

 TriMeshSDF ()=delete
 Default disallowed constructor.
 
 TriMeshSDF (const std::shared_ptr< Mesh > &a_mesh, const BVH::Build a_build, const size_t a_maxLeafGroups) noexcept
 Full constructor. Takes a DCEL mesh and creates the input triangles. Then creates the BVH.
 
 TriMeshSDF (const std::vector< std::shared_ptr< Tri > > &a_triangles, const BVH::Build a_build, const size_t a_maxLeafGroups) noexcept
 Full constructor. Takes the input triangles and creates the BVH.
 
 ~TriMeshSDF () override=default
 Destructor.
 
 TriMeshSDF (const TriMeshSDF &a_other)=default
 Copy constructor.
 
TriMeshSDFoperator= (const TriMeshSDF &a_other)=default
 Copy assignment operator.
 
 TriMeshSDF (TriMeshSDF &&a_other) noexcept=default
 Move constructor.
 
TriMeshSDFoperator= (TriMeshSDF &&a_other) noexcept=default
 Move assignment operator.
 
signedDistance (const Vec3T< T > &a_point) const noexcept override
 Compute the signed distance from a_point to the triangle mesh.
 
virtual std::shared_ptr< Root > & getRoot () noexcept
 Get the PackedBVH storing SoA triangle groups.
 
virtual const std::shared_ptr< Root > & getRoot () const noexcept
 Get the PackedBVH storing SoA triangle groups (const overload).
 
EBGeometry::BoundingVolumes::AABBT< T > computeBoundingVolume () const noexcept
 Compute the AABB enclosing the entire triangle mesh.
 
- Public Member Functions inherited from EBGeometry::SignedDistanceFunction< T >
 SignedDistanceFunction ()=default
 Default constructor.
 
 ~SignedDistanceFunction () override=default
 Destructor.
 
value (const Vec3T< T > &a_point) const noexcept final
 Implementation of ImplicitFunction::value; delegates to signedDistance().
 
virtual Vec3T< T > normal (const Vec3T< T > &a_point, const T &a_delta) const noexcept
 Compute the outward normal using central finite differences.
 
- Public Member Functions inherited from EBGeometry::ImplicitFunction< T >
 ImplicitFunction ()=default
 Default constructor.
 
virtual ~ImplicitFunction ()=default
 Default destructor.
 
operator() (const Vec3T< T > &a_point) const noexcept
 Call operator — alternative signature for the value function.
 
template<class BV >
BV approximateBoundingVolumeOctree (const Vec3T< T > &a_initialLowCorner, const Vec3T< T > &a_initialHighCorner, const unsigned int a_maxTreeDepth, const T &a_safety=0.0) const
 Compute an approximation to the bounding volume for the implicit surface using octree subdivision.
 

Static Protected Member Functions

static std::vector< TriSoAgroupTrianglesIntoSoA (const std::vector< std::shared_ptr< const Tri > > &a_triangles, uint32_t a_offset, uint32_t a_count)
 Leaf-conversion callback for TreeBVH::packWith: groups a BVH leaf's triangles into SoA blocks of width W.
 

Protected Attributes

std::shared_ptr< Rootm_bvh
 Bounding volume hierarchy storing SoA triangle groups.
 

Detailed Description

template<class T, class Meta, size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
class EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >

Signed distance function for a pure triangle mesh using SoA-grouped primitives in a compact (linearized) BVH.

Triangles are packed into SoA groups of W triangles each (TriangleSoAT<T,W>), enabling SIMD evaluation of up to W signed distances simultaneously.

No default arguments: this is a low-level constructor, and callers who excavate down to it must consciously choose K and W. Use Parser::readIntoTriangleBVH for sensible ISA-tuned defaults (BVH::DefaultBranchingRatio<T>() for K, TriangleSoA::DefaultWidth<T>() for W).

Template Parameters
TFloating-point precision type (float or double).
MetaTriangle metadata type.
KBVH branching factor (number of children per internal node). Must be >= 2.
WSoA width: number of triangles per SIMD group. Must be > 0.
StoragePolicyPackedBVH primitive storage policy (see BVH::SharedPtrStorage / BVH::ValueStorage). Defaults to BVH::ValueStorage<TriangleSoAT<T, W>>, storing each SoA group inline with no pointer indirection – unlike MeshSDF's faces, these groups are freshly constructed by groupTrianglesIntoSoA() during packing and shared with nothing else, so there is no aliasing benefit to give up. Note that instancing the same mesh multiple times (e.g. via Translate/Rotate/Scale or a CSG union) is unaffected either way: those wrappers hold a shared_ptr to the whole TriMeshSDF, so its packed data – however StoragePolicy stores it – is never duplicated per placement. See the user documentation for the full rationale.

Constructor & Destructor Documentation

◆ TriMeshSDF() [1/4]

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::TriMeshSDF ( const std::shared_ptr< Mesh > &  a_mesh,
const BVH::Build  a_build,
const size_t  a_maxLeafGroups 
)
noexcept

Full constructor. Takes a DCEL mesh and creates the input triangles. Then creates the BVH.

No default arguments: this is a low-level constructor, and callers who excavate down to it must consciously choose every parameter. Use Parser::readIntoTriangleBVH for sensible defaults.

Parameters
[in]a_meshDCEL mesh.
[in]a_buildBVH build strategy. SAH (binned Surface Area Heuristic) produces near-optimal traversal cost; TopDown (centroid median) is faster to build but yields deeper trees.
[in]a_maxLeafGroupsMaximum number of full W-sized TriangleSoA groups per BVH leaf; the actual raw-triangle leaf-size bound used is a_maxLeafGroups * W. This bounds the pre-packing tree's leaf size, not the packed representation directly: each leaf's triangles become their own TriangleSoA group(s) during packing, with no batching across leaves, so a leaf smaller than W wastes some of its group's SIMD lanes on padding. It is an upper bound, not a target — the SAH/TopDown partitioner still splits down to tighter, more selective leaves wherever the geometry warrants it. Expressing this as a count of W-sized groups (rather than a raw triangle count) makes it impossible to accidentally pick a leaf size that isn't a multiple of W. Must be > 0.

◆ TriMeshSDF() [2/4]

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::TriMeshSDF ( const std::vector< std::shared_ptr< Tri > > &  a_triangles,
const BVH::Build  a_build,
const size_t  a_maxLeafGroups 
)
noexcept

Full constructor. Takes the input triangles and creates the BVH.

Parameters
[in]a_trianglesInput triangle soup.
[in]a_buildBVH build strategy (see the mesh-based constructor for details).
[in]a_maxLeafGroupsMaximum number of full W-sized TriangleSoA groups per BVH leaf (see the mesh-based constructor for the tree-quality/SIMD-occupancy trade-off). Must be > 0.

◆ TriMeshSDF() [3/4]

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::TriMeshSDF ( const TriMeshSDF< T, Meta, K, W, StoragePolicy > &  a_other)
default

Copy constructor.

Explicitly defaulted for documentation purposes: TriMeshSDF's only member (m_bvh) is a shared_ptr, so the implicitly-generated copy is a cheap, correct handle-copy.

Parameters
[in]a_otherOther instance to copy.

◆ TriMeshSDF() [4/4]

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::TriMeshSDF ( TriMeshSDF< T, Meta, K, W, StoragePolicy > &&  a_other)
defaultnoexcept

Move constructor.

Explicitly defaulted: the user-declared destructor above would otherwise suppress the implicitly-generated move constructor.

Parameters
[in,out]a_otherOther instance to move from.

Member Function Documentation

◆ computeBoundingVolume()

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
EBGeometry::BoundingVolumes::AABBT< T > EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::computeBoundingVolume ( ) const
noexcept

Compute the AABB enclosing the entire triangle mesh.

Returns
Axis-aligned bounding box of the mesh.

◆ getRoot() [1/2]

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
virtual const std::shared_ptr< Root > & EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::getRoot ( ) const
virtualnoexcept

Get the PackedBVH storing SoA triangle groups (const overload).

Returns
Const reference to the shared-pointer owning the packed BVH root.

◆ getRoot() [2/2]

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
virtual std::shared_ptr< Root > & EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::getRoot ( )
virtualnoexcept

Get the PackedBVH storing SoA triangle groups.

Returns
Mutable reference to the shared-pointer owning the packed BVH root.

◆ groupTrianglesIntoSoA()

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
static std::vector< TriSoA > EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::groupTrianglesIntoSoA ( const std::vector< std::shared_ptr< const Tri > > &  a_triangles,
uint32_t  a_offset,
uint32_t  a_count 
)
staticprotected

Leaf-conversion callback for TreeBVH::packWith: groups a BVH leaf's triangles into SoA blocks of width W.

Shared by both constructors; stateless (captures nothing), so it is a static member rather than a per-constructor lambda.

Parameters
[in]a_trianglesLeaf's triangle list.
[in]a_offsetIndex of the first triangle in this leaf to convert.
[in]a_countNumber of triangles in this leaf to convert.
Returns
SoA-packed triangle groups covering [a_offset, a_offset + a_count).

◆ operator=() [1/2]

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
TriMeshSDF & EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::operator= ( const TriMeshSDF< T, Meta, K, W, StoragePolicy > &  a_other)
default

Copy assignment operator.

Parameters
[in]a_otherOther instance to copy.
Returns
Reference to *this.

◆ operator=() [2/2]

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
TriMeshSDF & EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::operator= ( TriMeshSDF< T, Meta, K, W, StoragePolicy > &&  a_other)
defaultnoexcept

Move assignment operator.

Parameters
[in,out]a_otherOther instance to move from.
Returns
Reference to *this.

◆ signedDistance()

template<class T , class Meta , size_t K, size_t W, class StoragePolicy = BVH::ValueStorage<EBGeometry::TriangleSoAT<T, W>>>
T EBGeometry::TriMeshSDF< T, Meta, K, W, StoragePolicy >::signedDistance ( const Vec3T< T > &  a_point) const
overridevirtualnoexcept

Compute the signed distance from a_point to the triangle mesh.

Parameters
[in]a_pointQuery point.
Returns
Signed distance to the nearest triangle; negative inside the mesh.

Implements EBGeometry::SignedDistanceFunction< T >.


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