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 Member Functions | Static Public Attributes | List of all members
EBGeometry::BVHSmoothUnion< T, K, Blend, Ps > Class Template Reference

BVH-accelerated smooth union of many primitives of one or more types. More...

#include <EBGeometry_BVHUnion.hpp>

Inheritance diagram for EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >:
Inheritance graph
[legend]
Collaboration diagram for EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >:
Collaboration graph
[legend]

Classes

struct  Layout
 The smooth union's arrays and parameters, with no location: what an outer union stores when this one is its primitive (see PoolHandle). With several types it also holds the per-type arrays (its base). More...
 

Public Types

using Leaf = CSGDetail::Leaf< Ps... >
 What the BVH's leaves hold; see BVHUnion::Leaf.
 
using Root = BVH::PackedBVH< T, Leaf, K >
 Alias for the packed BVH type.
 
using BV = BoundingVolumes::AABBT< T >
 Alias for the bounding volume type.
 
using First = std::tuple_element_t< 0, std::tuple< Ps... > >
 The first primitive type: the only one for the constructors that take boxes.
 

Public Member Functions

 BVHSmoothUnion ()=delete
 Disallowed, use the full constructor.
 
 BVHSmoothUnion (Pool &a_pool, T a_smoothLen, const std::vector< Ps > &... a_primitives)
 Build the smooth union of the given primitives with a default-constructed Blend, SAH and the default leaf sizes.
 
 BVHSmoothUnion (Pool &a_pool, T a_smoothLen, Blend a_blend, const std::vector< Ps > &... a_primitives)
 Build the smooth union of the given primitives with a smooth-minimum operator.
 
 BVHSmoothUnion (Pool &a_pool, const BVH::BuildSettings &a_settings, T a_smoothLen, Blend a_blend, const std::vector< Ps > &... a_primitives)
 Build the smooth union with a construction method and, optionally, leaf sizes.
 
template<size_t N = sizeof...(Ps), std::enable_if_t< N==1, int > = 0>
 BVHSmoothUnion (Pool &a_pool, const std::vector< First > &a_primitives, const std::vector< BV > &a_boundingVolumes, T a_smoothLen, Blend a_blend=Blend{}, BVH::Construction a_construction=BVH::Construction::SAH)
 Build a smooth union of one type with the caller's bounding boxes.
 
template<size_t N = sizeof...(Ps), std::enable_if_t< N==1, int > = 0>
 BVHSmoothUnion (Pool &a_pool, const std::vector< First > &a_primitives, const std::vector< BV > &a_boundingVolumes, T a_smoothLen, Blend a_blend, BVH::Construction a_construction, const BVH::ConstructionOptions &a_options)
 Build a smooth union of one type with the caller's bounding boxes and leaf-size settings.
 
T signedDistance (const Vec3T< T > &a_point) const noexcept
 Evaluate the smooth union at a point.
 
uint32_t getNumMembers () const noexcept
 How many members (primitives) the union holds.
 
uint32_t getMemberIndex (uint32_t a_position) const noexcept
 A member's index in the order the constructor was given the primitives (type by type, in the order of the arrays, each array in its own order), from its place in the union's storage: the unbounded members first (getUnboundedPrimitives()), then the BVH's leaves in order (getBVH().getPrimitives()).
 
uint32_t getNumSurfaces () const noexcept
 How many surfaces the union numbers (see hasSurfaces): one per member, or a container member's own getNumSurfaces().
 
uint32_t getFirstSurface (uint32_t a_member) const noexcept
 A member's first surface: member i covers [getFirstSurface(i), getFirstSurface(i + 1)).
 
SurfaceRef< T > closestSurface (const Vec3T< T > &a_point) const noexcept
 The surface that decides the union's value at a point (see hasSurfaces): the member with the smallest value (the one that dominates the blend), ties going to the lower member index (with several types, to the earlier type), drilled into if it is a container.
 
BV computeBoundingVolume () const noexcept
 The axis-aligned bounding box enclosing all primitives.
 
Root getBVH () const noexcept
 Get the packed BVH over the primitives whose bounding box is bounded.
 
PODSpan< const Leaf > getUnboundedPrimitives () const noexcept
 Get the leaves of the primitives whose bounding box is unbounded, which every query evaluates.
 
template<class F >
auto visit (const Leaf &a_leaf, F &&a_f) const noexcept
 Call a_f with the primitive a leaf stands for; see BVHUnion::visit().
 
BVHSmoothUnion rebasedView (const Pool &a_pool) const noexcept
 Produce a copy of this smooth union that resolves against a_pool; see BVHUnion.
 
