11#ifndef EBGEOMETRY_CLOUDBVH_HPP
12#define EBGEOMETRY_CLOUDBVH_HPP
34namespace PointCloudDetail {
99template <
class T,
size_t W>
112 static constexpr const char*
ClassName =
"PointCloudBVH";
118 static constexpr const char*
Plural =
"points";
145 a_lo =
min(a_lo, a_item);
146 a_hi =
max(a_hi, a_item);
156 requireValid(
const char* a_who,
const std::vector<Item>& a_items)
noexcept
165 template <
class Source>
178template <
class Prim,
class Source>
193 return Prim::center(
m_source(a_index));
208template <
class T,
size_t K,
size_t W,
class Prim>
215 using Item =
typename Prim::Item;
297 template <
class Source>
301 const Source& a_source,
303 std::size_t a_targetLeafSize,
319 const std::vector<Item>& a_items,
320 std::size_t a_targetLeafSize,
331 template <
class Source>
334 reinitialize(
const Source& a_source, uint32_t a_numItems,
const char* a_who);
363 sizesFor(uint32_t a_numItems, uint32_t a_leafSize,
const char* a_who)
noexcept;
398 template <
class Source>
401 shape(
const Scratch& a_scratch,
void* a_base,
const Source& a_source, uint32_t a_numItems,
const char* a_who);
412 template <
class Source>
415 write(
const Scratch& a_scratch,
void* a_base,
const Sizes& a_sizes,
const Source& a_source, uint32_t a_numItems);
426 run(std::size_t a_count,
const F& a_f)
const;
438 scan(std::uint32_t* a_values, std::uint32_t a_count, std::uint32_t* a_scratch)
const;
449 static inline std::vector<U>
507#include "EBGeometry_CloudBVHImplem.hpp"
Declarations of bounding volume types used in bounding volume hierarchies.
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
Scalar helpers and numeric limits that compile for both host and device.
Placement-independent POD array views for the GPU memory foundation.
The flattened, device-callable bounding volume hierarchy: PackedBVH, its node layout,...
Declaration of a PointSoAT group that carries point ids.
Internal helpers shared by PointCloudBVH and PointCloudHashGrid, and by their builds.
Query results and helpers shared by the point-cloud search structures.
Growable bump arena for the GPU memory foundation.
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:365
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
The state and build of a linear BVH over a cloud of primitives (points or spheres),...
Definition EBGeometry_CloudBVH.hpp:210
PODVector< std::uint32_t > m_order
Cloud indices in leaf (build) order; the spatially coherent batch-query order.
Definition EBGeometry_CloudBVH.hpp:475
void write(const Scratch &a_scratch, void *a_base, const Sizes &a_sizes, const Source &a_source, uint32_t a_numItems)
Build step 6 (see PointCloudBVH): write the arrays reserved for the tree shape() gave.
std::uint32_t m_maxItems
The most primitives a rebuild can take, 0 for none.
Definition EBGeometry_CloudBVH.hpp:485
Sizes shape(const Scratch &a_scratch, void *a_base, const Source &a_source, uint32_t a_numItems, const char *a_who)
Build steps 1 to 5 (see PointCloudBVH): the box, the sorted keys, the tree's levels,...
static Sizes sizesFor(uint32_t a_numItems, uint32_t a_leafSize, const char *a_who) noexcept
Bounds on the array sizes of a build over a_numItems primitives.
std::uint32_t scan(std::uint32_t *a_values, std::uint32_t a_count, std::uint32_t *a_scratch) const
An exclusive scan, where the build runs; see GPU::exclusiveScan().
void initialize(Pool &a_pool, const std::vector< Item > &a_items, std::size_t a_targetLeafSize, uint32_t a_maxItems, const char *a_who)
Build over the primitives of a host array, where the pool's memory is: for a pool in device memory,...
void copyInto(CloudBVH &a_copy, Pool &a_dstPool) const
Duplicate this object's storage into a_dstPool, for a_copy, a copy of this object: the body of PointC...
void run(std::size_t a_count, const F &a_f) const
Run a build step: through GPU::parallelFor() for a build there, and in a host loop otherwise.
typename Packed::Node Node
Flat node type of the held BVH.
Definition EBGeometry_CloudBVH.hpp:230
PODVector< Item > m_items
The primitives, indexed by cloud index.
Definition EBGeometry_CloudBVH.hpp:460
std::uint32_t m_depth
The tree's depth in node levels (the root is level 1), 0 for an empty cloud.
Definition EBGeometry_CloudBVH.hpp:495
PODVector< std::uint32_t > m_leafOff
Per-primitive own-leaf group offset (for seeding).
Definition EBGeometry_CloudBVH.hpp:465
std::uint32_t m_leafSize
The largest leaf, max(a_targetLeafSize, K): a node of more primitives is cut.
Definition EBGeometry_CloudBVH.hpp:490
bool m_parallel
Whether the build runs through GPU::parallelFor() (the pool's memory is device-accessible).
Definition EBGeometry_CloudBVH.hpp:500
Scratch m_scratch
The scratch arrays a rebuild uses; empty for a BVH without room for one.
Definition EBGeometry_CloudBVH.hpp:480
typename Prim::Item Item
What a source of the primitives returns.
Definition EBGeometry_CloudBVH.hpp:215
void rebase(const Pool &a_pool) noexcept
Resolve this object against a_pool: the body of PointCloudBVH::rebasedView(), on a copy.
void reinitialize(const Source &a_source, uint32_t a_numItems, const char *a_who)
Build again in the arrays initialize() reserved: the body of PointCloudBVH::rebuild().
void reserveArrays(Pool &a_pool, const Sizes &a_sizes, uint32_t a_numItems)
Reserve the BVH's and the cloud's arrays from a_pool.
typename Prim::Group Group
The SoA leaf primitive: a group of up to W primitives carrying their cloud indices.
Definition EBGeometry_CloudBVH.hpp:220
static std::vector< U > toHost(const PODVector< U > &a_array, const void *a_base)
Copy one pool-resident array back into a host std::vector.
static Scratch reserveScratch(Pool &a_pool, uint32_t a_numItems, uint32_t a_leafSize, const char *a_who)
Reserve a build's scratch from a_pool, for up to a_numItems primitives.
PODVector< std::uint32_t > m_leafCnt
Per-primitive own-leaf group count (for seeding).
Definition EBGeometry_CloudBVH.hpp:470
CloudBVH() noexcept=default
An empty BVH, to be reserved and filled.
void initialize(Pool &a_pool, const Source &a_source, uint32_t a_numItems, std::size_t a_targetLeafSize, uint32_t a_maxItems, const char *a_who)
Build over the primitives of a source, where the pool's memory is: the body of PointCloudBVH::build()...
Packed::Layout m_bvhLayout
The packed BVH over the groups, as a layout: it shares this object's location.
Definition EBGeometry_CloudBVH.hpp:455
Base of every pool-resident handle: the one PoolLocation its arrays resolve against.
Definition EBGeometry_Pool.hpp:506
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:188
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
void requireValidCloud(const char *a_who, const std::vector< Vec3T< T > > &a_positions) noexcept
Abort with a message unless a point cloud can be indexed.
Definition EBGeometry_PointCloudDetail.hpp:50
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:1135
Compact BVH node stored in the flat node array.
Definition EBGeometry_PackedBVH.hpp:389
Placement-independent descriptor of a POD array inside a Pool.
Definition EBGeometry_PODVector.hpp:119
A PointSoAT<T, W> group that also carries each point's cloud index.
Definition EBGeometry_PointAoSoA.hpp:44
One node of a cloud BVH build, in breadth-first order.
Definition EBGeometry_CloudBVH.hpp:66
uint32_t m_subtree
Nodes in the node's subtree, itself included.
Definition EBGeometry_CloudBVH.hpp:83
uint32_t m_parent
The parent's breadth-first index (0 for the root).
Definition EBGeometry_CloudBVH.hpp:74
uint32_t m_depthFirst
The node's index in the depth-first node array.
Definition EBGeometry_CloudBVH.hpp:86
uint32_t m_hi
One past the node's last primitive, in sorted order.
Definition EBGeometry_CloudBVH.hpp:71
uint32_t m_slot
The node's position among its parent's children.
Definition EBGeometry_CloudBVH.hpp:77
uint32_t m_lo
First of the node's primitives, in sorted order.
Definition EBGeometry_CloudBVH.hpp:68
uint32_t m_firstChild
The first child's breadth-first index (interior nodes).
Definition EBGeometry_CloudBVH.hpp:80
A source of primitive centers, from a source of primitives.
Definition EBGeometry_CloudBVH.hpp:180
Source m_source
The primitives.
Definition EBGeometry_CloudBVH.hpp:182
auto operator()(const uint32_t a_index) const noexcept
The center of a primitive.
Definition EBGeometry_CloudBVH.hpp:191
The scratch arrays of a build: in the BVH's pool for a BVH with room for a rebuild,...
Definition EBGeometry_CloudBVH.hpp:248
PODVector< Vec3T< T > > m_box
GPU::boundingBoxOf()'s scratch.
Definition EBGeometry_CloudBVH.hpp:253
PODVector< MortonKey > m_keys
The primitives' sort keys, a power of two of them (the padding sorts last).
Definition EBGeometry_CloudBVH.hpp:250
PODVector< std::uint32_t > m_groups
By depth-first index, each leaf's first group.
Definition EBGeometry_CloudBVH.hpp:266
PODVector< std::uint32_t > m_scan
GPU::exclusiveScan()'s scratch.
Definition EBGeometry_CloudBVH.hpp:269
PODVector< BuildNode > m_nodes
The build's nodes, in breadth-first order.
Definition EBGeometry_CloudBVH.hpp:256
PODVector< std::uint32_t > m_rows
A level's interior flags, scanned into ranks; then, by depth-first index, each interior node's row.
Definition EBGeometry_CloudBVH.hpp:263
PODVector< AABB > m_boxes
Each build node's box, indexed like m_nodes.
Definition EBGeometry_CloudBVH.hpp:259
The largest array sizes any cloud of a given size can need; see PointCloudBVH's build steps.
Definition EBGeometry_CloudBVH.hpp:276
std::uint32_t m_groups
Groups.
Definition EBGeometry_CloudBVH.hpp:284
std::uint32_t m_interior
Interior nodes, one child-box row each.
Definition EBGeometry_CloudBVH.hpp:281
std::uint32_t m_nodes
Nodes.
Definition EBGeometry_CloudBVH.hpp:278
A primitive's sort key in a cloud BVH build: its center's Morton code, ties broken by its cloud index...
Definition EBGeometry_CloudBVH.hpp:41
uint32_t m_index
The primitive's cloud index.
Definition EBGeometry_CloudBVH.hpp:46
uint64_t m_code
The Morton code of the primitive center's cell.
Definition EBGeometry_CloudBVH.hpp:43
bool operator<(const MortonKey &a_other) const noexcept
Whether this key sorts before a_other: by code, then by cloud index.
Definition EBGeometry_CloudBVH.hpp:55
The primitive of PointCloudBVH: a point, packed into PointAoSoA groups.
Definition EBGeometry_CloudBVH.hpp:101
static constexpr const char * MaxParameter
build()'s parameter giving the room for a rebuild, for the messages.
Definition EBGeometry_CloudBVH.hpp:121
static constexpr const char * ClassName
The class built over these primitives, for the messages.
Definition EBGeometry_CloudBVH.hpp:112
static void grow(Vec3T< T > &a_lo, Vec3T< T > &a_hi, const Item &a_item) noexcept
Grow a box to hold a primitive.
Definition EBGeometry_CloudBVH.hpp:143
static const Vec3T< T > & center(const Item &a_item) noexcept
The point a primitive's Morton key is taken at.
Definition EBGeometry_CloudBVH.hpp:130
static constexpr const char * Singular
One primitive, for the messages.
Definition EBGeometry_CloudBVH.hpp:115
static void requireValid(const char *a_who, const std::vector< Item > &a_items) noexcept
Abort with a message unless the primitives of a host array can be built over.
Definition EBGeometry_CloudBVH.hpp:156
static void requireValidWhereBuilt(const Source &, uint32_t, bool, Vec3T< T > *, const char *) noexcept
Check, where the build runs, what the box of the centers does not: nothing for a point.
Definition EBGeometry_CloudBVH.hpp:168
static constexpr const char * Plural
Primitives, for the messages.
Definition EBGeometry_CloudBVH.hpp:118
A source of point positions for the builds that take one (PointCloudHashGrid::build()): an array of V...
Definition EBGeometry_PointCloud.hpp:227