EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_Tape.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
24#ifndef EBGEOMETRY_TAPE_HPP
25#define EBGEOMETRY_TAPE_HPP
26
27// Std includes
28#include <cstddef>
29#include <cstdint>
30#include <tuple>
31#include <type_traits>
32#include <vector>
33
34// Our includes
40#include "EBGeometry_Expr.hpp"
41#include "EBGeometry_GPU.hpp"
46#include "EBGeometry_Pool.hpp"
48#include "EBGeometry_Ray.hpp"
49#include "EBGeometry_Vec.hpp"
50
51namespace EBGeometry {
52
69
98namespace TapeFeature {
99
103struct Tag
104{
105};
106
114{
115};
116
117} // namespace TapeFeature
118
119namespace TapeDetail {
120
127enum class Op : uint8_t
128{
129 Primitive,
130 PushAffine,
132 PopPoint,
133 Negate,
134 Abs,
137 Min,
138 Max,
139 PairInit,
140 PairInsert,
141 PairBlend,
143 Blur,
144 Mollify,
145 Repeat,
147 UnionBVH,
150};
151
159enum class RayOp : uint8_t
160{
161 Leaf,
164 Marched,
172 Union,
174 Complement,
175 PushAffine,
176 PopAffine,
177 UnionBVH
179};
180
187{
191 RayOp m_op = RayOp::Leaf;
192
196 uint8_t m_flags = 0;
197
201 uint16_t m_type = 0;
202
206 uint32_t m_a = 0;
207
211 uint32_t m_b = 0;
212
216 uint32_t m_c = 0;
217};
218
219static_assert(sizeof(RayClause) == 16, "TapeDetail::RayClause must be 16 bytes");
220
225struct Clause
226{
230 Op m_op = Op::Primitive;
231
235 uint8_t m_flags = 0;
236
240 uint16_t m_type = 0;
241
245 uint32_t m_a = 0;
246
250 uint32_t m_b = 0;
251
255 uint32_t m_c = 0;
256};
257
258static_assert(sizeof(Clause) == 16, "TapeDetail::Clause must be 16 bytes");
259
266[[nodiscard]] EBGEOMETRY_HOST_DEVICE
267inline Clause
268stored(const RayClause& a_clause) noexcept
269{
270 Clause c;
271
272 c.m_op = static_cast<Op>(a_clause.m_op);
273 c.m_flags = a_clause.m_flags;
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;
278
279 return c;
280}
281
288[[nodiscard]] EBGEOMETRY_HOST_DEVICE
289inline RayClause
290rayClause(const Clause& a_clause) noexcept
291{
292 RayClause c;
293
294 c.m_op = static_cast<RayOp>(a_clause.m_op);
295 c.m_flags = a_clause.m_flags;
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;
300
301 return c;
302}
303
309{
313 uint32_t m_begin = 0;
314
318 uint32_t m_end = 0;
319};
320
328template <class T, size_t K>
341
347template <class... Ps>
349{
353 static constexpr size_t size = sizeof...(Ps);
354};
355
362template <size_t I, class List>
363struct TypeAt;
364
371template <size_t I, class... Ps>
372struct TypeAt<I, TypeList<Ps...>>
373{
377 using type = std::tuple_element_t<I, std::tuple<Ps...>>;
378};
379
386template <class P, class List>
387struct IndexOf;
388
394template <class P>
395struct IndexOf<P, TypeList<>>
396{
400 static constexpr size_t value = 0;
401};
402
410template <class P, class Q, class... Rest>
411struct IndexOf<P, TypeList<Q, Rest...>>
412{
416 static constexpr size_t value = std::is_same_v<P, Q> ? 0 : 1 + IndexOf<P, TypeList<Rest...>>::value;
417};
418
424template <class... Lists>
425struct Concat
426{
431};
432
439template <class... Ps, class... Rest>
440struct Concat<TypeList<Ps...>, Rest...>
441{
445 using type = typename Concat<TypeList<Ps...>, typename Concat<Rest...>::type>::type;
446};
447
454template <class... Ps, class... Qs>
455struct Concat<TypeList<Ps...>, TypeList<Qs...>>
456{
460 using type = TypeList<Ps..., Qs...>;
461};
462
468template <class A>
469inline constexpr bool IsFeature = std::is_base_of_v<TapeFeature::Tag, A>;
470
476template <class... Args>
478
484template <class... Args>
486
492template <class... Ps>
494{
495};
496
503template <class P, class... Ps>
516
522template <class List>
523struct StoreOf;
524
530template <class... Ps>
531struct StoreOf<TypeList<Ps...>>
532{
536 using type = PrimitiveStore<Ps...>;
537};
538
548template <size_t I, class P, class... Ps>
549[[nodiscard]] EBGEOMETRY_HOST_DEVICE
550inline const auto&
551storeAt(const PrimitiveStore<P, Ps...>& a_store) noexcept
552{
553 if constexpr (I == 0) {
554 return a_store.m_head;
555 }
556 else {
557 return storeAt<I - 1>(a_store.m_tail);
558 }
559}
560
570template <size_t I, class P, class... Ps>
571[[nodiscard]] EBGEOMETRY_HOST_DEVICE
572inline auto&
574{
575 if constexpr (I == 0) {
576 return a_store.m_head;
577 }
578 else {
579 return storeAt<I - 1>(a_store.m_tail);
580 }
581}
582
590template <class T, class... UserPrimitives>
594 BoxSDF<T>,
606 TriMeshSDF<T, BVH::DefaultBranchingRatio<T>(), TriangleSoA::DefaultWidth<T>()>>,
607 UserTypesOf<UserPrimitives...>>::type;
608
615template <class T, class List>
617
624template <class T, class... Ps>
625struct UserTypes<T, TypeList<Ps...>>
626{
630 static constexpr bool shapes = (isShape<Ps> && ...);
631
635 static constexpr bool precision = (std::is_same_v<ShapePrecision<Ps>, T> && ...);
636};
637
645template <class T, size_t K, class List>
646struct Staging;
647
648} // namespace TapeDetail
649
681template <class T, class... UserPrimitives>
682class Tape : public PoolHandle
683{
684public:
685 static_assert(std::is_floating_point_v<T>, "Tape requires a floating-point type T");
686 static_assert(TapeDetail::UserTypes<T, TapeDetail::UserTypesOf<UserPrimitives...>>::shapes,
687 "Tape: every user primitive type must be a shape (see isShape)");
688 static_assert(TapeDetail::UserTypes<T, TapeDetail::UserTypesOf<UserPrimitives...>>::precision,
689 "Tape: every user primitive type must have the tape's precision");
690
694 using Features = TapeDetail::FeaturesOf<UserPrimitives...>;
695
700 template <class F>
701 static constexpr bool hasFeature = TapeDetail::IndexOf<F, Features>::value < Features::size;
702
707
711 static constexpr size_t BranchingRatio = 4;
712
716 static constexpr unsigned MaxCallDepth = 4;
717
721 static constexpr uint32_t ValueStackSize = 16;
722
726 static constexpr uint32_t PointStackSize = 8;
727
731 static constexpr uint32_t RayStackSize = 4;
732
736 using Primitives = TapeDetail::Primitives<T, UserPrimitives...>;
737
742
804
808 Tape() = delete;
809
818 Tape(Pool& a_pool, const Expr<T>& a_expr, const TapeOptions& a_options = TapeOptions());
819
829 Tape(const Layout& a_layout, const PoolLocation& a_location) noexcept : PoolHandle(a_location), m_layout(a_layout)
830 {}
831
841 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
842 inline T
843 signedDistance(const Vec3T<T>& a_point) const noexcept;
844
855 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
856 inline PrimitiveRef<T>
857 closestPrimitive(const Vec3T<T>& a_point) const noexcept;
858
871 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
872 inline HitT<T>
873 firstHit(const RayT<T>& a_ray, T a_tMin, T a_tMax, const RayOptions<T>& a_options = RayOptions<T>()) const noexcept;
874
885 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
886 inline HitT<T>
887 firstHit(const Vec3T<T>& a_from,
888 const Vec3T<T>& a_to,
889 T a_tMin = T(0),
890 const RayOptions<T>& a_options = RayOptions<T>()) const noexcept;
891
901 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
902 inline HitStatus
903 intersects(const RayT<T>& a_ray, T a_tMin, T a_tMax, const RayOptions<T>& a_options = RayOptions<T>()) const noexcept;
904
914 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
915 inline HitStatus
916 intersects(const Vec3T<T>& a_from,
917 const Vec3T<T>& a_to,
918 T a_tMin = T(0),
919 const RayOptions<T>& a_options = RayOptions<T>()) const noexcept;
920
927 template <class P>
928 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
929 inline bool
930 isPrimitive(const PrimitiveRef<T>& a_ref) const noexcept;
931
940 template <class P>
941 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
942 inline P
943 primitive(const PrimitiveRef<T>& a_ref) const noexcept;
944
954 template <class F>
956 inline void
957 visitPrimitive(const PrimitiveRef<T>& a_ref, F&& a_f) const noexcept;
958
963 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
964 inline BV
965 computeBoundingVolume() const noexcept;
966
973 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
974 inline DistanceQuality
975 getDistanceQuality() const noexcept;
976
981 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
982 inline uint32_t
983 getNumPrograms() const noexcept;
984
989 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
990 inline uint32_t
991 getNumClauses() const noexcept;
992
997 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
998 inline uint32_t
999 getNumBVHUnions() const noexcept;
1000
1005 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1006 inline uint32_t
1007 getCallDepth() const noexcept;
1008
1013 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1014 inline const Layout&
1015 layout() const noexcept;
1016
1024 [[nodiscard]] EBGEOMETRY_HOST
1025 inline Tape
1026 rebasedView(const Pool& a_pool) const noexcept;
1027
1033 [[nodiscard]] EBGEOMETRY_HOST
1034 inline Tape
1035 deepCopy(Pool& a_dstPool) const;
1036
1037private:
1041 friend struct RayForm<Tape>;
1042
1046 static constexpr uint32_t MarchedLeaf = UINT32_MAX;
1047
1051 static constexpr uint32_t LevelLeaf = UINT32_MAX - 1;
1052
1056 Layout m_layout;
1057
1062 template <unsigned D>
1063 struct Subtree
1064 {
1068 const Tape* m_tape;
1069
1073 uint32_t m_program;
1074
1078 BV m_box;
1079
1083 DistanceQuality m_quality;
1084
1088 const void* m_base;
1089
1093 PoolLocation m_location;
1094
1100 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1101 inline T
1102 signedDistance(const Vec3T<T>& a_point) const noexcept
1103 {
1104 return m_tape->template evaluate<D>(m_program, a_point, m_base, m_location);
1105 }
1106
1111 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1112 inline BV
1113 computeBoundingVolume() const noexcept
1114 {
1115 return m_box;
1116 }
1117
1122 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1123 inline DistanceQuality
1124 getDistanceQuality() const noexcept
1125 {
1126 return m_quality;
1127 }
1128 };
1129
1138 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1139 inline HitT<T>
1140 traceRay(const RayT<T>& a_ray, T a_tMin, T a_tMax, const RayOptions<T>& a_options) const noexcept;
1141
1152 inline void
1153 raySpans(const RayT<T>& a_ray,
1154 T a_tMin,
1155 T a_tMax,
1156 const RayOptions<T>& a_options,
1157 bool a_firstOnly,
1158 RaySpansT<T>& a_spans) const noexcept;
1159
1173 template <unsigned D>
1176 inline void
1177 rayEvaluate(uint32_t a_program,
1178 const RayT<T>& a_ray,
1179 T a_t0,
1180 T a_t1,
1181 const RayOptions<T>& a_options,
1182 bool a_all,
1183 const void* a_base,
1184 const PoolLocation& a_location,
1185 RaySpansT<T>& a_spans) const noexcept;
1186
1206 template <unsigned D, bool Level = false>
1207 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1209 inline HitT<T>
1210 rayLeafHit(uint32_t a_program,
1211 const RayT<T>& a_ray,
1212 T a_t,
1213 uint32_t a_clause,
1214 const RayOptions<T>& a_options,
1215 const void* a_base,
1216 const PoolLocation& a_location) const noexcept;
1217
1230 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1232 inline HitT<T>
1233 primitiveLeafHit(const TapeDetail::RayClause& a_clause,
1234 const RayT<T>& a_ray,
1235 T a_t,
1236 const RayOptions<T>& a_options,
1237 const void* a_base,
1238 const PoolLocation& a_location) const noexcept;
1239
1252 template <size_t I>
1253 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1254 inline HitT<T>
1255 dispatchLeafHit(const TapeDetail::RayClause& a_clause,
1256 const RayT<T>& a_ray,
1257 T a_t,
1258 const RayOptions<T>& a_options,
1259 const void* a_base,
1260 const PoolLocation& a_location) const noexcept;
1261
1277 template <unsigned D>
1280 inline void
1281 rayMarchedWithin(const TapeDetail::RayClause& a_clause,
1282 const RayT<T>& a_ray,
1283 const RayOptions<T>& a_options,
1284 bool a_firstOnly,
1285 const RaySpansT<T>& a_within,
1286 const void* a_base,
1287 const PoolLocation& a_location,
1288 RaySpansT<T>& a_spans) const noexcept;
1289
1304 inline void
1305 rayLeaf(const TapeDetail::RayClause& a_clause,
1306 const RayT<T>& a_ray,
1307 T a_t0,
1308 T a_t1,
1309 const RayOptions<T>& a_options,
1310 bool a_firstOnly,
1311 const void* a_base,
1312 const PoolLocation& a_location,
1313 RaySpansT<T>& a_spans) const noexcept;
1314
1332 void
1333 rayLevelLeaf(const TapeDetail::RayClause& a_clause,
1334 const RayT<T>& a_ray,
1335 T a_t0,
1336 T a_t1,
1337 const RayOptions<T>& a_options,
1338 bool a_firstOnly,
1339 const void* a_base,
1340 const PoolLocation& a_location,
1341 RaySpansT<T>& a_spans) const noexcept;
1342
1359 void
1360 rayLevelWithin(const TapeDetail::RayClause& a_clause,
1361 const RayT<T>& a_ray,
1362 const RayOptions<T>& a_options,
1363 bool a_firstOnly,
1364 const RaySpansT<T>& a_within,
1365 const void* a_base,
1366 const PoolLocation& a_location,
1367 RaySpansT<T>& a_spans) const noexcept;
1368
1381 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1384 HitT<T>
1385 levelClauseHit(const TapeDetail::RayClause& a_clause,
1386 const RayT<T>& a_ray,
1387 T a_t,
1388 const RayOptions<T>& a_options,
1389 const void* a_base,
1390 const PoolLocation& a_location) const noexcept;
1391
1405 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1408 HitT<T>
1409 resolveLevelHit(uint32_t a_clause,
1410 const RayT<T>& a_ray,
1411 T a_t,
1412 const RayOptions<T>& a_options,
1413 const void* a_base,
1414 const PoolLocation& a_location) const noexcept;
1415
1427 template <size_t I, bool MeshOnly, class Visit>
1429 inline void
1430 visitLevelPrimitive(const TapeDetail::RayClause& a_clause,
1431 const void* a_base,
1432 const PoolLocation& a_location,
1433 const Visit& a_visit) const noexcept;
1434
1448 template <size_t I>
1450 inline void
1451 dispatchRayLeaf(const TapeDetail::RayClause& a_clause,
1452 const RayT<T>& a_ray,
1453 T a_t0,
1454 T a_t1,
1455 const RayOptions<T>& a_options,
1456 bool a_firstOnly,
1457 const void* a_base,
1458 const PoolLocation& a_location,
1459 RaySpansT<T>& a_spans) const noexcept;
1460
1475 template <unsigned D>
1477 inline void
1478 rayUnion(const TapeDetail::RayClause& a_clause,
1479 const RayT<T>& a_ray,
1480 T a_t0,
1481 T a_t1,
1482 const RayOptions<T>& a_options,
1483 bool a_all,
1484 const void* a_base,
1485 const PoolLocation& a_location,
1486 RaySpansT<T>& a_spans) const noexcept;
1487
1505 template <unsigned D, class V = T>
1506 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1508 inline V
1509 evaluate(const uint32_t a_program,
1510 const Vec3T<T>& a_point,
1511 const void* a_base,
1512 const PoolLocation& a_location) const noexcept;
1513
1525 template <unsigned D, class V = T>
1526 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1527 inline V
1528 evaluateBody(const uint32_t a_program,
1529 const Vec3T<T>& a_point,
1530 const void* a_base,
1531 const PoolLocation& a_location) const noexcept;
1532
1541 template <size_t I, class F>
1543 inline void
1544 dispatchVisit(const PrimitiveRef<T>& a_ref, F&& a_f) const noexcept;
1545
1558 template <size_t I, bool Handles>
1559 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1560 inline T
1561 dispatchPrimitive(const uint32_t a_type,
1562 const uint32_t a_index,
1563 const Vec3T<T>& a_point,
1564 const void* a_base,
1565 const PoolLocation& a_location) const noexcept;
1566
1572 static constexpr size_t DispatchSplit = 6;
1573
1583 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1585 T
1586 dispatchRest(const uint32_t a_type,
1587 const uint32_t a_index,
1588 const Vec3T<T>& a_point,
1589 const void* a_base,
1590 const PoolLocation& a_location) const noexcept;
1591
1601 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1602 inline T
1603 evaluatePrimitive(const uint32_t a_type,
1604 const uint32_t a_index,
1605 const Vec3T<T>& a_point,
1606 const void* a_base,
1607 const PoolLocation& a_location) const noexcept;
1608
1621 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1623 inline T
1624 evaluateHandle(const uint32_t a_type,
1625 const uint32_t a_index,
1626 const Vec3T<T>& a_point,
1627 const void* a_base,
1628 const PoolLocation& a_location) const noexcept;
1629
1641 template <unsigned D, class V = T>
1642 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1644 inline V
1645 evaluateBlur(const TapeDetail::Clause& a_clause,
1646 const Vec3T<T>& a_point,
1647 const T* a_params,
1648 const void* a_base,
1649 const PoolLocation& a_location) const noexcept;
1650
1664 template <unsigned D, class V = T>
1665 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1666 inline V
1667 evaluateRepeat(const TapeDetail::Clause& a_clause,
1668 const Vec3T<T>& a_point,
1669 const T* a_params,
1670 const void* a_base,
1671 const PoolLocation& a_location) const noexcept;
1672
1684 template <unsigned D, class V = T>
1685 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1686 inline V
1687 evaluateUnion(const TapeDetail::Clause& a_clause,
1688 const Vec3T<T>& a_point,
1689 const T* a_params,
1690 const void* a_base,
1691 const PoolLocation& a_location) const noexcept;
1692
1699 void
1700 finalize(Pool& a_pool, const TapeDetail::Staging<T, BranchingRatio, Primitives>& a_staging);
1701};
1702
1708template <class T, class... UserPrimitives>
1709struct RayForm<Tape<T, UserPrimitives...>>
1710{
1720 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1721 static inline HitT<T>
1723 const RayT<T>& a_ray,
1724 T a_tMin,
1725 T a_tMax,
1726 const RayOptions<T>& a_options) noexcept
1727 {
1728 return a_shape.traceRay(a_ray, a_tMin, a_tMax, a_options);
1729 }
1730
1742 static inline void
1744 const RayT<T>& a_ray,
1745 T a_tMin,
1746 T a_tMax,
1747 const RayOptions<T>& a_options,
1748 bool a_firstOnly,
1749 RaySpansT<T>& a_spans) noexcept
1750 {
1751 a_shape.raySpans(a_ray, a_tMin, a_tMax, a_options, a_firstOnly, a_spans);
1752 }
1753};
1754
1755} // namespace EBGeometry
1756
1757#include "EBGeometry_TapeImplem.hpp"
1758
1759#endif
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.
The ray forms (see RayForm) of compositions: the fused union, intersection, difference,...
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.
Ray forms of offsets and annuli: the level sets of their operands' values.
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
static HitT< T > firstHit(const Tape< T, UserPrimitives... > &a_shape, const RayT< T > &a_ray, T a_tMin, T a_tMax, const RayOptions< T > &a_options) noexcept
The first crossing of the tape's object along a ray.
Definition EBGeometry_Tape.hpp:1722
static void spans(const Tape< T, UserPrimitives... > &a_shape, const RayT< T > &a_ray, T a_tMin, T a_tMax, const RayOptions< T > &a_options, bool a_firstOnly, RaySpansT< T > &a_spans) noexcept
Where a ray is inside the tape's object over an interval.
Definition EBGeometry_Tape.hpp:1743
How to ray trace a shape directly, instead of marching its signed distance.
Definition EBGeometry_Ray.hpp:347
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