12#ifndef EBGEOMETRY_SPHERECLOUDBVH_HPP
13#define EBGEOMETRY_SPHERECLOUDBVH_HPP
35namespace PointCloudDetail {
44template <
class T,
class Source>
59 const T radius =
m_source(a_index).m_radius;
61 return Vec3T<T>(radius, radius, radius);
72template <
class T,
size_t W>
85 static constexpr const char*
ClassName =
"SphereCloudBVH";
88 static constexpr const char*
Singular =
"sphere";
91 static constexpr const char*
Plural =
"spheres";
105 return a_item.m_center;
120 a_lo =
min(a_lo, a_item.m_center - radius);
121 a_hi =
max(a_hi, a_item.m_center + radius);
132 requireValid(
const char* a_who,
const std::vector<Item>& a_items)
noexcept
134 for (std::size_t i = 0; i < a_items.size(); i++) {
135 const Item& sphere = a_items[i];
139 "%s: sphere %zu of %zu has a non-finite coordinate",
144 "%s: sphere %zu of %zu has a non-finite or negative radius",
168 template <
class Source>
172 const uint32_t a_numItems,
173 const bool a_parallel,
175 const char* a_who)
noexcept
177 if (a_numItems == 0) {
188 EBGEOMETRY_REQUIRE(std::isfinite(smallest) && std::isfinite(largest) && smallest >= T(0),
189 "%s: a sphere has a non-finite or negative radius",
195 for (uint32_t i = 0; i < a_numItems; i++) {
196 const T radius = a_source(i).m_radius;
199 "%s: sphere %u of %u has a non-finite or negative radius",
202 unsigned(a_numItems));
234template <class T, size_t K = BVH::DefaultBranchingRatio<T>(),
size_t W = PointSoA::DefaultWidth<T>()>
342 const std::vector<
Vec3T<T>>& a_centers,
343 const std::vector<T>& a_radii,
344 std::
size_t a_targetLeafSize = 16 * W);
366 template <class Source>
370 const Source& a_source,
371 uint32_t a_numSpheres,
372 std::
size_t a_targetLeafSize = 16 * W,
373 uint32_t a_maxSpheres = 0);
387 const std::vector<
Sphere>& a_spheres,
388 std::
size_t a_targetLeafSize = 16 * W,
389 uint32_t a_maxSpheres = 0);
405 const std::vector<
Vec3T<T>>& a_centers,
406 const std::vector<T>& a_radii,
407 std::
size_t a_targetLeafSize = 16 * W,
408 uint32_t a_maxSpheres = 0);
421 template <class Source>
424 rebuild(const Source& a_source, uint32_t a_numSpheres);
486 template <class Visit>
503 template <class Visit>
509 uint32_t a_exclude = SphereCloud::InvalidIndex) const noexcept;
574 using
Base = PointCloudDetail::
CloudBVH<T, K, W, PointCloudDetail::SpherePrimitive<T, W>>;
576 using
Base::m_bvhLayout;
579 using
Base::m_leafCnt;
580 using
Base::m_leafOff;
581 using
Base::m_maxItems;
595static_assert(std::is_trivially_copyable_v<
SphereCloudBVH<
double>>,
600#include "EBGeometry_SphereCloudBVHImplem.hpp"
Declarations of bounding volume types used in bounding volume hierarchies.
The linear BVH build shared by PointCloudBVH and SphereCloudBVH, over a cloud of points or spheres.
Building blocks for builds that run with GPU::parallelFor(): a bounding-box reduction,...
#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
#define EBGEOMETRY_REQUIRE(cond,...)
Always-on check of user input and one-time host setup.
Definition EBGeometry_Macros.hpp:200
The flattened, device-callable bounding volume hierarchy: PackedBVH, its node layout,...
Growable bump arena for the GPU memory foundation.
Declaration of a PointAoSoA group with a radius lane: a group of spheres carrying their ids.
The sphere, query result and sphere sources of SphereCloudBVH.
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.
Forward declaration of the linearised BVH, defined below.
Definition EBGeometry_PackedBVH.hpp:371
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
Vec3T< T > & getLowCorner() noexcept
Get a modifiable reference to the low corner of the AABB.
Vec3T< T > & getHighCorner() noexcept
Get a modifiable reference to the high corner of the AABB.
The state and build of a linear BVH over a cloud of primitives (points or spheres),...
Definition EBGeometry_CloudBVH.hpp:192
CloudBVH() noexcept=default
An empty BVH, to be reserved and filled.
Base of every pool-resident handle: the one PoolLocation its arrays resolve against.
Definition EBGeometry_Pool.hpp:573
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:210
A BVH over spheres of differing radii (polydisperse particles), with the signed distance to their uni...
Definition EBGeometry_SphereCloudBVH.hpp:236
T signedDistance(const Vec3T< T > &a_point) const noexcept
Signed distance to the union of the spheres: min_i(|p - c_i| - r_i); see the class.
Hit closestSphere(const Vec3T< T > &a_point) const noexcept
The sphere whose surface is nearest to a point, in the signed sense of signedDistance().
void forEachContact(uint32_t a_index, T a_gap, Visit &&a_visit) const noexcept
Visit every sphere in contact with sphere a_index: each sphere j != a_index whose separation |c_i - c...
SphereCloudBVH(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.
SphereCloudBVH deepCopy(Pool &a_dstPool) const
Duplicate this object's storage into a_dstPool.
SphereCloudBVH rebasedView(const Pool &a_pool) const noexcept
Produce a copy of this object that resolves against a_pool.
AABB computeBoundingVolume() const noexcept
The box of all the spheres.
uint32_t numSpheres() const noexcept
Number of spheres in the cloud.
uint32_t getNumSurfaces() const noexcept
How many surfaces the cloud numbers: one per cloud index it can hold (maxSpheres(),...
void rebuild(const Source &a_source, uint32_t a_numSpheres)
Build the BVH again, in the arrays build() reserved, from new spheres.
Packed getBVH() const noexcept
The held packed BVH over the sphere groups.
SurfaceRef< T > closestSurface(const Vec3T< T > &a_point) const noexcept
The sphere whose surface decides the cloud's value at a point, as a container names it (see hasSurfac...
void * base() noexcept
The base address this object's arrays are offsets from; see PoolHandle::base().
Definition EBGeometry_Pool.hpp:649
Sphere sphere(uint32_t a_index) const noexcept
The sphere with a cloud index.
static SphereCloudBVH build(Pool &a_pool, const Source &a_source, uint32_t a_numSpheres, std::size_t a_targetLeafSize=16 *W, uint32_t a_maxSpheres=0)
Build a BVH over spheres, where the pool's memory is.
uint32_t maxSpheres() const noexcept
The most spheres rebuild() can take.
Layout layout() const noexcept
The BVH's arrays without its location, for storing it inside another pool-resident object.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
static constexpr Vec3T< T > ones() noexcept
Return a vector with x = y = z = 1.
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Vec2T< T > min(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Component-wise minimum of two vectors.
Vec2T< T > max(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Component-wise maximum of two vectors.
The BVH's arrays as offsets into its pool, and its root box: a PackedBVH minus its location.
Definition EBGeometry_PackedBVH.hpp:1142
Placement-independent descriptor of a POD array inside a Pool.
Definition EBGeometry_PODVector.hpp:131
A source of points that are a sphere's radius in every coordinate: GPU::boundingBoxOf() over it finds...
Definition EBGeometry_SphereCloudBVH.hpp:46
Source m_source
The spheres.
Definition EBGeometry_SphereCloudBVH.hpp:48
Vec3T< T > operator()(const uint32_t a_index) const noexcept
The radius of a sphere, in every coordinate.
Definition EBGeometry_SphereCloudBVH.hpp:57
The primitive of SphereCloudBVH: a sphere, keyed at its center and packed into SphereAoSoA groups; se...
Definition EBGeometry_SphereCloudBVH.hpp:74
static void requireValid(const char *a_who, const std::vector< Item > &a_items) noexcept
Abort with a message unless the spheres of a host array can be built over: a finite center,...
Definition EBGeometry_SphereCloudBVH.hpp:132
static constexpr const char * Singular
One primitive, for the messages.
Definition EBGeometry_SphereCloudBVH.hpp:88
static const Vec3T< T > & center(const Item &a_item) noexcept
The point a sphere's Morton key is taken at.
Definition EBGeometry_SphereCloudBVH.hpp:103
static constexpr const char * ClassName
The class built over these primitives, for the messages.
Definition EBGeometry_SphereCloudBVH.hpp:85
static constexpr const char * Plural
Primitives, for the messages.
Definition EBGeometry_SphereCloudBVH.hpp:91
static void requireValidWhereBuilt(const Source &a_source, const uint32_t a_numItems, const bool a_parallel, Vec3T< T > *a_scratch, const char *a_who) noexcept
Check every radius, where the build runs: finite, and at least 0.
Definition EBGeometry_SphereCloudBVH.hpp:171
static void grow(Vec3T< T > &a_lo, Vec3T< T > &a_hi, const Item &a_item) noexcept
Grow a box to hold a sphere.
Definition EBGeometry_SphereCloudBVH.hpp:116
static constexpr const char * MaxParameter
build()'s parameter giving the room for a rebuild, for the messages.
Definition EBGeometry_SphereCloudBVH.hpp:94
Where a pool-resident descriptor resolves its offsets, and the rules for moving it.
Definition EBGeometry_Pool.hpp:99
A group of up to W spheres carrying their cloud indices: a PointAoSoA<T, W> of the centers,...
Definition EBGeometry_SphereAoSoA.hpp:37
The BVH's arrays as offsets into its pool, with no location (see PoolHandle).
Definition EBGeometry_SphereCloudBVH.hpp:269
PODVector< uint32_t > m_leafCnt
Per-sphere number of groups in its own leaf.
Definition EBGeometry_SphereCloudBVH.hpp:288
uint32_t m_depth
The tree's depth in node levels, which rebasedView() checks against a device's traversal stack.
Definition EBGeometry_SphereCloudBVH.hpp:298
PODVector< uint32_t > m_leafOff
Per-sphere offset of its own leaf's first group.
Definition EBGeometry_SphereCloudBVH.hpp:283
PODVector< Sphere > m_spheres
The spheres, by cloud index.
Definition EBGeometry_SphereCloudBVH.hpp:278
Packed::Layout m_bvh
The packed BVH over the sphere groups.
Definition EBGeometry_SphereCloudBVH.hpp:273
PODVector< uint32_t > m_order
Cloud indices in leaf (build) order.
Definition EBGeometry_SphereCloudBVH.hpp:293
A source of spheres reading one array of Sphere<T>, indexed by cloud index.
Definition EBGeometry_SphereCloud.hpp:86
One query result: the cloud index of a sphere and the signed distance to its surface.
Definition EBGeometry_SphereCloud.hpp:62
A sphere of a sphere cloud: a center and a radius.
Definition EBGeometry_SphereCloud.hpp:48
Vec3T< T > m_center
The center.
Definition EBGeometry_SphereCloud.hpp:49
T m_radius
The radius, at least 0.
Definition EBGeometry_SphereCloud.hpp:50
The surface that decides a shape's value at a point, as closestSurface() reports it.
Definition EBGeometry_SurfaceRef.hpp:39