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

The tape's front end: Expr, a host-side value that describes a composed object, and the free functions that build it (Union, SmoothUnion, Intersection, Difference, Translate, Rotate, ...). More...

#include <cstddef>
#include <cstdint>
#include <memory>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <utility>
#include <vector>
#include "EBGeometry_Affine.hpp"
#include "EBGeometry_BoundingVolumes.hpp"
#include "EBGeometry_DistanceQuality.hpp"
#include "EBGeometry_Pool.hpp"
#include "EBGeometry_Vec.hpp"
#include "EBGeometry_ExprImplem.hpp"
Include dependency graph for EBGeometry_Expr.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  EBGeometry::ExprDetail::BoxPrecision< B >
 The precision of a bounding box type: T for AABBT<T>, nothing otherwise. More...
 
struct  EBGeometry::ExprDetail::BoxPrecision< BoundingVolumes::AABBT< T > >
 The precision of AABBT<T>. More...
 
struct  EBGeometry::ExprDetail::HasSignedDistance< S, T, class >
 Whether S has a const signedDistance(const Vec3T<T>&) returning something convertible to T. More...
 
struct  EBGeometry::ExprDetail::HasSignedDistance< S, T, std::void_t< decltype(std::declval< const S & >().signedDistance(std::declval< const Vec3T< T > & >()))> >
 Specialization for types that have signedDistance(). More...
 
struct  EBGeometry::ExprDetail::ShapeInfo< S, class >
 Shape detection: a type with computeBoundingVolume() returning AABBT<T>. More...
 
struct  EBGeometry::ExprDetail::ShapeInfo< S, std::void_t< typename BoxPrecision< std::decay_t< decltype(std::declval< const S & >().computeBoundingVolume())> >::type > >
 Shape detection for types with computeBoundingVolume(). More...
 
struct  EBGeometry::ExprDetail::Leaf
 A shape held by an expression, with its type erased. More...
 
struct  EBGeometry::ExprDetail::Node< T >
 An expression node. More...
 
struct  EBGeometry::ExprDetail::ExprLike< A, class >
 Whether A is a shape or an Expr, and its precision: the primary template is neither. More...
 
struct  EBGeometry::ExprDetail::ExprLike< Expr< T >, void >
 An Expr<T> is expression-like, with precision T. More...
 
struct  EBGeometry::ExprDetail::ExprLike< S, std::enable_if_t< isShape< S > > >
 A shape is expression-like, with its own precision. More...
 
class  EBGeometry::Expr< T >
 A composed object: an immutable tree of shapes and operations, built on the host and compiled by a Tape. More...
 

Namespaces

namespace  EBGeometry
 Namespace containing all of EBGeometry's functionality.
 

Typedefs

template<class S >
using EBGeometry::ShapePrecision = typename ExprDetail::ShapeInfo< S >::precision
 The precision of a shape type: T for a shape whose box type is AABBT<T>.
 
template<class A >
using EBGeometry::ExprPrecision = typename ExprDetail::ExprLike< A >::type
 The precision of an expression-like type: T for Expr<T> or for a shape of precision T. Not defined for other types, so a function taking it drops out of overload resolution.
 

Enumerations

enum class  EBGeometry::BlendKind : uint8_t { EBGeometry::Polynomial , EBGeometry::Exponential }
 How a smooth union, intersection or difference blends the two extreme values. More...
 
enum class  EBGeometry::ExprDetail::Kind : uint8_t {
  Primitive , Affine , Elongate , Repeat ,
  Complement , Offset , Annular , Blur ,
  Mollify , Union , Intersection , SmoothUnion ,
  SmoothIntersection
}
 What an expression node does. More...
 

Functions

template<class A >
Expr< ExprPrecision< A > > EBGeometry::toExpr (const A &a_operand)
 Convert a shape or an Expr to an Expr.
 
template<class A , class B >
Expr< ExprPrecision< A > > EBGeometry::Union (const A &a_first, const B &a_second)
 Union of two objects: the minimum of their values.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Union (const std::vector< A > &a_operands)
 Union of any number of objects: the minimum of their values.
 
template<class A , class B >
Expr< ExprPrecision< A > > EBGeometry::SmoothUnion (const A &a_first, const B &a_second, const ExprPrecision< A > a_smooth, const BlendKind a_blend=BlendKind::Polynomial)
 Smooth union of two objects: a smooth minimum of their values.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::SmoothUnion (const std::vector< A > &a_operands, const ExprPrecision< A > a_smooth, const BlendKind a_blend=BlendKind::Polynomial)
 Smooth union of any number of objects: a smooth minimum of the two smallest values.
 
template<class A , class B >
Expr< ExprPrecision< A > > EBGeometry::Intersection (const A &a_first, const B &a_second)
 Intersection of two objects: the maximum of their values.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Intersection (const std::vector< A > &a_operands)
 Intersection of any number of objects: the maximum of their values.
 
template<class A , class B >
Expr< ExprPrecision< A > > EBGeometry::SmoothIntersection (const A &a_first, const B &a_second, const ExprPrecision< A > a_smooth, const BlendKind a_blend=BlendKind::Polynomial)
 Smooth intersection of two objects: a smooth maximum of their values.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::SmoothIntersection (const std::vector< A > &a_operands, const ExprPrecision< A > a_smooth, const BlendKind a_blend=BlendKind::Polynomial)
 Smooth intersection of any number of objects: a smooth maximum of the two largest values.
 
