12 #ifndef EBGeometry_CSG
13 #define EBGeometry_CSG
17 #include <type_traits>
28 template <
class T,
class P = ImplicitFunction<T>>
29 std::shared_ptr<ImplicitFunction<T>>
30 Union(
const std::vector<std::shared_ptr<P>>& a_implicitFunctions) noexcept;
38 template <
class T,
class P1,
class P2>
39 std::shared_ptr<ImplicitFunction<T>>
40 Union(
const std::shared_ptr<P1>& a_implicitFunctionA,
const std::shared_ptr<P2>& a_implicitFunctionB) noexcept;
48 template <
class T,
class P = ImplicitFunction<T>>
49 std::shared_ptr<ImplicitFunction<T>>
50 SmoothUnion(
const std::vector<std::shared_ptr<P>>& a_implicitFunctions,
const T a_smooth) noexcept;
59 template <
class T,
class P1,
class P2>
60 std::shared_ptr<ImplicitFunction<T>>
62 const std::shared_ptr<P2>& a_implicitFunctionB,
63 const T a_smooth) noexcept;
71 template <
class T,
class P,
class BV,
size_t K>
72 std::shared_ptr<ImplicitFunction<T>>
73 FastUnion(
const std::vector<std::shared_ptr<P>>& a_implicitFunctions,
74 const std::vector<BV>& a_boundingVolumes) noexcept;
83 template <
class T,
class P,
class BV,
size_t K>
84 std::shared_ptr<ImplicitFunction<T>>
86 const std::vector<BV>& a_boundingVolumes,
87 const T a_smoothLen) noexcept;
94 template <
class T,
class P>
95 std::shared_ptr<ImplicitFunction<T>>
96 Intersection(
const std::vector<std::shared_ptr<P>>& a_implicitFunctions) noexcept;
104 template <
class T,
class P1,
class P2>
105 std::shared_ptr<ImplicitFunction<T>>
106 Intersection(
const std::shared_ptr<std::shared_ptr<P1>>& a_implicitFunctionA,
107 const std::shared_ptr<std::shared_ptr<P2>>& a_implicitFunctionB) noexcept;
115 template <
class T,
class P>
116 std::shared_ptr<ImplicitFunction<T>>
117 SmoothIntersection(
const std::vector<std::shared_ptr<P>>& a_implicitFunctions,
const T a_smooth) noexcept;
126 template <
class T,
class P1,
class P2>
127 std::shared_ptr<ImplicitFunction<T>>
129 const std::shared_ptr<P2>& a_implicitFunctionB,
130 const T a_smooth) noexcept;
138 template <
class T,
class P1 = ImplicitFunction<T>,
class P2 = ImplicitFunction<T>>
139 std::shared_ptr<ImplicitFunction<T>>
140 Difference(
const std::shared_ptr<P1>& a_implicitFunctionA,
const std::shared_ptr<P2>& a_implicitFunctionB) noexcept;
149 template <
class T,
class P1 = ImplicitFunction<T>,
class P2 = ImplicitFunction<T>>
150 std::shared_ptr<ImplicitFunction<T>>
152 const std::shared_ptr<P2>& a_implicitFunctionB,
153 const T a_smoothLen) noexcept;
163 template <
class T,
class P = ImplicitFunction<T>>
164 std::shared_ptr<ImplicitFunction<T>>
168 const Vec3T<T>& a_repeatHi) noexcept;
177 std::function<T(
const T& a,
const T& b,
const T& s)>
expMin = [](
const T& a,
const T& b,
const T& s) -> T {
178 T ret = exp(-a / s) + exp(-b / s);
180 return -log(ret) * s;
190 std::function<T(
const T& a,
const T& b,
const T& s)>
smoothMin = [](
const T& a,
const T& b,
const T& s) -> T {
191 const T h =
std::max(s - std::abs(a - b), 0.0) / s;
193 return std::min(a, b) - 0.25 * h * h * s;
203 std::function<T(
const T& a,
const T& b,
const T& s)>
smoothMax = [](
const T& a,
const T& b,
const T& s) -> T {
204 const T h =
std::max(s - std::abs(a - b), 0.0) / s;
206 return std::max(a, b) + 0.25 * h * h * s;
266 const std::function<T(
const T& a,
const T& b,
const T& s)> a_smoothMin = smoothMin<T>) noexcept;
300 template <
class T,
class P,
class BV,
size_t K>
304 static_assert(std::is_base_of<EBGeometry::ImplicitFunction<T>, P>::
value,
305 "FastUnionIF requires an implicit function");
310 using Root =
typename EBGeometry::BVH::LinearBVH<T, P, BV, K>;
315 using Node =
typename Root::LinearNode;
326 FastUnionIF(
const std::vector<std::pair<std::shared_ptr<const P>, BV>>& a_primsAndBVs) noexcept;
333 FastUnionIF(
const std::vector<std::shared_ptr<P>>& a_primitives,
const std::vector<BV>& a_boundingVolumes) noexcept;
365 buildTree(const std::vector<std::pair<std::shared_ptr<const P>, BV>>& a_primsAndBVs,
374 template <class T, class P, class BV,
size_t K>
378 static_assert(std::is_base_of<EBGeometry::ImplicitFunction<T>, P>::
value,
379 "FastSmoothUnionIF requires an implicit function");
384 using Root =
typename EBGeometry::BVH::LinearBVH<T, P, BV, K>;
389 using Node =
typename Root::LinearNode;
404 const std::vector<BV>& a_boundingVolumes,
406 const std::function<T(
const T&,
const T&,
const T&)> a_smoothMin = smoothMin<T>) noexcept;
491 const std::function<T(
const T& a,
const T& b,
const T& s)>& a_smoothMax = smoothMax<T>) noexcept;
501 const std::function<T(
const T& a,
const T& b,
const T& s)>& a_smoothMax = smoothMax<T>) noexcept;
606 const std::function<T(
const T& a,
const T& b,
const T& s)>& a_smoothMax = smoothMax<T>) noexcept;
618 const std::function<T(
const T& a,
const T& b,
const T& s)>& a_smoothMax = smoothMax<T>) noexcept;
663 const Vec3T<T>& a_repeatHi) noexcept;
701 #include "EBGeometry_CSGImplem.hpp"
std::function< T(const T &a, const T &b, const T &s)> expMin
Exponential minimum function for CSG.
Definition: EBGeometry_CSG.hpp:177
std::shared_ptr< ImplicitFunction< T > > FastSmoothUnion(const std::vector< std::shared_ptr< P >> &a_implicitFunctions, const std::vector< BV > &a_boundingVolumes, const T a_smoothLen) noexcept
Convenience function for taking the BVH-accelerated union of a bunch of a implicit functions.
std::shared_ptr< ImplicitFunction< T > > Intersection(const std::vector< std::shared_ptr< P >> &a_implicitFunctions) noexcept
Convenience function for taking the intersection of a bunch of a implicit functions.
std::shared_ptr< ImplicitFunction< T > > SmoothIntersection(const std::vector< std::shared_ptr< P >> &a_implicitFunctions, const T a_smooth) noexcept
Convenience function for taking the smooth intersection of a bunch of a 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) noexcept
Convenience function for taking the smooth CSG difference.
std::shared_ptr< ImplicitFunction< T > > Union(const std::vector< std::shared_ptr< P >> &a_implicitFunctions) noexcept
Convenience function for taking the union of a bunch of a implicit 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) noexcept
Convenience function for creating a periodically repeated implicit function (FiniteRepetitionIF).
std::shared_ptr< ImplicitFunction< T > > FastUnion(const std::vector< std::shared_ptr< P >> &a_implicitFunctions, const std::vector< BV > &a_boundingVolumes) noexcept
Convenience function for taking the BVH-accelerated union of a bunch of a implicit functions.
std::function< T(const T &a, const T &b, const T &s)> smoothMin
Smooth minimum function for CSG.
Definition: EBGeometry_CSG.hpp:190
std::shared_ptr< ImplicitFunction< T > > Difference(const std::shared_ptr< P1 > &a_implicitFunctionA, const std::shared_ptr< P2 > &a_implicitFunctionB) noexcept
Convenience function for taking the CSG difference.
std::shared_ptr< ImplicitFunction< T > > SmoothUnion(const std::vector< std::shared_ptr< P >> &a_implicitFunctions, const T a_smooth) noexcept
Convenience function for taking the union of a bunch of a implicit functions.
std::function< T(const T &a, const T &b, const T &s)> smoothMax
Smooth maximum function for CSG.
Definition: EBGeometry_CSG.hpp:203
Abstract base class for representing an implicit function.
Vec2T< T > max(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Maximum function. Returns new vector with component-wise minimums.
Vec2T< T > min(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Minimum function. Returns new vector with component-wise minimums.
CSG difference between two implicit functions.
Definition: EBGeometry_CSG.hpp:537
DifferenceIF(const std::shared_ptr< ImplicitFunction< T >> &a_implicitFunctionA, const std::vector< std::shared_ptr< ImplicitFunction< T >>> &a_implicitFunctionsB) noexcept
Full constructor. Computes the CSG difference between A and the union of the B's.
std::shared_ptr< ImplicitFunction< T > > m_implicitFunctionA
First implicit function.
Definition: EBGeometry_CSG.hpp:576
virtual ~DifferenceIF()=default
Destructor (does nothing)
DifferenceIF(const std::shared_ptr< ImplicitFunction< T >> &a_implicitFunctionA, const std::shared_ptr< ImplicitFunction< T >> &a_implicitFunctionB) noexcept
Full constructor. Computes the CSG difference.
DifferenceIF()=delete
Disallowed, use the full constructor.
std::shared_ptr< ImplicitFunction< T > > m_implicitFunctionB
Subtracted implicit function.
Definition: EBGeometry_CSG.hpp:581
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
Implicit function smoothed union using BVHs.
Definition: EBGeometry_CSG.hpp:376
FastSmoothUnionIF()=delete
Disallowed, use the full constructor.
T m_smoothLen
Smoothing length.
Definition: EBGeometry_CSG.hpp:424
virtual ~FastSmoothUnionIF()=default
Destructor (does nothing)
std::function< T(const T &, const T &, const T &)> m_smoothMin
Smooth min operator.
Definition: EBGeometry_CSG.hpp:429
FastSmoothUnionIF(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
Full constructor - constructs bounding volumes in place.
virtual T value(const Vec3T< T > &a_point) const noexcept override
Value function.
Implicit function union using BVHs.
Definition: EBGeometry_CSG.hpp:302
FastUnionIF()=delete
Disallowed, use the full constructor.
std::shared_ptr< EBGeometry::BVH::LinearBVH< T, P, BV, K > > m_bvh
Root node for linearized BVH tree.
Definition: EBGeometry_CSG.hpp:357
FastUnionIF(const std::vector< std::shared_ptr< P >> &a_primitives, const std::vector< BV > &a_boundingVolumes) noexcept
Full constructor - constructs bounding volumes in place.
typename EBGeometry::BVH::LinearBVH< T, P, BV, K > Root
Alias for linear BVH type.
Definition: EBGeometry_CSG.hpp:310
FastUnionIF(const std::vector< std::pair< std::shared_ptr< const P >, BV >> &a_primsAndBVs) noexcept
Full constructor - constructs bounding volumes in place.
typename Root::LinearNode Node
Alias for linear BVH node.
Definition: EBGeometry_CSG.hpp:315
void buildTree(const std::vector< std::pair< std::shared_ptr< const P >, BV >> &a_primsAndBVs, const BVH::Build a_build=BVH::Build::TopDown) noexcept
Build BVH tree for the input objects.
virtual T value(const Vec3T< T > &a_point) const noexcept override
Value function.
const BV & getBoundingVolume() const noexcept
Get the bounding volume.
virtual ~FastUnionIF()=default
Destructor (does nothing)
Class which creates a periodic repetition of an implicit function.
Definition: EBGeometry_CSG.hpp:646
virtual ~FiniteRepetitionIF()=default
Destructor (does nothing)
std::shared_ptr< ImplicitFunction< T > > m_implicitFunction
Underlying implicit function.
Definition: EBGeometry_CSG.hpp:696
Vec3T< T > m_repeatLo
Number of repetition over increasing coordinate direction.
Definition: EBGeometry_CSG.hpp:691
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
Full constructor.
Vec3T< T > m_repeatHi
Number of repetition over increasing coordinate direction.
Definition: EBGeometry_CSG.hpp:686
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
FiniteRepetitionIF()=delete
Disallowed - use the full constructor.
Vec3T< T > m_period
Repetition period.
Definition: EBGeometry_CSG.hpp:681
Abstract representation of an implicit function function (not necessarily signed distance).
Definition: EBGeometry_ImplicitFunction.hpp:27
CSG intersection. Computes the maximum value of all input primitives.
Definition: EBGeometry_CSG.hpp:437
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
IntersectionIF()=delete
Disallowed, use the full constructor.
IntersectionIF(const std::vector< std::shared_ptr< ImplicitFunction< T >>> &a_implicitFunctions) noexcept
Full constructor. Computes the CSG intersection.
std::vector< std::shared_ptr< const ImplicitFunction< T > > > m_implicitFunctions
List of primitives.
Definition: EBGeometry_CSG.hpp:466
virtual ~IntersectionIF()=default
Destructor (does nothing)
CSG difference between two implicit functions.
Definition: EBGeometry_CSG.hpp:589
virtual ~SmoothDifferenceIF()=default
Destructor (does nothing)
SmoothDifferenceIF()=delete
Disallowed, use the full constructor.
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
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
Full constructor. Computes the CSG difference between A and the union of the B's.
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
Full constructor. Computes the smooth CSG difference.
std::shared_ptr< SmoothIntersectionIF< T > > m_smoothIntersectionIF
Resulting smooth intersection.
Definition: EBGeometry_CSG.hpp:636
Smooth intersection.
Definition: EBGeometry_CSG.hpp:474
std::vector< std::shared_ptr< const ImplicitFunction< T > > > m_implicitFunctions
List of primitives.
Definition: EBGeometry_CSG.hpp:519
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
Full constructor. Computes the CSG intersection.
std::function< T(const T &a, const T &b, const T &s)> m_smoothMax
Smooth max operator.
Definition: EBGeometry_CSG.hpp:529
SmoothIntersectionIF()=delete
Disallowed, use the full constructor.
T m_smoothLen
Smoothing parameter.
Definition: EBGeometry_CSG.hpp:524
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
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
Full constructor. Computes the CSG intersection.
virtual ~SmoothIntersectionIF()=default
Destructor (does nothing)
Smooth CSG union. Computes the minimum value of all input primitives.
Definition: EBGeometry_CSG.hpp:251
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
SmoothUnionIF()=delete
Disallowed, use the full constructor.
std::vector< std::shared_ptr< const ImplicitFunction< T > > > m_implicitFunctions
List of primitives.
Definition: EBGeometry_CSG.hpp:284
std::function< T(const T &, const T &, const T &)> m_smoothMin
Function for taking the smooth minimum.
Definition: EBGeometry_CSG.hpp:294
T m_smoothLen
Smoothing parameter.
Definition: EBGeometry_CSG.hpp:289
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 >) noexcept
Full constructor. Computes the CSG union.
virtual ~SmoothUnionIF()=default
Destructor (does nothing)
CSG union. Computes the minimum value of all input primitives.
Definition: EBGeometry_CSG.hpp:214
UnionIF(const std::vector< std::shared_ptr< ImplicitFunction< T >>> &a_implicitFunctions) noexcept
Full constructor. Computes the CSG union.
virtual ~UnionIF()=default
Destructor (does nothing)
std::vector< std::shared_ptr< const ImplicitFunction< T > > > m_implicitFunctions
List of primitives.
Definition: EBGeometry_CSG.hpp:243
UnionIF()=delete
Disallowed, use the full constructor.
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
Three-dimensional vector class with arithmetic operators.
Definition: EBGeometry_Vec.hpp:218
Namespace for various bounding volume hierarchy (BVH) functionality.
Definition: EBGeometry_BVH.hpp:30
Build
Enum for specifying whether or not the construction is top-down or bottom-up.
Definition: EBGeometry_BVH.hpp:36
Name space for all of EBGeometry.
Definition: EBGeometry.hpp:21