EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
EBGeometry_OffsetRayForms.hpp File Reference

Ray forms of offsets and annuli: the level sets of their operands' values. More...

#include <cmath>
#include <cstdint>
#include <type_traits>
#include "EBGeometry_AnalyticDistanceFunctions.hpp"
#include "EBGeometry_AnalyticRayForms.hpp"
#include "EBGeometry_BVHQuery.hpp"
#include "EBGeometry_CSGRayForms.hpp"
#include "EBGeometry_DCEL_Iterator.hpp"
#include "EBGeometry_Fused.hpp"
#include "EBGeometry_Math.hpp"
#include "EBGeometry_MeshDistanceFunctions.hpp"
#include "EBGeometry_MeshRayForms.hpp"
#include "EBGeometry_Ray.hpp"
#include "EBGeometry_RaySpans.hpp"
Include dependency graph for EBGeometry_OffsetRayForms.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  EBGeometry::RayDetail::Piece< T >
 Where a ray is inside a convex piece: [m_in, m_out], with the outward normals there; empty if m_in > m_out. More...
 
struct  EBGeometry::RayDetail::GrownRayQuery< T >
 A BVH ray query whose boxes are grown by a radius: what a mesh's offset faces are walked with. More...
 
struct  EBGeometry::RayDetail::OffsetFaceUnion< T >
 The union of the offset faces a ray meets, as disjoint spans merged as they come, at most Capacity: an offset face that would begin a span beyond them is dropped and lowers the horizon to its entry, which is also the walk's bound, so that the boxes beyond are left out. More...
 
struct  EBGeometry::RayDetail::MeshFaces< S >
 How a mesh's faces are walked along a ray, each given as its normal, a point in its plane, its edges, its squared distance from a point and its id. More...
 
struct  EBGeometry::RayDetail::MeshFaces< TriMeshSDF< T, K, W > >
 TriMeshSDF: its BVH, a triangle per SoA lane. More...
 
struct  EBGeometry::RayDetail::MeshFaces< MeshSDF< T, K > >
 MeshSDF: its BVH, a polygon face per leaf entry. More...
 
struct  EBGeometry::RayDetail::MeshFaces< FlatMeshSDF< T > >
 FlatMeshSDF: every face, in turn. More...
 
struct  EBGeometry::RayDetail::NearestOffsetFace< T >
 What a mesh's nearest offset-face walk finds. More...
 
struct  EBGeometry::RayDetail::IsMeshLevel< S >
 Whether a shape's level sets are a mesh's (its faces offset), or a fused affine map of one: costly to trace over a whole ray, cheap up to a first crossing. More...
 
struct  EBGeometry::RayDetail::IsMeshLevel< TriMeshSDF< T, K, W > >
 TriMeshSDF. More...
 
struct  EBGeometry::RayDetail::IsMeshLevel< MeshSDF< T, K > >
 MeshSDF. More...
 
struct  EBGeometry::RayDetail::IsMeshLevel< FlatMeshSDF< T > >
 FlatMeshSDF. More...
 
struct  EBGeometry::RayDetail::IsMeshLevel< Fused::Node< Fused::AffineOp< T >, C > >
 A fused affine map of one. More...
 
struct  EBGeometry::RayDetail::DeferredOperand< Fused::Node< Fused::ShiftOp< T, IsAnnulus >, C >, std::enable_if_t< IsMeshLevel< C >::value > >
 An intersection traces a fused offset or annulus of a mesh only within its other operands' spans, where it needs only first crossings: the nearest offset face, not the union of all along the ray. More...
 
struct  EBGeometry::RayDetail::LevelForm< S, class >
 A level set {f <= c} of a shape's value f along a ray. More...
 
struct  EBGeometry::RayDetail::LevelForm< SphereSDF< T > >
 A sphere's level set: the sphere of radius r + c. More...
 
struct  EBGeometry::RayDetail::LevelForm< CapsuleSDF< T > >
 A capsule's level set: the capsule of radius r + c. More...
 
struct  EBGeometry::RayDetail::LevelForm< InfiniteCylinderSDF< T > >
 An infinite cylinder's level set: the cylinder of radius r + c. More...
 
