EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_RegionSettings.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
11#ifndef EBGEOMETRY_REGIONSETTINGS_HPP
12#define EBGEOMETRY_REGIONSETTINGS_HPP
13
14// Std includes
15#include <cstdint>
16#include <type_traits>
17
18// Our includes
19#include "EBGeometry_GPU.hpp"
21
22namespace EBGeometry {
23
27enum class RegionColoring : uint8_t
28{
29 Region,
30 Material,
32 Surface,
33 Part,
34 Interface,
36};
37
44template <class T>
46{
51
55 bool m_secondary = false;
56};
57
66{
70 static constexpr uint32_t None = 0xFFFFFFFFU;
71
75 static constexpr uint32_t MaxSeenThrough = 8;
76
81 static constexpr uint32_t Highlighted = 0xFFFFFFFDU;
82
86 uint64_t m_hidden = 0U;
87
92
96 uint32_t m_only = None;
97
102
107 uint64_t m_throughRegions = 0U;
108
115
120
125 uint64_t m_highlightRegions = 0U;
126
132 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
133 inline bool
134 isRegionHighlighted(const uint32_t a_region) const noexcept
135 {
136 return a_region < 64U && ((m_highlightRegions >> a_region) & 1U) != 0U;
137 }
138
142 static constexpr uint32_t MaxSelected = 16;
143
149 static constexpr uint32_t Selected = 0xFFFFFFC0U;
150
156
160 uint32_t m_numSelected = 0U;
161
168 bool m_onlySelected = false;
169
176 template <typename T>
177 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
178 inline uint32_t
179 selectionOf(const SurfaceRef<T>& a_surface) const noexcept
180 {
181 for (uint32_t i = 0; i < m_numSelected && i < MaxSelected; i++) {
182 if (m_selected[i].matches(a_surface)) {
183 return i;
184 }
185 }
186
187 return None;
188 }
189
195 uint64_t m_sectionRegions = 0U;
196
200 static constexpr uint8_t ExcludedSubdomain = 0xFFU;
201
208 bool m_sectionDomain = false;
209
214 uint8_t m_sectionSubdomains[64] = {};
215
220 uint32_t m_hiddenGroups = 0U;
221
227 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
228 inline bool
229 isSurfaceGroupHidden(const uint32_t a_group) const noexcept
230 {
231 return a_group < 32U && ((m_hiddenGroups >> a_group) & 1U) != 0U;
232 }
233
240 inline void
241 setSurfaceGroupHidden(const uint32_t a_group, const bool a_hidden) noexcept
242 {
243 if (a_group < 32U) {
244 const uint32_t bit = 1U << a_group;
245
246 m_hiddenGroups = a_hidden ? (m_hiddenGroups | bit) : (m_hiddenGroups & ~bit);
247 }
248 }
249
254 uint32_t m_throughGroups = 0U;
255
261 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
262 inline bool
263 isSurfaceGroupSeenThrough(const uint32_t a_group) const noexcept
264 {
265 return a_group < 32U && ((m_throughGroups >> a_group) & 1U) != 0U;
266 }
267
274 inline void
275 setSurfaceGroupSeenThrough(const uint32_t a_group, const bool a_through) noexcept
276 {
277 if (a_group < 32U) {
278 const uint32_t bit = 1U << a_group;
279
280 m_throughGroups = a_through ? (m_throughGroups | bit) : (m_throughGroups & ~bit);
281 }
282 }
283
290 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
291 static inline uint32_t
292 interfaceKey(const uint32_t a_first, const uint32_t a_second) noexcept
293 {
294 return ((a_first < a_second ? a_first : a_second) << 16U) | (a_first < a_second ? a_second : a_first);
295 }
296
303 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
304 inline bool
305 isVisible(const uint32_t a_region, const uint32_t a_numRegions) const noexcept
306 {
307 return a_region > 0U && a_region < a_numRegions && (a_region >= 64U || ((m_hidden >> a_region) & 1U) == 0U);
308 }
309
316 inline void
317 setVisible(const uint32_t a_region, const bool a_visible) noexcept
318 {
319 if (a_region > 0U && a_region < 64U) {
320 const uint64_t bit = uint64_t(1) << a_region;
321
322 m_hidden = a_visible ? (m_hidden & ~bit) : (m_hidden | bit);
323 }
324 }
325
331 inline void
332 showOnly(const uint32_t a_region) noexcept
333 {
334 m_hidden = ~uint64_t(0);
335
336 this->setVisible(a_region, true);
337 }
338
344 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
345 inline bool
346 isSeenThrough(const uint32_t a_key) const noexcept
347 {
348 for (uint32_t i = 0; i < MaxSeenThrough; i++) {
349 if (m_through[i] == a_key && a_key != None) {
350 return true;
351 }
352 }
353
354 return false;
355 }
356
364 inline void
365 setSeenThrough(const uint32_t a_key, const bool a_through) noexcept
366 {
367 for (uint32_t i = 0; i < MaxSeenThrough; i++) {
368 if (m_through[i] == a_key) {
369 m_through[i] = None;
370 }
371 }
372
373 if (a_through) {
374 for (uint32_t i = 0; i < MaxSeenThrough; i++) {
375 if (m_through[i] == None) {
376 m_through[i] = a_key;
377
378 break;
379 }
380 }
381 }
382 }
383
389 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
390 inline bool
391 isRegionSeenThrough(const uint32_t a_region) const noexcept
392 {
393 return a_region < 64U && ((m_throughRegions >> a_region) & 1U) != 0U;
394 }
395
402 inline void
403 setRegionSeenThrough(const uint32_t a_region, const bool a_through) noexcept
404 {
405 if (a_region < 64U) {
406 const uint64_t bit = uint64_t(1) << a_region;
407
408 m_throughRegions = a_through ? (m_throughRegions | bit) : (m_throughRegions & ~bit);
409 }
410 }
411
416 inline void
418 {
419 for (uint32_t i = 0; i < MaxSeenThrough; i++) {
420 m_through[i] = None;
421 }
422
423 m_throughRegions = 0U;
424 m_throughGroups = 0U;
425 }
426
434 inline void
435 setColoring(const RegionColoring a_coloring) noexcept
436 {
437 m_coloring = a_coloring;
438 m_only = None;
439
440 for (uint32_t i = 0; i < MaxSeenThrough; i++) {
441 m_through[i] = None;
442 }
443 }
444};
445
446static_assert(std::is_trivially_copyable_v<RegionSettings>,
447 "RegionSettings must be a plain value, for a kernel to take it");
448
449} // namespace EBGeometry
450
451#endif
GPU portability layer: host/device decoration macros and backend detection.
#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
SurfaceSelector and SurfaceGroups: which surfaces a downstream code groups under one meaning.
A domain's surface groups, read on the host or a device: each group a set of surfaces,...
Definition EBGeometry_SurfaceGroups.hpp:296
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.
@ Region
The region the surface belongs to, as seen.
A section plane's field at a point (RegionView::contourSample()): its value, negative inside,...
Definition EBGeometry_RegionSettings.hpp:46
T m_value
The field's value.
Definition EBGeometry_RegionSettings.hpp:50
bool m_secondary
Whether the lines there are secondary.
Definition EBGeometry_RegionSettings.hpp:55
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
void setSurfaceGroupSeenThrough(const uint32_t a_group, const bool a_through) noexcept
See through a surface group, or make it opaque again.
Definition EBGeometry_RegionSettings.hpp:275
void showOnly(const uint32_t a_region) noexcept
Show one region and hide the others.
Definition EBGeometry_RegionSettings.hpp:332
RegionColoring m_coloring
What a surface is colored and named by.
Definition EBGeometry_RegionSettings.hpp:91
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
void setRegionSeenThrough(const uint32_t a_region, const bool a_through) noexcept
See through a region, or make it opaque again (regions from 64 on are left as they are).
Definition EBGeometry_RegionSettings.hpp:403
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
static constexpr uint8_t ExcludedSubdomain
An entry of m_sectionSubdomains: the region is in no subdomain (Domain::Excluded).
Definition EBGeometry_RegionSettings.hpp:200
void clearSeenThrough() noexcept
Make every surface opaque: no key, no region and no surface group seen through.
Definition EBGeometry_RegionSettings.hpp:417
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
void setSurfaceGroupHidden(const uint32_t a_group, const bool a_hidden) noexcept
Hide a surface group, or show it again.
Definition EBGeometry_RegionSettings.hpp:241
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
void setSeenThrough(const uint32_t a_key, const bool a_through) noexcept
See through the surfaces of a key, or make them opaque again (at most MaxSeenThrough keys; beyond the...
Definition EBGeometry_RegionSettings.hpp:365
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
void setVisible(const uint32_t a_region, const bool a_visible) noexcept
Show or hide a region.
Definition EBGeometry_RegionSettings.hpp:317
bool isRegionHighlighted(const uint32_t a_region) const noexcept
Whether a region is highlighted.
Definition EBGeometry_RegionSettings.hpp:134
uint64_t m_highlightRegions
The highlighted regions, a bit each (bit k for region k, the background's bit 0 included): every surf...
Definition EBGeometry_RegionSettings.hpp:125
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
SurfaceSelector m_selected[MaxSelected]
The selected surfaces, the first m_numSelected entries (a viewer's picked parts or regions): a surfac...
Definition EBGeometry_RegionSettings.hpp:155
void setColoring(const RegionColoring a_coloring) noexcept
Color and name surfaces by another key; the keys shown alone and seen through, which meant another th...
Definition EBGeometry_RegionSettings.hpp:435
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
The surface that decides a shape's value at a point, as closestSurface() reports it.
Definition EBGeometry_SurfaceRef.hpp:39
Conditions on a point of a surface, all of which must hold; an unset one (Any) matches anything.
Definition EBGeometry_SurfaceGroups.hpp:40