EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_TriangleAoSoA.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_TRIANGLEAOSOA_HPP
12#define EBGEOMETRY_TRIANGLEAOSOA_HPP
13
14// Std includes
15#include <cstddef>
16#include <cstdint>
17#include <type_traits>
18
19// Our includes
20#include "EBGeometry_Array.hpp"
23#include "EBGeometry_Vec.hpp"
24
25namespace EBGeometry {
26
48template <class T, size_t W = TriangleSoA::DefaultWidth<T>()>
50{
51 static_assert(W > 0, "W must be positive");
52 static_assert(std::is_floating_point_v<T>, "TriangleAoSoA requires a floating-point type T");
53
54public:
65 void
66 pack(const Triangle<T>* a_triangles, uint32_t a_count) noexcept;
67
75 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
76 T
77 signedDistance(const Vec3T<T>& a_point) const noexcept;
78
91 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
92 T
93 signedDistance(const Vec3T<T>& a_point, uint32_t& a_closestFaceId) const noexcept;
94
101 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
102 uint32_t
103 nearestLane(const Vec3T<T>& a_point, T& a_d2) const noexcept
104 {
105 return m_triangles.nearestLane(a_point, a_d2);
106 }
107
114 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
115 T
116 signedDistanceAt(uint32_t a_lane, const Vec3T<T>& a_point) const noexcept
117 {
118 return m_triangles.signedDistanceAt(a_lane, a_point);
119 }
120
132 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
133 T
134 rayCrossing(const Vec3T<T>& a_origin,
135 const Vec3T<T>& a_direction,
136 T a_tMin,
137 T a_tMax,
138 uint32_t& a_faceId,
139 Vec3T<T>& a_normal) const noexcept;
140
152 void
154 const Vec3T<T>& a_origin, const Vec3T<T>& a_direction, T a_tMin, T a_tMax, T* a_crossings) const noexcept;
155
161 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
163 getNormal(size_t a_lane) const noexcept;
164
172 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
173 uint32_t
174 getFaceId(size_t a_lane) const noexcept;
175
182 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
183 inline Vec3T<T>
184 getVertex(size_t a_lane, size_t a_vertex) const noexcept
185 {
186 return m_triangles.getVertex(a_lane, a_vertex);
187 }
188
196 template <class BV>
197 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
198 BV
199 computeBoundingVolume() const noexcept;
200
201protected:
206
211 Array<uint32_t, W> m_faceIds;
212
221 uint32_t m_validCount = 0;
222};
223
224static_assert(std::is_trivially_copyable_v<TriangleAoSoA<float>>, "TriangleAoSoA<float> must be trivially copyable");
225static_assert(std::is_trivially_copyable_v<TriangleAoSoA<double>>, "TriangleAoSoA<double> must be trivially copyable");
226
227} // namespace EBGeometry
228
229#include "EBGeometry_TriangleAoSoAImplem.hpp"
230
231#endif
A fixed-size array that compiles for both host and device.
#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
Declaration of SoA triangle group for SIMD signed-distance evaluation.
Declaration of a triangle class with signed distance functionality.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Triangle class with signed distance functionality.
Definition EBGeometry_Triangle.hpp:52
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
Face-id-carrying wrapper around a single TriangleSoAT<T, W>.
Definition EBGeometry_TriangleAoSoA.hpp:50
Vec3T< T > getVertex(size_t a_lane, size_t a_vertex) const noexcept
Vertex a_vertex of the triangle in lane a_lane (padded lanes repeat the last real triangle).
Definition EBGeometry_TriangleAoSoA.hpp:184
uint32_t m_validCount
Number of valid (non-padded) triangles in this group (1..W).
Definition EBGeometry_TriangleAoSoA.hpp:221
T rayCrossing(const Vec3T< T > &a_origin, const Vec3T< T > &a_direction, T a_tMin, T a_tMax, uint32_t &a_faceId, Vec3T< T > &a_normal) const noexcept
Where a ray first crosses a triangle in this group, with that triangle's face id and normal.
Array< uint32_t, W > m_faceIds
Per-lane face ids, physically separate from m_triangles. m_faceIds[j] = face id of triangle j....
Definition EBGeometry_TriangleAoSoA.hpp:211
T signedDistanceAt(uint32_t a_lane, const Vec3T< T > &a_point) const noexcept
One lane's signed distance (TriangleSoAT::signedDistanceAt()).
Definition EBGeometry_TriangleAoSoA.hpp:116
TriangleSoAT< T, W > m_triangles
The wrapped, coordinate-only SoA block. SIMD-hot: this is all signedDistance() touches.
Definition EBGeometry_TriangleAoSoA.hpp:205
BV computeBoundingVolume() const noexcept
Compute the bounding volume enclosing all valid triangles in this group.
T signedDistance(const Vec3T< T > &a_point, uint32_t &a_closestFaceId) const noexcept
Evaluate signed distance from a_point to the closest triangle and report that triangle's face id.
void pack(const Triangle< T > *a_triangles, uint32_t a_count) noexcept
Pack a_count triangles from a_triangles[0..a_count-1] into this group.
void rayCrossings(const Vec3T< T > &a_origin, const Vec3T< T > &a_direction, T a_tMin, T a_tMax, T *a_crossings) const noexcept
Where a ray crosses each triangle in this group.
Vec3T< T > getNormal(size_t a_lane) const noexcept
The unit normal of one lane's triangle.
uint32_t getFaceId(size_t a_lane) const noexcept
Get the face id for one lane of this group.
uint32_t nearestLane(const Vec3T< T > &a_point, T &a_d2) const noexcept
The lane nearest a point and its squared unsigned distance (TriangleSoAT::nearestLane()).
Definition EBGeometry_TriangleAoSoA.hpp:103
T signedDistance(const Vec3T< T > &a_point) const noexcept
Evaluate signed distance from a_point to the closest triangle in this group.
SoA (Structure of Arrays) layout for W triangles, enabling SIMD evaluation.
Definition EBGeometry_TriangleSoA.hpp:142