struct  EBGeometry::RayDetail::LevelForm< PlaneSDF< T > >
 A plane's level set: the half-space moved by c along the normal. More...
 
struct  EBGeometry::RayDetail::LevelForm< BoxSDF< T > >
 A box's level set: the box shrunk by -c, or grown by c into a rounded box. More...
 
struct  EBGeometry::RayDetail::MeshLevelForm< S >
 A mesh's level set: the mesh united with its faces offset by c, or less its faces offset by -c. More...
 
struct  EBGeometry::RayDetail::LevelForm< TriMeshSDF< T, K, W > >
 TriMeshSDF's level sets. More...
 
struct  EBGeometry::RayDetail::LevelForm< MeshSDF< T, K > >
 MeshSDF's level sets. More...
 
struct  EBGeometry::RayDetail::LevelForm< FlatMeshSDF< T > >
 FlatMeshSDF's level sets. More...
 
struct  EBGeometry::RayDetail::HasLevelForm< S, class >
 Whether a shape's level sets have a closed form (a LevelForm specialisation). More...
 
struct  EBGeometry::RayDetail::HasLevelForm< S, std::void_t< decltype(LevelForm< S >::Convex)> >
 A shape with a LevelForm. More...
 
struct  EBGeometry::RayDetail::LevelForm< Fused::Node< Fused::AffineOp< T >, C >, std::enable_if_t< HasLevelForm< C >::value > >
 A fused affine map's level sets: its operand's, at the level divided by the map's value scale, along the mapped ray. More...
 
struct  EBGeometry::RayDetail::LevelView< S >
 A level set of a shape, {f <= c}, or an annulus of it, {f <= c} less {f < -c}: a shape whose ray form traces it from the shape's closed-form level sets. More...
 
struct  EBGeometry::RayDetail::IsComposition< LevelView< S > >
 A level view is called out of line on a device where its shape is. More...
 
struct  EBGeometry::RayForm< RayDetail::LevelView< S >, std::enable_if_t< RayDetail::HasLevelForm< S >::value > >
 The ray form of a level view (RayDetail::LevelView): an offset or an annulus of a shape traced from its closed-form level sets, exactly and callable on a device. More...
 
struct  EBGeometry::RayForm< Fused::Node< Fused::ShiftOp< T, IsAnnulus >, C >, std::enable_if_t< RayDetail::HasLevelForm< C >::value > >
 The ray form of a fused offset or annulus of a shape whose level sets have a closed form (see RayDetail::LevelForm): traced through its level view. More...
 

Namespaces

namespace  EBGeometry
 Namespace containing all of EBGeometry's functionality.
 

Functions

template<class T >
Piece< T > EBGeometry::RayDetail::ballPiece (const RayT< T > &a_ray, const Vec3T< T > &a_center, const T a_radius) noexcept
 A ray through a ball.
 
template<class T >
Piece< T > EBGeometry::RayDetail::tubePiece (const RayT< T > &a_ray, const Vec3T< T > &a_point, const Vec3T< T > &a_axis, const T a_radius) noexcept
 A ray through an infinite cylinder: the points within a radius of a line.
 
template<class T >
Piece< T > EBGeometry::RayDetail::capsulePiece (const RayT< T > &a_ray, const Vec3T< T > &a_a, const Vec3T< T > &a_b, const T a_radius) noexcept
 A ray through a capsule: the segment [a, b] grown by a radius, the cylinder between the end planes united with the balls at the ends, which hold the end discs.
 
template<class T >
Piece< T > EBGeometry::RayDetail::boxPiece (const RayT< T > &a_ray, const Vec3T< T > &a_lo, const Vec3T< T > &a_hi) noexcept
 A ray through an axis-aligned box.
 
template<class T >
Piece< T > EBGeometry::RayDetail::roundedBoxPiece (const RayT< T > &a_ray, const Vec3T< T > &a_lo, const Vec3T< T > &a_hi, const T a_radius) noexcept
 A ray through a box grown by a radius: three boxes each grown along one axis, and a capsule along each of the twelve edges.
 
