EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_PointCloudBVH.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
12#ifndef EBGEOMETRY_POINTCLOUDBVH_HPP
13#define EBGEOMETRY_POINTCLOUDBVH_HPP
14
15// Std includes
16#include <cstddef>
17#include <cstdint>
18#include <type_traits>
19#include <vector>
20
21// Our includes
24#include "EBGeometry_GPU.hpp"
25#include "EBGeometry_Math.hpp"
32#include "EBGeometry_Pool.hpp"
33#include "EBGeometry_Vec.hpp"
34
35namespace EBGeometry {
36
111template <class T, size_t K = BVH::DefaultBranchingRatio<T>(), size_t W = PointSoA::DefaultWidth<T>()>
112class PointCloudBVH : public PointCloudDetail::CloudBVH<T, K, W, PointCloudDetail::PointPrimitive<T, W>>
113{
114public:
119
124
128 using Node = typename Packed::Node;
129
134
141
152 inline PointCloudBVH(Pool& a_pool, const std::vector<Vec3T<T>>& a_positions, std::size_t a_targetLeafSize = 16 * W);
153
185 template <class Source>
186 [[nodiscard]] EBGEOMETRY_HOST
187 static inline PointCloudBVH
188 build(Pool& a_pool,
189 const Source& a_source,
190 uint32_t a_numPoints,
191 std::size_t a_targetLeafSize = 16 * W,
192 uint32_t a_maxPoints = 0);
193
203 [[nodiscard]] EBGEOMETRY_HOST
204 static inline PointCloudBVH
205 build(Pool& a_pool,
206 const std::vector<Vec3T<T>>& a_positions,
207 std::size_t a_targetLeafSize = 16 * W,
208 uint32_t a_maxPoints = 0);
209
223 template <class Source>
225 inline void
226 rebuild(const Source& a_source, uint32_t a_numPoints);
227
232 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
233 inline uint32_t
234 maxPoints() const noexcept
235 {
236 return m_maxItems;
237 }
238
244 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
245 inline Hit
246 closestPoint(const Vec3T<T>& a_query) const noexcept;
247
256 inline std::size_t
257 closestPoints(const Vec3T<T>& a_query, std::size_t a_k, Hit* a_out) const noexcept;
258
264 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
265 inline Hit
266 nearestNeighbor(uint32_t a_point) const noexcept;
267
276 inline std::size_t
277 nearestNeighbors(uint32_t a_point, std::size_t a_k, Hit* a_out) const noexcept;
278
289 [[nodiscard]] EBGEOMETRY_HOST
290 inline std::vector<Hit>
291 allNearestNeighbors(std::size_t a_k = 1) const;
292
297 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
298 inline std::size_t
299 numPoints() const noexcept
300 {
301 return m_items.size();
302 }
303
309 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
310 inline const Vec3T<T>&
311 position(uint32_t a_index) const noexcept
312 {
313 EBGEOMETRY_EXPECT(a_index < m_items.size());
314
315 return m_items.at(this->base(), a_index);
316 }
317
324 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
325 inline Packed
326 getBVH() const noexcept
327 {
328 return Packed(m_bvhLayout, this->location());
329 }
330
335 using PoolHandle::base;
336
352 [[nodiscard]] EBGEOMETRY_HOST
353 inline PointCloudBVH
354 rebasedView(const Pool& a_pool) const noexcept;
355
366 [[nodiscard]] EBGEOMETRY_HOST
367 inline PointCloudBVH
368 deepCopy(Pool& a_dstPool) const;
369
370private:
375
376 using Base::m_bvhLayout;
377 using Base::m_items;
378 using Base::m_leafCnt;
379 using Base::m_leafOff;
380 using Base::m_maxItems;
381 using Base::m_order;
382
386 PointCloudBVH() noexcept = default;
387
401 inline std::size_t
402 query(const Vec3T<T>& a_query,
403 std::size_t a_k,
404 Hit* a_out,
405 uint32_t a_exclude,
406 std::uint32_t a_seedOff,
407 std::uint32_t a_seedCnt) const noexcept;
408};
409
414static_assert(std::is_trivially_copyable_v<PointCloudBVH<float>>, "PointCloudBVH<float> must be trivially copyable");
415static_assert(std::is_trivially_copyable_v<PointCloudBVH<double>>, "PointCloudBVH<double> must be trivially copyable");
416
417} // namespace EBGeometry
418
419#include "EBGeometry_PointCloudBVHImplem.hpp"
420
421#endif
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.
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
#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.
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.
Declaration of a true SoA point-position group for SIMD nearest-neighbor evaluation.
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:369
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
A BVH over a point cloud, with a fast build and turnkey queries.
Definition EBGeometry_PointCloudBVH.hpp:113
PointCloudBVH(Pool &a_pool, const std::vector< Vec3T< T > > &a_positions, std::size_t a_targetLeafSize=16 *W)
Build a BVH over a point cloud on the host: shorthand for build(a_pool, a_positions,...
BVH::PackedBVH< T, PointGroup, K > Packed
The packed BVH this class holds over its point groups.
Definition EBGeometry_PointCloudBVH.hpp:123
std::size_t closestPoints(const Vec3T< T > &a_query, std::size_t a_k, Hit *a_out) const noexcept
The a_k closest cloud points to an arbitrary query point, nearest first.
static PointCloudBVH build(Pool &a_pool, const Source &a_source, uint32_t a_numPoints, std::size_t a_targetLeafSize=16 *W, uint32_t a_maxPoints=0)
Build a BVH over a point cloud, where the pool's memory is.
Hit nearestNeighbor(uint32_t a_point) const noexcept
Nearest other point to a point already in the cloud (seed-from-own-leaf search).
static PointCloudBVH build(Pool &a_pool, const std::vector< Vec3T< T > > &a_positions, std::size_t a_targetLeafSize=16 *W, uint32_t a_maxPoints=0)
Build a BVH over points on the host, where the pool's memory is; see the build() above.
uint32_t maxPoints() const noexcept
The most points rebuild() can take.
Definition EBGeometry_PointCloudBVH.hpp:234
Hit closestPoint(const Vec3T< T > &a_query) const noexcept
Closest cloud point to an arbitrary query point.
const Vec3T< T > & position(uint32_t a_index) const noexcept
Position of the point with the given cloud index.
Definition EBGeometry_PointCloudBVH.hpp:311
std::vector< Hit > allNearestNeighbors(std::size_t a_k=1) const
For every point, its a_k nearest other points (the k-nearest-neighbor graph).
typename Packed::Node Node
Flat node type of the held BVH.
Definition EBGeometry_PointCloudBVH.hpp:128
Packed getBVH() const noexcept
The held packed BVH over the point groups.
Definition EBGeometry_PointCloudBVH.hpp:326
void rebuild(const Source &a_source, uint32_t a_numPoints)
Build the BVH again, in the arrays build() reserved, from new positions.
PointCloudBVH deepCopy(Pool &a_dstPool) const
Duplicate this object's storage into a_dstPool.
void * base() noexcept
The base address this object's arrays are offsets from; see PoolHandle::base().
Definition EBGeometry_Pool.hpp:639
PointCloudBVH rebasedView(const Pool &a_pool) const noexcept
Produce a copy of this object that resolves against a_pool.
std::size_t nearestNeighbors(uint32_t a_point, std::size_t a_k, Hit *a_out) const noexcept
The a_k nearest other points to a point already in the cloud, nearest first.
std::size_t numPoints() const noexcept
Number of points in the cloud.
Definition EBGeometry_PointCloudBVH.hpp:299
PointCloud::Hit< T > Hit
One query result: the cloud index of a matched point and its squared distance.
Definition EBGeometry_PointCloudBVH.hpp:140
The state and build of a linear BVH over a cloud of primitives (points or spheres),...
Definition EBGeometry_CloudBVH.hpp:192
PODVector< std::uint32_t > m_order
Cloud indices in leaf (build) order; the spatially coherent batch-query order.
Definition EBGeometry_CloudBVH.hpp:457
std::uint32_t m_maxItems
The most primitives a rebuild can take, 0 for none.
Definition EBGeometry_CloudBVH.hpp:467
PODVector< Item > m_items
The primitives, indexed by cloud index.
Definition EBGeometry_CloudBVH.hpp:442
PODVector< std::uint32_t > m_leafOff
Per-primitive own-leaf group offset (for seeding).
Definition EBGeometry_CloudBVH.hpp:447
PODVector< std::uint32_t > m_leafCnt
Per-primitive own-leaf group count (for seeding).
Definition EBGeometry_CloudBVH.hpp:452
Packed::Layout m_bvhLayout
The packed BVH over the groups, as a layout: it shares this object's location.
Definition EBGeometry_CloudBVH.hpp:437
PoolLocation location() const noexcept
Where this handle's arrays live.
Definition EBGeometry_Pool.hpp:571
void * base() noexcept
The base address this handle's offsets resolve against; see PoolLocation::base().
Definition EBGeometry_Pool.hpp:639
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:205
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Compact BVH node stored in the flat node array.
Definition EBGeometry_PackedBVH.hpp:393
T & at(void *a_base, uint32_t a_i) const noexcept
Mutable element access against a_base.
Definition EBGeometry_PODVector.hpp:220
uint32_t size() const noexcept
Number of constructed elements.
Definition EBGeometry_PODVector.hpp:248
A PointSoAT<T, W> group that also carries each point's cloud index.
Definition EBGeometry_PointAoSoA.hpp:44
One query result: the cloud index of a matched point and its squared distance.
Definition EBGeometry_PointCloud.hpp:53