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

Signed distance function for a DCEL mesh. Does not use BVHs. More...

#include <EBGeometry_MeshDistanceFunctions.hpp>

Inheritance diagram for EBGeometry::FlatMeshSDF< T >:
Inheritance graph
[legend]
Collaboration diagram for EBGeometry::FlatMeshSDF< T >:
Collaboration graph
[legend]

Classes

struct  Layout
 The object's arrays as offsets into its pool, with no location (see PoolHandle). More...
 

Public Types

using Mesh = EBGeometry::DCEL::MeshT< T >
 Alias for DCEL mesh type.
 

Public Member Functions

 FlatMeshSDF ()=delete
 Disallowed constructor.
 
 FlatMeshSDF (const Layout &a_layout, const PoolLocation &a_location) noexcept
 Rebuild a handle from a stored layout and the location of the pool that holds it.
 
Layout layout () const noexcept
 The object's arrays without its location, for storing it inside another pool-resident object.
 
 FlatMeshSDF (const Mesh &a_mesh, Pool &a_pool) noexcept
 Full constructor.
 
T signedDistance (const Vec3T< T > &a_point) const noexcept
 Compute the signed distance from a_point to the mesh.
 
ClosestFace< T > getClosestFace (const Vec3T< T > &a_point) const noexcept
 Find the face closest to a_point, and the signed distance to it.
 
Mesh getMesh () const noexcept
 Get the underlying DCEL mesh descriptor.
 
FlatMeshSDF rebasedView (const Pool &a_pool) const noexcept
 Produce a copy of this object that resolves against a_pool.
 
FlatMeshSDF deepCopy (Pool &a_dstPool) const
 Duplicate the mesh's storage into a_dstPool.
 
EBGeometry::BoundingVolumes::AABBT< T > computeBoundingVolume () const noexcept
 Compute the AABB enclosing the entire mesh.
 
- Public Member Functions inherited from EBGeometry::PoolHandle
PoolLocation location () const noexcept
 Where this handle's arrays live.
 
bool isAttachedTo (const Pool &a_pool) const noexcept
 Check whether this handle's arrays were reserved from a_pool.
 

Static Public Attributes

static constexpr DistanceQuality distanceQuality = DistanceQuality::Exact
 How far signedDistance() can be trusted as a distance: the Euclidean distance to a watertight mesh.
 

Additional Inherited Members

- Protected Member Functions inherited from EBGeometry::PoolHandle
 PoolHandle () noexcept=default
 An unset location; the first reservation attaches it.
 
 PoolHandle (const PoolLocation &a_location) noexcept
 Adopt a location, as a handle rebuilt from a stored layout does.
 
 PoolHandle (const PoolHandle &) noexcept=default
 Copy a handle, as a derived handle's copy does.
 
 PoolHandle (PoolHandle &&) noexcept=default
 Move a handle; the same as a copy.
 
PoolHandle & operator= (const PoolHandle &) noexcept=default
 Copy-assign a handle, as a derived handle's assignment does.
 
PoolHandle & operator= (PoolHandle &&) noexcept=default
 Move-assign a handle; the same as a copy.
 
 ~PoolHandle () noexcept=default
 Destructor; protected, since a PoolHandle exists only as the base of a handle.
 
void * base () noexcept
 The base address this handle's offsets resolve against; see PoolLocation::base().
 
const void * base () const noexcept
 The base address this handle's offsets resolve against, for read-only access.
 
void attach (const Pool &a_pool, const char *a_who) noexcept
 Follow a_pool, as the first reservation does; see PoolLocation::attach().
 
PoolLocation rebasedLocation (const Pool &a_pool, uint64_t a_endByte, const char *a_who) const noexcept
 The location of this handle's arrays in another pool of its mirror chain; see PoolLocation::rebasedOnto().
 
void setLocation (const PoolLocation &a_location) noexcept
 Replace the location, for a view or a copy made by a derived handle.
 

Detailed Description

template<class T>
class EBGeometry::FlatMeshSDF< T >

Signed distance function for a DCEL mesh. Does not use BVHs.

Iterates over every face of the mesh on every query – O(N) per call. Suitable only for very small meshes, debugging, and as a brute-force reference for the BVH-accelerated mesh SDFs.

