12#ifndef EBGEOMETRY_REGIONVIEW_HPP
13#define EBGEOMETRY_REGIONVIEW_HPP
49template <
class TapeType>
63 explicit RegionView(
const TapeType& a_tape) noexcept : m_tape(a_tape)
78 return this->functionOf(a_point,
false);
90 return m_tape.getDistanceQuality();
124 return this->domainSample(a_point);
129 const T value = this->functionOf(a_point,
true);
140 m_tape.regionDistances(a_point, [&](
const uint32_t a_region,
const T a_value) {
142 field =
Math::min(field, std::abs(a_value));
150 const bool inside = in < Math::Limits<T>::max() && in < out;
165 return m_tape.getMaterialOf(m_tape.region(a_point)).value();
181 const uint32_t region = m_tape.region(a_point);
184 ref.
m_leaf = this->keyOf(m_tape.closestSurface(a_point, region), region);
205 return this->crossingSeen(a_ray, a_tMin, a_tMax, a_options,
false);
228 return any ? this->crossingSeen(a_ray, a_tMin, a_tMax, a_options,
true) :
HitT<T>();
246 crossingSeen(
const RayT<T>& a_ray,
250 const bool a_seenThrough)
const noexcept
254 for (uint32_t steps = 0; steps < a_options.m_maxSteps; steps++) {
255 const SurfaceHitT<T> change = m_tape.firstRegionChange(a_ray, t, a_tMax, a_options);
257 if (!change.
m_hit.hit()) {
261 const uint32_t from = change.
m_surface.m_ownerRegion;
262 const uint32_t to = change.
m_surface.m_neighborRegion;
271 const uint32_t group =
282 for (
const uint32_t seen : sides) {
291 const bool entering = (seen == to);
293 HitT<T> hit = change.
m_hit;
296 hit.m_normal = entering ? -change.
m_hit.m_normal : change.
m_hit.m_normal;
297 hit.m_entering = entering;
311 const uint32_t key = this->keyOf(change.
m_surface, seen);
317 const uint32_t chosen =
320 const bool through = !lit && chosen ==
None &&
331 hit.m_primitive = key;
352 t = change.
m_hit.m_t + (change.
m_hit.m_exact ?
T(0) :
T(4) * a_options.m_tolerance * this->scaleOf(a_options));
365 scaleOf(
const RayOptions<T>& a_options)
const noexcept
367 if (a_options.m_scale >
T(0)) {
368 return a_options.m_scale;
371 const auto box = m_tape.computeBoundingVolume();
372 const T diagonal = (box.getHighCorner() - box.getLowCorner()).
length();
374 return (diagonal >
T(0) && diagonal < Math::Limits<T>::max()) ? diagonal :
T(1);
390 view.m_tape = m_tape.rebasedView(a_pool);
413 const T step = (size >
T(0) && size < Math::Limits<T>::max()) ?
T(1e-4) * size :
T(1e-4);
414 const T length = a_normal.length();
422 uint32_t seen = m_tape.region(a_point - step * n);
426 seen = m_tape.region(a_point + step * n);
437 inline const TapeType&
451 return m_tape.computeBoundingVolume();
462 return m_tape.getNumRegions();
487 view.m_settings = a_settings;
504 static inline uint32_t
527 return m_tape.traceProgram(0U, a_ray,
T(0), a_tMax, a_options);
560 return m_settings.
isVisible(a_region, m_tape.getNumRegions());
583 withVisible(
const uint32_t a_region,
const bool a_visible)
const noexcept
587 view.m_settings.setVisible(a_region, a_visible);
602 view.m_settings.m_hidden = 0U;
618 view.m_settings.showOnly(a_region);
634 view.m_settings.m_only = a_key;
651 view.m_settings.setSeenThrough(a_key, a_through);
666 view.m_settings.clearSeenThrough();
682 view.m_settings.setColoring(a_coloring);
698 view.m_settings.m_surfaceGroups = a_groups;
713 domainSample(
const Vec3T<T>& a_point)
const noexcept
715 constexpr uint32_t Slots = 33U;
716 constexpr uint32_t Excluded = Slots - 1U;
720 for (uint32_t l = 0; l < Slots; l++) {
724 m_tape.regionDistances(a_point, [&](
const uint32_t a_region,
const T a_value) {
725 const uint8_t subdomain =
726 (a_region < 64U) ? m_settings.
m_sectionSubdomains[a_region] : RegionSettings::ExcludedSubdomain;
727 const uint32_t l = (subdomain < Excluded) ? uint32_t(subdomain) : Excluded;
729 smallest[l] =
Math::min(smallest[l], a_value);
733 T first = Math::Limits<T>::max();
734 T second = Math::Limits<T>::max();
735 uint32_t own = Excluded;
737 for (uint32_t l = 0; l < Slots; l++) {
738 if (smallest[l] < first) {
748 return ContourSample<T>{
T(0.5) * (first - second), own == Excluded};
761 functionOf(
const Vec3T<T>& a_point,
const bool a_section)
const noexcept
763 T in = Math::Limits<T>::max();
764 T out = Math::Limits<T>::max();
768 m_tape.regionDistances(a_point, [&](
const uint32_t a_region,
const T a_value) {
770 a_section ? (a_region < 64U && ((section >> a_region) & 1U) != 0U) : this->
isVisible(a_region);
780 return (in < Math::Limits<T>::max()) ?
T(0.5) * (in - out) : Math::Limits<
T>::
max();
791 RegionSettings m_settings;
801 keyOf(
const SurfaceRef<T>& a_surface,
const uint32_t a_region)
const noexcept
803 switch (m_settings.m_coloring) {
808 return m_settings.m_surfaceGroups.surfaceGroupOf(a_surface);
811 return m_tape.getMaterialOf(a_region).value();
814 return a_surface.m_surfaceLabel.value();
817 return a_surface.m_surface;
820 return a_surface.m_part;
833template <
class TapeType>
858 return a_view.firstHit(a_ray, a_tMin, a_tMax, a_options);
866template <
class S,
class =
void>
877 std::void_t<decltype(std::declval<const S&>().getNumRegions()),
878 decltype(std::declval<const S&>().getSettings()),
879 decltype(std::declval<const S&>().withSettings(std::declval<const RegionSettings&>())),
880 decltype(std::declval<const S&>().getTape()),
Declarations of bounding volume types used in bounding volume hierarchies.
The tape's front end: Expr, a host-side value that describes a composed object, and the free function...
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_DEVICE_NOINLINE
Keep a function out of line in the device pass (CUDA/HIP); nothing on the host.
Definition EBGeometry_GPU.hpp:110
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
LeafRef: which leaf of a composition decides its value at a point.
#define EBGEOMETRY_EXPECT(cond)
Runtime precondition assertion for EBGeometry.
Definition EBGeometry_Macros.hpp:269
Scalar helpers and numeric limits that compile for both host and device.
Ray queries on any shape: where a ray, or the segment between two points, first crosses its surface (...
RegionSettings: how the regions of an object are shown (visibility, coloring, a domain's surface grou...
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
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.
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:205
The visible regions of a tape, as a shape to look at: its surfaces are the regions' surfaces,...
Definition EBGeometry_RegionView.hpp:51
ShapePrecision< TapeType > T
Floating-point precision.
Definition EBGeometry_RegionView.hpp:56
T signedDistance(const Vec3T< T > &a_point) const noexcept
The value: the function of the visible regions, as a subdomain's (see Tape::signedDistance(p,...
Definition EBGeometry_RegionView.hpp:76
bool showsWholeObject() const noexcept
Whether the view shows the whole object's outer surface, as the tape itself is drawn: every region sh...
Definition EBGeometry_RegionView.hpp:539
static constexpr uint32_t None
No key (RegionSettings::None).
Definition EBGeometry_RegionView.hpp:495
static uint32_t interfaceKey(const uint32_t a_first, const uint32_t a_second) noexcept
The key of the interface between two regions (RegionSettings::interfaceKey()).
Definition EBGeometry_RegionView.hpp:505
RegionView withVisible(const uint32_t a_region, const bool a_visible) const noexcept
The same view with a region shown or hidden (RegionSettings::setVisible()).
Definition EBGeometry_RegionView.hpp:583
ContourSample< T > contourSample(const Vec3T< T > &a_point) const noexcept
The field a section plane shows (its contours and lines of equal distance): with a whole domain shown...
Definition EBGeometry_RegionView.hpp:121
RegionView withNoneSeenThrough() const noexcept
The same view with every surface opaque.
Definition EBGeometry_RegionView.hpp:662
HitT< T > objectHit(const RayT< T > &a_ray, const T a_tMax, const RayOptions< T > &a_options) const noexcept
The first crossing of the whole object's surface along a ray, from the tape's ray program,...
Definition EBGeometry_RegionView.hpp:523
RegionView(const TapeType &a_tape) noexcept
Every region visible, colored by region.
Definition EBGeometry_RegionView.hpp:63
DistanceQuality getDistanceQuality() const noexcept
The distance quality of the view's functions: the tape's (Tape::getDistanceQuality()),...
Definition EBGeometry_RegionView.hpp:88
RegionView rebasedView(const Pool &a_pool) const
The same view of the tape rebased onto another pool, a mirror of its own (for a device: see Tape::reb...
Definition EBGeometry_RegionView.hpp:386
HitT< T > firstHit(const RayT< T > &a_ray, const T a_tMin, const T a_tMax, const RayOptions< T > &a_options) const noexcept
The first crossing along a ray that touches a visible region (see the class description).
Definition EBGeometry_RegionView.hpp:203
RegionView withOnly(const uint32_t a_region) const noexcept
The same view with one region shown and the others hidden.
Definition EBGeometry_RegionView.hpp:614
HitT< T > firstSeenThrough(const RayT< T > &a_ray, const T a_tMin, const T a_tMax, const RayOptions< T > &a_options) const noexcept
The first crossing along a ray on a surface seen through (setSeenThrough()), where firstHit() passes ...
Definition EBGeometry_RegionView.hpp:220
T contourValue(const Vec3T< T > &a_point) const noexcept
The field a section plane shows (its contours and lines of equal distance), its value (see contourSam...
Definition EBGeometry_RegionView.hpp:101
RegionView withSeenThrough(const uint32_t a_key, const bool a_through) const noexcept
The same view with the surfaces of a key seen through, or opaque again (RegionSettings::setSeenThroug...
Definition EBGeometry_RegionView.hpp:647
LeafRef< T > closestLeaf(const Vec3T< T > &a_point) const noexcept
The key of the region a point inside the view is in (for a cut face), as a leaf reference (only m_lea...
Definition EBGeometry_RegionView.hpp:177
RegionView withSurfaceGroups(const SurfaceGroups &a_groups) const noexcept
The same view with a domain's surface groups (RegionColoring::SurfaceGroup colors by them).
Definition EBGeometry_RegionView.hpp:694
const TapeType & getTape() const noexcept
The tape the view shows.
Definition EBGeometry_RegionView.hpp:438
RegionView withOnlyKey(const uint32_t a_key) const noexcept
The same view, showing only the surfaces with a key (by the coloring); None shows them all.
Definition EBGeometry_RegionView.hpp:630
RegionView withAllVisible() const noexcept
The same view with every region shown.
Definition EBGeometry_RegionView.hpp:598
BoundingVolumes::AABBT< T > computeBoundingVolume() const noexcept
The tape's box.
Definition EBGeometry_RegionView.hpp:449
const RegionSettings & getSettings() const noexcept
What the view shows.
Definition EBGeometry_RegionView.hpp:471
RegionView withSettings(const RegionSettings &a_settings) const noexcept
The same view, showing what other settings say (the renderer gives it its own, Render::Settings::m_re...
Definition EBGeometry_RegionView.hpp:483
SurfaceRef< T > pieceAt(const Vec3T< T > &a_point, const Vec3T< T > &a_normal) const noexcept
The piece of surface at a point a ray met (firstHit()): the surface, its part and label,...
Definition EBGeometry_RegionView.hpp:408
bool isSeenThrough(const uint32_t a_key) const noexcept
Whether the surfaces with a key are seen through.
Definition EBGeometry_RegionView.hpp:570
uint32_t sectionKey(const Vec3T< T > &a_point) const noexcept
What a point is in, for a section plane's fill: its region's material, whatever the surfaces are colo...
Definition EBGeometry_RegionView.hpp:163
bool isVisible(const uint32_t a_region) const noexcept
Whether a region is shown (the background never is).
Definition EBGeometry_RegionView.hpp:558
uint32_t getNumRegions() const noexcept
How many regions the tape has, the background included.
Definition EBGeometry_RegionView.hpp:460
RegionView withColoring(const RegionColoring a_coloring) const noexcept
The same view, naming surfaces by another key (RegionSettings::setColoring()).
Definition EBGeometry_RegionView.hpp:678
A domain's surface groups, read on the host or a device: each group a set of surfaces,...
Definition EBGeometry_SurfaceGroups.hpp:296
uint32_t surfaceGroupOf(const SurfaceRef< T > &a_surface) const noexcept
The surface group a surface point is in: that of the first selector it matches, those of the remainin...
Definition EBGeometry_SurfaceGroups.hpp:447
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
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
RegionColoring
What a view of regions names a surface by, the key a renderer colors by (Render::ColorBy::Primitive).
Definition EBGeometry_RegionSettings.hpp:28
@ SurfaceGroup
The surface group the surface is in (RegionSettings::m_surfaceGroups), or none.
@ Interface
The pair of regions on its two sides there (see RegionSettings::interfaceKey()).
@ Part
The surface's part: a box's face, a mesh's face.
@ Surface
The surface itself (SurfaceRef::m_surface): each shape, each member of a collection.
@ SurfaceLabel
The surface's label (SurfaceLabel()).
@ Material
That region's material.
T length(const Vec2T< T > &v) noexcept
Euclidean length of a 2D vector.
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
DistanceQuality
How far the value of a signed distance function can be trusted, from strongest to weakest.
Definition EBGeometry_DistanceQuality.hpp:25
Vec2T< T > max(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Component-wise maximum of two vectors.
constexpr bool hasRegionVisibility
Whether a shape's regions are shown by region settings (RegionView): the primary template is false.
Definition EBGeometry_RegionView.hpp:867
A section plane's field at a point (RegionView::contourSample()): its value, negative inside,...
Definition EBGeometry_RegionSettings.hpp:46
Where a ray first crosses a surface.
Definition EBGeometry_Ray.hpp:98
The deciding leaf of a composition at a point: the primitive whose surface the composed value comes f...
Definition EBGeometry_LeafRef.hpp:42
Vec3T< T > m_localPoint
The point in the primitive's own frame (after the composition's maps), at which it can be queried its...
Definition EBGeometry_LeafRef.hpp:68
uint32_t m_leaf
The leaf: its number in expression order, depth first, each occurrence counted.
Definition EBGeometry_LeafRef.hpp:51
Numeric limits, with the meanings of the std::numeric_limits members of the same names.
Definition EBGeometry_Math.hpp:91
How a query marches, where a shape has no ray form.
Definition EBGeometry_Ray.hpp:203
A ray: the points origin + t * direction.
Definition EBGeometry_Ray.hpp:56
How the regions of an object are shown (see RegionView): which regions are visible,...
Definition EBGeometry_RegionSettings.hpp:66
bool isSeenThrough(const uint32_t a_key) const noexcept
Whether the surfaces with a key are seen through.
Definition EBGeometry_RegionSettings.hpp:346
bool isRegionSeenThrough(const uint32_t a_region) const noexcept
Whether a region is seen through (m_throughRegions).
Definition EBGeometry_RegionSettings.hpp:391
uint32_t m_only
The key shown alone, or None.
Definition EBGeometry_RegionSettings.hpp:96
uint32_t m_through[MaxSeenThrough]
The keys seen through; None marks an unused entry.
Definition EBGeometry_RegionSettings.hpp:101
bool m_onlySelected
Whether only the selected surfaces are shown, all of them, those other surfaces hid included,...
Definition EBGeometry_RegionSettings.hpp:168
uint32_t m_numSelected
How many entries of m_selected are used.
Definition EBGeometry_RegionSettings.hpp:160
uint32_t m_highlightGroup
The surface group whose surfaces are highlighted (keyed Highlighted), or None.
Definition EBGeometry_RegionSettings.hpp:119
uint8_t m_sectionSubdomains[64]
With m_sectionDomain, each region's subdomain (regions 0 to 63; later ones are excluded): below 32,...
Definition EBGeometry_RegionSettings.hpp:214
uint32_t m_hiddenGroups
The hidden surface groups, a bit each (bit g for surface group g): their surfaces are not drawn,...
Definition EBGeometry_RegionSettings.hpp:220
bool isSurfaceGroupHidden(const uint32_t a_group) const noexcept
Whether a surface group is hidden.
Definition EBGeometry_RegionSettings.hpp:229
SurfaceGroups m_surfaceGroups
A solver's groups of surfaces (RegionColoring::SurfaceGroup colors by them): a view of selectors in a...
Definition EBGeometry_RegionSettings.hpp:114
bool isSurfaceGroupSeenThrough(const uint32_t a_group) const noexcept
Whether a surface group is seen through (m_throughGroups).
Definition EBGeometry_RegionSettings.hpp:263
static constexpr uint32_t Selected
The key of the first selected surface: a surface entry i of the selection matches first (see m_select...
Definition EBGeometry_RegionSettings.hpp:149
static constexpr uint32_t Highlighted
The key a view of regions gives the surfaces of the highlighted surface group (m_highlightGroup),...
Definition EBGeometry_RegionSettings.hpp:81
uint64_t m_hidden
The hidden regions, a bit each (bit k for region k); regions from 64 on are always shown.
Definition EBGeometry_RegionSettings.hpp:86
bool isVisible(const uint32_t a_region, const uint32_t a_numRegions) const noexcept
Whether a region is shown (the background never is).
Definition EBGeometry_RegionSettings.hpp:305
uint64_t m_throughRegions
The regions seen through, a bit each (bit k for region k; regions from 64 on never are): every surfac...
Definition EBGeometry_RegionSettings.hpp:107
static constexpr uint32_t None
No key.
Definition EBGeometry_RegionSettings.hpp:70
static constexpr uint32_t MaxSeenThrough
How many keys can be seen through at once.
Definition EBGeometry_RegionSettings.hpp:75
bool isRegionHighlighted(const uint32_t a_region) const noexcept
Whether a region is highlighted.
Definition EBGeometry_RegionSettings.hpp:134
bool m_sectionDomain
Whether the section plane shows a whole domain: at each point the function of its own subdomain (its ...
Definition EBGeometry_RegionSettings.hpp:208
static uint32_t interfaceKey(const uint32_t a_first, const uint32_t a_second) noexcept
The key of the interface between two regions, the same whichever side it is seen from.
Definition EBGeometry_RegionSettings.hpp:292
uint32_t selectionOf(const SurfaceRef< T > &a_surface) const noexcept
The entry of the selection a surface is selected by.
Definition EBGeometry_RegionSettings.hpp:179
static constexpr uint32_t MaxSelected
How many selectors the selection holds at most.
Definition EBGeometry_RegionSettings.hpp:142
uint32_t m_throughGroups
The surface groups seen through, a bit each (bit g for surface group g): their surfaces drawn translu...
Definition EBGeometry_RegionSettings.hpp:254
uint64_t m_sectionRegions
The regions whose function the section plane shows (its fill and contours, and the value under a view...
Definition EBGeometry_RegionSettings.hpp:195
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
The surface that decides a shape's value at a point, as closestSurface() reports it.
Definition EBGeometry_SurfaceRef.hpp:39