EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_BVHUnion.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
13#ifndef EBGEOMETRY_BVHUNION_HPP
14#define EBGEOMETRY_BVHUNION_HPP
15
16// Std includes
17#include <cstddef>
18#include <cstdint>
19#include <optional>
20#include <tuple>
21#include <type_traits>
22#include <utility>
23#include <vector>
24
25// Our includes
26#include "EBGeometry_BVH.hpp"
27#include "EBGeometry_Blend.hpp"
29#include "EBGeometry_GPU.hpp"
30#include "EBGeometry_Macros.hpp"
31#include "EBGeometry_Math.hpp"
33#include "EBGeometry_Pool.hpp"
35#include "EBGeometry_Vec.hpp"
36
37namespace EBGeometry {
38
39namespace BVH {
40
47{
52
56 std::optional<ConstructionOptions> m_options;
57};
58
59} // namespace BVH
60
64namespace CSGDetail {
65
73template <class P, bool = isPoolHandle<P>>
75{
79 using type = P;
80};
81
86template <class P>
87struct StoredAs<P, true>
88{
92 using type = typename P::Layout;
93};
94
99template <class P>
100using Stored = typename StoredAs<P>::type;
101
108template <class P>
109[[nodiscard]] EBGEOMETRY_HOST
110inline Stored<P>
111toStored(const P& a_primitive) noexcept
112{
113 if constexpr (isPoolHandle<P>) {
114 return a_primitive.layout();
115 }
116 else {
117 return a_primitive;
118 }
119}
120
131template <class P>
132[[nodiscard]] EBGEOMETRY_HOST_DEVICE
133inline P
134fromStored(const Stored<P>& a_stored, [[maybe_unused]] const PoolLocation& a_location) noexcept
135{
136 if constexpr (isPoolHandle<P>) {
137 return P(a_stored, a_location);
138 }
139 else {
140 return a_stored;
141 }
142}
143
152template <class T, class P, size_t K>
165
172{
176 uint32_t m_type;
177
181 uint32_t m_index;
182};
183
191template <class T, class... Ps>
192inline constexpr bool hasContainers = (hasSurfaces<Ps, T> || ...);
193
200template <class... Ps>
202{
203};
204
211template <class P, class... Ps>
212struct UnionArrays<P, Ps...>
213{
218
223};
224
233template <class... Ps>
235{
240};
241
247template <class P>
248struct ArraysOf<P>
249{
250};
251
257template <class... Ps>
258struct LeafOf
259{
264};
265
271template <class P>
272struct LeafOf<P>
273{
278};
279
284template <class... Ps>
285using Leaf = typename LeafOf<Ps...>::type;
286
292template <class B>
294
299template <class T>
300struct BoxPrecision<BoundingVolumes::AABBT<T>>
301{
305 using type = T;
306};
307
312template <class P>
314 typename BoxPrecision<std::decay_t<decltype(std::declval<const P&>().computeBoundingVolume())>>::type;
315
322template <class P, class T, class = void>
323inline constexpr bool hasPrecision = true;
324
330template <class P, class T>
331inline constexpr bool hasPrecision<P, T, std::void_t<decltype(std::declval<const P&>().computeBoundingVolume())>> =
332 std::is_same_v<PrimitivePrecision<P>, T>;
333
339template <class X>
340inline constexpr bool isBox = false;
341
346template <class T>
347inline constexpr bool isBox<BoundingVolumes::AABBT<T>> = true;
348
354template <class X>
355inline constexpr bool isVector = false;
356
362template <class V, class A>
363inline constexpr bool isVector<std::vector<V, A>> = true;
364
369template <class... Ps>
371 ((distanceQualityOf<Ps> == DistanceQuality::NotADistance) || ...) ? DistanceQuality::NotADistance
373
388template <class F, class P, class... Ps>
389[[nodiscard]] EBGEOMETRY_HOST_DEVICE
390inline auto
392 const uint32_t a_type,
393 const uint32_t a_index,
394 const PoolLocation& a_location,
395 F&& a_f) noexcept
396{
397 if constexpr (sizeof...(Ps) == 0) {
398 EBGEOMETRY_EXPECT(a_type == 0);
399
400 return CallableDetail::call(a_f, fromStored<P>(a_arrays.m_head.at(a_location.base(), a_index), a_location));
401 }
402 else {
403 if (a_type == 0) {
404 return CallableDetail::call(a_f, fromStored<P>(a_arrays.m_head.at(a_location.base(), a_index), a_location));
405 }
406
407 return visitArrays(a_arrays.m_tail, a_type - 1, a_index, a_location, static_cast<F&&>(a_f));
408 }
409}
410
411} // namespace CSGDetail
412
450template <class T, size_t K, class... Ps>
451class BVHUnion : public PoolHandle, private CSGDetail::ArraysOf<Ps...>
452{
453public:
454 static_assert(std::is_floating_point_v<T>, "BVHUnion requires a floating-point type T");
455 static_assert(sizeof...(Ps) > 0, "BVHUnion requires at least one primitive type");
456 static_assert((CSGDetail::hasPrecision<Ps, T> && ...),
457 "BVHUnion requires every primitive type to have the union's precision T");
458 static_assert((std::is_trivially_copyable_v<Ps> && ...), "BVHUnion requires trivially copyable primitive types");
459 static_assert(K > 1, "BVHUnion BVH branching factor K must be at least 2");
460
467
471 static constexpr size_t NumTypes = sizeof...(Ps);
472
476 static constexpr bool HasContainers = CSGDetail::hasContainers<T, Ps...>;
477
481 static constexpr bool HasParts = (hasParts<Ps, T> || ...);
482
487 using Leaf = CSGDetail::Leaf<Ps...>;
488
493
498
502 using First = std::tuple_element_t<0, std::tuple<Ps...>>;
503
507 BVHUnion() = delete;
508
516 [[nodiscard]] EBGEOMETRY_HOST
522
531 explicit BVHUnion(Pool& a_pool, const std::vector<Ps>&... a_primitives);
532
542 BVHUnion(Pool& a_pool, const BVH::BuildSettings& a_settings, const std::vector<Ps>&... a_primitives);
543
553 template <size_t N = sizeof...(Ps), std::enable_if_t<N == 1, int> = 0>
555 BVHUnion(Pool& a_pool,
556 const std::vector<First>& a_primitives,
557 const std::vector<BV>& a_boundingVolumes,
559
568 template <size_t N = sizeof...(Ps), std::enable_if_t<N == 1, int> = 0>
570 BVHUnion(Pool& a_pool,
571 const std::vector<First>& a_primitives,
572 const std::vector<BV>& a_boundingVolumes,
573 BVH::Construction a_construction,
574 const BVH::ConstructionOptions& a_options);
575
583 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
584 inline T
585 signedDistance(const Vec3T<T>& a_point) const noexcept;
586
591 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
592 inline uint32_t
593 getNumMembers() const noexcept;
594
602 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
603 inline uint32_t
604 getMemberIndex(uint32_t a_position) const noexcept;
605
611 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
612 inline uint32_t
613 getNumSurfaces() const noexcept;
614
620 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
621 inline uint32_t
622 getFirstSurface(uint32_t a_member) const noexcept;
623
631 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
632 inline SurfaceRef<T>
633 closestSurface(const Vec3T<T>& a_point) const noexcept;
634
639 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
640 inline BV
641 computeBoundingVolume() const noexcept;
642
648 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
649 inline Root
650 getBVH() const noexcept;
651
658 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
659 inline PODSpan<const Leaf>
660 getUnboundedPrimitives() const noexcept;
661
673 template <class F>
674 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
675 inline auto
676 visit(const Leaf& a_leaf, F&& a_f) const noexcept;
677
688 [[nodiscard]] EBGEOMETRY_HOST
689 inline BVHUnion
690 rebasedView(const Pool& a_pool) const noexcept;
691
697 [[nodiscard]] EBGEOMETRY_HOST
698 inline BVHUnion
699 deepCopy(Pool& a_dstPool) const;
700
706 struct Layout : CSGDetail::ArraysOf<Ps...>
707 {
712
717
723 };
724
733 BVHUnion(const Layout& a_layout, const PoolLocation& a_location) noexcept
734 : PoolHandle(a_location),
735 CSGDetail::ArraysOf<Ps...>(a_layout),
736 m_bvh(a_layout.m_bvh),
737 m_unbounded(a_layout.m_unbounded),
738 m_members(a_layout.m_members)
739 {}
740
745 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
746 Layout
747 layout() const noexcept
748 {
749 Layout layout{};
750
751 static_cast<CSGDetail::ArraysOf<Ps...>&>(layout) = *this;
752 layout.m_bvh = m_bvh;
753 layout.m_unbounded = m_unbounded;
754 layout.m_members = m_members;
755
756 return layout;
757 }
758
759private:
769 template <class F>
770 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
771 inline auto
772 visitAt(const Leaf& a_leaf, const PoolLocation& a_location, F&& a_f) const noexcept;
779 explicit BVHUnion(const std::pair<Layout, PoolLocation>& a_built) noexcept : BVHUnion(a_built.first, a_built.second)
780 {}
781
785 typename Root::Layout m_bvh;
786
790 typename Root::Layout m_unbounded;
791
795 PODVector<uint32_t> m_members;
796};
797
806template <class P, class... Ps, std::enable_if_t<!(CSGDetail::isBox<Ps> || ...), int> = 0>
807BVHUnion(Pool& a_pool, const std::vector<P>& a_first, const std::vector<Ps>&... a_primitives)
809 BVH::DefaultBranchingRatio<CSGDetail::PrimitivePrecision<P>>(),
810 P,
811 Ps...>;
812
822template <class P, class... Ps>
824 const BVH::BuildSettings& a_settings,
825 const std::vector<P>& a_first,
826 const std::vector<Ps>&... a_primitives)
828 BVH::DefaultBranchingRatio<CSGDetail::PrimitivePrecision<P>>(),
829 P,
830 Ps...>;
831
840template <class P, class B, std::enable_if_t<CSGDetail::isBox<B>, int> = 0>
841BVHUnion(Pool& a_pool, const std::vector<P>& a_first, const std::vector<B>& a_boxes)
842 -> BVHUnion<CSGDetail::PrimitivePrecision<P>, BVH::DefaultBranchingRatio<CSGDetail::PrimitivePrecision<P>>(), P>;
843
854template <class P, class B, class... Rest, std::enable_if_t<CSGDetail::isBox<B>, int> = 0>
856 const std::vector<P>& a_first,
857 const std::vector<B>& a_boxes,
858 BVH::Construction a_construction,
859 const Rest&... a_rest)
860 -> BVHUnion<CSGDetail::PrimitivePrecision<P>, BVH::DefaultBranchingRatio<CSGDetail::PrimitivePrecision<P>>(), P>;
861
876template <class T, size_t K, class Blend = SmoothMinOp<T>, class... Ps>
877class BVHSmoothUnion : public PoolHandle, private CSGDetail::ArraysOf<Ps...>
878{
879public:
880 static_assert(std::is_floating_point_v<T>, "BVHSmoothUnion requires a floating-point type T");
881 static_assert(sizeof...(Ps) > 0, "BVHSmoothUnion requires at least one primitive type");
882 static_assert((CSGDetail::hasPrecision<Ps, T> && ...),
883 "BVHSmoothUnion requires every primitive type to have the union's precision T");
884 static_assert((std::is_trivially_copyable_v<Ps> && ...),
885 "BVHSmoothUnion requires trivially copyable primitive types");
886 static_assert(std::is_trivially_copyable_v<Blend>, "BVHSmoothUnion requires a trivially copyable blend operator");
887 static_assert(K > 1, "BVHSmoothUnion BVH branching factor K must be at least 2");
888
895
899 static constexpr size_t NumTypes = sizeof...(Ps);
900
904 static constexpr bool HasContainers = CSGDetail::hasContainers<T, Ps...>;
905
909 static constexpr bool HasParts = (hasParts<Ps, T> || ...);
910
914 using Leaf = CSGDetail::Leaf<Ps...>;
915
920
925
929 using First = std::tuple_element_t<0, std::tuple<Ps...>>;
930
934 BVHSmoothUnion() = delete;
935
940 [[nodiscard]] EBGEOMETRY_HOST
946
956 BVHSmoothUnion(Pool& a_pool, T a_smoothLen, const std::vector<Ps>&... a_primitives);
957
966 BVHSmoothUnion(Pool& a_pool, T a_smoothLen, Blend a_blend, const std::vector<Ps>&... a_primitives);
967
978 const BVH::BuildSettings& a_settings,
979 T a_smoothLen,
980 Blend a_blend,
981 const std::vector<Ps>&... a_primitives);
982
993 template <size_t N = sizeof...(Ps), std::enable_if_t<N == 1, int> = 0>
996 const std::vector<First>& a_primitives,
997 const std::vector<BV>& a_boundingVolumes,
998 T a_smoothLen,
999 Blend a_blend = Blend{},
1000 BVH::Construction a_construction = BVH::Construction::SAH);
1001
1013 template <size_t N = sizeof...(Ps), std::enable_if_t<N == 1, int> = 0>
1016 const std::vector<First>& a_primitives,
1017 const std::vector<BV>& a_boundingVolumes,
1018 T a_smoothLen,
1019 Blend a_blend,
1020 BVH::Construction a_construction,
1021 const BVH::ConstructionOptions& a_options);
1022
1029 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1030 inline T
1031 signedDistance(const Vec3T<T>& a_point) const noexcept;
1032
1037 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1038 inline uint32_t
1039 getNumMembers() const noexcept;
1040
1048 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1049 inline uint32_t
1050 getMemberIndex(uint32_t a_position) const noexcept;
1051
1057 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1058 inline uint32_t
1059 getNumSurfaces() const noexcept;
1060
1066 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1067 inline uint32_t
1068 getFirstSurface(uint32_t a_member) const noexcept;
1069
1077 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1078 inline SurfaceRef<T>
1079 closestSurface(const Vec3T<T>& a_point) const noexcept;
1080
1085 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1086 inline BV
1087 computeBoundingVolume() const noexcept;
1088
1093 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1094 inline Root
1095 getBVH() const noexcept;
1096
1101 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1102 inline PODSpan<const Leaf>
1103 getUnboundedPrimitives() const noexcept;
1104
1112 template <class F>
1113 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1114 inline auto
1115 visit(const Leaf& a_leaf, F&& a_f) const noexcept;
1116
1122 [[nodiscard]] EBGEOMETRY_HOST
1123 inline BVHSmoothUnion
1124 rebasedView(const Pool& a_pool) const noexcept;
1125
1132 [[nodiscard]] EBGEOMETRY_HOST
1133 inline BVHSmoothUnion
1134 deepCopy(Pool& a_dstPool) const;
1135
1141 struct Layout : CSGDetail::ArraysOf<Ps...>
1142 {
1147
1152
1157
1161 Blend m_blend;
1162
1168 };
1169
1177 BVHSmoothUnion(const Layout& a_layout, const PoolLocation& a_location) noexcept
1178 : PoolHandle(a_location),
1179 CSGDetail::ArraysOf<Ps...>(a_layout),
1180 m_bvh(a_layout.m_bvh),
1181 m_unbounded(a_layout.m_unbounded),
1182 m_smoothLen(a_layout.m_smoothLen),
1183 m_blend(a_layout.m_blend),
1184 m_members(a_layout.m_members)
1185 {}
1186
1192 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1193 Layout
1194 layout() const noexcept
1195 {
1196 Layout layout{};
1197
1198 static_cast<CSGDetail::ArraysOf<Ps...>&>(layout) = *this;
1199 layout.m_bvh = m_bvh;
1200 layout.m_unbounded = m_unbounded;
1201 layout.m_smoothLen = m_smoothLen;
1202 layout.m_blend = m_blend;
1203 layout.m_members = m_members;
1204
1205 return layout;
1206 }
1207
1208private:
1218 template <class F>
1219 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
1220 inline auto
1221 visitAt(const Leaf& a_leaf, const PoolLocation& a_location, F&& a_f) const noexcept;
1231 BVHSmoothUnion(const std::pair<Layout, PoolLocation>& a_built, T a_smoothLen, Blend a_blend) noexcept
1232 : BVHSmoothUnion(a_built.first, a_built.second)
1233 {
1234 m_smoothLen = Math::max(a_smoothLen, Math::Limits<T>::min());
1235 m_blend = a_blend;
1236 }
1237
1241 typename Root::Layout m_bvh;
1242
1246 typename Root::Layout m_unbounded;
1247
1251 T m_smoothLen;
1252
1256 Blend m_blend;
1257
1261 PODVector<uint32_t> m_members;
1262};
1263
1273template <class P, class... Ps, std::enable_if_t<!(CSGDetail::isBox<Ps> || ...), int> = 0>
1276 const std::vector<P>& a_first,
1277 const std::vector<Ps>&... a_primitives)
1279 BVH::DefaultBranchingRatio<CSGDetail::PrimitivePrecision<P>>(),
1281 P,
1282 Ps...>;
1283
1295template <class B, class P, class... Ps, std::enable_if_t<!CSGDetail::isVector<B>, int> = 0>
1298 B a_blend,
1299 const std::vector<P>& a_first,
1300 const std::vector<Ps>&... a_primitives)
1302 BVH::DefaultBranchingRatio<CSGDetail::PrimitivePrecision<P>>(),
1303 B,
1304 P,
1305 Ps...>;
1306
1319template <class B, class P, class... Ps, std::enable_if_t<!CSGDetail::isVector<B>, int> = 0>
1321 const BVH::BuildSettings& a_settings,
1323 B a_blend,
1324 const std::vector<P>& a_first,
1325 const std::vector<Ps>&... a_primitives)
1327 BVH::DefaultBranchingRatio<CSGDetail::PrimitivePrecision<P>>(),
1328 B,
1329 P,
1330 Ps...>;
1331
1341template <class P, class V, std::enable_if_t<CSGDetail::isBox<V>, int> = 0>
1343 const std::vector<P>& a_first,
1344 const std::vector<V>& a_boxes,
1347 BVH::DefaultBranchingRatio<CSGDetail::PrimitivePrecision<P>>(),
1349 P>;
1350
1364template <class P, class V, class B, class... Rest, std::enable_if_t<CSGDetail::isBox<V>, int> = 0>
1366 const std::vector<P>& a_first,
1367 const std::vector<V>& a_boxes,
1369 B a_blend,
1370 const Rest&... a_rest) -> BVHSmoothUnion<CSGDetail::PrimitivePrecision<P>,
1371 BVH::DefaultBranchingRatio<CSGDetail::PrimitivePrecision<P>>(),
1372 B,
1373 P>;
1374
1375} // namespace EBGeometry
1376
1377#include "EBGeometry_BVHUnionImplem.hpp"
1378
1379// The ray forms, through the fused operations: firstHit() is a template, and a file that included this header
1380// without them would march a BVH union that another file traces exactly, two definitions of one function.
1381// Included last, after the classes they specialize for, since those headers include this one.
1382#include "EBGeometry_Fused.hpp"
1383
1384#endif
Bounding volume hierarchies: everything in EBGeometry_PackedBVH.hpp, EBGeometry_TreeBVH....
The blend operators that smooth unions, intersections and differences use: ExpMinOp,...
How far a function's value can be trusted as a distance: DistanceQuality, and the distanceQualityOf t...
Fused CSG: the operations of the expression builder (EBGeometry_Expr.hpp) as types,...
GPU portability layer: host/device decoration macros and backend detection.
#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
Utility macros for EBGeometry.
#define EBGEOMETRY_EXPECT(cond)
Runtime precondition assertion for EBGeometry.
Definition EBGeometry_Macros.hpp:269
Scalar helpers and numeric limits that compile for both host and device.
Placement-independent POD array views for the GPU memory foundation.
Growable bump arena for the GPU memory foundation.
SurfaceRef: which surface of a shape decides its value at a point, and the container protocol that na...
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
BVH-accelerated smooth union of many primitives of one or more types.
Definition EBGeometry_BVHUnion.hpp:878
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,...
auto visit(const Leaf &a_leaf, F &&a_f) const noexcept
Call a_f with the primitive a leaf stands for; see BVHUnion::visit().
uint32_t getNumSurfaces() const noexcept
How many surfaces the union numbers (see hasSurfaces): one per member, or a container member's own ge...
Layout layout() const noexcept
The union's arrays and parameters without its location, for storing it inside an outer union.
Definition EBGeometry_BVHUnion.hpp:1194
BVHSmoothUnion rebasedView(const Pool &a_pool) const noexcept
Produce a copy of this smooth union that resolves against a_pool; see BVHUnion.
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 ...
uint32_t getNumMembers() const noexcept
How many members (primitives) the union holds.
static constexpr bool HasParts
Whether a primitive type has parts (see hasParts), which closestSurface() reports.
Definition EBGeometry_BVHUnion.hpp:909
CSGDetail::Leaf< Ps... > Leaf
What the BVH's leaves hold; see BVHUnion::Leaf.
Definition EBGeometry_BVHUnion.hpp:914
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...
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.
static BVH::ConstructionOptions defaultConstructionOptions() noexcept
The leaf-size settings the constructors without options use; the same as BVHUnion's.
Definition EBGeometry_BVHUnion.hpp:942
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.
static constexpr bool HasContainers
Whether a primitive type is a container (see hasSurfaces), whose surfaces the union numbers too.
Definition EBGeometry_BVHUnion.hpp:904
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.
Definition EBGeometry_BVHUnion.hpp:1177
std::tuple_element_t< 0, std::tuple< Ps... > > First
The first primitive type: the only one for the constructors that take boxes.
Definition EBGeometry_BVHUnion.hpp:929
BV computeBoundingVolume() const noexcept
The axis-aligned bounding box enclosing all primitives.
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.
Root getBVH() const noexcept
Get the packed BVH over the primitives whose bounding box is bounded.
BVHSmoothUnion deepCopy(Pool &a_dstPool) const
Duplicate this smooth union's storage, and that of any pool-resident primitive, into a_dstPool.
BVHSmoothUnion()=delete
Disallowed, use the full constructor.
static constexpr size_t NumTypes
How many primitive types the union holds.
Definition EBGeometry_BVHUnion.hpp:899
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: a bound, or only a sign if any primitive type'...
Definition EBGeometry_BVHUnion.hpp:894
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.
uint32_t getFirstSurface(uint32_t a_member) const noexcept
A member's first surface: member i covers [getFirstSurface(i), getFirstSurface(i + 1)).
T signedDistance(const Vec3T< T > &a_point) const noexcept
Evaluate the smooth union at a point.
PODSpan< const Leaf > getUnboundedPrimitives() const noexcept
Get the leaves of the primitives whose bounding box is unbounded, which every query evaluates.
BVH-accelerated union of many primitives of one or more types.
Definition EBGeometry_BVHUnion.hpp:452
BVHUnion(Pool &a_pool, const std::vector< First > &a_primitives, const std::vector< BV > &a_boundingVolumes, BVH::Construction a_construction, const BVH::ConstructionOptions &a_options)
Build a union of one type with the caller's bounding boxes and leaf-size settings.
CSGDetail::Leaf< Ps... > Leaf
What the BVH's leaves hold: with one type the primitive (or its layout, for a pool-resident one),...
Definition EBGeometry_BVHUnion.hpp:487
std::tuple_element_t< 0, std::tuple< Ps... > > First
The first primitive type: the only one for the constructors that take boxes.
Definition EBGeometry_BVHUnion.hpp:502
BV computeBoundingVolume() const noexcept
The axis-aligned bounding box enclosing all primitives.
uint32_t getNumMembers() const noexcept
How many members (primitives) the union holds.
BVHUnion(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_BVHUnion.hpp:733
static constexpr size_t NumTypes
How many primitive types the union holds.
Definition EBGeometry_BVHUnion.hpp:471
T signedDistance(const Vec3T< T > &a_point) const noexcept
Evaluate the union at a point.
BVHUnion deepCopy(Pool &a_dstPool) const
Duplicate this union's storage, and that of any pool-resident primitive, into a_dstPool.
static constexpr bool HasContainers
Whether a primitive type is a container (see hasSurfaces), whose surfaces the union numbers too.
Definition EBGeometry_BVHUnion.hpp:476
static BVH::ConstructionOptions defaultConstructionOptions() noexcept
The leaf-size settings the constructors without options use.
Definition EBGeometry_BVHUnion.hpp:518
BVHUnion(Pool &a_pool, const std::vector< First > &a_primitives, const std::vector< BV > &a_boundingVolumes, BVH::Construction a_construction=BVH::Construction::SAH)
Build a union of one type with the caller's bounding boxes, which may be tighter than the primitives'...
BVHUnion(Pool &a_pool, const BVH::BuildSettings &a_settings, const std::vector< Ps > &... a_primitives)
Build the union with a construction method and, optionally, leaf sizes.
PODSpan< const Leaf > getUnboundedPrimitives() const noexcept
Get the leaves of the primitives whose bounding box is unbounded, which every query evaluates.
uint32_t getNumSurfaces() const noexcept
How many surfaces the union numbers (see hasSurfaces): one per member, or a container member's own ge...
static constexpr DistanceQuality distanceQuality
How far signedDistance() can be trusted as a distance: a bound, or only a sign if any primitive type'...
Definition EBGeometry_BVHUnion.hpp:466
uint32_t getFirstSurface(uint32_t a_member) const noexcept
A member's first surface: member i covers [getFirstSurface(i), getFirstSurface(i + 1)).
auto visit(const Leaf &a_leaf, F &&a_f) const noexcept
Call a_f with the primitive a leaf stands for (one of the BVH's leaves, or of getUnboundedPrimitives(...
static constexpr bool HasParts
Whether a primitive type has parts (see hasParts), which closestSurface() reports.
Definition EBGeometry_BVHUnion.hpp:481
Root getBVH() const noexcept
Get the packed BVH over the primitives whose bounding box is bounded.
BVHUnion rebasedView(const Pool &a_pool) const noexcept
Produce a copy of this union that resolves against a_pool.
BVHUnion()=delete
Disallowed, use the full constructor.
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...
Layout layout() const noexcept
The union's arrays without its location, for storing it inside an outer union.
Definition EBGeometry_BVHUnion.hpp:747
BVHUnion(Pool &a_pool, const std::vector< Ps > &... a_primitives)
Build the union of the given primitives, with SAH and the default leaf sizes.
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,...
Forward declaration of the linearised BVH, defined below.
Definition EBGeometry_PackedBVH.hpp:369
static BVH::ConstructionOptions defaultConstructionOptions() noexcept
The leaf-size settings build() uses when it is given none.
Definition EBGeometry_PackedBVH.hpp:616
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
Base of every pool-resident handle: the one PoolLocation its arrays resolve against.
Definition EBGeometry_Pool.hpp:563
PoolHandle() noexcept=default
An unset location; the first reservation attaches it.
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:205
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
constexpr bool isVector
Whether X is a std::vector: keeps the smooth unions' deduction guides that take a blend from taking t...
Definition EBGeometry_BVHUnion.hpp:355
typename LeafOf< Ps... >::type Leaf
Shorthand for what a union's BVH leaves hold.
Definition EBGeometry_BVHUnion.hpp:285
constexpr bool hasContainers
Whether a union holds members that are containers themselves (see hasSurfaces), whose surfaces it num...
Definition EBGeometry_BVHUnion.hpp:192
typename BoxPrecision< std::decay_t< decltype(std::declval< const P & >().computeBoundingVolume())> >::type PrimitivePrecision
The precision of primitive type P, for the unions' deduction guides.
Definition EBGeometry_BVHUnion.hpp:314
Stored< P > toStored(const P &a_primitive) noexcept
Convert a primitive to the form a BVH union stores.
Definition EBGeometry_BVHUnion.hpp:111
typename StoredAs< P >::type Stored
Shorthand for the type a BVH union stores for a primitive of type P.
Definition EBGeometry_BVHUnion.hpp:100
constexpr DistanceQuality unionQuality
The weakest distance quality among primitive types: not a distance if any is not, else a bound.
Definition EBGeometry_BVHUnion.hpp:370
P fromStored(const Stored< P > &a_stored, const PoolLocation &a_location) noexcept
The primitive a stored entry stands for, resolving against a_location.
Definition EBGeometry_BVHUnion.hpp:134
constexpr bool hasPrecision
Whether a primitive type is of precision T: true if its computeBoundingVolume() returns an AABBT<T>,...
Definition EBGeometry_BVHUnion.hpp:323
auto visitArrays(const UnionArrays< P, Ps... > &a_arrays, const uint32_t a_type, const uint32_t a_index, const PoolLocation &a_location, F &&a_f) noexcept
Call a_f with the primitive a MemberRef stands for, testing its type against the arrays' types in ord...
Definition EBGeometry_BVHUnion.hpp:391
constexpr bool isBox
Whether X is a box, which an array of primitives never holds: keeps the deduction guide for several t...
Definition EBGeometry_BVHUnion.hpp:340
constexpr T max(const T &a_a, const T &a_b) noexcept
The larger of two values.
Definition EBGeometry_Math.hpp:61
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
DistanceQuality
How far the value of a signed distance function can be trusted, from strongest to weakest.
Definition EBGeometry_DistanceQuality.hpp:25
@ Bound
The value's magnitude never exceeds the distance to the surface: it may underestimate,...
@ NotADistance
Only the sign is meaningful, so the function describes a surface (its zero level set) but says nothin...
@ BVH
Through a BVH over the operands' boxes, however many there are.
The smooth union's arrays and parameters, with no location: what an outer union stores when this one ...
Definition EBGeometry_BVHUnion.hpp:1142
Blend m_blend
Smooth-minimum operator.
Definition EBGeometry_BVHUnion.hpp:1161
Root::Layout m_unbounded
The primitives with unbounded boxes, as one leaf.
Definition EBGeometry_BVHUnion.hpp:1151
PODVector< uint32_t > m_members
The members' table: with one type, each storage place's member index (see getMemberIndex()); then,...
Definition EBGeometry_BVHUnion.hpp:1167
T m_smoothLen
Smoothing length.
Definition EBGeometry_BVHUnion.hpp:1156
Root::Layout m_bvh
BVH over the primitives with bounded boxes.
Definition EBGeometry_BVHUnion.hpp:1146
The union's arrays as offsets into its pool, with no location: what an outer union stores when this u...
Definition EBGeometry_BVHUnion.hpp:707
Root::Layout m_unbounded
The primitives with unbounded boxes, as one leaf.
Definition EBGeometry_BVHUnion.hpp:716
PODVector< uint32_t > m_members
The members' table: with one type, each storage place's member index (see getMemberIndex()); then,...
Definition EBGeometry_BVHUnion.hpp:722
Root::Layout m_bvh
BVH over the primitives with bounded boxes.
Definition EBGeometry_BVHUnion.hpp:711
How a BVH union is built: the construction method and, optionally, its leaf sizes.
Definition EBGeometry_BVHUnion.hpp:47
Construction m_construction
Preset construction method; every BVH::Construction value is supported.
Definition EBGeometry_BVHUnion.hpp:51
std::optional< ConstructionOptions > m_options
Leaf-size settings; empty for the union's defaultConstructionOptions().
Definition EBGeometry_BVHUnion.hpp:56
Leaf-size settings for the preset construction methods, one per family of methods.
Definition EBGeometry_PackedBVH.hpp:115
The BVH's arrays as offsets into its pool, and its root box: a PackedBVH minus its location.
Definition EBGeometry_PackedBVH.hpp:1140
What a union of several types adds to the one-type layout: its per-type arrays. Empty for one type,...
Definition EBGeometry_BVHUnion.hpp:235
UnionArrays< Ps... > m_arrays
The per-type arrays.
Definition EBGeometry_BVHUnion.hpp:239
T type
The precision.
Definition EBGeometry_BVHUnion.hpp:305
The precision of a primitive type: the T of the box its computeBoundingVolume() returns.
Definition EBGeometry_BVHUnion.hpp:293
Stored< P > type
The stored primitive.
Definition EBGeometry_BVHUnion.hpp:277
What a union's BVH leaves hold: the primitive itself for one type, a MemberRef for several.
Definition EBGeometry_BVHUnion.hpp:259
A leaf of a union of several primitive types: the primitive's type, and its index in that type's arra...
Definition EBGeometry_BVHUnion.hpp:172
uint32_t m_type
Index of the primitive's type among the union's types.
Definition EBGeometry_BVHUnion.hpp:176
uint32_t m_index
Index of the primitive in its type's array.
Definition EBGeometry_BVHUnion.hpp:181
typename P::Layout type
The stored type: P's layout.
Definition EBGeometry_BVHUnion.hpp:92
How a BVH union stores a primitive of type P: as is, or, for a pool-resident handle,...
Definition EBGeometry_BVHUnion.hpp:75
P type
The stored type: P itself.
Definition EBGeometry_BVHUnion.hpp:79
UnionArrays< Ps... > m_tail
The other types' arrays.
Definition EBGeometry_BVHUnion.hpp:222
PODVector< Stored< P > > m_head
The first type's primitives, as stored (see Stored).
Definition EBGeometry_BVHUnion.hpp:217
The arrays of a union of several primitive types, one per type in the order given: a recursive list,...
Definition EBGeometry_BVHUnion.hpp:202
What a BVH union is built into: a BVH over the primitives whose bounding box is bounded,...
Definition EBGeometry_BVHUnion.hpp:154
BVH::PackedBVH< T, Stored< P >, K > unbounded
The primitives with unbounded boxes, as one leaf; empty if there are none.
Definition EBGeometry_BVHUnion.hpp:163
BVH::PackedBVH< T, Stored< P >, K > bvh
BVH over the primitives with bounded boxes.
Definition EBGeometry_BVHUnion.hpp:158
Numeric limits, with the meanings of the std::numeric_limits members of the same names.
Definition EBGeometry_Math.hpp:91
Raw pointer + size view into a Pool block, for hot inner loops.
Definition EBGeometry_PODVector.hpp:52
Placement-independent descriptor of a POD array inside a Pool.
Definition EBGeometry_PODVector.hpp:131
Where a pool-resident descriptor resolves its offsets, and the rules for moving it.
Definition EBGeometry_Pool.hpp:99
Quadratic polynomial smooth minimum for blending two signed-distance values.
Definition EBGeometry_Blend.hpp:99
The surface that decides a shape's value at a point, as closestSurface() reports it.
Definition EBGeometry_SurfaceRef.hpp:39