EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_BVHQuery.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
17#ifndef EBGEOMETRY_BVHQUERY_HPP
18#define EBGEOMETRY_BVHQUERY_HPP
19
20// Std includes
21#include <cstddef>
22#include <cstdint>
23#include <type_traits>
24#include <utility>
25
26// Our includes
27#include "EBGeometry_Array.hpp"
29#include "EBGeometry_GPU.hpp"
30#include "EBGeometry_Math.hpp"
31#include "EBGeometry_Vec.hpp"
32
33namespace EBGeometry {
34
35namespace BVH {
36
45template <class T, size_t K>
47{
58 static constexpr size_t RowAlignment =
59 (((sizeof(T) * K) & ((sizeof(T) * K) - 1)) == 0) ? (sizeof(T) * K) : alignof(T);
60
64 alignas(RowAlignment) T m_lo[3][K];
65
69 alignas(RowAlignment) T m_hi[3][K];
70};
71
77{
78};
79
84{
85};
86
93{
94};
95
101{
108 template <class... Args>
110 constexpr bool
111 operator()(const Args&... a_args) const noexcept
112 {
113 ((void)a_args, ...);
114
115 return true;
116 }
117};
118
125template <class Q, class = void>
127{
131 using type = typename Q::Scalar;
132};
133
138template <class Q>
139struct QueryKey<Q, std::void_t<typename Q::Key>>
140{
144 using type = typename Q::Key;
145};
146
154template <class Q, class = void>
156{
160 static constexpr uint32_t value = 1;
161};
162
167template <class Q>
168struct QueryLanes<Q, std::void_t<decltype(Q::Lanes)>>
169{
173 static constexpr uint32_t value = Q::Lanes;
174};
175
182template <class Q, class = void>
183struct IsQuery : std::false_type
184{
185};
186
191template <class Q>
192struct IsQuery<Q,
193 std::void_t<typename Q::Scalar,
194 decltype(std::declval<const Q&>().key(
195 std::declval<const BoundingVolumes::AABBT<typename Q::Scalar>&>()))>> : std::true_type
196{
197};
198
213template <class T>
215{
219 using Scalar = T;
220
224 using Key = T;
225
230
239 template <size_t K>
240 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
241 inline Array<T, K>
242 keys(const ChildBoxes<T, K>& a_row) const noexcept;
243
251 template <size_t K>
252 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
253 inline T
254 key(const ChildBoxes<T, K>& a_row, size_t a_k) const noexcept;
255
261 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
262 inline T
263 key(const BoundingVolumes::AABBT<T>& a_box) const noexcept;
264};
265
270template <class T>
272
284template <class T>
286{
290 using Scalar = T;
291
295 using Key = T;
296
301
306
311
319 inline RayQuery(const Vec3T<T>& a_origin, const Vec3T<T>& a_direction, T a_tMin = T(0)) noexcept;
320
328 template <size_t K>
329 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
330 inline Array<T, K>
331 keys(const ChildBoxes<T, K>& a_row) const noexcept;
332
340 template <size_t K>
341 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
342 inline T
343 key(const ChildBoxes<T, K>& a_row, size_t a_k) const noexcept;
344
350 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
351 inline T
352 key(const BoundingVolumes::AABBT<T>& a_box) const noexcept;
353};
354
355} // namespace BVH
356
357} // namespace EBGeometry
358
359#include "EBGeometry_BVHQueryImplem.hpp"
360
361#endif
A fixed-size array that compiles for both host and device.
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
Scalar helpers and numeric limits that compile for both host and device.
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
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Fixed-size array with host- and device-callable members.
Definition EBGeometry_Array.hpp:33
Visit the children within the bound in the order they are stored (first slot first),...
Definition EBGeometry_BVHQuery.hpp:93
The boxes of the K children of one interior node, in SoA layout: m_lo[axis][child] and m_hi[axis][chi...
Definition EBGeometry_BVHQuery.hpp:47
T m_lo[3][K]
Lower corners: m_lo[axis][child], axis in {0, 1, 2}, child in {0, ..., K - 1}.
Definition EBGeometry_BVHQuery.hpp:64
static constexpr size_t RowAlignment
Alignment of one axis row, in bytes.
Definition EBGeometry_BVHQuery.hpp:58
T m_hi[3][K]
Upper corners: m_hi[axis][child], axis in {0, 1, 2}, child in {0, ..., K - 1}.
Definition EBGeometry_BVHQuery.hpp:69
The default visit callback of PackedBVH::traverse(): enter every node that passes the bound.
Definition EBGeometry_BVHQuery.hpp:101
constexpr bool operator()(const Args &... a_args) const noexcept
Always descend.
Definition EBGeometry_BVHQuery.hpp:111
Visit the children within the bound farthest first (largest key first).
Definition EBGeometry_BVHQuery.hpp:84
Whether a type is a query type: it names its precision (Scalar) and keys a node's children.
Definition EBGeometry_BVHQuery.hpp:184
Visit the children within the bound nearest first (smallest key first). The default: a nearest-primit...
Definition EBGeometry_BVHQuery.hpp:77
A point tracked through a BVH: the key of a box is the squared distance from the point to it (0 insid...
Definition EBGeometry_BVHQuery.hpp:215
T key(const BoundingVolumes::AABBT< T > &a_box) const noexcept
The squared distance from the point to a box (the root's).
T Key
Key type: a squared distance.
Definition EBGeometry_BVHQuery.hpp:224
T Scalar
Floating-point precision.
Definition EBGeometry_BVHQuery.hpp:219
Vec3T< T > m_point
The point.
Definition EBGeometry_BVHQuery.hpp:229
T key(const ChildBoxes< T, K > &a_row, size_t a_k) const noexcept
The squared distance from the point to one child box, bit for bit what keys() gives it.
Array< T, K > keys(const ChildBoxes< T, K > &a_row) const noexcept
The squared distances from the point to the K child boxes of a node.
typename Q::Key type
The key type.
Definition EBGeometry_BVHQuery.hpp:144
The key type of a query type: Q::Key if it declares one, else Q::Scalar.
Definition EBGeometry_BVHQuery.hpp:127
typename Q::Scalar type
The key type.
Definition EBGeometry_BVHQuery.hpp:131
How many queries a query type carries. 1 unless the type says otherwise.
Definition EBGeometry_BVHQuery.hpp:156
static constexpr uint32_t value
Number of queries.
Definition EBGeometry_BVHQuery.hpp:160
A ray tracked through a BVH: the key of a box is the distance along the ray at which it enters the bo...
Definition EBGeometry_BVHQuery.hpp:286
RayQuery(const Vec3T< T > &a_origin, const Vec3T< T > &a_direction, T a_tMin=T(0)) noexcept
The ray origin + t * direction, t >= tMin.
T m_tMin
Start of the ray: crossings before it are ignored.
Definition EBGeometry_BVHQuery.hpp:310
T Key
Key type: a distance along the ray.
Definition EBGeometry_BVHQuery.hpp:295
T key(const ChildBoxes< T, K > &a_row, size_t a_k) const noexcept
Where the ray enters one child box, bit for bit what keys() gives it.
T Scalar
Floating-point precision.
Definition EBGeometry_BVHQuery.hpp:290
Vec3T< T > m_inverseDirection
1 / direction, per component (+-infinity for a zero component).
Definition EBGeometry_BVHQuery.hpp:305
Array< T, K > keys(const ChildBoxes< T, K > &a_row) const noexcept
Where the ray enters the K child boxes of a node (+infinity where it misses one).
Vec3T< T > m_origin
Ray origin.
Definition EBGeometry_BVHQuery.hpp:300