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

Signed distance field for a profile turned about the y axis (a solid of revolution, as made on a lathe), or extruded along it. More...

#include <EBGeometry_Profile.hpp>

Collaboration diagram for EBGeometry::ProfileSDF< T >:
Collaboration graph
[legend]

Public Member Functions

 ProfileSDF ()
 Default constructor: the square from (0, 0) to (1, 1), turned, which is the cylinder of radius 1 from y = 0 to 1.
 
 ProfileSDF (const ProfileSDF &)=default
 Copy constructor.
 
 ProfileSDF (ProfileSDF &&)=default
 Move constructor.
 
ProfileSDF & operator= (const ProfileSDF &)=default
 Copy assignment.
 
ProfileSDF & operator= (ProfileSDF &&)=default
 Move assignment.
 
bool isRevolved () const noexcept
 Whether the profile is turned about the y axis (otherwise it is extruded).
 
T getHeight () const noexcept
 How far an extruded profile is extruded (0 for a turned one).
 
uint32_t getNumEdges () const noexcept
 How many edges the outline has.
 
ProfileEdge getEdgeKind (const uint32_t a_edge) const noexcept
 An edge's kind.
 
const Vec2T< T > & getEdgeStart (const uint32_t a_edge) const noexcept
 Where an edge starts.
 
const Vec2T< T > & getEdgeEnd (const uint32_t a_edge) const noexcept
 Where an edge ends: where the next one starts.
 
const Vec2T< T > & getEdgeControl (const uint32_t a_edge) const noexcept
 An arc's center, or a Bezier curve's control point (unused for a straight edge).
 
uint32_t getEdgePart (const uint32_t a_edge) const noexcept
 The part an edge belongs to.
 
bool isOnAxis (const uint32_t a_edge) const noexcept
 Whether an edge lies on the axis of a turned profile: it turns into a line, which is no surface, and is left out of the distance.
 
bool isCounterclockwise () const noexcept
 Whether the outline runs counterclockwise in its plane (its inside on the left of each edge, the r axis first and h second for a turned profile, u first and v second for an extruded one), as it was drawn.
 
T profileDistance (const Vec2T< T > &a_point) const noexcept
 The signed distance from a point to the outline, in its plane; negative inside.
 
T signedDistance (const Vec3T< T > &a_point) const noexcept
 Signed distance function for the solid.
 
uint32_t getNumParts () const noexcept
 How many parts the shape has (see hasParts): the profile's, and an extrusion's two ends.
 
uint32_t closestPart (const Vec3T< T > &a_point) const noexcept
 The part nearest a point (see hasParts): that of the nearest edge (the first on a tie), or, for an extrusion, the end the point is nearer, when the slab between the ends decides the distance there.
 
BoundingVolumes::AABBT< T > computeBoundingVolume () const noexcept
 The shape's axis-aligned bounding box: that of the outline, turned or extruded.
 
Vec2T< T > inPlane (const Vec3T< T > &a_point) const noexcept
 Where a point is in the outline's plane: (sqrt(x^2 + z^2), y) turned, (x, z) extruded.
 

Static Public Member Functions

static ProfileSDF revolve (const Profile< T > &a_profile)
 A profile turned about the y axis: its point (r, h) sweeps the circle of radius r at height y = h.
 
static ProfileSDF extrude (const Profile< T > &a_profile, T a_height)
 A profile extruded along y: its point (u, v) is (x, z) = (u, v), from y = 0 to the height.
 

Static Public Attributes

static constexpr DistanceQuality distanceQuality = DistanceQuality::Exact
 How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
 
static constexpr uint32_t MaxEdges = Profile<T>::MaxEdges
 The most edges a profile can have.
 

Protected Member Functions

void build (const Profile< T > &a_profile, bool a_revolved, T a_height, const char *a_who)
 Sets the shape from a profile.
 
uint32_t nearestEdge (const Vec2T< T > &a_point, T &a_squared) const noexcept
 The nearest edge to a point in the plane, and the square of its distance.
 
bool insideOutline (const Vec2T< T > &a_point) const noexcept
 Whether a point in the plane is inside the outline: the ray from it towards +u crosses the outline an odd number of times (arcs and curves split where they turn back in v).
 

Protected Attributes

uint32_t m_numEdges = 0U
 Number of edges.
 
uint32_t m_numParts = 0U
 Number of the profile's parts.
 
uint32_t m_revolved = 1U
 1 if turned, 0 if extruded.
 
uint32_t m_counterclockwise = 1U
 1 if the outline runs counterclockwise in its plane, 0 if clockwise: which side of each edge is outside.
 
T m_height = T(0)
 An extrusion's height.
 
Vec2T< T > m_lo
 The low corner of the outline's box in its plane.
 
Vec2T< T > m_hi
 The high corner of the outline's box in its plane.
 
Array< Vec2T< T >, MaxEdges > m_points
 Where each edge starts.
 