template<class T , class Edges >
T EBGeometry::RayDetail::twiceArea (const Vec3T< T > &a_n, const Edges &a_edges) noexcept
 Twice a planar polygon's signed area along its normal.
 
template<class T , class Edges >
bool EBGeometry::RayDetail::offsetFaceEntry (const RayT< T > &a_ray, const Vec3T< T > &a_n, const Vec3T< T > &a_p0, const Edges &a_edges, const T a_radius, const T a_tMin, const T a_best, T &a_t, Vec3T< T > &a_normal, bool &a_inSlab) noexcept
 Where a ray first enters a planar convex face offset by a radius, if before a bound: the offset face's flat side towards the ray first (where the ray enters the face's slab over the face), its rim (a capsule along each edge) only if that misses.
 
template<class T , class Edges >
Piece< T > EBGeometry::RayDetail::offsetFacePiece (const RayT< T > &a_ray, const Vec3T< T > &a_n, const Vec3T< T > &a_p0, const Edges &a_edges, const T a_radius) noexcept
 Where a ray is inside a planar convex face offset by a radius: its slab over the face, united with a capsule around each edge.
 
template<class T , class S >
NearestOffsetFace< T > EBGeometry::RayDetail::nearestOffsetFace (const S &a_mesh, const RayT< T > &a_ray, const T a_tMin, const T a_tMax, const T a_radius) noexcept
 The nearest entry after a_tMin of a mesh's faces offset by a radius, and whether one holds a_tMin.
 
template<class T , class S >
void EBGeometry::RayDetail::offsetFaceUnion (const S &a_mesh, const RayT< T > &a_ray, const T a_tMin, const T a_tMax, const T a_radius, OffsetFaceUnion< T > &a_union) noexcept
 The union of a mesh's faces offset by a radius along a ray, merged span by span.
 
template<class T , class S >
void EBGeometry::RayDetail::meshSpans (const S &a_mesh, const RayT< T > &a_ray, const T a_tMin, const T a_tMax, const RayOptions< T > &a_options, const bool a_firstOnly, RaySpansT< T > &a_spans) noexcept
 A mesh's own spans (RayDetail::shapeSpans()), out of line on a device, where its level sets need them: one copy of its walk per kernel.
 
template<class T , class S >
int EBGeometry::RayDetail::convexLevelSpans (const LevelView< S > &a_view, const RayT< T > &a_ray, Piece< T >(&a_spans)[2]) noexcept
 The spans of a convex level form's offset (one piece) or annulus (the outer piece less the inner, at most two), with the outward normals at their ends.
 
template<class T >
HitT< T > EBGeometry::RayDetail::levelHitAt (const RayT< T > &a_ray, const T a_t, const Vec3T< T > &a_normal, const bool a_entering, const uint32_t a_primitive)
 A crossing at a distance, with its normal, as a hit.
 
template<class T , class S >
Vec3T< T > EBGeometry::RayDetail::levelNormal (const LevelView< S > &a_view, const Vec3T< T > &a_point, const T a_h) noexcept
 A level view's outward normal at a point, from its shape's gradient (out of line already): reversed on an annulus's inner side, where the shape's value is negative.
 
template<class T , class S >
void EBGeometry::RayDetail::levelSpans (const LevelView< S > &a_view, const RayT< T > &a_ray, const T a_tMin, const T a_tMax, const RayOptions< T > &a_options, const bool a_firstOnly, RaySpansT< T > &a_spans) noexcept
 A level view's spans (its ray form's spans()), out of line on a device.
 

Detailed Description

Ray forms of offsets and annuli: the level sets of their operands' values.

