VTK  9.7.20261004
vtkCellGridToUnstructuredGrid.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
40
41#ifndef vtkCellGridToUnstructuredGrid_h
42#define vtkCellGridToUnstructuredGrid_h
43
44#include "vtkCellGrid.h" // For subclass
45#include "vtkCellType.h" // For initializer
46#include "vtkFiltersCellGridModule.h" // For export macro
47#include "vtkNew.h" // For ivar
48#include "vtkStringToken.h" // For ivars
50
51#include <atomic> // For atomic
52#include <unordered_map> // For unordered_map
53#include <vector> // For vector
54
55VTK_ABI_NAMESPACE_BEGIN
56
57class vtkDoubleArray;
58class vtkIdTypeArray;
59
60class VTKFILTERSCELLGRID_EXPORT vtkCellGridToUnstructuredGrid : public vtkUnstructuredGridAlgorithm
61{
62public:
66 class Query : public vtkCellGridQuery
67 {
68 public:
69 static Query* New();
71 void PrintSelf(ostream& os, vtkIndent indent) override;
72
100
104 using OutputAllocations = std::unordered_map<vtkStringToken, OutputAllocation>;
105
127
128 bool Initialize() override;
129 void StartPass() override;
130 bool Finalize() override;
131
141 vtkSetClampMacro(SubdivisionLevel, int, 0, VTK_INT_MAX);
142 vtkGetMacro(SubdivisionLevel, int);
144
153 vtkSetClampMacro(PointMergeTolerance, double, 0., VTK_DOUBLE_MAX);
154 vtkGetMacro(PointMergeTolerance, double);
156
162 bool IsAborted() { return this->Algorithm && this->Algorithm->CheckAbort(); }
163
170 {
171 constexpr int maxShift = 8 * static_cast<int>(sizeof(vtkIdType)) - 2;
172 unsigned shift = static_cast<unsigned>(
173 this->SubdivisionLevel > maxShift ? maxShift : this->SubdivisionLevel);
174 return static_cast<vtkIdType>(1) << shift;
175 }
176
178 bool IsAnotherPassRequired() override { return this->Pass < PassType::GeneratePointData; }
179
181 vtkUnstructuredGrid* GetOutput() const { return this->Output; }
183 vtkCellGrid* GetInput() const { return this->Input; }
184
187 const OutputAllocations& GetOutputAllocations() const { return this->OutputOffsets; }
188
191
202 vtkDoubleArray* GetSampleCoordinates() { return this->SampleCoordinates.GetPointer(); }
203
208 vtkIdTypeArray* GetSampleToPoint() { return this->SampleToPoint.GetPointer(); }
209
214 using ConnectivityCountType = std::vector<std::atomic<int>>;
215
219 using ConnectivityWeightType = std::vector<float>;
221
222 protected:
224 Query() = default;
225 ~Query() override = default;
226
227 vtkCellGrid* Input{ nullptr };
229
233 double PointMergeTolerance{ 1e-12 };
236
240 // Map input to output attributes:
241 std::unordered_map<vtkCellAttribute*, vtkDataArray*> AttributeMap;
256
259
260 private:
261 Query(const Query&) = delete;
262 void operator=(const Query&) = delete;
263 };
264
267 void PrintSelf(ostream& os, vtkIndent indent) override;
268
285 virtual void SetSubdivisionLevel(int level);
286 virtual int GetSubdivisionLevel() const;
288
300 virtual void SetPointMergeTolerance(double tolerance);
301 virtual double GetPointMergeTolerance() const;
303
304protected:
306 ~vtkCellGridToUnstructuredGrid() override = default;
307
308 int FillInputPortInformation(int port, vtkInformation* info) override;
310 vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* ouInfo) override;
311
313
314private:
316 void operator=(const vtkCellGridToUnstructuredGrid&) = delete;
317};
318
319VTK_ABI_NAMESPACE_END
320#endif // vtkCellGridToUnstructuredGrid_h
A function defined over the physical domain of a vtkCellGrid.
vtkCellGridQuery()=default
A query corresponding to this algorithm.
std::unordered_map< vtkCellAttribute *, vtkDataArray * > AttributeMap
vtkNew< vtkIdTypeArray > SampleToPoint
The output point each sample was merged into.
ConnectivityWeightType ConnectivityWeights
The reciprocal of every entry in ConnectivityCount.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
std::unordered_map< vtkStringToken, OutputAllocation > OutputAllocations
A map used to allocate space for the unstructured-grid's vtkCellArray.
const OutputAllocations & GetOutputAllocations() const
vtkCellGrid * GetInput() const
Get the request's input cell-grid.
vtkNew< vtkIdTypeArray > CellArrayOffsets
Storage handed to the output vtkCellArray, written by index.
vtkIdType GetSubdivisionCount() const
Return the number of subdivisions along each parametric axis.
bool IsAborted()
Return true if the user has asked the filter to stop.
ConnectivityCountType ConnectivityCount
The number of samples merged into each output point.
bool IsAnotherPassRequired() override
Force one pass per PassType through this query.
vtkIdTypeArray * GetSampleToPoint()
Map a sample index to the output point the sample was merged into.
OutputAllocations & GetOutputAllocations()
Return the data structure used in the CountOutputs pass.
double PointMergeTolerance
The relative distance within which samples merge (see SetPointMergeTolerance()).
OutputAllocations OutputOffsets
Map output cell-typename to input cell-typename to count (offset after the AllocateOutputs pass has r...
vtkDataArray * GetOutputArray(vtkCellAttribute *inputAttribute)
Return an output attribute (or null).
std::vector< float > ConnectivityWeightType
The reciprocal of the number of samples merged into each output point.
void StartPass() override
Mark the start of a pass through each cell type.
bool Finalize() override
Override this if your query-result state requires finalization.
vtkUnstructuredGrid * GetOutput() const
Get the request's output cell-grid.
vtkCellGridToUnstructuredGrid * Algorithm
The algorithm running this query, used only to poll for an abort.
std::vector< std::atomic< int > > ConnectivityCountType
How many samples were merged into each output point.
@ CountOutputs
Responders should insert into GetOutputAllocations().
@ GeneratePointData
Responders should populate point-data.
@ GenerateSamples
Responders should write sample coordinates and their source cell + parameters.
@ GenerateConnectivity
Responders should write output point-ids, connectivity, and cell types.
bool Initialize() override
Override this if your query-result state requires initialization.
vtkNew< vtkDoubleArray > SampleCoordinates
One candidate output point per sample, before coincident ones merge.
vtkDoubleArray * GetSampleCoordinates()
Return the array holding one candidate output point per sample.
void MergeSamplesIntoPoints()
Merge coincident samples and allocate the output points they became.
int SubdivisionLevel
How many times each cell is halved per axis (see SetSubdivisionLevel()).
vtkIdType TotalCells
Totals over every cell type, accumulated with the offsets below.
virtual void SetSubdivisionLevel(int level)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual double GetPointMergeTolerance() const
virtual int GetSubdivisionLevel() const
virtual void SetPointMergeTolerance(double tolerance)
static vtkCellGridToUnstructuredGrid * New()
~vtkCellGridToUnstructuredGrid() override=default
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
int RequestData(vtkInformation *request, vtkInformationVector **inInfo, vtkInformationVector *ouInfo) override
This is called by the superclass.
Visualization data composed of cells of arbitrary type.
Definition vtkCellGrid.h:49
dynamic, self-adjusting array of double
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Allocate and hold a VTK object.
Definition vtkNew.h:168
dataset represents arbitrary combinations of all possible cell types
A placeholder for space to be occupied in a vtkCellArray.
vtkIdType NumberOfSamples
How many samples the responder will take of its cells and sides.
vtkIdType NumberOfConnectivityIds
The number of point-ids this type contributes to the output connectivity, not counting the per-cell o...
vtkIdType SampleOffset
Where this type's share of the output begins.
@ VTK_EMPTY_CELL
Definition vtkCellType.h:37
#define vtkDataArray
int vtkIdType
Definition vtkType.h:363
#define VTK_DOUBLE_MAX
Definition vtkType.h:202
#define VTK_INT_MAX
Definition vtkType.h:192