A plain value type: it holds the mesh descriptor by value (offsets into a Pool plus the pool's control block or base address) and nothing else, so it is trivially copyable and every query is callable on the host and on a device. It has no virtual functions: a class with them can never be passed to a kernel.

It visits every face, so on the 100,000-face armadillo the BVH-backed mesh SDFs are hundreds of times faster.

Copying a FlatMeshSDF copies descriptors only: every copy resolves against the same pool memory, and the pool must outlive all of them. A FlatMeshSDF sees the mesh as it was when it was constructed; build a new one after changing the mesh's size. To evaluate on a device, freeze and mirror the pool, then pass rebasedView() into a kernel:

hostPool.freeze();
Pool devicePool = Pool::mirror(hostPool, deviceMemoryResource());
const auto deviceSDF = flatSDF.rebasedView(devicePool);
myKernel<<<blocks, threads>>>(deviceSDF, ...);
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:183
static Pool mirror(const Pool &a_src, MemoryResource &a_dstResource)
Mirror a frozen pool's whole block into another resource.
DeviceMemoryResource & deviceMemoryResource() noexcept
Process-wide default device memory resource.
Template Parameters
TFloating-point precision type (float or double).

Constructor & Destructor Documentation

◆ FlatMeshSDF() [1/2]

template<class T >
EBGeometry::FlatMeshSDF< T >::FlatMeshSDF ( const Layout &  a_layout,
const PoolLocation &  a_location 
)
inlinenoexcept

Rebuild a handle from a stored layout and the location of the pool that holds it.

How an outer pool-resident object, such as a BVHUnion, evaluates a FlatMeshSDF it stores as a layout. a_location must belong to the pool the layout was reserved from, or to a mirror of it; nothing is checked, since a device has no pool to check against.

Parameters
[in]a_layoutThe arrays.
[in]a_locationWhere they live.

◆ FlatMeshSDF() [2/2]

template<class T >
EBGeometry::FlatMeshSDF< T >::FlatMeshSDF ( const Mesh &  a_mesh,
Pool &  a_pool 
)
inlinenoexcept

Full constructor.

Copies the mesh descriptor. Nothing is frozen or bound: the mesh resolves its storage through a_pool's control block on every access, so this object is queryable at once and stays queryable across a Pool::reserve that grows and moves the block. a_pool is taken to check that a_mesh really was reserved from it, and to make visible at the call site that it must outlive this object and every copy of it.

Parameters
[in]a_meshInput mesh, built against a_pool.
[in,out]a_poolPool a_mesh's storage was reserved from. Must outlive this object.

Member Function Documentation

◆ computeBoundingVolume()

template<class T >
EBGeometry::BoundingVolumes::AABBT< T > EBGeometry::FlatMeshSDF< T >::computeBoundingVolume ( ) const
inlinenoexcept

Compute the AABB enclosing the entire mesh.

A componentwise min/max over the mesh vertices, so it is callable on host and device alike. An empty mesh yields an inverted box (low corner +max, high corner -max).

Returns
Axis-aligned bounding box of the mesh.

◆ deepCopy()

template<class T >
FlatMeshSDF EBGeometry::FlatMeshSDF< T >::deepCopy ( Pool &  a_dstPool) const
inline

Duplicate the mesh's storage into a_dstPool.

The copy constructor copies descriptors only, leaving both objects resolving against the same pool memory. This is the operation that gives genuinely independent storage.

Parameters
[in,out]a_dstPoolPool to reserve the copy's mesh from; may be this object's own pool.
Returns
A FlatMeshSDF over an independent copy of the mesh, attached to a_dstPool.

◆ getClosestFace()

template<class T >
ClosestFace< T > EBGeometry::FlatMeshSDF< T >::getClosestFace ( const Vec3T< T > &  a_point) const
inlinenoexcept

Find the face closest to a_point, and the signed distance to it.

Scans every face with the rule of DCEL::MeshT::SearchAlgorithm::Direct2, the mesh's default: the face with the smallest unsigned distance wins.

Parameters
[in]a_pointQuery point. Must be finite.
Returns
The closest face's id (its index in the mesh) and signed distance. The signed distance equals what signedDistance() returns for the same point, unless the mesh's search algorithm was changed (DCEL::MeshT::setSearchAlgorithm()).

◆ getMesh()

template<class T >
Mesh EBGeometry::FlatMeshSDF< T >::getMesh ( ) const
inlinenoexcept

Get the underlying DCEL mesh descriptor.

Returns
The mesh.

◆ layout()

template<class T >
Layout EBGeometry::FlatMeshSDF< T >::layout ( ) const
inlinenoexcept

The object's arrays without its location, for storing it inside another pool-resident object.

Returns
The layout.

◆ rebasedView()

template<class T >
FlatMeshSDF EBGeometry::FlatMeshSDF< T >::rebasedView ( const Pool &  a_pool) const
inlinenoexcept

Produce a copy of this object that resolves against a_pool.

Rebases the mesh descriptor; see DCEL::MeshT::rebasedView() for the contract. This is the one sanctioned crossing to a device.

Parameters
[in]a_poolPool to rebase onto: the object's own pool or one in its mirror chain.
Returns
A FlatMeshSDF resolving against a_pool.

◆ signedDistance()

template<class T >
T EBGeometry::FlatMeshSDF< T >::signedDistance ( const Vec3T< T > &  a_point) const
inlinenoexcept

Compute the signed distance from a_point to the mesh.

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

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