An offset by r is the level set {f <= r} of its operand's value f, and an annulus of half-thickness d is {f <= d} less {f < -d}. Where the operand's level sets have a closed form, a ray traces them exactly instead of marching: a sphere's, a capsule's and an infinite cylinder's radius grows by the level, a plane moves, a box shrinks or grows into a rounded box, and a mesh's surface grown by d is the union of its faces offset by d (each face's slab over the face, with a capsule around each edge). The level passes through an affine map divided by the map's value scale. RayDetail::LevelView is such a level set of a shape. The fused Offset and Annular trace through it always; a tape's ray program traces its Annular and Offset clauses through it only when the tape lists TapeFeature::ExactOffsets, and marches them otherwise. An offset or annulus of anything else (a composition, CylinderSDF, whose grown rim is a torus, TorusSDF, or another offset or annulus) is marched.

Author
Robert Marskar

Function Documentation

◆ ballPiece()

template<class T >
Piece< T > EBGeometry::RayDetail::ballPiece ( const RayT< T > &  a_ray,
const Vec3T< T > &  a_center,
const T  a_radius 
)
inlinenoexcept

A ray through a ball.

Internal helper; not part of the public API. The discriminant is r^2 less the squared distance from the center to the ray, from the ray's nearest point: b^2 - |oc|^2 would lose the digits of a far origin.

Template Parameters
TFloating-point precision.
Parameters
[in]a_rayThe ray, with a unit direction.
[in]a_centerCenter.
[in]a_radiusRadius.
Returns
The piece.

◆ boxPiece()

template<class T >
Piece< T > EBGeometry::RayDetail::boxPiece ( const RayT< T > &  a_ray,
const Vec3T< T > &  a_lo,
const Vec3T< T > &  a_hi 
)
inlinenoexcept

A ray through an axis-aligned box.

Internal helper; not part of the public API.

Template Parameters
TFloating-point precision.
Parameters
[in]a_rayThe ray.
[in]a_loLow corner.
[in]a_hiHigh corner.
Returns
The piece, empty if the box is.

◆ capsulePiece()

template<class T >
Piece< T > EBGeometry::RayDetail::capsulePiece ( const RayT< T > &  a_ray,
const Vec3T< T > &  a_a,
const Vec3T< T > &  a_b,
const T  a_radius 
)
inlinenoexcept

A ray through a capsule: the segment [a, b] grown by a radius, the cylinder between the end planes united with the balls at the ends, which hold the end discs.

Internal helper; not part of the public API. Out of line on a device, as are roundedBoxPiece() and offsetFacePiece(): a rounded box tests twelve capsules and a face one per edge, and inlined in every tape kernel (through its leaf dispatch) they took ptxas several times as long.

Template Parameters
TFloating-point precision.
Parameters
[in]a_rayThe ray, with a unit direction.
[in]a_aOne end.
[in]a_bThe other end.
[in]a_radiusRadius.
Returns
The piece.

◆ convexLevelSpans()

template<class T , class S >
int EBGeometry::RayDetail::convexLevelSpans ( const LevelView< S > &  a_view,
const RayT< T > &  a_ray,
Piece< T >(&)  a_spans[2] 
)
inlinenoexcept

The spans of a convex level form's offset (one piece) or annulus (the outer piece less the inner, at most two), with the outward normals at their ends.

Internal helper; not part of the public API.

Template Parameters
TFloating-point precision.
SShape type.
Parameters
[in]a_viewThe view.
[in]a_rayThe ray.
[out]a_spansThe spans.
Returns
How many.

◆ levelHitAt()

template<class T >
HitT< T > EBGeometry::RayDetail::levelHitAt ( const RayT< T > &  a_ray,
const T  a_t,
const Vec3T< T > &  a_normal,
const bool  a_entering,
const uint32_t  a_primitive 
)
inline

A crossing at a distance, with its normal, as a hit.

Internal helper; not part of the public API.

Template Parameters
TFloating-point precision.
Parameters
[in]a_rayThe ray.
[in]a_tDistance.
[in]a_normalOutward normal.
[in]a_enteringWhether the ray enters there.
[in]a_primitiveThe primitive.
Returns
The hit.

◆ levelNormal()

template<class T , class S >
Vec3T< T > EBGeometry::RayDetail::levelNormal ( const LevelView< S > &  a_view,
const Vec3T< T > &  a_point,
const T  a_h 
)
inlinenoexcept

A level view's outward normal at a point, from its shape's gradient (out of line already): reversed on an annulus's inner side, where the shape's value is negative.

Internal helper; not part of the public API. Where a crossing's own normal is not found (see levelLeafHit()); the view's own value would bring another copy of a mesh's distance into a kernel.

Template Parameters
TFloating-point precision.
SShape type.
Parameters
[in]a_viewThe view.
[in]a_pointThe point.
[in]a_hFinite-difference step.
Returns
The normal.

◆ levelSpans()

template<class T , class S >
void EBGeometry::RayDetail::levelSpans ( const LevelView< S > &  a_view,
const RayT< T > &  a_ray,
const T  a_tMin,
const T  a_tMax,
const RayOptions< T > &  a_options,
const bool  a_firstOnly,
RaySpansT< T > &  a_spans 
)
inlinenoexcept

A level view's spans (its ray form's spans()), out of line on a device.