BVHSmoothUnion deepCopy (Pool &a_dstPool) const
 Duplicate this smooth union's storage, and that of any pool-resident primitive, into a_dstPool.
 
 BVHSmoothUnion (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; see BVHUnion.
 
Layout layout () const noexcept
 The union's arrays and parameters without its location, for storing it inside an outer union.
 
- 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 Member Functions

static BVH::ConstructionOptions defaultConstructionOptions () noexcept
 The leaf-size settings the constructors without options use; the same as BVHUnion's.
 

Static Public Attributes

static constexpr DistanceQuality distanceQuality = CSGDetail::unionQuality<Ps...>
 How far signedDistance() can be trusted as a distance: a bound, or only a sign if any primitive type's values are not distances. SmoothMinOp and ExpMinOp weight the two primitives' gradients by weights that sum to one, so they do not make the blend steeper than its inputs.
 
static constexpr size_t NumTypes = sizeof...(Ps)
 How many primitive types the union holds.
 
static constexpr bool HasContainers = CSGDetail::hasContainers<T, Ps...>
 Whether a primitive type is a container (see hasSurfaces), whose surfaces the union numbers too.
 
static constexpr bool HasParts = (hasParts<Ps, T> || ...)
 Whether a primitive type has parts (see hasParts), which closestSurface() reports.
 

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, const bool a_deviceWritten=false) 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, size_t K, class Blend = SmoothMinOp<T>, class... Ps>
class EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >

BVH-accelerated smooth union of many primitives of one or more types.

Uses the BVH to find the two primitives with the smallest values and blends those values with a smooth-minimum operator, yielding C1 (or better) blending across nearby surfaces with sub-linear query cost. Otherwise identical to BVHUnion (the primitive types, deduced from the arrays, and how several are stored): a plain, trivially copyable value type whose signedDistance() is callable on the host and on a device.

Template Parameters
TFloating-point precision.
KBVH branching factor.
BlendSmooth-minimum operator: a trivially copyable function object with an EBGEOMETRY_HOST_DEVICE T operator()(const T& a, const T& b, const T& s) const, such as SmoothMinOp (the default) or ExpMinOp.
PsPrimitive types (at least one); see BVHUnion.

Constructor & Destructor Documentation

◆ BVHSmoothUnion() [1/6]

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::BVHSmoothUnion ( Pool &  a_pool,
T  a_smoothLen,
const std::vector< Ps > &...  a_primitives 
)

Build the smooth union of the given primitives with a default-constructed Blend, SAH and the default leaf sizes.

Each primitive's box is its computeBoundingVolume().

Parameters
[in,out]a_poolPool the union is reserved from; see BVHUnion.
[in]a_smoothLenSmoothing length (must be > 0).
[in]a_primitivesOne array per primitive type; empty arrays are allowed, but not all of them.

◆ BVHSmoothUnion() [2/6]

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::BVHSmoothUnion ( Pool &  a_pool,
T  a_smoothLen,
Blend  a_blend,
const std::vector< Ps > &...  a_primitives 
)

Build the smooth union of the given primitives with a smooth-minimum operator.

Parameters
[in,out]a_poolPool the union is reserved from; see BVHUnion.
[in]a_smoothLenSmoothing length (must be > 0).
[in]a_blendSmooth-minimum operator.
[in]a_primitivesOne array per primitive type; empty arrays are allowed, but not all of them.

◆ BVHSmoothUnion() [3/6]

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::BVHSmoothUnion ( Pool &  a_pool,
const BVH::BuildSettings &  a_settings,
T  a_smoothLen,
Blend  a_blend,
const std::vector< Ps > &...  a_primitives 
)

Build the smooth union with a construction method and, optionally, leaf sizes.

Parameters
[in,out]a_poolPool the union is reserved from; see BVHUnion.
[in]a_settingsConstruction method and leaf sizes.
[in]a_smoothLenSmoothing length (must be > 0).
[in]a_blendSmooth-minimum operator.
[in]a_primitivesOne array per primitive type; empty arrays are allowed, but not all of them.

◆ BVHSmoothUnion() [4/6]

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
template<size_t N = sizeof...(Ps), std::enable_if_t< N==1, int > = 0>
EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::BVHSmoothUnion ( Pool &  a_pool,
const std::vector< First > &  a_primitives,
const std::vector< BV > &  a_boundingVolumes,
T  a_smoothLen,
Blend  a_blend = Blend{},
BVH::Construction  a_construction = BVH::Construction::SAH 
)

Build a smooth union of one type with the caller's bounding boxes.

Parameters
[in,out]a_poolPool the union is reserved from; see BVHUnion.
[in]a_primitivesPrimitives (must be non-empty).
[in]a_boundingVolumesBounding box of each primitive (same length as a_primitives).
[in]a_smoothLenSmoothing length (must be > 0).
[in]a_blendSmooth-minimum operator.
[in]a_constructionPreset construction method; every BVH::Construction value is supported. The leaf sizes are defaultConstructionOptions().

◆ BVHSmoothUnion() [5/6]

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
template<size_t N = sizeof...(Ps), std::enable_if_t< N==1, int > = 0>
EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::BVHSmoothUnion ( Pool &  a_pool,
const std::vector< First > &  a_primitives,
const std::vector< BV > &  a_boundingVolumes,
T  a_smoothLen,
Blend  a_blend,
BVH::Construction  a_construction,
const BVH::ConstructionOptions &  a_options 
)

