VTK  9.7.1
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"
10 #include "vtkHyperTreeGridSource.h"
11 #include "vtkInformation.h"
12 #include "vtkInformationVector.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 {
33 public:
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 
48 protected:
50  {
51  info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkHyperTreeGrid");
52  return 1;
53  }
54 
56  {
57  this->SetNumberOfInputPorts(0);
58  this->SetNumberOfOutputPorts(1);
59  }
60 
62  vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) override
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 
96  vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) override
97  {
98  vtkInformation* outInfo = outputVector->GetInformationObject(0);
100  if (!output)
101  {
102  return 0;
103  }
104 
106  {
107  RequestedTime = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
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 
129 private:
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 {
149 public:
150  static vtkTemporalTableSource* New();
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 
163 protected:
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 
228 private:
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
void SetDescriptors(const std::vector< std::string > &descriptors)
virtual void SetNumberOfTuples(vtkIdType numTuples)
Set the number of tuples (a component group) in the array.
Store vtkAlgorithm input/output information.
static vtkHyperTreeGrid * SafeDownCast(vtkObjectBase *o)
void AddTemporalColumn(const std::string &name, const std::vector< std::vector< int >> &values)
virtual void SetNumberOfInputPorts(int n)
Set the number of input ports used by the algorithm.
virtual bool Update(int port)
Bring this algorithm's outputs up-to-date.
A dataset containing a grid of vtkHyperTree instances arranged as a rectilinear grid.
virtual bool GetUseMask()
Set/get whether the material mask should be used.
static vtkHTGChangingDescriptorSource * New()
virtual int UpdatePiece(int piece, int numPieces, int ghostLevels, const int extents[6]=nullptr)
Convenience method to update an algorithm after passing requests to its first output port...
vtkInformation * GetInformationObject(int index)
Get/Set the vtkInformation instance stored at the given index in the vector.
void AddTemporalColumn(const std::string &name, const std::vector< std::vector< double >> &values)
static vtkInformationDoubleKey * UPDATE_TIME_STEP()
Update time steps requested by the pipeline.
static vtkInformationDoubleVectorKey * TIME_RANGE()
Key to store available time range for continuous sources.
vtkDataObject * GetOutputDataObject(int port)
Get the data object that will contain the algorithm output for the given port.
virtual void SetNumberOfOutputPorts(int n)
Set the number of output ports provided by the algorithm.
void SetMaxDepth(unsigned int levels)
Set the maximum number of levels of the hypertrees.
static vtkInformationDoubleVectorKey * TIME_STEPS()
Key to store available time steps.
virtual void SetName(const char *)
Set/get array's name.
void SetMasks(const std::vector< std::string > &masks)
int Get(vtkInformationIntegerKey *key)
Get/Set an integer-valued entry.
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
int Has(vtkInformationKey *key) VTK_FUTURE_CONST
Check whether the given key appears in this information object.
int FillOutputPortInformation(int, vtkInformation *info) override
Fill the output port information objects for this algorithm.
virtual void SetUseMask(bool)
Set/get whether the material mask should be used.
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
virtual void SetBranchFactor(unsigned int)
Set/Get the subdivision factor in the grid refinement scheme.
static vtkInformationIntegerKey * TIME_DEPENDENT_INFORMATION()
Whether there are time dependent meta information if there is, the pipeline will perform two extra pa...
Custom source to generate time-dependent vtkTable.
int FillOutputPortInformation(int, vtkInformation *info) override
Define default input and output port types.
static vtkInformationStringKey * DATA_TYPE_NAME()
Information keys to describe the content of this vtkDataObject.
void Set(vtkInformationRequestKey *key)
Get/Set a request-valued entry.
void SetDimensions(const std::array< unsigned int, 3 > &dimensions)
virtual void SetDescriptor(const char *)
Set/Get the string used to describe the grid.
virtual void SetMask(const char *)
Set/Get the string used to as a material mask.
int ProcessTrees(vtkHyperTreeGrid *, vtkDataObject *) override
Main routine to process individual trees in the grid This is pure virtual method to be implemented by...
static vtkInformationIntegerKey * CAN_HANDLE_PIECE_REQUEST()
Key that tells the pipeline that a particular algorithm can or cannot handle piece request...
Superclass for algorithms that produce a hyper tree grid as output.
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *outputVector) override
This is called by the superclass.
Superclass for algorithms that produce only vtkTables as output.
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *outputVector) override
Store zero or more vtkInformation instances.
static vtkTable * SafeDownCast(vtkObjectBase *o)
Executive supporting partial updates.
Custom source to generate time-dependent HTG.
general representation of visualization data
Definition: vtkDataObject.h:55
static vtkTemporalTableSource * New()
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *outputVector) override
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *outputVector) override
This is called by the superclass.
static vtkInformationDataObjectKey * DATA_OBJECT()
Store a vtkDataObject pointer.
void SetDimensions(const unsigned int *dims)
Set/Get the number of root cells + 1 in each dimension of the grid.