Internal helper; not part of the public API. What a tape's leaf dispatch and a fused offset or annulus call: inlined, every call site copied a mesh's offset-face walks and a box's rounded edges, and ptxas took several times as long and as much memory on a tape kernel.

Template Parameters
TFloating-point precision.
SShape type.
Parameters
[in]a_viewThe view.
[in]a_rayThe ray.
[in]a_tMinStart.
[in]a_tMaxEnd.
[in]a_optionsHow to march.
[in]a_firstOnlyWhether only the first crossing is needed.
[out]a_spansThe list.

◆ meshSpans()

template<class T , class S >
void EBGeometry::RayDetail::meshSpans ( const S &  a_mesh,
const RayT< T > &  a_ray,
const T  a_tMin,
const T  a_tMax,
const RayOptions< T > &  a_options,
const bool  a_firstOnly,
RaySpansT< T > &  a_spans 
)
inlinenoexcept

A mesh's own spans (RayDetail::shapeSpans()), out of line on a device, where its level sets need them: one copy of its walk per kernel.

Internal helper; not part of the public API.

Template Parameters
TFloating-point precision.
SMesh type.
Parameters
[in]a_meshThe mesh.
[in]a_rayThe ray.
[in]a_tMinStart.
[in]a_tMaxEnd.
[in]a_optionsHow to march.
[in]a_firstOnlyWhether only the first crossing is needed.
[out]a_spansThe list.

◆ nearestOffsetFace()

template<class T , class S >
NearestOffsetFace< T > EBGeometry::RayDetail::nearestOffsetFace ( const S &  a_mesh,
const RayT< T > &  a_ray,
const T  a_tMin,
const T  a_tMax,
const T  a_radius 
)
inlinenoexcept

The nearest entry after a_tMin of a mesh's faces offset by a radius, and whether one holds a_tMin.

Internal helper; not part of the public API. Out of line on a device, like every mesh trace.

Template Parameters
TFloating-point precision.
SMesh type.
Parameters
[in]a_meshThe mesh.
[in]a_rayThe ray.
[in]a_tMinStart.
[in]a_tMaxEnd.
[in]a_radiusRadius, positive.
Returns
What the walk found.

◆ offsetFaceEntry()

template<class T , class Edges >
bool EBGeometry::RayDetail::offsetFaceEntry ( const RayT< T > &  a_ray,
const Vec3T< T > &  a_n,
const Vec3T< T > &  a_p0,
const Edges &  a_edges,
const T  a_radius,
const T  a_tMin,
const T  a_best,
T &  a_t,
Vec3T< T > &  a_normal,
bool &  a_inSlab 
)
inlinenoexcept

Where a ray first enters a planar convex face offset by a radius, if before a bound: the offset face's flat side towards the ray first (where the ray enters the face's slab over the face), its rim (a capsule along each edge) only if that misses.

Internal helper; not part of the public API. The offset face lies in the slab |n . (x - p0)| <= radius, so a ray outside the slab over [a_tMin, a_best] does not enter it there, and nothing of it is entered before the slab. A ray whose part in the slab lies further than the radius outside one edge's line passes the face by more than the radius. The rest test each edge's capsule if the ray passes within the radius of the edge's line.

