EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_TriangleSoA.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
11#ifndef EBGEOMETRY_TRIANGLESOA_HPP
12#define EBGEOMETRY_TRIANGLESOA_HPP
13
14// Std includes
15#include <array>
16#include <cstddef>
17#include <cstdint>
18#include <type_traits>
19#include <vector>
20
21#if defined(__SSE4_1__) || defined(__AVX__) || defined(__AVX512F__)
22#include <immintrin.h>
23#endif
24
25// Our includes
27#include "EBGeometry_Vec.hpp"
28
29namespace EBGeometry {
30
34namespace TriangleSoA {
35
55template <typename T>
56[[nodiscard]] constexpr size_t
58{
59 static_assert(std::is_floating_point_v<T>, "EBGeometry::TriangleSoA::DefaultWidth requires a floating-point T");
60#if defined(__AVX512F__)
61 if constexpr (std::is_same_v<T, double>) {
62 return 8;
63 }
64 else {
65 return 16;
66 }
67#elif defined(__AVX__)
68 if constexpr (std::is_same_v<T, double>) {
69 return 4;
70 }
71 else {
72 return 8;
73 }
74#else
75 return 4;
76#endif
77}
78
79} // namespace TriangleSoA
80
100template <class T, size_t W>
102{
103 static_assert(W > 0, "W must be positive");
104 static_assert(std::is_floating_point_v<T>, "TriangleSoAT requires a floating-point type T");
105
106public:
115 template <class Meta>
116 void
118
129 [[nodiscard]] T
130 signedDistance(const Vec3T<T>& a_point) const noexcept;
131
145 [[nodiscard]] std::array<T, W>
146 signedDistances(const Vec3T<T>& a_point) const noexcept;
147
155 template <class BV>
156 [[nodiscard]] BV
158
168 [[nodiscard]] T
170
174 alignas(W * sizeof(T)) T m_vx[3][W];
175
179 T m_vy[3][W];
180
184 T m_vz[3][W];
185
190
194 T m_ny[W];
195
199 T m_nz[W];
200
204 alignas(W * sizeof(T)) T m_vnx[3][W];
205
209 T m_vny[3][W];
210
214 T m_vnz[3][W];
215
219 alignas(W * sizeof(T)) T m_enx[3][W];
220
224 T m_eny[3][W];
225
229 T m_enz[3][W];
230
238};
239
240} // namespace EBGeometry
241
242#include "EBGeometry_TriangleSoAImplem.hpp"
243
244#endif
Declaration of a triangle class with signed distance functionality.
Declaration of 2D and 3D point/vector classes with templated precision. Used with DCEL tools.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:225
constexpr size_t DefaultWidth() noexcept
Returns the SIMD-optimal SoA width (triangles per TriangleSoAT group) for type T on the current targe...
Definition EBGeometry_TriangleSoA.hpp:57
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:31
SoA (Structure of Arrays) layout for W triangles, enabling SIMD evaluation.
Definition EBGeometry_TriangleSoA.hpp:102
T m_vz[3][W]
z-coordinates of vertex positions. m_vz[i][j] = z-coord of vertex i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:184
T m_enz[3][W]
z-components of edge normals. m_enz[i][j] = z of edge normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:229
T m_nx[W]
x-components of face normals. m_nx[j] = x-component of the face normal for triangle j.
Definition EBGeometry_TriangleSoA.hpp:189
uint32_t m_validCount
Number of valid (non-padded) triangles in this group (1..W).
Definition EBGeometry_TriangleSoA.hpp:237
T m_vnz[3][W]
z-components of vertex normals. m_vnz[i][j] = z of vertex normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:214
void pack(const Triangle< T, Meta > *tris, uint32_t count) noexcept
Pack count triangles from tris[0..count-1] into this SoA group.
T signedDistanceLane(uint32_t a_lane, const Vec3T< T > &a_point) const noexcept
Signed distance from a_point to the single triangle stored in lane a_lane.
T m_ny[W]
y-components of face normals.
Definition EBGeometry_TriangleSoA.hpp:194
T m_enx[3][W]
x-components of edge normals. m_enx[i][j] = x of edge normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:219
T m_vy[3][W]
y-coordinates of vertex positions. m_vy[i][j] = y-coord of vertex i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:179
T m_nz[W]
z-components of face normals.
Definition EBGeometry_TriangleSoA.hpp:199
T m_vx[3][W]
x-coordinates of vertex positions. m_vx[i][j] = x-coord of vertex i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:174
BV computeBoundingVolume() const noexcept
Compute the bounding volume enclosing all valid triangles in this group.
T m_eny[3][W]
y-components of edge normals. m_eny[i][j] = y of edge normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:224
T m_vny[3][W]
y-components of vertex normals. m_vny[i][j] = y of vertex normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:209
std::array< T, W > signedDistances(const Vec3T< T > &a_point) const noexcept
Signed distances from a_point to every one of the W lane triangles.
T m_vnx[3][W]
x-components of vertex normals. m_vnx[i][j] = x of vertex normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:204
T signedDistance(const Vec3T< T > &a_point) const noexcept
Evaluate signed distance from a_point to the closest triangle in this group.