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::TriangleAoSoA< T, W > Struct Template Reference

Face-id-carrying wrapper around a single TriangleSoAT<T, W>. More...

#include <EBGeometry_TriangleAoSoA.hpp>

Collaboration diagram for EBGeometry::TriangleAoSoA< T, W >:
Collaboration graph
[legend]

Public Member Functions

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.
 
T signedDistance (const Vec3T< T > &a_point) const noexcept
 Evaluate signed distance from a_point to the closest triangle 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.
 
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()).
 
T signedDistanceAt (uint32_t a_lane, const Vec3T< T > &a_point) const noexcept
 One lane's signed distance (TriangleSoAT::signedDistanceAt()).
 
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.
 
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.
 
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).
 
template<class BV >
BV computeBoundingVolume () const noexcept
 Compute the bounding volume enclosing all valid triangles in this group.
 

Protected Attributes

TriangleSoAT< T, W > m_triangles
 The wrapped, coordinate-only SoA block. SIMD-hot: this is all signedDistance() touches.
 
Array< uint32_t, W > m_faceIds
 Per-lane face ids, physically separate from m_triangles. m_faceIds[j] = face id of triangle j. Never read by signedDistance(const Vec3T<T>&).
 
uint32_t m_validCount = 0
 Number of valid (non-padded) triangles in this group (1..W).
 

Detailed Description

template<class T, size_t W = TriangleSoA::DefaultWidth<T>()>
struct EBGeometry::TriangleAoSoA< T, W >

Face-id-carrying wrapper around a single TriangleSoAT<T, W>.

Structurally this is an AoSoA (Array of Structures of Arrays): TriangleSoAT<T, W> itself is true SoA (one flat array per coordinate, no per-triangle structure at all), and TriangleAoSoA adds an Array<uint32_t, W> of face ids (and its own count of valid lanes) alongside it. The two are never merged or interleaved: the hot signedDistance(const Vec3T<T>&) query is delegated straight through to the embedded TriangleSoAT and never reads m_faceIds at all, so a pure signed-distance traversal over TriangleAoSoA-packed leaves touches exactly the same bytes it would touch over bare TriangleSoAT-packed leaves. The face ids are read only afterward, once a query already knows which lane (and therefore which triangle) it cares about, via getFaceId() or the id-reporting signedDistance(point, uint32_t&) overload – so a caller can recover which face is closest at no cost to the throughput signedDistance() path.

Warning
Inherits the embedded TriangleSoAT's over-alignment (up to 64 bytes, for AVX-512F). The library's own usage (PackedBVH storing groups in a Pool-backed PODVector<TriangleAoSoA>, reserved at alignof(TriangleAoSoA) inside a PoolBaseAlign-aligned block) is safe. If you allocate a TriangleAoSoA 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(TriangleAoSoA<T, W>).
Template Parameters
TFloating-point precision.
WSIMD width; see TriangleSoAT. Defaults to TriangleSoA::DefaultWidth<T>().

Member Function Documentation

◆ computeBoundingVolume()

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
template<class BV >
BV EBGeometry::TriangleAoSoA< T, W >::computeBoundingVolume ( ) const
noexcept

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

Delegates entirely to the embedded TriangleSoAT<T, W>.

Template Parameters
BVBounding volume type (e.g. AABBT<T>); must be constructible from a point array (a Vec3T<T> pointer and a count).
Returns
Bounding volume enclosing all vertices of the valid triangles.

◆ getFaceId()

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
uint32_t EBGeometry::TriangleAoSoA< T, W >::getFaceId ( size_t  a_lane) const
noexcept

Get the face id for one lane of this group.

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