Template Parameters
TFloating-point precision.
EdgesCalls its argument with each edge's ends, in order around the face.
Parameters
[in]a_rayThe ray.
[in]a_nUnit normal, zero for a face of no area.
[in]a_p0A point in the face's plane.
[in]a_edgesThe edges.
[in]a_radiusRadius, positive.
[in]a_tMinStart.
[in]a_bestEntries at or beyond it are not wanted.
[out]a_tThe entry.
[out]a_normalIts outward normal.
[out]a_inSlabWhether a_tMin is in the slab (the ray may start inside the offset face).
Returns
Whether an entry in [a_tMin, a_best) was found.

◆ offsetFacePiece()

template<class T , class Edges >
Piece< T > EBGeometry::RayDetail::offsetFacePiece ( const RayT< T > &  a_ray,
const Vec3T< T > &  a_n,
const Vec3T< T > &  a_p0,
const Edges &  a_edges,
const T  a_radius 
)
inlinenoexcept

Where a ray is inside a planar convex face offset by a radius: its slab over the face, united with a capsule around each edge.

Internal helper; not part of the public API.

Template Parameters
TFloating-point precision.
EdgesCalls its argument with each edge's ends, in order around the face.
Parameters
[in]a_rayThe ray.
[in]a_nUnit normal, zero for a face of no area.
[in]a_p0A point in the face's plane.
[in]a_edgesThe edges.
[in]a_radiusRadius, positive.
Returns
The piece.

◆ offsetFaceUnion()

template<class T , class S >
void EBGeometry::RayDetail::offsetFaceUnion ( const S &  a_mesh,
const RayT< T > &  a_ray,
const T  a_tMin,
const T  a_tMax,
const T  a_radius,
OffsetFaceUnion< T > &  a_union 
)
inlinenoexcept

The union of a mesh's faces offset by a radius along a ray, merged span by span.

Internal helper; not part of the public API. Out of line on a device, like every mesh trace.

Template Parameters
TFloating-point precision.
SMesh type.
Parameters
[in]a_meshThe mesh.
[in]a_rayThe ray.
[in]a_tMinStart.
[in]a_tMaxEnd.
[in]a_radiusRadius, positive.
[out]a_unionThe merged spans, with the normals at their exits.

◆ roundedBoxPiece()

template<class T >
Piece< T > EBGeometry::RayDetail::roundedBoxPiece ( const RayT< T > &  a_ray,
const Vec3T< T > &  a_lo,
const Vec3T< T > &  a_hi,
const T  a_radius 
)
inlinenoexcept

A ray through a box grown by a radius: three boxes each grown along one axis, and a capsule along each of the twelve edges.

Internal helper; not part of the public API.

Template Parameters
TFloating-point precision.
Parameters
[in]a_rayThe ray.
[in]a_loLow corner.
[in]a_hiHigh corner.
[in]a_radiusRadius, positive.
Returns
The piece.

◆ tubePiece()

template<class T >
Piece< T > EBGeometry::RayDetail::tubePiece ( const RayT< T > &  a_ray,
const Vec3T< T > &  a_point,
const Vec3T< T > &  a_axis,
const T  a_radius 
)
inlinenoexcept

A ray through an infinite cylinder: the points within a radius of a line.

Internal helper; not part of the public API. The discriminant is taken as for a ball.

Template Parameters
TFloating-point precision.
Parameters
[in]a_rayThe ray, with a unit direction.
[in]a_pointA point on the line.
[in]a_axisThe line's direction, unit length.
[in]a_radiusRadius.
Returns
The piece.

◆ twiceArea()

template<class T , class Edges >
T EBGeometry::RayDetail::twiceArea ( const Vec3T< T > &  a_n,
const Edges &  a_edges 
)
inlinenoexcept

Twice a planar polygon's signed area along its normal.

Internal helper; not part of the public API. Its sign says whether the edges run counter-clockwise about the normal (positive), which sets which side of each edge is inside.

Template Parameters
TFloating-point precision.
EdgesCalls its argument with each edge's ends, in order around the polygon.
Parameters
[in]a_nUnit normal.
[in]a_edgesThe edges.
Returns
The area.