Array< Vec2T< T >, MaxEdges > m_controls
 Each arc's center, or each Bezier curve's control point.
 
Array< uint8_t, MaxEdges > m_kinds
 Each edge's kind (a ProfileEdge).
 
Array< uint8_t, MaxEdges > m_parts
 Each edge's part.
 

Static Protected Attributes

static constexpr uint8_t OnAxis = 0x80U
 The bit of m_kinds that marks a straight edge on the axis of a turned profile, which is no surface.
 

Detailed Description

template<class T>
class EBGeometry::ProfileSDF< T >

Signed distance field for a profile turned about the y axis (a solid of revolution, as made on a lathe), or extruded along it.

A profile (see Profile) is a closed outline of straight edges, circular arcs and quadratic Bezier curves. Turned (revolve()), its point (r, h) sweeps the circle of radius r about the y axis at height y = h, so the solid is the outline's inside turned about the axis; every point of the outline must have r >= 0, and edges may lie on the axis. Extruded (extrude()), its point (u, v) is (x, z) = (u, v), from y = 0 to the height. Move or turn either with Translate and Rotate, like TorusSDF and ConeSDF.

The distance is exact. That to the outline in its plane is exact (a straight edge's and an arc's in closed form, a quadratic Bezier curve's from the roots of a cubic, polished by Newton steps), and its sign comes from how often a ray in the plane crosses the outline, each arc and curve taken as its pieces that run one way in v. Turned, the distance to the solid is the outline's at (sqrt(x^2 + z^2), y); extruded, it is the outline's at (x, z) combined with that to the slab between the ends, as for any extrusion. The edges are held in the shape itself, in arrays of fixed size, so it is trivially copyable and needs no pool.

Part k is edge k's part (see Profile); an extrusion's ends are the two parts after them, the one at y = 0 first. By default the shape is the square from (0, 0) to (1, 1), turned: the cylinder of radius 1 from y = 0 to 1.

Template Parameters
TFloating-point precision.

Member Function Documentation

◆ build()

template<class T >
void EBGeometry::ProfileSDF< T >::build ( const Profile< T > &  a_profile,
bool  a_revolved,
T  a_height,
const char *  a_who 
)
protected

Sets the shape from a profile.

Parameters
[in]a_profileThe profile.
[in]a_revolvedWhether it is turned.
[in]a_heightAn extrusion's height.
[in]a_whoThe factory's name, for the messages.

◆ closestPart()

template<class T >
uint32_t EBGeometry::ProfileSDF< T >::closestPart ( const Vec3T< T > &  a_point) const
noexcept

The part nearest a point (see hasParts): that of the nearest edge (the first on a tie), or, for an extrusion, the end the point is nearer, when the slab between the ends decides the distance there.

Out of line on a device, as profileDistance().

Parameters
[in]a_pointPosition.
Returns
The part.

◆ computeBoundingVolume()

template<class T >
BoundingVolumes::AABBT< T > EBGeometry::ProfileSDF< T >::computeBoundingVolume ( ) const
noexcept

The shape's axis-aligned bounding box: that of the outline, turned or extruded.

Returns
The bounding box.

◆ extrude()

template<class T >
static ProfileSDF EBGeometry::ProfileSDF< T >::extrude ( const Profile< T > &  a_profile,
T  a_height 
)
static

A profile extruded along y: its point (u, v) is (x, z) = (u, v), from y = 0 to the height.

Parameters
[in]a_profileThe profile.
[in]a_heightHow far it is extruded; finite and positive.
Returns
The solid.

◆ getEdgeControl()

template<class T >
const Vec2T< T > & EBGeometry::ProfileSDF< T >::getEdgeControl ( const uint32_t  a_edge) const
inlinenoexcept

An arc's center, or a Bezier curve's control point (unused for a straight edge).

Parameters
[in]a_edgeThe edge, below getNumEdges().
Returns
The point.

◆ getEdgeEnd()

template<class T >
const Vec2T< T > & EBGeometry::ProfileSDF< T >::getEdgeEnd ( const uint32_t  a_edge) const
inlinenoexcept

Where an edge ends: where the next one starts.

Parameters
[in]a_edgeThe edge, below getNumEdges().
Returns
The point.

◆ getEdgeKind()

template<class T >
ProfileEdge EBGeometry::ProfileSDF< T >::getEdgeKind ( const uint32_t  a_edge) const
inlinenoexcept

An edge's kind.

Parameters
[in]a_edgeThe edge, below getNumEdges().
Returns
The kind.

◆ getEdgePart()

template<class T >
uint32_t EBGeometry::ProfileSDF< T >::getEdgePart ( const uint32_t  a_edge) const
inlinenoexcept

The part an edge belongs to.

Parameters
[in]a_edgeThe edge, below getNumEdges().
Returns
The part.

◆ getEdgeStart()

template<class T >
const Vec2T< T > & EBGeometry::ProfileSDF< T >::getEdgeStart ( const uint32_t  a_edge) const
inlinenoexcept

Where an edge starts.

Parameters
[in]a_edgeThe edge, below getNumEdges().
Returns
The point.

◆ getHeight()

template<class T >
T EBGeometry::ProfileSDF< T >::getHeight ( ) const
inlinenoexcept

How far an extruded profile is extruded (0 for a turned one).

Returns
The height.

◆ getNumEdges()

template<class T >
uint32_t EBGeometry::ProfileSDF< T >::getNumEdges ( ) const
inlinenoexcept

How many edges the outline has.

Returns
The count.

◆ getNumParts()

template<class T >
uint32_t EBGeometry::ProfileSDF< T >::getNumParts ( ) const
inlinenoexcept

How many parts the shape has (see hasParts): the profile's, and an extrusion's two ends.

Returns
The count.

◆ inPlane()

template<class T >
Vec2T< T > EBGeometry::ProfileSDF< T >::inPlane ( const Vec3T< T > &  a_point) const
inlinenoexcept

Where a point is in the outline's plane: (sqrt(x^2 + z^2), y) turned, (x, z) extruded.

Parameters
[in]a_pointPosition.
Returns
The point in the plane.

◆ insideOutline()

template<class T >
bool EBGeometry::ProfileSDF< T >::insideOutline ( const Vec2T< T > &  a_point) const
protectednoexcept

Whether a point in the plane is inside the outline: the ray from it towards +u crosses the outline an odd number of times (arcs and curves split where they turn back in v).

Parameters
[in]a_pointThe point in the plane.
Returns
Whether it is inside.

◆ isCounterclockwise()

template<class T >
bool EBGeometry::ProfileSDF< T >::isCounterclockwise ( ) const
inlinenoexcept

Whether the outline runs counterclockwise in its plane (its inside on the left of each edge, the r axis first and h second for a turned profile, u first and v second for an extruded one), as it was drawn.

Returns
Whether it does.

◆ isOnAxis()

template<class T >
bool EBGeometry::ProfileSDF< T >::isOnAxis ( const uint32_t  a_edge) const
inlinenoexcept

Whether an edge lies on the axis of a turned profile: it turns into a line, which is no surface, and is left out of the distance.

Parameters
[in]a_edgeThe edge, below getNumEdges().
Returns
Whether it does.

◆ isRevolved()

template<class T >
bool EBGeometry::ProfileSDF< T >::isRevolved ( ) const
inlinenoexcept

Whether the profile is turned about the y axis (otherwise it is extruded).

Returns
True for a turned profile.

◆ nearestEdge()

template<class T >
uint32_t EBGeometry::ProfileSDF< T >::nearestEdge ( const Vec2T< T > &  a_point,
T &  a_squared 
) const
protectednoexcept

The nearest edge to a point in the plane, and the square of its distance.

Parameters
[in]a_pointThe point in the plane.
[out]a_squaredThe square of the distance.
Returns
The edge.

◆ operator=() [1/2]

template<class T >
ProfileSDF & EBGeometry::ProfileSDF< T >::operator= ( const ProfileSDF< T > &  )
default

Copy assignment.

Returns
Reference to (*this).

◆ operator=() [2/2]

template<class T >
ProfileSDF & EBGeometry::ProfileSDF< T >::operator= ( ProfileSDF< T > &&  )
default

Move assignment.

Returns
Reference to (*this).

◆ profileDistance()

template<class T >
T EBGeometry::ProfileSDF< T >::profileDistance ( const Vec2T< T > &  a_point) const
noexcept

The signed distance from a point to the outline, in its plane; negative inside.

Out of line on a device (its loop over the edges is the whole distance): inlined, it would be copied into every level of every tape kernel, whatever shapes the tape holds, which makes the device compile of every tape kernel much slower.

Parameters
[in]a_pointThe point, as (r, h) for a turned profile or (u, v) for an extruded one.
Returns
The distance.

◆ revolve()

template<class T >
static ProfileSDF EBGeometry::ProfileSDF< T >::revolve ( const Profile< T > &  a_profile)
static

A profile turned about the y axis: its point (r, h) sweeps the circle of radius r at height y = h.

Parameters
[in]a_profileThe profile; every point of it must have r >= 0.
Returns
The solid.

◆ signedDistance()

template<class T >
T EBGeometry::ProfileSDF< T >::signedDistance ( const Vec3T< T > &  a_point) const
noexcept

Signed distance function for the solid.

Out of line on a device, whole (not only profileDistance()): what a tape's evaluator inlines of a shape is copied into every level of every tape kernel, and the few lines around the outline's distance were enough to raise the plain tape kernels' register count.

Parameters
[in]a_pointPosition.
Returns
Signed distance from a_point to the surface; negative inside.

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