EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
EBGeometry::TriangleSoAT< T, W > Struct Template Reference

SoA (Structure of Arrays) layout for W triangles, enabling SIMD evaluation. More...

#include <EBGeometry_TriangleSoA.hpp>

Public Member Functions

template<class Meta >
void pack (const Triangle< T, Meta > *tris, uint32_t count) noexcept
 Pack count triangles from tris[0..count-1] into this SoA group.
 
signedDistance (const Vec3T< T > &a_point) const noexcept
 Evaluate signed distance from a_point to the closest triangle in this group.
 
template<class BV >
BV computeBoundingVolume () const noexcept
 Compute the bounding volume enclosing all valid triangles in this group.
 

Protected Attributes

m_vx [3][W]
 x-coordinates of vertex positions. m_vx[i][j] = x-coord of vertex i for triangle j.
 
m_vy [3][W]
 y-coordinates of vertex positions. m_vy[i][j] = y-coord of vertex i for triangle j.
 
m_vz [3][W]
 z-coordinates of vertex positions. m_vz[i][j] = z-coord of vertex i for triangle j.
 
m_nx [W]
 x-components of face normals. m_nx[j] = x-component of the face normal for triangle j.
 
m_ny [W]
 y-components of face normals.
 
m_nz [W]
 z-components of face normals.
 
m_vnx [3][W]
 x-components of vertex normals. m_vnx[i][j] = x of vertex normal i for triangle j.
 
m_vny [3][W]
 y-components of vertex normals. m_vny[i][j] = y of vertex normal i for triangle j.
 
m_vnz [3][W]
 z-components of vertex normals. m_vnz[i][j] = z of vertex normal i for triangle j.
 
m_enx [3][W]
 x-components of edge normals. m_enx[i][j] = x of edge normal i for triangle j.
 
m_eny [3][W]
 y-components of edge normals. m_eny[i][j] = y of edge normal i for triangle j.
 
m_enz [3][W]
 z-components of edge normals. m_enz[i][j] = z of edge normal i for triangle j.
 
uint32_t m_validCount = 0
 Number of valid (non-padded) triangles in this group (1..W).
 

Detailed Description

template<class T, size_t W>
struct EBGeometry::TriangleSoAT< T, W >

SoA (Structure of Arrays) layout for W triangles, enabling SIMD evaluation.

signedDistance() dispatches to a packed intrinsics path for (T,W) combinations that fill a SIMD register exactly — SSE4.1 (float, W=4), AVX (float, W=8; double, W=4 or W=8), or AVX-512F (float, W=16; double, W=8) — evaluating all W triangles simultaneously. Any other (T,W) falls back to a scalar loop over m_validCount triangles.

Warning
This type is over-aligned (up to 64 bytes, for AVX-512F) via alignas. The library's own usage (PackedBVH storing groups inside a std::vector<TriangleSoAT>) is safe: C++17 mandates that std::allocator respect over-alignment, which has been verified empirically for every (T,W) combination this class supports. If you allocate a TriangleSoAT yourself outside of that path — a raw new, a container with a custom/pre-C++17-style allocator, placement-new into externally-owned storage, or a malloc'd buffer — you are responsible for ensuring the memory is aligned to alignof(TriangleSoAT<T, W>); nothing in this class enforces or checks that, and a misaligned SIMD load will crash (or silently read the wrong data on some platforms) rather than failing gracefully.
Template Parameters
TFloating-point precision.
WSIMD width: 4 for SSE (128-bit), 8 for AVX (256-bit float) or AVX-512F (512-bit double), 16 for AVX-512F (512-bit float).

Member Function Documentation

◆ computeBoundingVolume()

template<class T , size_t W>
template<class BV >
BV EBGeometry::TriangleSoAT< T, W >::computeBoundingVolume ( ) const
noexcept

Compute the bounding volume enclosing all valid triangles in this group.

Requires the group to have already been packed via pack() (1 <= m_validCount <= W).

Template Parameters
BVBounding volume type (e.g. AABBT<T>); must be constructible from a std::vector<Vec3T<T>> of vertex positions.
Returns
Bounding volume enclosing all vertices of the m_validCount triangles.

◆ pack()

template<class T , size_t W>
template<class Meta >
void EBGeometry::TriangleSoAT< T, W >::pack ( const Triangle< T, Meta > *  tris,
uint32_t  count 
)
noexcept

Pack count triangles from tris[0..count-1] into this SoA group.

Pads lanes count..W-1 by repeating the last real triangle so that all W lanes hold valid data and SIMD loads never read uninitialised memory.

Template Parameters
MetaTriangle meta-data type (forwarded from Triangle<T,Meta>).
Parameters
[in]trisSource triangle array with at least count elements. Must not be null.
[in]countNumber of valid triangles to pack. Must satisfy 1 <= count <= W.

◆ signedDistance()

template<class T , size_t W>
T EBGeometry::TriangleSoAT< T, W >::signedDistance ( const Vec3T< T > &  a_point) const
noexcept

Evaluate signed distance from a_point to the closest triangle in this group.

Returns the signed distance with minimum absolute value among m_validCount triangles. Dispatches to an SSE4.1 packed-float path for (T=float, W=4), to AVX packed-float for (T=float, W=8), to AVX packed-double for (T=double, W=4 or W=8), or to a scalar fallback. Requires the group to have already been packed via pack() (1 <= m_validCount <= W).

Parameters
[in]a_pointQuery point. Must be finite.
Returns
Signed distance from a_point to the closest valid triangle, with sign determined by the outward normal of the nearest feature (face, edge, or vertex).

Member Data Documentation

◆ m_validCount

template<class T , size_t W>
uint32_t EBGeometry::TriangleSoAT< T, W >::m_validCount = 0
protected

Number of valid (non-padded) triangles in this group (1..W).

Zero-initialized so that a default-constructed (not-yet-packed) group reliably fails the EBGEOMETRY_EXPECT(m_validCount >= 1) precondition in signedDistance() and computeBoundingVolume(), rather than reading whatever indeterminate value happened to be there.


The documentation for this struct was generated from the following file: