EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_PointCloudDetail.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
11#ifndef EBGEOMETRY_POINTCLOUDDETAIL_HPP
12#define EBGEOMETRY_POINTCLOUDDETAIL_HPP
13
14// Std includes
15#include <cmath>
16#include <cstddef>
17#include <cstdint>
18#include <cstdio>
19#include <cstdlib>
20#include <vector>
21
22// Our includes
24#include "EBGeometry_GPU.hpp"
26#include "EBGeometry_Macros.hpp"
27#include "EBGeometry_Math.hpp"
29#include "EBGeometry_Vec.hpp"
30
31namespace EBGeometry {
32
36namespace PointCloudDetail {
37
48template <class T>
49inline void
50requireValidCloud(const char* a_who, const std::vector<Vec3T<T>>& a_positions) noexcept
51{
52 EBGEOMETRY_REQUIRE(a_positions.size() < std::size_t(PointCloud::InvalidIndex),
53 "%s: too many points for 32-bit indices (%zu points, limit %zu)",
54 a_who,
55 a_positions.size(),
56 std::size_t(PointCloud::InvalidIndex) - 1);
57
58 for (std::size_t i = 0; i < a_positions.size(); i++) {
59 const Vec3T<T>& p = a_positions[i];
60
61 EBGEOMETRY_REQUIRE(std::isfinite(p[0]) && std::isfinite(p[1]) && std::isfinite(p[2]),
62 "%s: point %zu of %zu has a non-finite coordinate",
63 a_who,
64 i,
65 a_positions.size());
66 }
67}
68
76[[nodiscard]] EBGEOMETRY_HOST
77inline uint32_t
78keyCount(const uint32_t a_n) noexcept
79{
80 uint32_t n = (a_n == 0) ? 0 : 1;
81
82 while (n < a_n) {
83 n *= 2;
84 }
85
86 return n;
87}
88
105template <class T, class Source>
106[[nodiscard]] EBGEOMETRY_HOST
108boxOf(const Source& a_source,
109 const uint32_t a_numPoints,
110 const bool a_parallel,
111 Vec3T<T>* a_scratch,
112 const char* a_who,
113 const char* a_noun = "point")
114{
115 if (a_numPoints == 0) {
117 }
118
119 if (a_parallel) {
120 const BoundingVolumes::AABBT<T> box = GPU::boundingBoxOf<T>(a_source, a_numPoints, a_scratch);
121
122 const Vec3T<T>& lo = box.getLowCorner();
123 const Vec3T<T>& hi = box.getHighCorner();
124
125 EBGEOMETRY_REQUIRE(std::isfinite(lo[0]) && std::isfinite(lo[1]) && std::isfinite(lo[2]) && std::isfinite(hi[0]) &&
126 std::isfinite(hi[1]) && std::isfinite(hi[2]),
127 "%s: a %s has a non-finite coordinate",
128 a_who,
129 a_noun);
130
131 return box;
132 }
133
134 Vec3T<T> lo = +Vec3T<T>::max();
135 Vec3T<T> hi = -Vec3T<T>::max();
136
137 for (uint32_t i = 0; i < a_numPoints; i++) {
138 const Vec3T<T> p = a_source(i);
139
140 EBGEOMETRY_REQUIRE(std::isfinite(p[0]) && std::isfinite(p[1]) && std::isfinite(p[2]),
141 "%s: %s %u of %u has a non-finite coordinate",
142 a_who,
143 a_noun,
144 unsigned(i),
145 unsigned(a_numPoints));
146
147 lo = min(lo, p);
148 hi = max(hi, p);
149 }
150
151 return BoundingVolumes::AABBT<T>(lo, hi);
152}
153
154} // namespace PointCloudDetail
155
156} // namespace EBGeometry
157
158#endif
Declarations of bounding volume types used in bounding volume hierarchies.
Building blocks for builds that run with GPU::parallelFor(): a bounding-box reduction,...
GPU portability layer: host/device decoration macros and backend detection.
#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_REQUIRE(cond,...)
Always-on check of user input and one-time host setup.
Definition EBGeometry_Macros.hpp:84
Scalar helpers and numeric limits that compile for both host and device.
Query results and helpers shared by the point-cloud search structures.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
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.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
static constexpr Vec3T< T > max() noexcept
Return the most-positive representable vector.
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
uint32_t keyCount(const uint32_t a_n) noexcept
The smallest power of two at least a_n, and 0 for 0: how many keys a build sorts with GPU::bitonicSor...
Definition EBGeometry_PointCloudDetail.hpp:78
BoundingVolumes::AABBT< T > boxOf(const Source &a_source, const uint32_t a_numPoints, const bool a_parallel, Vec3T< T > *a_scratch, const char *a_who, const char *a_noun="point")
The box of a cloud, found where a build runs, and every coordinate checked finite.
Definition EBGeometry_PointCloudDetail.hpp:108
constexpr uint32_t InvalidIndex
The cloud index of "no point": a miss, or a result slot a query could not fill.
Definition EBGeometry_PointCloud.hpp:41
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.