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 <functional>
#include <initializer_list>
#include <memory>
#include <string>
#include <string_view>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
#include "EBGeometry_Affine.hpp"
#include "EBGeometry_BoundingVolumes.hpp"
#include "EBGeometry_DistanceQuality.hpp"
#include "EBGeometry_FaceGroups.hpp"
#include "EBGeometry_Pool.hpp"
#include "EBGeometry_SurfaceRef.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...
 
struct  EBGeometry::ExprDetail::OtherPrecision< S, T, class >
 Whether a type is expression-like with a precision other than T (a shape or an Expr): the primary template, for other types, is false. More...
 
struct  EBGeometry::ExprDetail::OtherPrecision< S, T, std::void_t< typename ExprLike< S >::type > >
 An expression-like type: true when its precision is not T. 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...
 
class  EBGeometry::ExprIndex< T >
 The nodes of an expression, numbered, with the leaves below each and their labels: on the host, the way from what a Tape reports (a leaf, see LeafRef::m_leaf and HitT::m_primitive) back to the expression. More...
 
struct  EBGeometry::ExprIndex< T >::Node
 One node of the expression. More...
 
struct  EBGeometry::ExprIndex< T >::Region
 One region of the object (see Overlay()): the background (region 0), an operand of an Overlay, or, for an expression with no Overlay, the whole object (region 1). More...
 
struct  EBGeometry::ExprIndex< T >::RegionGroup
 A group of regions: an Overlay, whose regions are a contiguous range (a nested Overlay a range inside its parent's). 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::Accelerate : uint8_t { EBGeometry::None , EBGeometry::BVH }
 How a Tape evaluates a union of many objects: as written, or through a BVH over the objects' boxes. 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, Accelerate a_accelerate=Accelerate::None)
 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, const Accelerate a_accelerate=Accelerate::None)
 Smooth union of any number of objects: a smooth minimum of the two smallest values.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::SmoothUnion (const std::vector< A > &a_operands, const ExprPrecision< A > a_smooth, const Accelerate a_accelerate)
 Smooth union of any number of objects with the polynomial blend, through a BVH or as written.
 
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, Accelerate a_accelerate=Accelerate::None)
 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.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::SurfaceLabel (const A &a_operand, std::string a_name)
 Name an object: every leaf below it gets the label, unless a part of it has a label of its own.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::SurfaceLabel (const A &a_operand, FaceGroups a_groups)
 Name a shape's parts by group (see hasParts): each part in a group gets the label of the group's name, which wins over any label above it; a part in no group keeps those.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::Overlay (const std::vector< A > &a_operands)
 Regions by priority, a priority union: each operand is a region of its own, later operands on top of earlier ones where they overlap; the outside, region 0, is the background.
 
template<class A , class B , class... Rest>
Expr< ExprPrecision< A > > EBGeometry::Overlay (const A &a_first, const B &a_second, const Rest &... a_rest)
 Regions by priority, of two or more operands, each on top of the ones before it (see Overlay()).
 
Expr< double > EBGeometry::Overlay (std::initializer_list< Expr< double > > a_operands)
 Regions by priority, of a braced list of shapes and Exprs of any types, double precision: Overlay({air, jacket, CylinderSDF<double>(...)}) (see Overlay()).
 
Expr< float > EBGeometry::Overlay (std::initializer_list< Expr< float > > a_operands)
 Regions by priority, of a braced list of shapes and Exprs of any types, single precision (see Overlay()).
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::MaterialLabel (const A &a_operand, std::string a_name)
 Name the material of a region: an operand of an Overlay, a whole Overlay nested in another (a default for its regions without one of their own), or a whole object.
 
template<class A >
Expr< ExprPrecision< A > > EBGeometry::RegionName (const A &a_operand, std::string a_name)
 Name a region: an operand of an Overlay ("fluid", "wall"), or a whole Overlay nested in another (its region group).
 

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.