Build a smooth union of one type with the caller's bounding boxes and leaf-size settings.

The chosen method reads only its own field of a_options; see BVH::ConstructionOptions.

Parameters
[in,out]a_poolPool the union is reserved from; see BVHUnion.
[in]a_primitivesPrimitives (must be non-empty).
[in]a_boundingVolumesBounding box of each primitive (same length as a_primitives).
[in]a_smoothLenSmoothing length (must be > 0).
[in]a_blendSmooth-minimum operator.
[in]a_constructionPreset construction method; every BVH::Construction value is supported.
[in]a_optionsLeaf-size settings, in primitives.

◆ BVHSmoothUnion() [6/6]

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::BVHSmoothUnion ( 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; see BVHUnion.

Parameters
[in]a_layoutThe union's arrays and parameters.
[in]a_locationWhere they live.

Member Function Documentation

◆ closestSurface()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
SurfaceRef< T > EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::closestSurface ( const Vec3T< T > &  a_point) const
inlinenoexcept

The surface that decides the union's value at a point (see hasSurfaces): the member with the smallest value (the one that dominates the blend), ties going to the lower member index (with several types, to the earlier type), drilled into if it is a container.

Parameters
[in]a_pointQuery point.
Returns
The surface, and the point in its member's frame.

◆ computeBoundingVolume()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
BV EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::computeBoundingVolume ( ) const
inlinenoexcept

The axis-aligned bounding box enclosing all primitives.

Returns
The BVH's root box merged with the boxes of the unbounded primitives.

◆ deepCopy()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
BVHSmoothUnion EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::deepCopy ( Pool &  a_dstPool) const
inline

Duplicate this smooth union's storage, and that of any pool-resident primitive, into a_dstPool.

Parameters
[in,out]a_dstPoolPool to reserve the copy from.
Returns
A BVHSmoothUnion with the same structure, backed by a_dstPool.

◆ defaultConstructionOptions()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
static BVH::ConstructionOptions EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::defaultConstructionOptions ( )
inlinestaticnoexcept

The leaf-size settings the constructors without options use; the same as BVHUnion's.

Returns
The default settings.

◆ getBVH()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
Root EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::getBVH ( ) const
inlinenoexcept

Get the packed BVH over the primitives whose bounding box is bounded.

Returns
The BVH.

◆ getFirstSurface()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
uint32_t EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::getFirstSurface ( uint32_t  a_member) const
inlinenoexcept

A member's first surface: member i covers [getFirstSurface(i), getFirstSurface(i + 1)).

Parameters
[in]a_memberMember index, in the constructor's order, at most getNumMembers().
Returns
The surface.

◆ getMemberIndex()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
uint32_t EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::getMemberIndex ( uint32_t  a_position) const
inlinenoexcept

A member's index in the order the constructor was given the primitives (type by type, in the order of the arrays, each array in its own order), from its place in the union's storage: the unbounded members first (getUnboundedPrimitives()), then the BVH's leaves in order (getBVH().getPrimitives()).

Parameters
[in]a_positionPlace in the storage, below getNumMembers().
Returns
The member's index.

◆ getNumMembers()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
uint32_t EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::getNumMembers ( ) const
inlinenoexcept

How many members (primitives) the union holds.

Returns
The count.

◆ getNumSurfaces()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
uint32_t EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::getNumSurfaces ( ) const
inlinenoexcept

How many surfaces the union numbers (see hasSurfaces): one per member, or a container member's own getNumSurfaces().

Returns
The count.

◆ getUnboundedPrimitives()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
PODSpan< const Leaf > EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::getUnboundedPrimitives ( ) const
inlinenoexcept

Get the leaves of the primitives whose bounding box is unbounded, which every query evaluates.

Returns
Span over those leaves; empty if there are none.

◆ layout()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
Layout EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::layout ( ) const
inlinenoexcept

The union's arrays and parameters without its location, for storing it inside an outer union.

Returns
The layout.

◆ rebasedView()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
BVHSmoothUnion EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::rebasedView ( const Pool &  a_pool) const
inlinenoexcept

Produce a copy of this smooth union that resolves against a_pool; see BVHUnion.

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

◆ signedDistance()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
T EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::signedDistance ( const Vec3T< T > &  a_point) const
inlinenoexcept

Evaluate the smooth union at a point.

Blends the two smallest primitive values with the smooth-minimum operator.

Parameters
[in]a_point3D query point.
Returns
The blended value.

◆ visit()

template<class T , size_t K, class Blend = SmoothMinOp<T>, class... Ps>
template<class F >
auto EBGeometry::BVHSmoothUnion< T, K, Blend, Ps >::visit ( const Leaf &  a_leaf,
F &&  a_f 
) const
inlinenoexcept

Call a_f with the primitive a leaf stands for; see BVHUnion::visit().

Template Parameters
FCallable on each primitive type.
Parameters
[in]a_leafA leaf of this union.
[in]a_fWhat to call.
Returns
What a_f returns.

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