11#ifndef EBGEOMETRY_SURFACEPIECES_HPP
12#define EBGEOMETRY_SURFACEPIECES_HPP
80template <
class TapeType>
82std::vector<SurfacePiece<ShapePrecision<TapeType>>>
87 std::vector<SurfacePiece<T>> pieces;
100 const T margin = T(0.01) * size.
length();
103 const T jitter = T(0.4142135623730950488);
105 for (
int axis = 0; axis < 3; axis++) {
106 const int u = (axis + 1) % 3;
107 const int v = (axis + 2) % 3;
109 for (uint32_t i = 0; i < a_resolution; i++) {
110 for (uint32_t j = 0; j < a_resolution; j++) {
113 origin[axis] = low[axis] - margin;
114 origin[u] = low[u] + (T(i) + jitter) * size[u] / T(a_resolution);
115 origin[v] = low[v] + (T(j) + T(1) - jitter) * size[v] / T(a_resolution);
119 direction[axis] = T(1);
121 const RayT<T> ray{origin, direction};
122 const T tMax = size[axis] + T(2) * margin;
126 for (uint32_t crossing = 0; crossing < 4096U; crossing++) {
127 const SurfaceHitT<T> change = a_tape.firstRegionChange(ray, t, tMax);
129 if (!change.
m_hit.hit()) {
166 if (known ==
nullptr) {
169 known = &pieces.back();
196 static constexpr uint32_t
None = 0xFFFFFFFFU;
250 for (uint32_t leaf = 0; leaf < a_index.
getNumLeaves(); leaf++) {
257 for (uint32_t surface = 0; surface < a_index.
getNumSurfaces(); surface++) {
261 for (uint32_t region = 0; region < a_index.
getNumRegions(); region++) {
265 for (uint32_t node = 0; node < a_index.
getNumNodes(); node++) {
271 for (uint32_t leaf = 0; leaf < a_index.
getNumLeaves(); leaf++) {
285 std::vector<SurfaceLevel>
288 std::vector<SurfaceLevel> levels;
290 if (m_nodes.empty()) {
294 const uint32_t leafNode = m_leafNodes[this->
getLeaf(a_surface)];
297 if (m_nodes[leafNode].m_numSurfaces > 1U) {
304 levels.push_back(member);
307 for (uint32_t node = leafNode; node !=
SurfaceLevel::None; node = m_nodes[node].m_parent) {
308 const NodeLevel& n = m_nodes[node];
311 levels.back().m_firstSurface == n.m_firstSurface &&
312 levels.back().m_numSurfaces == n.m_numSurfaces;
338 return static_cast<uint32_t
>(m_surfaceLeaves.size());
351 "SurfaceInventory: surface %u of %zu",
353 m_surfaceLeaves.size());
355 return m_surfaceLeaves[a_surface];
367 return m_leafParts[this->
getLeaf(a_surface)];
378 getLabel(
const uint32_t a_surface,
const uint32_t a_part)
const
380 const uint32_t leaf = this->
getLeaf(a_surface);
381 const std::vector<SurfaceLabelId>& parts = m_leafPartLabels[leaf];
383 return (a_part < parts.size()) ? parts[a_part] : m_leafLabels[leaf];
395 return !m_leafPartLabels[this->
getLeaf(a_surface)].empty();
404 const std::vector<std::pair<uint32_t, uint32_t>>&
407 return m_leafSides[this->
getLeaf(a_surface)];
419 return (a_region < m_regionMaterials.size()) ? m_regionMaterials[a_region] :
MaterialLabelId::none();
426 std::vector<uint32_t> m_surfaceLeaves;
431 std::vector<uint32_t> m_leafParts;
436 std::vector<SurfaceLabelId> m_leafLabels;
441 std::vector<std::vector<SurfaceLabelId>> m_leafPartLabels;
446 std::vector<std::vector<std::pair<uint32_t, uint32_t>>> m_leafSides;
451 std::vector<MaterialLabelId> m_regionMaterials;
459 uint32_t m_firstSurface;
460 uint32_t m_numSurfaces;
462 std::string m_operation;
468 std::vector<NodeLevel> m_nodes;
473 std::vector<uint32_t> m_leafNodes;
505inline std::vector<PossiblePiece>
508 std::vector<PossiblePiece> pieces;
510 for (uint32_t surface = 0; surface < a_inventory.
getNumSurfaces(); surface++) {
511 for (
const auto& [first, second] : a_inventory.
getSides(surface)) {
564 const std::vector<uint32_t>& a_parts)
566 bool partConditions =
false;
567 bool labelConditions =
false;
591 std::vector<uint32_t> checked;
594 for (
const uint32_t part : a_parts) {
596 checked.push_back(part);
600 if (checked.empty()) {
601 for (uint32_t part = 0; part < parts; part++) {
602 checked.push_back(part);
607 checked.push_back(0U);
610 const uint32_t checks =
static_cast<uint32_t
>(checked.size());
611 uint32_t covered = 0;
615 for (
const uint32_t part : checked) {
619 const uint32_t labeled = (parts == 0U) ? 0U : part;
627 mixed = mixed || (covered > 0U && g != group);
658 return coverageOf(a_piece, a_inventory, a_setup, std::vector<uint32_t>());
DomainSetup: how a domain is made, as an editable value on the host (see Domain).
The tape's front end: Expr, a host-side value that describes a composed object, and the free function...
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Utility macros for EBGeometry.
#define EBGEOMETRY_REQUIRE(cond,...)
Always-on check of user input and one-time host setup.
Definition EBGeometry_Macros.hpp:200
Ray queries on any shape: where a ray, or the segment between two points, first crosses its surface (...
SurfaceRef: which surface of a shape decides its value at a point, and the container protocol that na...
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
Vec3T< T > & getLowCorner() noexcept
Get a modifiable reference to the low corner of the AABB.
Vec3T< T > & getHighCorner() noexcept
Get a modifiable reference to the high corner of the AABB.
How a domain is made: its subdomains (the regions each computes in) and its surface groups (the selec...
Definition EBGeometry_DomainSetup.hpp:39
uint32_t getNumSelectors() const noexcept
How many selectors there are, over all surface groups.
Definition EBGeometry_DomainSetup.hpp:290
const SurfaceSelector & getSelector(const uint32_t a_selector) const
A selector.
Definition EBGeometry_DomainSetup.hpp:302
uint32_t surfaceGroupOf(const SurfaceRef< T > &a_surface) const noexcept
The surface group a surface point is in (as SurfaceGroups::surfaceGroupOf()).
Definition EBGeometry_DomainSetup.hpp:328
The nodes of an expression, numbered, with the leaves below each and their labels: on the host,...
Definition EBGeometry_Expr.hpp:1058
MaterialLabelId getMaterialOf(uint32_t a_region) const
A region's material (see Region::m_material).
uint32_t getNumSurfaces() const noexcept
The number of surfaces: Tape::getNumSurfaces() of a tape compiled from the expression.
const std::vector< std::pair< uint32_t, uint32_t > > & getSidesOfLeaf(uint32_t a_leaf) const
The pairs of regions a leaf's surface may separate, conservatively: every pair it does is listed,...
uint32_t getNumPartsOfLeaf(uint32_t a_leaf) const
How many parts a leaf's shape has (see hasParts): one for a shape without parts, a mesh's faces,...
SurfaceLabelId getSurfaceLabel(uint32_t a_leaf) const
A leaf's label: that of the nearest labeled node on its path, the leaf's own included,...
uint32_t getLeafNode(uint32_t a_leaf) const
The node of a leaf.
uint32_t getLeafOfSurface(uint32_t a_surface) const
The leaf a surface belongs to: SurfaceRef::m_leaf of a tape's closestSurface() that reported it.
uint32_t getNumRegions() const noexcept
The number of regions: the background (region 0), and one per operand of the Overlays,...
const std::vector< SurfaceLabelId > & getPartSurfaceLabels(uint32_t a_leaf) const
The labels of a leaf's parts, one per part, as getPartSurfaceLabel() gives them; empty for a leaf who...
uint32_t getNumLeaves() const noexcept
The number of leaves: Tape::getNumPrimitives() of a tape compiled from the expression.
const Node & getNode(uint32_t a_node) const
A node.
uint32_t getNumNodes() const noexcept
The number of nodes.
static constexpr uint32_t None
No surface group: a surface no selector matches.
Definition EBGeometry_SurfaceGroups.hpp:301
What an expression's index says about its surfaces, kept for checking surface groups against them wit...
Definition EBGeometry_SurfacePieces.hpp:234
MaterialLabelId getMaterial(const uint32_t a_region) const noexcept
A region's material.
Definition EBGeometry_SurfacePieces.hpp:417
SurfaceInventory()=default
An empty inventory: no surfaces.
SurfaceInventory(const ExprIndex< T > &a_index)
The inventory of an expression's index.
Definition EBGeometry_SurfacePieces.hpp:248
bool hasPartLabels(const uint32_t a_surface) const
Whether a surface's parts have labels of their own (face groups).
Definition EBGeometry_SurfacePieces.hpp:393
uint32_t getNumParts(const uint32_t a_surface) const
How many parts a surface's shape has (ExprIndex::getNumPartsOfLeaf()): 0 for a collection's member.
Definition EBGeometry_SurfacePieces.hpp:365
std::vector< SurfaceLevel > levelsOf(const uint32_t a_surface) const
The levels a surface belongs to, innermost first: the surface (when it is one member of a collection,...
Definition EBGeometry_SurfacePieces.hpp:286
uint32_t getNumSurfaces() const noexcept
How many surfaces there are.
Definition EBGeometry_SurfacePieces.hpp:336
uint32_t getLeaf(const uint32_t a_surface) const
A surface's shape.
Definition EBGeometry_SurfacePieces.hpp:348
const std::vector< std::pair< uint32_t, uint32_t > > & getSides(const uint32_t a_surface) const
The pairs of regions a surface may separate, smaller region first.
Definition EBGeometry_SurfacePieces.hpp:405
SurfaceLabelId getLabel(const uint32_t a_surface, const uint32_t a_part) const
A part's surface label: its face group's, or its shape's.
Definition EBGeometry_SurfacePieces.hpp:378
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
T length() const noexcept
Compute vector length.
static constexpr Vec3T< T > zeros() noexcept
Return a vector with x = y = z = 0.
constexpr T max(const T &a_a, const T &a_b) noexcept
The larger of two values.
Definition EBGeometry_Math.hpp:61
constexpr T min(const T &a_a, const T &a_b) noexcept
The smaller of two values.
Definition EBGeometry_Math.hpp:44
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Coverage
How much of a piece a domain's surface groups hold.
Definition EBGeometry_SurfacePieces.hpp:523
@ Partly
Some parts, not all.
PieceCoverage coverageOf(const PossiblePiece &a_piece, const SurfaceInventory &a_inventory, const DomainSetup &a_setup, const std::vector< uint32_t > &a_parts)
How a domain's surface groups cover a piece an object may have, judged on the parts of it found (a Su...
Definition EBGeometry_SurfacePieces.hpp:561
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
Vec3T< T > normal(const F &a_function, const Vec3T< T > &a_point, const T &a_delta) noexcept
Outward unit normal of a function's level set, by central finite differences.
std::vector< SurfacePiece< ShapePrecision< TapeType > > > findSurfacePieces(const TapeType &a_tape, const uint32_t a_resolution=64)
The pieces of surface an object with regions has, as rays find them: every surface between every pair...
Definition EBGeometry_SurfacePieces.hpp:83
std::vector< PossiblePiece > possiblePieces(const SurfaceInventory &a_inventory)
Every piece of surface an object may have: each surface between each pair of regions its index says i...
Definition EBGeometry_SurfacePieces.hpp:506
@ None
As written: the tape evaluates every operand, however many there are.
One node of the expression.
Definition EBGeometry_Expr.hpp:1069
uint32_t m_numSurfaces
How many surfaces are below it: one per leaf, or a container leaf's own count (see hasSurfaces).
Definition EBGeometry_Expr.hpp:1093
uint32_t m_parent
The node it is an operand of; None for the root.
Definition EBGeometry_Expr.hpp:1073
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
uint32_t m_firstSurface
The first surface below it (see Tape::closestSurface()).
Definition EBGeometry_Expr.hpp:1088
constexpr bool isNone() const noexcept
Whether this is no label.
Definition EBGeometry_LabelId.hpp:85
static constexpr LabelId none() noexcept
No label.
Definition EBGeometry_LabelId.hpp:63
Numeric limits, with the meanings of the std::numeric_limits members of the same names.
Definition EBGeometry_Math.hpp:91
How surface groups cover a piece: how much of it they hold, and the surface group when one holds all ...
Definition EBGeometry_SurfacePieces.hpp:534
uint32_t m_surfaceGroup
The surface group holding all of it, or SurfaceGroups::None (none, or several).
Definition EBGeometry_SurfacePieces.hpp:543
Coverage m_coverage
How much.
Definition EBGeometry_SurfacePieces.hpp:538
A piece of surface an object may have: a surface between two regions, the later inside.
Definition EBGeometry_SurfacePieces.hpp:480
uint32_t m_ownerRegion
The later region.
Definition EBGeometry_SurfacePieces.hpp:489
uint32_t m_surface
The surface.
Definition EBGeometry_SurfacePieces.hpp:484
uint32_t m_neighborRegion
The earlier region.
Definition EBGeometry_SurfacePieces.hpp:494
How a query marches, where a shape has no ray form.
Definition EBGeometry_Ray.hpp:203
T m_tolerance
The march's tolerance, times the scale.
Definition EBGeometry_Ray.hpp:211
A ray: the points origin + t * direction.
Definition EBGeometry_Ray.hpp:56
A ray's first crossing of a shape's surface, with the surface it crossed, as firstSurface() reports i...
Definition EBGeometry_Ray.hpp:550
SurfaceRef< T > m_surface
The surface crossed, drilled down as closestSurface() does (its surface, leaf, label,...
Definition EBGeometry_Ray.hpp:560
HitT< T > m_hit
The crossing, as firstHit() reports it.
Definition EBGeometry_Ray.hpp:554
One level a surface belongs to (SurfaceInventory::levelsOf()): the surface itself,...
Definition EBGeometry_SurfacePieces.hpp:192
std::string m_operation
What it is: the node's operation (ExprIndex::Node::m_operation), or "Member" for one member of a coll...
Definition EBGeometry_SurfacePieces.hpp:222
SurfaceLabelId m_label
Its own surface label (SurfaceLabel() on the node, or on a node covering the same surfaces),...
Definition EBGeometry_SurfacePieces.hpp:217
uint32_t m_node
The node of the expression (ExprIndex numbering), the outermost of those covering the same surfaces; ...
Definition EBGeometry_SurfacePieces.hpp:202
static constexpr uint32_t None
No node.
Definition EBGeometry_SurfacePieces.hpp:196
uint32_t m_numSurfaces
How many surfaces it covers, from m_firstSurface.
Definition EBGeometry_SurfacePieces.hpp:212
uint32_t m_firstSurface
The first surface it covers.
Definition EBGeometry_SurfacePieces.hpp:207
One piece of an object's surface, as found: a shape's surface between two regions (see SurfaceSelecto...
Definition EBGeometry_SurfacePieces.hpp:37
Vec3T< T > m_normal
The normal there, pointing outside (into m_surface.m_neighborRegion).
Definition EBGeometry_SurfacePieces.hpp:52
uint32_t m_crossings
How many rays crossed it: a measure of its size.
Definition EBGeometry_SurfacePieces.hpp:57
std::vector< uint32_t > m_parts
The parts of it the rays crossed (a box's faces, a mesh's faces), sorted.
Definition EBGeometry_SurfacePieces.hpp:62
Vec3T< T > m_point
A point on it, where a ray crossed it first.
Definition EBGeometry_SurfacePieces.hpp:47
SurfaceRef< T > m_surface
The piece where it was first crossed: its surface, part and labels, and its two sides,...
Definition EBGeometry_SurfacePieces.hpp:42
The surface that decides a shape's value at a point, as closestSurface() reports it.
Definition EBGeometry_SurfaceRef.hpp:39
uint32_t m_ownerRegion
Set by a tape's region queries: the owner, the region the surface is reported from at the queried poi...
Definition EBGeometry_SurfaceRef.hpp:74
SurfaceLabelId m_surfaceLabel
Set by a tape: the surface's label, or none. A part labeled through face groups (SurfaceLabel(shape,...
Definition EBGeometry_SurfaceRef.hpp:59
uint32_t m_part
The part of the deepest shape reached, read from its own formula at the local point (see hasParts): a...
Definition EBGeometry_SurfaceRef.hpp:65
uint32_t m_leaf
Set by a tape: the leaf the surface belongs to, as Tape::closestLeaf() numbers it.
Definition EBGeometry_SurfaceRef.hpp:53
uint32_t m_neighborRegion
Set by a tape's region queries: the neighbor, the region across the surface from the owner at the que...
Definition EBGeometry_SurfaceRef.hpp:80
MaterialLabelId m_ownerMaterial
Set with the sides: the owner's material (m_ownerRegion's MaterialLabel()), or none.
Definition EBGeometry_SurfaceRef.hpp:85
uint32_t m_surface
The surface, numbered within the shape that was asked (across the scene when that is a tape).
Definition EBGeometry_SurfaceRef.hpp:48
MaterialLabelId m_neighborMaterial
Set with the sides: the neighbor's material (m_neighborRegion's), or none.
Definition EBGeometry_SurfaceRef.hpp:90
static constexpr uint32_t Any
An unset condition: matches anything.
Definition EBGeometry_SurfaceGroups.hpp:44
uint32_t m_label
The surface label (SurfaceRef::m_surfaceLabel), or Any.
Definition EBGeometry_SurfaceGroups.hpp:69
uint32_t m_part
The part (SurfaceRef::m_part), or Any.
Definition EBGeometry_SurfaceGroups.hpp:54