24#ifndef EBGEOMETRY_TAPE_HPP
25#define EBGEOMETRY_TAPE_HPP
98namespace TapeFeature {
119namespace TapeDetail {
127enum class Op : uint8_t
219static_assert(
sizeof(
RayClause) == 16,
"TapeDetail::RayClause must be 16 bytes");
258static_assert(
sizeof(
Clause) == 16,
"TapeDetail::Clause must be 16 bytes");
272 c.
m_op =
static_cast<Op>(a_clause.m_op);
274 c.
m_type = a_clause.m_type;
275 c.
m_a = a_clause.m_a;
276 c.
m_b = a_clause.m_b;
277 c.
m_c = a_clause.m_c;
294 c.
m_op =
static_cast<RayOp>(a_clause.m_op);
296 c.
m_type = a_clause.m_type;
297 c.
m_a = a_clause.m_a;
298 c.
m_b = a_clause.m_b;
299 c.
m_c = a_clause.m_c;
328template <
class T,
size_t K>
347template <
class... Ps>
353 static constexpr size_t size =
sizeof...(Ps);
362template <
size_t I,
class List>
371template <
size_t I,
class... Ps>
377 using type = std::tuple_element_t<I, std::tuple<Ps...>>;
386template <
class P,
class List>
400 static constexpr size_t value = 0;
410template <
class P,
class Q,
class... Rest>
416 static constexpr size_t value = std::is_same_v<P, Q> ? 0 : 1 +
IndexOf<P,
TypeList<Rest...>>::value;
424template <
class... Lists>
439template <
class... Ps,
class... Rest>
454template <
class... Ps,
class... Qs>
469inline constexpr bool IsFeature = std::is_base_of_v<TapeFeature::Tag, A>;
476template <
class... Args>
484template <
class... Args>
492template <
class... Ps>
503template <
class P,
class... Ps>
530template <
class... Ps>
548template <
size_t I,
class P,
class... Ps>
553 if constexpr (I == 0) {
554 return a_store.m_head;
557 return storeAt<I - 1>(a_store.m_tail);
570template <
size_t I,
class P,
class... Ps>
575 if constexpr (I == 0) {
576 return a_store.m_head;
579 return storeAt<I - 1>(a_store.m_tail);
590template <
class T,
class... UserPrimitives>
615template <
class T,
class List>
624template <
class T,
class... Ps>
630 static constexpr bool shapes = (isShape<Ps> && ...);
635 static constexpr bool precision = (std::is_same_v<ShapePrecision<Ps>, T> && ...);
645template <
class T,
size_t K,
class List>
681template <
class T,
class... UserPrimitives>
685 static_assert(std::is_floating_point_v<T>,
"Tape requires a floating-point type T");
687 "Tape: every user primitive type must be a shape (see isShape)");
689 "Tape: every user primitive type must have the tape's precision");
888 const
Vec3T<T>& a_to,
917 const
Vec3T<T>& a_to,
1046 static constexpr uint32_t MarchedLeaf = UINT32_MAX;
1051 static constexpr uint32_t LevelLeaf = UINT32_MAX - 1;
1062 template <
unsigned D>
1104 return m_tape->template evaluate<D>(m_program, a_point, m_base, m_location);
1140 traceRay(
const RayT<T>& a_ray, T a_tMin, T a_tMax,
const RayOptions<T>& a_options)
const noexcept;
1153 raySpans(
const RayT<T>& a_ray,
1173 template <
unsigned D>
1177 rayEvaluate(uint32_t a_program,
1206 template <
unsigned D,
bool Level = false>
1210 rayLeafHit(uint32_t a_program,
1277 template <
unsigned D>
1409 resolveLevelHit(uint32_t a_clause,
1427 template <
size_t I,
bool MeshOnly,
class Visit>
1433 const Visit& a_visit)
const noexcept;
1475 template <
unsigned D>
1505 template <
unsigned D,
class V = T>
1509 evaluate(
const uint32_t a_program,
1525 template <
unsigned D,
class V = T>
1528 evaluateBody(
const uint32_t a_program,
1541 template <
size_t I,
class F>
1558 template <
size_t I,
bool Handles>
1561 dispatchPrimitive(
const uint32_t a_type,
1562 const uint32_t a_index,
1572 static constexpr size_t DispatchSplit = 6;
1586 dispatchRest(
const uint32_t a_type,
1587 const uint32_t a_index,
1603 evaluatePrimitive(
const uint32_t a_type,
1604 const uint32_t a_index,
1624 evaluateHandle(
const uint32_t a_type,
1625 const uint32_t a_index,
1641 template <
unsigned D,
class V = T>
1664 template <
unsigned D,
class V = T>
1684 template <
unsigned D,
class V = T>
1708template <
class T,
class... UserPrimitives>
1728 return a_shape.traceRay(a_ray, a_tMin, a_tMax, a_options);
1751 a_shape.raySpans(a_ray, a_tMin, a_tMax, a_options, a_firstOnly, a_spans);
1757#include "EBGeometry_TapeImplem.hpp"
File containing various analytic signed distance fields.
BVH-accelerated unions of many primitives of one type: BVHUnion and BVHSmoothUnion.
Declarations of bounding volume types used in bounding volume hierarchies.
How far a function's value can be trusted as a distance: DistanceQuality, and the distanceQualityOf t...
The tape's front end: Expr, a host-side value that describes a composed object, and the free function...
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_HOST_NOINLINE
Keep a function out of line in a host pass (GCC and Clang); nothing in a device pass.
Definition EBGeometry_GPU.hpp:135
#define EBGEOMETRY_DEVICE_NOINLINE
Keep a function out of line in the device pass (CUDA/HIP); nothing on the host.
Definition EBGeometry_GPU.hpp:110
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Declaration of signed distance functions for DCEL meshes.
Placement-independent POD array views for the GPU memory foundation.
The flattened, device-callable bounding volume hierarchy: PackedBVH, its node layout,...
Growable bump arena for the GPU memory foundation.
PrimitiveRef: which leaf of a composition decides its value at a point.
Ray queries on any shape: where a ray, or the segment between two points, first crosses its surface (...
const auto & storeAt(const PrimitiveStore< P, Ps... > &a_store) noexcept
The pool array of the I-th primitive type.
Definition EBGeometry_Tape.hpp:551
typename Concat< TypeList< PlaneSDF< T >, SphereSDF< T >, BoxSDF< T >, TorusSDF< T >, CylinderSDF< T >, InfiniteCylinderSDF< T >, CapsuleSDF< T >, InfiniteConeSDF< T >, ConeSDF< T >, RoundedBoxSDF< T >, RoundedCylinderSDF< T >, PerlinSDF< T >, FlatMeshSDF< T >, MeshSDF< T, BVH::DefaultBranchingRatio< T >()>, TriMeshSDF< T, BVH::DefaultBranchingRatio< T >(), TriangleSoA::DefaultWidth< T >()> >, UserTypesOf< UserPrimitives... > >::type Primitives
The tape's primitive types: the twelve analytic shapes, the three mesh SDFs with the default branchin...
Definition EBGeometry_Tape.hpp:607
RayOp
The operations of a ray program.
Definition EBGeometry_Tape.hpp:160
@ PopAffine
Pop a ray, and map the top list back through the map at params[m_a..m_a+12).
RayClause rayClause(const Clause &a_clause) noexcept
The ray program clause a stored clause is.
Definition EBGeometry_Tape.hpp:290
Clause stored(const RayClause &a_clause) noexcept
A ray program clause, stored in the clause array (the two have the same fields).
Definition EBGeometry_Tape.hpp:268
Op
The tape's operations.
Definition EBGeometry_Tape.hpp:128
@ PairInsert
Pop v and insert it into the pair below: the two smallest, or largest if m_flags is 1.
@ MulConstant
v -> v * params[m_a].
@ PushAffine
Push the top point mapped by the affine map at params[m_a..m_a+12).
@ Max
Pop b and a, push max(a, b).
@ Min
Pop b and a, push min(a, b).
@ AddConstant
v -> v + params[m_a].
@ PushElongate
Push p - clamp(p, -h, h), h at params[m_a..m_a+3).
@ PairInit
Push the empty pair of extreme values (+inf, +inf), or (-inf, -inf) if m_flags is 1.
typename Concat< std::conditional_t< IsFeature< Args >, TypeList<>, TypeList< Args > >... >::type UserTypesOf
The user primitive types among a Tape's template arguments: those that are not features.
Definition EBGeometry_Tape.hpp:485
constexpr bool IsFeature
Whether a Tape template argument is a feature (see TapeFeature).
Definition EBGeometry_Tape.hpp:469
typename Concat< std::conditional_t< IsFeature< Args >, TypeList< Args >, TypeList<> >... >::type FeaturesOf
The features among a Tape's template arguments.
Definition EBGeometry_Tape.hpp:477
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Forward declaration of the linearised BVH, defined below.
Definition EBGeometry_PackedBVH.hpp:357
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
Signed distance field for an axis-aligned box (AABB).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:351
Signed distance field for a capsule (pill shape): a cylinder capped with hemispheres.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1117
Signed distance field for a finite cone.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1427
Signed distance field for a finite, flat-capped cylinder.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:728
A composed object: an immutable tree of shapes and operations, built on the host and compiled by a Ta...
Definition EBGeometry_Expr.hpp:357
Signed distance function for a DCEL mesh. Does not use BVHs.
Definition EBGeometry_MeshDistanceFunctions.hpp:79
Signed distance field for an infinite cone.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1301
Signed distance field for an infinitely long cylinder.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:947
A FlatMeshSDF must be trivially copyable: that is what lets a rebasedView() be byte-copied into a dev...
Definition EBGeometry_MeshDistanceFunctions.hpp:249
Ken Perlin's gradient-noise implicit function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1716
Base of every pool-resident handle: the one PoolLocation its arrays resolve against.
Definition EBGeometry_Pool.hpp:499
PoolHandle() noexcept=default
An unset location; the first reservation attaches it.
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:183
Signed distance field for an axis-aligned box with rounded edges and corners.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1570
Signed distance field for a cylinder with rounded (toroidal) edges.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:2018
Signed distance field for a sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:199
A composed object compiled into a pool: a trivially copyable handle that evaluates the object's signe...
Definition EBGeometry_Tape.hpp:683
static constexpr uint32_t RayStackSize
Span lists a ray program may hold at once; a subtree that would need more is marched.
Definition EBGeometry_Tape.hpp:731
HitStatus intersects(const RayT< T > &a_ray, T a_tMin, T a_tMax, const RayOptions< T > &a_options=RayOptions< T >()) const noexcept
Whether a ray crosses the object's surface in [a_tMin, a_tMax].
Tape(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.
Definition EBGeometry_Tape.hpp:829
void visitPrimitive(const PrimitiveRef< T > &a_ref, F &&a_f) const noexcept
Call a function with the primitive a reference names, as primitive.
static constexpr uint32_t ValueStackSize
Values a sub-program may hold at once.
Definition EBGeometry_Tape.hpp:721
Tape()=delete
No empty tape.
uint32_t getNumClauses() const noexcept
Number of clauses over all sub-programs (the ray programs' not counted).
static constexpr size_t BranchingRatio
Branching factor of the BVHs over union operands.
Definition EBGeometry_Tape.hpp:711
HitT< T > firstHit(const RayT< T > &a_ray, T a_tMin, T a_tMax, const RayOptions< T > &a_options=RayOptions< T >()) const noexcept
The first crossing of the object's surface along a ray, entering or leaving.
static constexpr uint32_t PointStackSize
Points a sub-program may hold at once (its input point included).
Definition EBGeometry_Tape.hpp:726
uint32_t getCallDepth() const noexcept
How deep sub-program calls nest (0 if the tape has no Blur, Mollify, FiniteRepetition or BVH union).
DistanceQuality getDistanceQuality() const noexcept
How far signedDistance() can be trusted as a distance.
uint32_t getNumPrograms() const noexcept
Number of sub-programs (1 plus one per Blur, Mollify, FiniteRepetition and BVH union operand).
TapeDetail::Primitives< T, UserPrimitives... > Primitives
The primitive types: the built-in ones, then UserPrimitives.
Definition EBGeometry_Tape.hpp:736
Tape deepCopy(Pool &a_dstPool) const
Copy the tape, and every pool-resident primitive and BVH it holds, into another pool.
bool isPrimitive(const PrimitiveRef< T > &a_ref) const noexcept
Whether a reference's leaf is a primitive of type P.
T signedDistance(const Vec3T< T > &a_point) const noexcept
The object's value at a point: negative inside, positive outside, zero on the surface.
TapeDetail::FeaturesOf< UserPrimitives... > Features
The features the tape compiles (see TapeFeature): its template arguments derived from TapeFeature::Ta...
Definition EBGeometry_Tape.hpp:694
P primitive(const PrimitiveRef< T > &a_ref) const noexcept
The primitive a reference names, by value: the shape itself, or for a pool-resident type (a mesh SDF,...
Tape rebasedView(const Pool &a_pool) const noexcept
A view of this tape resolving against another pool of its mirror chain.
PrimitiveRef< T > closestPrimitive(const Vec3T< T > &a_point) const noexcept
The deciding leaf at a point: the primitive whose surface the value comes from there (see PrimitiveRe...
Tape(Pool &a_pool, const Expr< T > &a_expr, const TapeOptions &a_options=TapeOptions())
Compile an expression into a pool.
const Layout & layout() const noexcept
The tape's arrays, with no location: what an outer pool-resident object stores.
static constexpr bool hasFeature
Whether the tape compiles feature F (see TapeFeature).
Definition EBGeometry_Tape.hpp:701
static constexpr unsigned MaxCallDepth
How deep Blur, Mollify, FiniteRepetition and BVH unions may nest.
Definition EBGeometry_Tape.hpp:716
BV computeBoundingVolume() const noexcept
A box enclosing the object.
uint32_t getNumBVHUnions() const noexcept
Number of unions evaluated with a BVH.
Signed distance field for a torus.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:533
Signed distance function for a pure triangle mesh using SoA-grouped primitives in a compact (lineariz...
Definition EBGeometry_MeshDistanceFunctions.hpp:514
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
Construction
The preset BVH construction methods that the library's own BVH users accept.
Definition EBGeometry_PackedBVH.hpp:65
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Expr< ExprPrecision< A > > Union(const A &a_first, const B &a_second)
Union of two objects: the minimum of their values.
Expr< ExprPrecision< A > > Intersection(const A &a_first, const B &a_second)
Intersection of two objects: the maximum of their values.
Expr< ExprPrecision< A > > Blur(const A &a_operand, const ExprPrecision< A > a_blur, const ExprPrecision< A > a_alpha=ExprPrecision< A >(0.5))
Blur an object: a weighted average of its values at the 27 points p + d (i, j, k),...
Expr< ExprPrecision< A > > Complement(const A &a_operand)
Complement: inside and outside swapped, -v.
DistanceQuality
How far the value of a signed distance function can be trusted, from strongest to weakest.
Definition EBGeometry_DistanceQuality.hpp:25
@ NotADistance
Only the sign is meaningful, so the function describes a surface (its zero level set) but says nothin...
HitStatus
The outcome of a ray query.
Definition EBGeometry_Ray.hpp:84
Expr< ExprPrecision< A > > Mollify(const A &a_operand, const ExprPrecision< A > a_dist, const size_t a_samples)
Mollify an object: convolve it with a smooth, non-negative bump kernel sampled on an n x n x n grid s...
The BVH's arrays as offsets into its pool, and its root box: a PackedBVH minus its location.
Definition EBGeometry_PackedBVH.hpp:1105
Where a ray first crosses a surface.
Definition EBGeometry_Ray.hpp:96
Placement-independent descriptor of a POD array inside a Pool.
Definition EBGeometry_PODVector.hpp:119
Where a pool-resident descriptor resolves its offsets, and the rules for moving it.
Definition EBGeometry_Pool.hpp:99
The deciding leaf of a composition at a point: the primitive whose surface the composed value comes f...
Definition EBGeometry_PrimitiveRef.hpp:41
How a query marches, where a shape has no ray form.
Definition EBGeometry_Ray.hpp:155
Where a ray is inside an object over an interval [t0, t1]: its spans, in order, each from where it en...
Definition EBGeometry_Ray.hpp:248
A ray: the points origin + t * direction.
Definition EBGeometry_Ray.hpp:54
One tape clause.
Definition EBGeometry_Tape.hpp:226
uint32_t m_a
First operand.
Definition EBGeometry_Tape.hpp:245
uint32_t m_b
Second operand.
Definition EBGeometry_Tape.hpp:250
Op m_op
Operation.
Definition EBGeometry_Tape.hpp:230
uint16_t m_type
Primitive type index (Primitive).
Definition EBGeometry_Tape.hpp:240
uint32_t m_c
Third operand.
Definition EBGeometry_Tape.hpp:255
uint8_t m_flags
Operation flags.
Definition EBGeometry_Tape.hpp:235
typename Concat< TypeList< Ps... >, typename Concat< Rest... >::type >::type type
The concatenation.
Definition EBGeometry_Tape.hpp:445
The concatenation of TypeLists.
Definition EBGeometry_Tape.hpp:426
TypeList<> type
The concatenation.
Definition EBGeometry_Tape.hpp:430
The index of type P in a TypeList (its size if P is not in it).
Definition EBGeometry_Tape.hpp:387
PODVector< CSGDetail::Stored< P > > m_head
The first type's primitives.
Definition EBGeometry_Tape.hpp:509
PrimitiveStore< Ps... > m_tail
The remaining types' primitives.
Definition EBGeometry_Tape.hpp:514
One pool array per primitive type, holding the type's stored form (CSGDetail::Stored).
Definition EBGeometry_Tape.hpp:494
A sub-program: a range of clauses.
Definition EBGeometry_Tape.hpp:309
uint32_t m_begin
First clause.
Definition EBGeometry_Tape.hpp:313
uint32_t m_end
One past the last clause.
Definition EBGeometry_Tape.hpp:318
One ray program clause.
Definition EBGeometry_Tape.hpp:187
RayOp m_op
Operation.
Definition EBGeometry_Tape.hpp:191
uint16_t m_type
Primitive type index (Leaf, and a Marched clause holding a deferred level set).
Definition EBGeometry_Tape.hpp:201
uint32_t m_c
Third operand.
Definition EBGeometry_Tape.hpp:216
uint8_t m_flags
Operation flags.
Definition EBGeometry_Tape.hpp:196
uint32_t m_a
First operand.
Definition EBGeometry_Tape.hpp:206
uint32_t m_b
Second operand.
Definition EBGeometry_Tape.hpp:211
Host-side arrays the compiler fills before they are reserved in the pool.
Definition EBGeometry_Tape.hpp:646
The PrimitiveStore for the types of a TypeList.
Definition EBGeometry_Tape.hpp:523
std::tuple_element_t< I, std::tuple< Ps... > > type
The type.
Definition EBGeometry_Tape.hpp:377
The I-th type of a TypeList.
Definition EBGeometry_Tape.hpp:363
A list of types.
Definition EBGeometry_Tape.hpp:349
static constexpr size_t size
Number of types.
Definition EBGeometry_Tape.hpp:353
A BVH union's two parts, as layouts in the tape's pool: a BVH over the sub-programs with bounded boxe...
Definition EBGeometry_Tape.hpp:330
BVH::PackedBVH< T, uint32_t, K >::Layout m_bvh
BVH over the sub-programs with bounded boxes.
Definition EBGeometry_Tape.hpp:334
BVH::PackedBVH< T, uint32_t, K >::Layout m_unbounded
Leaf holding the sub-programs with unbounded boxes.
Definition EBGeometry_Tape.hpp:339
Whether a tape's user primitive types are shapes of its precision.
Definition EBGeometry_Tape.hpp:616
Ray queries trace an Offset or Annular of a primitive with closed-form level sets (or of an affine ma...
Definition EBGeometry_Tape.hpp:114
Base of every feature: a Tape template argument derived from it is a feature, not a primitive type.
Definition EBGeometry_Tape.hpp:104
Settings for compiling an Expr into a Tape.
Definition EBGeometry_Tape.hpp:57
BVH::Construction m_construction
How those BVHs are built.
Definition EBGeometry_Tape.hpp:67
uint32_t m_bvhUnionThreshold
A union or smooth union of at least this many objects is evaluated with a BVH over the objects' boxes...
Definition EBGeometry_Tape.hpp:62
The tape's arrays as offsets into its pool, with no location (see PoolHandle).
Definition EBGeometry_Tape.hpp:747
uint32_t m_numPrograms
How many sub-programs there are (the first entries of m_programs).
Definition EBGeometry_Tape.hpp:796
uint32_t m_rayPrograms
Where in m_programs the ray programs begin: sub-program i's is entry m_rayPrograms + i (an empty rang...
Definition EBGeometry_Tape.hpp:802
BV m_boundingVolume
A box enclosing the object.
Definition EBGeometry_Tape.hpp:781
PODVector< TapeDetail::UnionBVH< T, BranchingRatio > > m_unions
The BVH unions.
Definition EBGeometry_Tape.hpp:776
PODVector< TapeDetail::Clause > m_clauses
The clauses of every sub-program, one after another.
Definition EBGeometry_Tape.hpp:756
PODVector< TapeDetail::Program > m_programs
Each sub-program's clause range; sub-program 0 is the whole object. After the m_numPrograms sub-progr...
Definition EBGeometry_Tape.hpp:766
DistanceQuality m_quality
How far the value can be trusted as a distance.
Definition EBGeometry_Tape.hpp:786
PODVector< T > m_params
Constant parameters the clauses refer to.
Definition EBGeometry_Tape.hpp:771
uint32_t m_callDepth
How deep sub-program calls nest from sub-program 0.
Definition EBGeometry_Tape.hpp:791
TapeDetail::StoreOf< Primitives >::type m_primitives
One array per primitive type.
Definition EBGeometry_Tape.hpp:751