Parameters
[in]a_laneLane index. Must satisfy 0 <= a_lane < W (padded lanes return the last real triangle's id – see pack()).
Returns
Face id of the triangle at a_lane.

◆ getNormal()

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
Vec3T< T > EBGeometry::TriangleAoSoA< T, W >::getNormal ( size_t  a_lane) const
noexcept

The unit normal of one lane's triangle.

Parameters
[in]a_laneLane index. Must satisfy 0 <= a_lane < W.
Returns
The face normal.

◆ getVertex()

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
Vec3T< T > EBGeometry::TriangleAoSoA< T, W >::getVertex ( size_t  a_lane,
size_t  a_vertex 
) const
inlinenoexcept

Vertex a_vertex of the triangle in lane a_lane (padded lanes repeat the last real triangle).

Parameters
[in]a_laneLane index, below W.
[in]a_vertexVertex index, below 3.
Returns
The vertex.

◆ nearestLane()

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
uint32_t EBGeometry::TriangleAoSoA< T, W >::nearestLane ( const Vec3T< T > &  a_point,
T &  a_d2 
) const
inlinenoexcept

The lane nearest a point and its squared unsigned distance (TriangleSoAT::nearestLane()).

Parameters
[in]a_pointThe point.
[out]a_d2The lane's squared distance.
Returns
The lane.

◆ pack()

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
void EBGeometry::TriangleAoSoA< T, W >::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.

Pads lanes a_count..W-1 by repeating the last real triangle (its coordinates and its face id), matching TriangleSoAT::pack()'s own padding convention, so all W lanes hold valid data. The coordinates go into the embedded TriangleSoAT; each triangle's face id (via Triangle::getFaceId()) goes into the parallel m_faceIds array.

Parameters
[in]a_trianglesSource triangle array with at least a_count elements. Must not be null.
[in]a_countNumber of valid triangles to pack. Must satisfy 1 <= a_count <= W.

◆ rayCrossing()

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
T EBGeometry::TriangleAoSoA< T, W >::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.

See TriangleSoAT::rayCrossing(). Requires the group to have already been packed via pack().

Parameters
[in]a_originRay origin.
[in]a_directionRay direction.
[in]a_tMinStart of the interval.
[in]a_tMaxEnd of the interval.
[out]a_faceIdSet to the face id of the triangle crossed; unchanged if there is none.
[out]a_normalSet to its unit normal; unchanged if there is none.
Returns
The distance along the ray of the crossing, or +infinity if there is none.

◆ rayCrossings()

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
void EBGeometry::TriangleAoSoA< T, W >::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.

See TriangleSoAT::rayCrossings(); the lanes' face ids and normals are getFaceId() and getNormal(). Requires the group to have already been packed via pack().

Parameters
[in]a_originRay origin.
[in]a_directionRay direction.
[in]a_tMinStart of the interval.
[in]a_tMaxEnd of the interval.
[out]a_crossingsW values: each lane's crossing, or +infinity.

◆ signedDistance() [1/2]

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
T EBGeometry::TriangleAoSoA< T, W >::signedDistance ( const Vec3T< T > &  a_point) const
noexcept

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

Delegates entirely to the embedded TriangleSoAT<T, W>; never touches m_faceIds, so the id array adds no cost to this hot (SIMD) path. See TriangleSoAT::signedDistance().

Parameters
[in]a_pointQuery point. Must be finite.
Returns
Signed distance from a_point to the closest valid triangle.

◆ signedDistance() [2/2]

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
T EBGeometry::TriangleAoSoA< T, W >::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.

The id-retrieving analogue of signedDistance(const Vec3T<T>&): it returns the same minimum-absolute-value signed distance, but also writes the winning triangle's face id to a_closestFaceId. Unlike the plain overload it keeps every lane's distance (TriangleSoAT::signedDistances()) to recover which lane won, then reads that lane's id – the extra work the throughput path deliberately avoids.

Parameters
[in]a_pointQuery point. Must be finite.
[out]a_closestFaceIdSet to the face id of the winning (minimum-|distance|) triangle.
Returns
Signed distance from a_point to the closest valid triangle.

◆ signedDistanceAt()

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
T EBGeometry::TriangleAoSoA< T, W >::signedDistanceAt ( uint32_t  a_lane,
const Vec3T< T > &  a_point 
) const
inlinenoexcept

One lane's signed distance (TriangleSoAT::signedDistanceAt()).

Parameters
[in]a_laneLane, below the number of packed triangles.
[in]a_pointThe point.
Returns
The signed distance.

Member Data Documentation

◆ m_validCount

template<class T , size_t W = TriangleSoA::DefaultWidth<T>()>
uint32_t EBGeometry::TriangleAoSoA< 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 getFaceId()/signedDistance(point, uint32_t&), rather than reading whatever indeterminate value happened to be there. (The plain signedDistance() gets the same protection for free from the embedded TriangleSoAT's own m_validCount.)


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