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 <cstddef>
16#include <cstdint>
17#include <type_traits>
18#include <vector>
19
20#if defined(__SSE4_1__) || defined(__AVX__) || defined(__AVX512F__)
21#include <immintrin.h>
22#endif
23
24// Our includes
26#include "EBGeometry_Vec.hpp"
27
28namespace EBGeometry {
29
33namespace TriangleSoA {
34
54template <typename T>
55[[nodiscard]] constexpr size_t
57{
58 static_assert(std::is_floating_point_v<T>, "EBGeometry::TriangleSoA::DefaultWidth requires a floating-point T");
59#if defined(__AVX512F__)
60 if constexpr (std::is_same_v<T, double>) {
61 return 8;
62 }
63 else {
64 return 16;
65 }
66#elif defined(__AVX__)
67 if constexpr (std::is_same_v<T, double>) {
68 return 4;
69 }
70 else {
71 return 8;
72 }
73#else
74 return 4;
75#endif
76}
77
78} // namespace TriangleSoA
79
99template <class T, size_t W>
101{
102 static_assert(W > 0, "W must be positive");
103 static_assert(std::is_floating_point_v<T>, "TriangleSoAT requires a floating-point type T");
104
105public:
114 template <class Meta>
115 void
117
128 [[nodiscard]] T
129 signedDistance(const Vec3T<T>& a_point) const noexcept;
130
138 template <class BV>
139 [[nodiscard]] BV
141
146 alignas(W * sizeof(T)) T m_vx[3][W];
147
151 T m_vy[3][W];
152
156 T m_vz[3][W];
157
162
166 T m_ny[W];
167
171 T m_nz[W];
172
176 alignas(W * sizeof(T)) T m_vnx[3][W];
177
181 T m_vny[3][W];
182
186 T m_vnz[3][W];
187
191 alignas(W * sizeof(T)) T m_enx[3][W];
192
196 T m_eny[3][W];
197
201 T m_enz[3][W];
202
210};
211
212} // namespace EBGeometry
213
214#include "EBGeometry_TriangleSoAImplem.hpp"
215
216#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:56
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:101
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:156
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:201
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:161
uint32_t m_validCount
Number of valid (non-padded) triangles in this group (1..W).
Definition EBGeometry_TriangleSoA.hpp:209
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:186
void pack(const Triangle< T, Meta > *tris, uint32_t count) noexcept
Pack count triangles from tris[0..count-1] into this SoA group.
T m_ny[W]
y-components of face normals.
Definition EBGeometry_TriangleSoA.hpp:166
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:191
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:151
T m_nz[W]
z-components of face normals.
Definition EBGeometry_TriangleSoA.hpp:171
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:146
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:196
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:181
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:176
T signedDistance(const Vec3T< T > &a_point) const noexcept
Evaluate signed distance from a_point to the closest triangle in this group.