template<class A , class B >
Expr< ExprPrecision< A > > EBGeometry::Difference (const A &a_first, const B &a_second)
 Difference A \ B: max(A, -B), inside A and outside B.
 
template<class A , class B >
Expr< ExprPrecision< A > > EBGeometry::Difference (const A &a_first, const std::vector< B > &a_others)
 Difference A \ (B1 u B2 u ...): max(A, -min_i Bi).
 
template<class A , class B >
Expr< ExprPrecision< A > > EBGeometry::SmoothDifference (const A &a_first, const B &a_second, const ExprPrecision< A > a_smooth, const BlendKind a_blend=BlendKind::Polynomial)
 Smooth difference A \ B: the smooth intersection of A and the complement of B.
 
template<class A , class B >
Expr< ExprPrecision< A > > EBGeometry::SmoothDifference (const A &a_first, const std::vector< B > &a_others, const ExprPrecision< A > a_smooth, const BlendKind a_blend=BlendKind::Polynomial)
 Smooth difference A \ (B1, B2, ...): the smooth intersection of A and the complement of each Bi.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::FiniteRepetition (const A &a_operand, const Vec3T< ExprPrecision< A > > &a_period, const Vec3T< ExprPrecision< A > > &a_repeatLo, const Vec3T< ExprPrecision< A > > &a_repeatHi)
 Finite repetition: copies of an object on a grid of tiles, a_repeatLo tiles below and a_repeatHi tiles above the home tile along each axis.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Complement (const A &a_operand)
 Complement: inside and outside swapped, -v.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Translate (const A &a_operand, const Vec3T< ExprPrecision< A > > &a_shift)
 Translate an object by a shift.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Rotate (const A &a_operand, const ExprPrecision< A > a_degrees, const size_t a_axis)
 Rotate an object about a coordinate axis through the origin.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Rotate (const A &a_operand, const ExprPrecision< A > a_degrees, const Vec3T< ExprPrecision< A > > &a_axis)
 Rotate an object about an arbitrary axis through the origin.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Scale (const A &a_operand, const ExprPrecision< A > a_factor)
 Scale an object uniformly about the origin.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Reflect (const A &a_operand, const size_t a_axis)
 Reflect an object in a coordinate plane through the origin.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Offset (const A &a_operand, const ExprPrecision< A > a_offset)
 Offset an object's surface outward by a distance, v - r.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Annular (const A &a_operand, const ExprPrecision< A > a_delta)
 A shell around an object's surface, |v| - delta.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Elongate (const A &a_operand, const Vec3T< ExprPrecision< A > > &a_elongation)
 Elongate an object: stretch it by inserting a box of half-lengths h at the origin.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Blur (const A &a_operand, const ExprPrecision< A > a_blur, const ExprPrecision< A > a_alpha=ExprPrecision< A >(0.5))
 Blur an object: a weighted average of its values at the 27 points p + d (i, j, k), i, j, k in {-1, 0, 1}.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Mollify (const A &a_operand, const ExprPrecision< A > a_dist, const size_t a_samples)
 Mollify an object: convolve it with a smooth, non-negative bump kernel sampled on an n x n x n grid spanning [-r, r]^3.
 

Variables

template<class S >
constexpr bool EBGeometry::isShape = ExprDetail::ShapeInfo<S>::value
 Whether S is a shape: a trivially copyable type with a const signedDistance(const Vec3T<T>&) returning T and a const computeBoundingVolume() returning BoundingVolumes::AABBT<T>.
 

Detailed Description

The tape's front end: Expr, a host-side value that describes a composed object, and the free functions that build it (Union, SmoothUnion, Intersection, Difference, Translate, Rotate, ...).

An Expr is an immutable tree of shapes and operations. It is cheap to copy (copies share the tree) and is never evaluated itself: a Tape compiles it into a pool, and the tape is what is evaluated, on the host or on a device. Any trivially copyable type with signedDistance() and computeBoundingVolume() is a shape (isShape) and converts to an Expr.

Author
Robert Marskar

Enumeration Type Documentation

◆ Kind

enum class EBGeometry::ExprDetail::Kind : uint8_t
strong

What an expression node does.

Internal helper; not part of the public API. Difference and SmoothDifference are built from Intersection, SmoothIntersection, Complement and Union, so they have no kind of their own.

Enumerator
Primitive 

A shape.

Affine 

Evaluate the child at m_map(p) and multiply by m_valueScale.

Elongate 

Evaluate the child at p - clamp(p, -h, h).

Repeat 

Evaluate the child at p folded into the home tile.

Complement 

-v.

Offset 

v - r.

Annular 

|v| - delta.

Blur 

27-tap weighted average of the child.

Mollify 

n^3-tap convolution of the child with a bump kernel.

Union 

Minimum over the children.

Intersection 

Maximum over the children.

SmoothUnion 

Smooth minimum of the two smallest children.

SmoothIntersection 

Smooth maximum of the two largest children.