11#ifndef EBGEOMETRY_CSG_HPP
12#define EBGEOMETRY_CSG_HPP
40template <
class T,
class P = ImplicitFunction<T>>
41[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
53template <
class T,
class P1,
class P2>
54[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
66template <
class T,
class P = ImplicitFunction<T>>
67[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
80template <
class T,
class P1,
class P2>
81[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
99template <
class T,
class P,
class BV,
size_t K>
100[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
116template <
class T,
class P,
class BV,
size_t K>
117[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
130template <
class T,
class P>
131[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
143template <
class T,
class P1,
class P2>
144[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
155template <
class T,
class P>
156[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
169template <
class T,
class P1,
class P2>
170[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
185template <
class T,
class P1 = ImplicitFunction<T>,
class P2 = ImplicitFunction<T>>
186[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
200template <
class T,
class P1 = ImplicitFunction<T>,
class P2 = ImplicitFunction<T>>
201[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
219template <
class T,
class P = ImplicitFunction<T>>
220[[
nodiscard]] std::shared_ptr<ImplicitFunction<T>>
237std::function<T(
const T&
a,
const T&
b,
const T&
s)>
ExpMin = [](
const T&
a,
const T&
b,
const T&
s) -> T {
238 static_assert(std::is_floating_point_v<T>,
"ExpMin requires a floating-point type T");
241 T
ret = std::exp(-
a /
s) + std::exp(-
b /
s);
243 return -std::log(
ret) *
s;
257std::function<T(
const T&
a,
const T&
b,
const T&
s)>
SmoothMin = [](
const T&
a,
const T&
b,
const T&
s) -> T {
258 static_assert(std::is_floating_point_v<T>,
"SmoothMin requires a floating-point type T");
261 const T
h = std::max(
s - std::abs(
a -
b), T(0)) /
s;
263 return std::min(
a,
b) - T(0.25) *
h *
h *
s;
277std::function<T(
const T&
a,
const T&
b,
const T&
s)>
SmoothMax = [](
const T&
a,
const T&
b,
const T&
s) -> T {
278 static_assert(std::is_floating_point_v<T>,
"SmoothMax requires a floating-point type T");
281 const T
h = std::max(
s - std::abs(
a -
b), T(0)) /
s;
283 return std::max(
a,
b) + T(0.25) *
h *
h *
s;
297 static_assert(std::is_floating_point_v<T>,
"UnionIF requires a floating-point type T");
342 static_assert(std::is_floating_point_v<T>,
"SmoothUnionIF requires a floating-point type T");
401template <
class T,
class P,
class BV,
size_t K>
405 static_assert(std::is_floating_point_v<T>,
"BVHUnionIF requires a floating-point type T");
406 static_assert(std::is_base_of_v<EBGeometry::ImplicitFunction<T>,
P>,
"BVHUnionIF requires an implicit function");
407 static_assert(K > 0,
"BVHUnionIF BVH branching factor K must be positive");
417 using Node =
typename Root::Node;
489 static_assert(std::is_floating_point_v<T>,
"BVHSmoothUnionIF requires a floating-point type T");
490 static_assert(std::is_base_of_v<EBGeometry::ImplicitFunction<T>,
P>,
491 "BVHSmoothUnionIF requires an implicit function");
492 static_assert(K > 0,
"BVHSmoothUnionIF BVH branching factor K must be positive");
502 using Node =
typename Root::Node;
580 static_assert(std::is_floating_point_v<T>,
"IntersectionIF requires a floating-point type T");
625 static_assert(std::is_floating_point_v<T>,
"SmoothIntersectionIF requires a floating-point type T");
696 static_assert(std::is_floating_point_v<T>,
"DifferenceIF requires a floating-point type T");
756 static_assert(std::is_floating_point_v<T>,
"SmoothDifferenceIF requires a floating-point type T");
818 static_assert(std::is_floating_point_v<T>,
"FiniteRepetitionIF requires a floating-point type T");
874#include "EBGeometry_CSGImplem.hpp"
Declaration of bounding volume hierarchy (BVH) classes.
Abstract base class for representing an implicit function.
Utility macros for EBGeometry.
#define EBGEOMETRY_EXPECT(cond)
Runtime precondition assertion for EBGeometry.
Definition EBGeometry_Macros.hpp:62
Declaration of 2D and 3D point/vector classes with templated precision. Used with DCEL tools.
BVH-accelerated smooth union of implicit functions.
Definition EBGeometry_CSG.hpp:487
~BVHSmoothUnionIF() override=default
Destructor.
BVHSmoothUnionIF(const std::vector< std::shared_ptr< P > > &a_distanceFunctions, const std::vector< BV > &a_boundingVolumes, const T a_smoothLen, const std::function< T(const T &, const T &, const T &)> a_smoothMin=SmoothMin< T >) noexcept
Constructs the BVH-accelerated smooth union.
const EBGeometry::BoundingVolumes::AABBT< T > & getBoundingVolume() const noexcept
Returns the axis-aligned bounding box enclosing all primitives.
typename Root::Node Node
Alias for a BVH node.
Definition EBGeometry_CSG.hpp:502
BVHSmoothUnionIF()=delete
Disallowed, use the full constructor.
T value(const Vec3T< T > &a_point) const noexcept override
Evaluates the smoothly blended signed distance at a_point using BVH traversal.
BVH-accelerated union of implicit functions.
Definition EBGeometry_CSG.hpp:403
BVHUnionIF(const std::vector< std::shared_ptr< P > > &a_primitives, const std::vector< BV > &a_boundingVolumes)
Constructs the BVH-accelerated union from separate primitive and bounding-volume lists.
T value(const Vec3T< T > &a_point) const noexcept override
Evaluates the signed distance at a_point using BVH traversal.
const EBGeometry::BoundingVolumes::AABBT< T > & getBoundingVolume() const noexcept
Returns the axis-aligned bounding box enclosing all primitives.
BVHUnionIF()=delete
Disallowed, use the full constructor.
~BVHUnionIF() override=default
Destructor.
std::shared_ptr< EBGeometry::BVH::PackedBVH< T, P, K > > m_bvh
Flat BVH over all input primitives.
Definition EBGeometry_CSG.hpp:463
BVHUnionIF(const std::vector< std::pair< std::shared_ptr< const P >, BV > > &a_primsAndBVs)
Constructs the BVH-accelerated union from pre-paired primitives and bounding volumes.
typename Root::Node Node
Alias for a BVH node.
Definition EBGeometry_CSG.hpp:417
void buildTree(const std::vector< std::pair< std::shared_ptr< const P >, BV > > &a_primsAndBVs, const BVH::Build a_build=BVH::Build::SAH) noexcept
Builds the internal BVH from primitive/BV pairs.
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:247
Implicit function whose interior is the set difference A \ B.
Definition EBGeometry_CSG.hpp:694
DifferenceIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunctionA, const std::vector< std::shared_ptr< ImplicitFunction< T > > > &a_implicitFunctionsB) noexcept
Constructs A \ union(Bs) from A and a list of subtrahends.
std::shared_ptr< ImplicitFunction< T > > m_implicitFunctionA
Minuend implicit function.
Definition EBGeometry_CSG.hpp:737
~DifferenceIF() override=default
Destructor.
std::shared_ptr< ImplicitFunction< T > > m_implicitFunctionB
Subtrahend implicit function (may wrap a union of multiple subtrahends).
Definition EBGeometry_CSG.hpp:742
DifferenceIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunctionA, const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunctionB) noexcept
Constructs A \ B from two implicit functions.
T value(const Vec3T< T > &a_point) const noexcept override
Evaluates the signed distance at a_point.
DifferenceIF()=delete
Disallowed, use the full constructor.
Implicit function that tiles a base function periodically within a finite repetition count.
Definition EBGeometry_CSG.hpp:816
std::shared_ptr< ImplicitFunction< T > > m_implicitFunction
Base implicit function to tile.
Definition EBGeometry_CSG.hpp:869
FiniteRepetitionIF()=delete
Disallowed, use the full constructor.
Vec3T< T > m_repeatLo
Repetition count for decreasing coordinate directions.
Definition EBGeometry_CSG.hpp:864
T value(const Vec3T< T > &a_point) const noexcept override
Evaluates the signed distance at a_point by folding into the nearest tile.
~FiniteRepetitionIF() override=default
Destructor.
Vec3T< T > m_period
Tile period in each coordinate direction.
Definition EBGeometry_CSG.hpp:854
FiniteRepetitionIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const Vec3T< T > &a_period, const Vec3T< T > &a_repeatLo, const Vec3T< T > &a_repeatHi) noexcept
Constructs the periodically tiled implicit function.
Vec3T< T > m_repeatHi
Repetition count for increasing coordinate directions.
Definition EBGeometry_CSG.hpp:859
Abstract representation of an implicit function (not necessarily a signed distance function).
Definition EBGeometry_ImplicitFunction.hpp:32
Implicit function whose interior is the intersection of all input function interiors.
Definition EBGeometry_CSG.hpp:578
T value(const Vec3T< T > &a_point) const noexcept override
Evaluates the signed distance at a_point.
std::vector< std::shared_ptr< const ImplicitFunction< T > > > m_implicitFunctions
Stored implicit functions.
Definition EBGeometry_CSG.hpp:611
IntersectionIF(const std::vector< std::shared_ptr< ImplicitFunction< T > > > &a_implicitFunctions) noexcept
Constructs the intersection of the given implicit functions.
~IntersectionIF() override=default
Destructor.
IntersectionIF()=delete
Disallowed, use the full constructor.
Implicit function representing a smoothly blended set difference A \ B.
Definition EBGeometry_CSG.hpp:754
SmoothDifferenceIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunctionA, const std::vector< std::shared_ptr< ImplicitFunction< T > > > &a_implicitFunctionsB, const T a_smoothLen, const std::function< T(const T &a, const T &b, const T &s)> &a_smoothMax=SmoothMax< T >) noexcept
Constructs the smooth difference A \ union(Bs) from A and a list of subtrahends.
~SmoothDifferenceIF() override=default
Destructor.
std::shared_ptr< SmoothIntersectionIF< T > > m_smoothIntersectionIF
Internal smooth intersection implementing smooth(A ∩ complement(B)).
Definition EBGeometry_CSG.hpp:805
SmoothDifferenceIF()=delete
Disallowed, use the full constructor.
SmoothDifferenceIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunctionA, const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunctionB, const T a_smoothLen, const std::function< T(const T &a, const T &b, const T &s)> &a_smoothMax=SmoothMax< T >) noexcept
Constructs the smooth difference A \ B from two implicit functions.
T value(const Vec3T< T > &a_point) const noexcept override
Evaluates the smoothly blended signed distance at a_point.
Implicit function whose interior is a smoothly blended intersection of all input function interiors.
Definition EBGeometry_CSG.hpp:623
T m_smoothLen
Smoothing length.
Definition EBGeometry_CSG.hpp:678
std::vector< std::shared_ptr< const ImplicitFunction< T > > > m_implicitFunctions
Stored implicit functions.
Definition EBGeometry_CSG.hpp:673
~SmoothIntersectionIF() override=default
Destructor.
SmoothIntersectionIF()=delete
Disallowed, use the full constructor.
std::function< T(const T &a, const T &b, const T &s)> m_smoothMax
Smooth-maximum operator.
Definition EBGeometry_CSG.hpp:683
SmoothIntersectionIF(const std::vector< std::shared_ptr< ImplicitFunction< T > > > &a_implicitFunctions, const T a_smoothLen, const std::function< T(const T &a, const T &b, const T &s)> &a_smoothMax=SmoothMax< T >) noexcept
Constructs the smooth intersection of a list of implicit functions.
T value(const Vec3T< T > &a_point) const noexcept override
Evaluates the smoothly blended signed distance at a_point.
SmoothIntersectionIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunctionA, const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunctionB, const T a_smoothLen, const std::function< T(const T &a, const T &b, const T &s)> &a_smoothMax=SmoothMax< T >) noexcept
Constructs the smooth intersection of two implicit functions.
Implicit function whose interior is a smoothly blended union of all input function interiors.
Definition EBGeometry_CSG.hpp:340
SmoothUnionIF()=delete
Disallowed, use the full constructor.
SmoothUnionIF(const std::vector< std::shared_ptr< ImplicitFunction< T > > > &a_implicitFunctions, const T a_smoothLen, const std::function< T(const T &a, const T &b, const T &s)> a_smoothMin=SmoothMin< T >)
Constructs the smooth union of the given implicit functions.
T value(const Vec3T< T > &a_point) const noexcept override
Evaluates the smoothly blended signed distance at a_point.
T m_smoothLen
Smoothing length.
Definition EBGeometry_CSG.hpp:383
std::vector< std::shared_ptr< const ImplicitFunction< T > > > m_implicitFunctions
Stored implicit functions.
Definition EBGeometry_CSG.hpp:378
std::function< T(const T &, const T &, const T &)> m_smoothMin
Smooth-minimum operator.
Definition EBGeometry_CSG.hpp:388
~SmoothUnionIF() override=default
Destructor.
Implicit function whose interior is the union of all input function interiors.
Definition EBGeometry_CSG.hpp:295
std::vector< std::shared_ptr< const ImplicitFunction< T > > > m_implicitFunctions
Stored implicit functions.
Definition EBGeometry_CSG.hpp:328
~UnionIF() override=default
Destructor.
UnionIF()=delete
Disallowed, use the full constructor.
UnionIF(const std::vector< std::shared_ptr< ImplicitFunction< T > > > &a_implicitFunctions)
Constructs the union of the given implicit functions.
T value(const Vec3T< T > &a_point) const noexcept override
Evaluates the signed distance at a_point.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:225
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:31
std::shared_ptr< ImplicitFunction< T > > SmoothUnion(const std::vector< std::shared_ptr< P > > &a_implicitFunctions, const T a_smooth)
Constructs an implicit function whose interior is a smoothly blended union of all input function inte...
std::shared_ptr< ImplicitFunction< T > > Difference(const std::shared_ptr< P1 > &a_implicitFunctionA, const std::shared_ptr< P2 > &a_implicitFunctionB)
Constructs an implicit function whose interior is the set difference A \ B.
std::shared_ptr< ImplicitFunction< T > > Union(const std::vector< std::shared_ptr< P > > &a_implicitFunctions)
Constructs an implicit function whose interior is the union of the interiors of all input functions.
std::shared_ptr< ImplicitFunction< T > > FiniteRepetition(const std::shared_ptr< P > &a_implicitFunction, const Vec3T< T > &a_period, const Vec3T< T > &a_repeatLo, const Vec3T< T > &a_repeatHi)
Constructs a periodically tiled implicit function with finite extent.
std::shared_ptr< ImplicitFunction< T > > BVHSmoothUnion(const std::vector< std::shared_ptr< P > > &a_implicitFunctions, const std::vector< BV > &a_boundingVolumes, const T a_smoothLen) noexcept
Constructs a BVH-accelerated smooth union of implicit functions.
std::function< T(const T &a, const T &b, const T &s)> SmoothMin
Quadratic polynomial smooth minimum for blending two signed-distance values.
Definition EBGeometry_CSG.hpp:257
std::function< T(const T &a, const T &b, const T &s)> ExpMin
Exponential smooth minimum for blending two signed-distance values.
Definition EBGeometry_CSG.hpp:237
std::shared_ptr< ImplicitFunction< T > > BVHUnion(const std::vector< std::shared_ptr< P > > &a_implicitFunctions, const std::vector< BV > &a_boundingVolumes)
Constructs a BVH-accelerated union of implicit functions.
std::shared_ptr< ImplicitFunction< T > > SmoothDifference(const std::shared_ptr< P1 > &a_implicitFunctionA, const std::shared_ptr< P2 > &a_implicitFunctionB, const T a_smoothLen)
Constructs an implicit function representing a smoothly blended set difference A \ B.
std::shared_ptr< ImplicitFunction< T > > SmoothIntersection(const std::vector< std::shared_ptr< P > > &a_implicitFunctions, const T a_smooth)
Constructs an implicit function whose interior is a smoothly blended intersection of all input functi...
std::function< T(const T &a, const T &b, const T &s)> SmoothMax
Quadratic polynomial smooth maximum for blending two signed-distance values.
Definition EBGeometry_CSG.hpp:277
std::shared_ptr< ImplicitFunction< T > > Intersection(const std::vector< std::shared_ptr< P > > &a_implicitFunctions)
Constructs an implicit function whose interior is the intersection of the interiors of all input func...