VTK  9.7.20261205
vtkAMRToBricksHelper.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef vtkAMRToBricksHelper_h
5#define vtkAMRToBricksHelper_h
6
7#include "vtkObject.h"
8#include "vtkSmartPointer.h"
9
10#include <array>
11#include <atomic>
12#include <cstdint>
13#include <limits>
14#include <vector>
15
16VTK_ABI_NAMESPACE_BEGIN
17
18class vtkDataObject;
19
43{
44public:
46 void PrintSelf(ostream& os, vtkIndent indent) override;
47
54 struct alignas(16) vtkExaBrick
55 {
56 float Bounds[6]; // World-space
57 uint32_t Level;
58 uint32_t Dims[3]; // Number of cells per axis (N, M, K)
59 uint32_t ScalarOffset;
61 };
62
70 struct alignas(16) vtkExaABR
71 {
72 float Bounds[6] = { 0.f, 0.f, 0.f, 0.f, 0.f, 0.f }; // World-space bounds of this region
73 float ScalarMin = std::numeric_limits<float>::max();
74 float ScalarMax = std::numeric_limits<float>::lowest();
75 float FinestCellWidth = std::numeric_limits<float>::max();
76 uint32_t BrickListOffset = 0; // Offset into ABRBrickLists array
77 uint32_t BrickCount = 0;
78 float MaxOpacity = 0.0f; // Max opacity of the TF over [ScalarMin, ScalarMax]
79 };
80
86 struct alignas(16) vtkExaBVHNode
87 {
88 float BoundsMin[3];
89 int32_t LeftIndex; // -1 if leaf
90 float BoundsMax[3];
91 int32_t RightIndex;
92 };
93
98 {
99 std::vector<vtkExaBrick> Bricks; // §3.1
100 std::vector<float> Scalars;
101 std::vector<float> InterfaceData;
102
103 std::vector<vtkExaABR> ABRs; // §3.2
104 std::vector<unsigned int> ABRBrickLists; // Concatenated brick ID lists
105
106 std::vector<vtkExaBVHNode> BVHNodes; // §3.3
107
108 std::array<float, 6> GlobalBounds;
109 unsigned int MaxLevel;
110
111 // True when InterfaceData actually carries per-cell interface planes.
112 // False (e.g. OverlappingAMR, or HTG without interface arrays) when all
113 // cells are pure, InterfaceData is then left empty to save 24 B/cell.
114 bool HasInterfaceData = false;
115
116 // Global scalar range over VALID cells only (per-brick min/max already
117 // exclude blanked/sentinel cells). Used for the color/opacity table so
118 // sentinel values (-1e30) stored for blanked cells don't corrupt it.
119 float ScalarMin = 0.0f;
120 float ScalarMax = 0.0f;
121 };
122
123 // Backward-compatible aliases for the historical names.
128
129 static constexpr float BLANKED_CELL_SENTINEL = -1e30f;
130
132
134
139 vtkSetMacro(MaxTraversalDepth, unsigned int);
140 vtkGetMacro(MaxTraversalDepth, unsigned int);
142
143 // Returns the built structures by value. The member is moved out, which is
144 // safe because BuildBricks() rebuilds BricksData from scratch on every call.
146
147protected:
150
154 virtual void CollectInput() = 0;
155
159 virtual void BuildBricksFromInput() {}
160
161 virtual const char* GetInputTypeName() const = 0;
162
168 {
169 float Min[3];
170 float Max[3];
171 unsigned int BrickID;
172 };
173
174 // Shared stages (input-agnostic), operating on BricksData.Bricks
177
185 void BuildABRs();
187 std::vector<SupportFragment> fragments, const float regionMin[3], const float regionMax[3]);
188 void CreateABRLeaf(const std::vector<SupportFragment>& fragments, const float regionMin[3],
189 const float regionMax[3]);
190
192
197 void BuildBVH();
199 std::vector<uint32_t>& indices, size_t start, size_t end, std::atomic<uint32_t>& nodeCounter);
201
203 std::vector<float> BrickScalarMin;
204
205 unsigned int MaxTraversalDepth = 0; // 0 = unlimited
206 std::vector<float> BrickScalarMax;
207
208 // Max brick width in cells/axis (see paper). Bigger bricks skip coarser.
209 static constexpr unsigned int MAX_BRICK_WIDTH = 32;
210
211 // Subdivide ABRs only while more fragments than this remain.
212 static constexpr unsigned int MIN_ABR_FRAGMENTS = 8;
213
214private:
216 void operator=(const vtkAMRToBricksHelper&) = delete;
217};
218
219VTK_ABI_NAMESPACE_END
220
221#endif
void BuildABRs()
Active Brick Regions (ABRs), paper §3.2.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void BuildABRsRecursive(std::vector< SupportFragment > fragments, const float regionMin[3], const float regionMax[3])
virtual const char * GetInputTypeName() const =0
static constexpr unsigned int MAX_BRICK_WIDTH
vtkExaBricks BuildBricks()
static vtkSmartPointer< vtkAMRToBricksHelper > NewForInput(vtkDataObject *input)
virtual void BuildBricksFromInput()
input-specific; default no-op (AMR patches are already bricks).
std::vector< float > BrickScalarMax
void CreateABRLeaf(const std::vector< SupportFragment > &fragments, const float regionMin[3], const float regionMax[3])
~vtkAMRToBricksHelper() override
int32_t BuildBVHRecursive(std::vector< uint32_t > &indices, size_t start, size_t end, std::atomic< uint32_t > &nodeCounter)
BVH over bricks, paper §3.3.
static constexpr float BLANKED_CELL_SENTINEL
static constexpr unsigned int MIN_ABR_FRAGMENTS
void BuildBVH()
BVH over bricks, paper §3.3.
std::vector< float > BrickScalarMin
virtual void CollectInput()=0
input-specific: fill BricksData + BrickScalarMin/Max + MaxLevel.
general representation of visualization data
a simple class to control print indentation
Definition vtkIndent.h:108
Hold a reference to a vtkObjectBase instance.
ABR build fragment: a brick's support box (half cell width beyond the brick bounds) tagged with the b...
ABR, paper §3.2, BrickListOffset + [0..BrickCount) indices into ABRBrickLists.
BVH node, paper §3.3, built over ABRs; leaf RightIndex = ABR index (LeftIndex = -1).
Brick, paper §3.1, 3D grid of same-level cells filling its bounds.
Result of BuildBricks: the three structures, ready for GPU upload.
std::vector< unsigned int > ABRBrickLists
std::vector< vtkExaBVHNode > BVHNodes