VTK  9.6.20260629
HDFTestUtilities.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#ifndef HDFTestUtilities_h
4#define HDFTestUtilities_h
5
7#include "vtkDoubleArray.h"
8#include "vtkHyperTreeGrid.h"
11#include "vtkInformation.h"
13#include "vtkIntArray.h"
14#include "vtkNew.h"
15#include "vtkObjectFactory.h"
17#include "vtkTable.h"
18#include "vtkTableAlgorithm.h"
19
20#include <array>
21#include <map>
22#include <numeric>
23#include <vector>
24
26{
32{
33public:
36
37 void SetDescriptors(const std::vector<std::string>& descriptors)
38 {
39 this->Descriptors = descriptors;
40 }
41 void SetMasks(const std::vector<std::string>& masks) { this->Masks = masks; }
42 void SetDimensions(const std::array<unsigned int, 3>& dimensions)
43 {
44 this->Dimensions = dimensions;
45 }
46 void SetBranchFactor(const unsigned int bf) { this->BranchFactor = bf; }
47
48protected:
50 {
51 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkHyperTreeGrid");
52 return 1;
53 }
54
60
63 {
64 vtkInformation* outInfo = outputVector->GetInformationObject(0);
65 std::vector<double> timeSteps(this->Descriptors.size());
66 std::iota(timeSteps.begin(), timeSteps.end(), 0);
67 double timeRange[2] = { timeSteps.front(), timeSteps.back() };
68 outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), timeSteps.data(),
69 static_cast<int>(timeSteps.size()));
71 static_cast<int>(sizeof(timeRange) / sizeof(timeRange[0])));
73 outInfo->Set(CAN_HANDLE_PIECE_REQUEST(), 1);
74 return 1;
75 }
76
78 {
79 intSource->SetDimensions(3, 3, 2);
80 intSource->SetBranchFactor(2);
81 intSource->SetMaxDepth(4);
82 intSource->SetUseMask(!this->Masks.empty());
83 intSource->SetDimensions(this->Dimensions.data());
84 intSource->SetBranchFactor(BranchFactor);
85 if (intSource->GetUseMask())
86 {
87 intSource->SetMask(this->Masks.at(static_cast<int>(this->RequestedTime)).c_str());
88 }
89
90 intSource->SetDescriptor(this->Descriptors.at(static_cast<int>(this->RequestedTime)).c_str());
91
92 return 1;
93 }
94
97 {
98 vtkInformation* outInfo = outputVector->GetInformationObject(0);
100 if (!output)
101 {
102 return 0;
103 }
104
106 {
108 }
109
110 this->ProcessTrees(nullptr, nullptr);
111
112 typedef vtkStreamingDemandDrivenPipeline vtkSDDP;
114 if (outInfo->Has(vtkSDDP::UPDATE_PIECE_NUMBER()))
115 {
116 intSource->UpdatePiece(outInfo->Get(vtkSDDP::UPDATE_PIECE_NUMBER()),
117 outInfo->Get(vtkSDDP::UPDATE_NUMBER_OF_PIECES()), 0);
118 }
119 else
120 {
121 intSource->Update();
122 }
123
124 output->ShallowCopy(intSource->GetOutputDataObject(0));
125
126 return 1;
127 }
128
129private:
131 void operator=(const vtkHTGChangingDescriptorSource&) = delete;
132
133 std::vector<std::string> Descriptors;
134 std::vector<std::string> Masks;
135 std::array<unsigned int, 3> Dimensions;
136 unsigned int BranchFactor = 2;
137
138 double RequestedTime = 0.0;
140};
141
148{
149public:
152
153 void AddTemporalColumn(const std::string& name, const std::vector<std::vector<int>>& values)
154 {
155 this->IntCols.insert({ name, values });
156 }
157
158 void AddTemporalColumn(const std::string& name, const std::vector<std::vector<double>>& values)
159 {
160 this->DoubleCols.insert({ name, values });
161 }
162
163protected:
165 {
166 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkTable");
167 return 1;
168 }
169
171 {
172 this->SetNumberOfInputPorts(0);
173 this->SetNumberOfOutputPorts(1);
174 }
175
177 vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) override
178 {
179 vtkInformation* outInfo = outputVector->GetInformationObject(0);
180 std::vector<double> timeSteps(this->IntCols.begin()->second.size());
181 std::iota(timeSteps.begin(), timeSteps.end(), 0);
182 double timeRange[2] = { timeSteps.front(), timeSteps.back() };
183 outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), timeSteps.data(),
184 static_cast<int>(timeSteps.size()));
186 static_cast<int>(sizeof(timeRange) / sizeof(timeRange[0])));
188 outInfo->Set(CAN_HANDLE_PIECE_REQUEST(), 1);
189 return 1;
190 }
191
193 vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) override
194 {
195 vtkInformation* outInfo = outputVector->GetInformationObject(0);
196 auto* output = vtkTable::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
197
198 int RequestedTime =
199 static_cast<int>(outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()));
200
201 for (const auto& it : IntCols)
202 {
204 arr->SetName(it.first.c_str());
205 arr->SetNumberOfTuples(it.second.at(RequestedTime).size());
206 for (int i = 0; i < arr->GetNumberOfTuples(); i++)
207 {
208 arr->SetValue(i, it.second.at(RequestedTime).at(i));
209 }
210 output->AddColumn(arr);
211 }
212
213 for (const auto& it : DoubleCols)
214 {
216 arr->SetName(it.first.c_str());
217 arr->SetNumberOfTuples(it.second.at(RequestedTime).size());
218 for (int i = 0; i < arr->GetNumberOfTuples(); i++)
219 {
220 arr->SetValue(i, it.second.at(RequestedTime).at(i));
221 }
222 output->AddColumn(arr);
223 }
224
225 return 1;
226 }
227
228private:
230 void operator=(const vtkTemporalTableSource&) = delete;
231
232 std::map<std::string, std::vector<std::vector<int>>> IntCols;
233 std::map<std::string, std::vector<std::vector<double>>> DoubleCols;
234};
235}
236#endif
Custom source to generate time-dependent HTG.
static vtkHTGChangingDescriptorSource * New()
void SetDimensions(const std::array< unsigned int, 3 > &dimensions)
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *outputVector) override
void SetMasks(const std::vector< std::string > &masks)
int ProcessTrees(vtkHyperTreeGrid *, vtkDataObject *) override
Main routine to process individual trees in the grid This is pure virtual method to be implemented by...
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *outputVector) override
This is called by the superclass.
void SetDescriptors(const std::vector< std::string > &descriptors)
int FillOutputPortInformation(int, vtkInformation *info) override
Fill the output port information objects for this algorithm.
Custom source to generate time-dependent vtkTable.
int FillOutputPortInformation(int, vtkInformation *info) override
Fill the output port information objects for this algorithm.
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *outputVector) override
This is called by the superclass.
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *outputVector) override
void AddTemporalColumn(const std::string &name, const std::vector< std::vector< double > > &values)
static vtkTemporalTableSource * New()
void AddTemporalColumn(const std::string &name, const std::vector< std::vector< int > > &values)
virtual void SetNumberOfOutputPorts(int n)
Set the number of output ports provided by the algorithm.
virtual void SetNumberOfInputPorts(int n)
Set the number of input ports used by the algorithm.
general representation of visualization data
A dataset containing a grid of vtkHyperTree instances arranged as a rectilinear grid.
static vtkHyperTreeGrid * SafeDownCast(vtkObjectBase *o)
Store zero or more vtkInformation instances.
vtkInformation * GetInformationObject(int index)
Get/Set the vtkInformation instance stored at the given index in the vector.
Store vtkAlgorithm input/output information.
int Get(vtkInformationIntegerKey *key)
Get/Set an integer-valued entry.
int Has(vtkInformationKey *key) VTK_FUTURE_CONST
Check whether the given key appears in this information object.
void Set(vtkInformationRequestKey *key)
Get/Set a request-valued entry.
Allocate and hold a VTK object.
Definition vtkNew.h:168
Executive supporting partial updates.
static vtkTable * SafeDownCast(vtkObjectBase *o)
static vtkInformationDoubleKey * UPDATE_TIME_STEP()
Update time steps requested by the pipeline.
static vtkInformationIntegerKey * CAN_HANDLE_PIECE_REQUEST()
Key that tells the pipeline that a particular algorithm can or cannot handle piece request.
static vtkInformationIntegerKey * TIME_DEPENDENT_INFORMATION()
Whether there are time dependent meta information if there is, the pipeline will perform two extra pa...
static vtkInformationDoubleVectorKey * TIME_RANGE()
Key to store available time range for continuous sources.
static vtkInformationStringKey * DATA_TYPE_NAME()
Information keys to describe the content of this vtkDataObject.
static vtkInformationDoubleVectorKey * TIME_STEPS()
Key to store available time steps.
static vtkInformationDataObjectKey * DATA_OBJECT()
Store a vtkDataObject pointer.