16#ifndef EBGEOMETRY_EXPR_HPP
17#define EBGEOMETRY_EXPR_HPP
23#include <initializer_list>
30#include <unordered_map>
95template <
class S,
class T,
class =
void>
106template <
class S,
class T>
110 std::void_t<decltype(std::declval<const S&>().signedDistance(std::declval<const Vec3T<T>&>()))>>
111 : std::is_convertible<decltype(std::declval<const S&>().signedDistance(std::declval<const Vec3T<T>&>())), T>
120template <
class S,
class =
void>
126 static constexpr bool value =
false;
137 std::void_t<typename BoxPrecision<std::decay_t<decltype(std::declval<const S&>().computeBoundingVolume())>>::type>>
181namespace ExprDetail {
220 std::type_index
m_type = std::type_index(
typeid(
void));
373template <
class A,
class =
void>
414template <
class S,
class T,
class =
void>
424template <
class S,
class T>
426 : std::bool_constant<!std::is_same_v<typename ExprLike<S>::type, T>>
454 static_assert(std::is_floating_point_v<T>,
"Expr requires a floating-point type T");
473 class = std::enable_if_t<!std::is_same_v<std::decay_t<S>,
Expr> &&
474 !std::is_convertible_v<S, std::shared_ptr<const ExprDetail::Node<T>>> &&
512 const ExprDetail::Node<T>&
519 std::shared_ptr<const ExprDetail::Node<T>> m_node;
541template <class A, class B>
544Union(const A& a_first, const B& a_second);
575template <class A, class B>
623template <class A, class B>
649template <class A, class B>
680template <class A, class B>
695template <class A, class B>
710template <class A, class B>
728template <class A, class B>
732 const std::vector<B>& a_others,
834Reflect(const A& a_operand, const
size_t a_axis);
981template <class A, class B, class... Rest>
984Overlay(const A& a_first, const B& a_second, const Rest&... a_rest);
1063 static constexpr uint32_t
None = 0xFFFFFFFFU;
1078 uint32_t m_firstLeaf = 0;
1083 uint32_t m_numLeaves = 0;
1088 uint32_t m_firstSurface = 0;
1093 uint32_t m_numSurfaces = 0;
1159 uint32_t m_firstRegion = 0;
1164 uint32_t m_numRegions = 0;
1204 getNode(uint32_t a_node) const;
1212 getNumLeaves() const noexcept;
1221 getLeafNode(uint32_t a_leaf) const;
1230 std::vector<uint32_t>
1231 pathOf(uint32_t a_leaf) const;
1239 getNumSurfaces() const noexcept;
1249 getFirstSurface(uint32_t a_leaf) const;
1258 getLeafOfSurface(uint32_t a_surface) const;
1268 getSurfaceLabel(uint32_t a_leaf) const;
1278 getNumPartsOfLeaf(uint32_t a_leaf) const;
1289 getPartSurfaceLabel(uint32_t a_leaf, uint32_t a_part) const;
1299 getPartSurfaceLabels(uint32_t a_leaf) const;
1307 getNumSurfaceLabels() const noexcept;
1325 findSurfaceLabel(std::string_view a_name) const;
1334 getNumRegions() const noexcept;
1343 getRegion(uint32_t a_region) const;
1352 getRegionOfLeaf(uint32_t a_leaf) const;
1361 getMaterialOf(uint32_t a_region) const;
1369 std::vector<uint32_t>
1370 getRegionsOfRegionGroup(uint32_t a_group) const;
1378 std::vector<uint32_t>
1391 const std::vector<std::pair<uint32_t, uint32_t>>&
1392 getSidesOfLeaf(uint32_t a_leaf) const;
1399 std::vector<std::pair<uint32_t, uint32_t>>
1400 getInterfaces() const;
1408 getNumRegionGroups() const noexcept;
1417 getRegionGroup(uint32_t a_group) const;
1425 getNumMaterialLabels() const noexcept;
1443 findMaterialLabel(std::string_view a_name) const;
1452 findRegion(std::string_view a_name) const;
1480 template <class TapeType>
1482 std::vector<std::
string>
1483 checkLabels(const
Expr<T>& a_expr, const TapeType& a_tape) const;
1489 std::vector<
Node> m_nodes;
1494 std::vector<uint32_t> m_leafNodes;
1504 std::vector<uint32_t> m_leafSurfaces;
1509 std::vector<std::vector<
SurfaceLabelId>> m_leafPartSurfaceLabels;
1514 std::vector<uint32_t> m_leafParts;
1519 std::vector<std::
string> m_surfaceLabelNames;
1524 std::unordered_map<std::
string,
SurfaceLabelId> m_surfaceLabelIds;
1530 std::vector<const ExprDetail::
Node<T>*> m_exprNodes;
1535 std::vector<std::vector<uint32_t>> m_operands;
1544 [[nodiscard]] std::
string
1545 whyHidden(uint32_t a_node,
1546 const std::vector<const ExprDetail::
Node<T>*>& a_nodes,
1547 const std::function<
bool(const ExprDetail::
Node<T>&, const
Vec3T<T>&, T&)>& a_leafValue) const;
1552 std::vector<
Region> m_regions;
1562 std::vector<uint32_t> m_leafRegions;
1567 std::vector<std::
string> m_materialLabelNames;
1592 uint32_t m_firstRegion;
1597 uint32_t m_numRegions;
1603 std::vector<BoundingVolumes::AABBT<T>> m_regionBoxes;
1608 std::vector<Mask> m_masks;
1613 std::vector<const ExprDetail::Node<T>*> m_maps;
1618 std::vector<std::vector<std::pair<uint32_t, uint32_t>>> m_leafSides;
1640 internMaterial(
const std::string& a_name);
1649 addRegions(uint32_t a_node, uint32_t a_group,
MaterialLabelId a_material);
1665#include "EBGeometry_ExprImplem.hpp"
Declaration of Affine3T, an affine map of 3D space (a 3x3 matrix and a shift).
Declarations of bounding volume types used in bounding volume hierarchies.
How far a function's value can be trusted as a distance: DistanceQuality, and the distanceQualityOf t...
Kind
What an expression node does.
Definition EBGeometry_Expr.hpp:189
@ Affine
Evaluate the child at m_map(p) and multiply by m_valueScale.
@ Repeat
Evaluate the child at p folded into the home tile.
FaceGroups: named groups of a mesh's faces, as a file names them.
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Growable bump arena for the GPU memory foundation.
SurfaceRef: which surface of a shape decides its value at a point, and the container protocol that na...
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
The nodes of an expression, numbered, with the leaves below each and their labels: on the host,...
Definition EBGeometry_Expr.hpp:1058
ExprIndex(const Expr< T > &a_expr)
Number the nodes, leaves and labels of an expression.
ExprIndex()=delete
No empty index.
uint32_t getNumNodes() const noexcept
The number of nodes.
A composed object: an immutable tree of shapes and operations, built on the host and compiled by a Ta...
Definition EBGeometry_Expr.hpp:452
Expr()=delete
No empty expression.
const BV & computeBoundingVolume() const noexcept
A box enclosing the object.
DistanceQuality getDistanceQuality() const noexcept
How far the object's value can be trusted as a distance.
const ExprDetail::Node< T > & node() const noexcept
The root node, for the tape compiler.
Expr(std::shared_ptr< const ExprDetail::Node< T > > a_node) noexcept
Wrap a node; used by the builder functions.
Expr(const S &a_shape)
Wrap a shape.
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:205
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
static constexpr Vec3T< T > zeros() noexcept
Return a vector with x = y = z = 0.
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Expr< ExprPrecision< A > > Union(const A &a_first, const B &a_second)
Union of two objects: the minimum of their values.
BlendKind
How a smooth union, intersection or difference blends the two extreme values.
Definition EBGeometry_Expr.hpp:49
@ Polynomial
SmoothMinOp/SmoothMaxOp: quadratic blend over a band of width s; deepens by at most s/4.
@ Exponential
ExpMinOp/ExpMaxOp: log-sum-exp blend with length scale s; deepens by at most s ln 2.
Expr< ExprPrecision< A > > Reflect(const A &a_operand, const size_t a_axis)
Reflect an object in a coordinate plane through the origin.
@ SurfaceLabel
The surface's label (SurfaceLabel()).
Expr< ExprPrecision< A > > Difference(const A &a_first, const B &a_second)
Difference A \ B: max(A, -B), inside A and outside B.
Expr< ExprPrecision< A > > 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.
Expr< ExprPrecision< A > > 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.
Expr< ExprPrecision< A > > 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 ...
constexpr bool isShape
Whether S is a shape: a trivially copyable type with a const signedDistance(const Vec3T<T>&) returnin...
Definition EBGeometry_Expr.hpp:169
Expr< ExprPrecision< A > > toExpr(const A &a_operand)
Convert a shape or an Expr to an Expr.
Expr< ExprPrecision< A > > Intersection(const A &a_first, const B &a_second)
Intersection of two objects: the maximum of their values.
typename ExprDetail::ShapeInfo< S >::precision ShapePrecision
The precision of a shape type: T for a shape whose box type is AABBT<T>.
Definition EBGeometry_Expr.hpp:176
Expr< ExprPrecision< A > > 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),...
Expr< ExprPrecision< A > > 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...
Expr< ExprPrecision< A > > Translate(const A &a_operand, const Vec3T< ExprPrecision< A > > &a_shift)
Translate an object by a shift.
Expr< ExprPrecision< A > > Complement(const A &a_operand)
Complement: inside and outside swapped, -v.
Expr< ExprPrecision< A > > 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.
Expr< ExprPrecision< A > > 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.
Expr< ExprPrecision< A > > 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 ...
Expr< ExprPrecision< A > > Scale(const A &a_operand, const ExprPrecision< A > a_factor)
Scale an object uniformly about the origin.
DistanceQuality
How far the value of a signed distance function can be trusted, from strongest to weakest.
Definition EBGeometry_DistanceQuality.hpp:25
@ Exact
The value's magnitude is the Euclidean distance to the surface.
Expr< ExprPrecision< A > > 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 s...
Expr< ExprPrecision< A > > Annular(const A &a_operand, const ExprPrecision< A > a_delta)
A shell around an object's surface, |v| - delta.
Expr< ExprPrecision< A > > Offset(const A &a_operand, const ExprPrecision< A > a_offset)
Offset an object's surface outward by a distance, v - r.
Expr< ExprPrecision< A > > 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 tile...
Expr< ExprPrecision< A > > 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.
Accelerate
How a Tape evaluates a union of many objects: as written, or through a BVH over the objects' boxes.
Definition EBGeometry_Expr.hpp:58
@ None
As written: the tape evaluates every operand, however many there are.
@ BVH
Through a BVH over the operands' boxes, however many there are.
typename ExprDetail::ExprLike< A >::type ExprPrecision
The precision of an expression-like type: T for Expr<T> or for a shape of precision T....
Definition EBGeometry_Expr.hpp:438
An affine map of 3D space, x -> A x + b, with A stored by rows.
Definition EBGeometry_Affine.hpp:37
static Affine3T identity() noexcept
The identity map.
T type
The precision.
Definition EBGeometry_Expr.hpp:86
The precision of a bounding box type: T for AABBT<T>, nothing otherwise.
Definition EBGeometry_Expr.hpp:72
T type
The precision.
Definition EBGeometry_Expr.hpp:389
ShapePrecision< S > type
The precision.
Definition EBGeometry_Expr.hpp:403
Whether A is a shape or an Expr, and its precision: the primary template is neither.
Definition EBGeometry_Expr.hpp:375
Whether S has a const signedDistance(const Vec3T<T>&) returning something convertible to T.
Definition EBGeometry_Expr.hpp:97
A shape held by an expression, with its type erased.
Definition EBGeometry_Expr.hpp:211
std::shared_ptr< const void > m_object
Copy of the shape.
Definition EBGeometry_Expr.hpp:215
uint32_t(* m_numParts)(const void *)
For a shape with parts (see hasParts): how many it has. Null for a shape with one part.
Definition EBGeometry_Expr.hpp:235
uint32_t(* m_numSurfaces)(const void *)
For a container (see hasSurfaces): how many surfaces it holds. Null for a shape with one surface.
Definition EBGeometry_Expr.hpp:230
bool(* m_isAttachedTo)(const void *, const Pool &)
For a pool-resident shape: whether it lives in a given pool. Null otherwise.
Definition EBGeometry_Expr.hpp:225
std::type_index m_type
The shape's type.
Definition EBGeometry_Expr.hpp:220
An expression node.
Definition EBGeometry_Expr.hpp:246
BoundingVolumes::AABBT< T > m_boundingVolume
A box enclosing the node's object.
Definition EBGeometry_Expr.hpp:322
Affine3T< T > m_map
Point map applied before the child is evaluated (Affine).
Definition EBGeometry_Expr.hpp:266
std::string m_regionName
The name RegionName() gave the node; empty for none.
Definition EBGeometry_Expr.hpp:347
Vec3T< T > m_vec1
Tiles in the decreasing direction of each axis, rounded to whole numbers (Repeat).
Definition EBGeometry_Expr.hpp:286
DistanceQuality m_quality
How far the node's value can be trusted as a distance.
Definition EBGeometry_Expr.hpp:327
BlendKind m_blend
Blend kind (smooth operations).
Definition EBGeometry_Expr.hpp:312
T m_scalar0
Offset distance (Offset), shell half-thickness (Annular), blur distance (Blur), mollification distanc...
Definition EBGeometry_Expr.hpp:297
Affine3T< T > m_inverse
Inverse of m_map, which maps the child's box to the node's (Affine).
Definition EBGeometry_Expr.hpp:271
std::shared_ptr< const FaceGroups > m_partGroups
For a primitive: the groups SurfaceLabel(shape, FaceGroups) put its parts in; null for none.
Definition EBGeometry_Expr.hpp:337
Vec3T< T > m_vec0
Elongation half-lengths (Elongate) or tile period (Repeat).
Definition EBGeometry_Expr.hpp:281
std::string m_materialLabel
The name MaterialLabel() gave the node; empty for none.
Definition EBGeometry_Expr.hpp:342
std::vector< Expr< T > > m_children
Children (none for a primitive, one for a map or value operation, any number for a union or intersect...
Definition EBGeometry_Expr.hpp:256
T m_scalar1
Blend weight alpha (Blur).
Definition EBGeometry_Expr.hpp:302
bool m_overlay
Whether this union is an Overlay: its operands are regions, later ones on top (see Overlay())....
Definition EBGeometry_Expr.hpp:353
Leaf m_leaf
The shape, for a primitive.
Definition EBGeometry_Expr.hpp:261
uint32_t m_count
Samples per axis (Mollify).
Definition EBGeometry_Expr.hpp:307
bool m_bvh
Whether a union asks the tape for a BVH over its operands (Accelerate::BVH).
Definition EBGeometry_Expr.hpp:317
std::string m_surfaceLabel
The name SurfaceLabel() gave the node; empty for none.
Definition EBGeometry_Expr.hpp:332
Vec3T< T > m_vec2
Tiles in the increasing direction of each axis, rounded to whole numbers (Repeat).
Definition EBGeometry_Expr.hpp:291
bool m_partition
Whether the node is a partition into regions: an Overlay, a map of one, or one clipped as the first o...
Definition EBGeometry_Expr.hpp:359
Kind m_kind
What the node does.
Definition EBGeometry_Expr.hpp:250
bool m_namesRegion
Whether the node, or a chain of maps below it, has a material label or a region name (MaterialLabel()...
Definition EBGeometry_Expr.hpp:365
T m_valueScale
Value multiplier applied after the child is evaluated (Affine): |s| for a scaling by s.
Definition EBGeometry_Expr.hpp:276
Whether a type is expression-like with a precision other than T (a shape or an Expr): the primary tem...
Definition EBGeometry_Expr.hpp:416
typename BoxPrecision< std::decay_t< decltype(std::declval< const S & >().computeBoundingVolume())> >::type precision
The shape's precision, read from its bounding box type.
Definition EBGeometry_Expr.hpp:143
Shape detection: a type with computeBoundingVolume() returning AABBT<T>.
Definition EBGeometry_Expr.hpp:122
static constexpr bool value
Whether S is a shape.
Definition EBGeometry_Expr.hpp:126
One node of the expression.
Definition EBGeometry_Expr.hpp:1069
MaterialLabelId m_materialLabel
Its own material label, or none (MaterialLabel()).
Definition EBGeometry_Expr.hpp:1103
SurfaceLabelId m_surfaceLabel
Its own surface label, or none (the label its leaves inherit from further up is getSurfaceLabel()'s).
Definition EBGeometry_Expr.hpp:1098
std::string m_operation
What it does: Primitive, Transform, Elongate, Repeat, Complement, Offset, Annulus,...
Definition EBGeometry_Expr.hpp:1110
A group of regions: an Overlay, whose regions are a contiguous range (a nested Overlay a range inside...
Definition EBGeometry_Expr.hpp:1145
MaterialLabelId m_material
Its material label, the default of its regions without one of their own; or none.
Definition EBGeometry_Expr.hpp:1169
std::string m_name
Its name (RegionName() on the Overlay); empty for none.
Definition EBGeometry_Expr.hpp:1174
One region of the object (see Overlay()): the background (region 0), an operand of an Overlay,...
Definition EBGeometry_Expr.hpp:1118
std::string m_name
Its name (RegionName() on its operand, or on a map above it); empty for none and the background.
Definition EBGeometry_Expr.hpp:1137
MaterialLabelId m_material
Its material: its operand's material label, or its group's, or none.
Definition EBGeometry_Expr.hpp:1132
Named groups of a mesh's faces: an OBJ file's g and o groups, or the named solids of an ASCII STL fil...
Definition EBGeometry_FaceGroups.hpp:29