VTK  9.3.1
vtkADIOS2CoreImageReader.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
21 #ifndef vtkADIOS2CoreImageReader_h
22 #define vtkADIOS2CoreImageReader_h
23 
24 #include <map> // For independently time stepped array indexing
25 #include <memory> // For std::unique_ptr
26 #include <string> // For variable name index mapping
27 #include <vector> // For independently time stepped array indexing
28 
29 #include "vtkDataObjectAlgorithm.h"
30 #include "vtkSetGet.h" // For property get/set macros
31 #include "vtkSmartPointer.h" // For the object cache
32 
33 #include "vtkIOADIOS2Module.h" // For export macro
34 
35 VTK_ABI_NAMESPACE_BEGIN
36 class vtkCellArray;
37 class vtkDataArray;
38 class vtkDataObject;
39 class vtkDataSet;
41 class vtkFieldData;
42 class vtkImageData;
45 class vtkStringArray;
46 
47 //----------------------------------------------------------------------------
48 
49 class VTKIOADIOS2_EXPORT vtkADIOS2CoreImageReader : public vtkDataObjectAlgorithm
50 {
51 public:
52  enum class VarType
53  {
54  PointData,
55  CellData
56  };
57  using Params = std::map<std::string, std::string>;
58  using StringToParams = std::map<std::string, Params>;
59  using InquireVariablesType = std::vector<std::pair<std::string, VarType>>;
60  static vtkADIOS2CoreImageReader* New();
62  void PrintSelf(ostream& os, vtkIndent indent) override;
63 
68  int CanReadFile(VTK_FILEPATH const std::string& name);
69 
70  virtual int CanReadFile(VTK_FILEPATH const char* filename);
71 
73 
76  vtkSetMacro(FileName, std::string);
77  vtkGetMacro(FileName, std::string);
79 
80  void SetFileName(VTK_FILEPATH const char* filename);
81 
83 
87  vtkSetVector3Macro(Origin, double);
88  vtkGetVector3Macro(Origin, double);
90 
92 
96  vtkSetVector3Macro(Spacing, double);
97  vtkGetVector3Macro(Spacing, double);
99 
101 
106  vtkStringArray* GetAllDimensionArrays();
107  vtkSetMacro(DimensionArray, std::string);
108  vtkGetMacro(DimensionArray, std::string);
110 
112 
116  vtkSetMacro(DimensionArrayAsCell, bool);
117  vtkGetMacro(DimensionArrayAsCell, bool);
118  vtkBooleanMacro(DimensionArrayAsCell, bool);
120 
121  vtkStringArray* GetAllTimeStepArrays();
123 
127  vtkSetMacro(TimeStepArray, std::string);
128  vtkGetMacro(TimeStepArray, std::string);
130 
132 
141  int GetNumberOfArrays();
142  const char* GetArrayName(int index);
143 
145 
149  void SetArrayStatus(const char* name, int status);
150  int GetArrayStatus(const char* name);
152 
154 
161  vtkSetMacro(IsColumnMajor, bool);
162  vtkGetMacro(IsColumnMajor, bool);
163  vtkBooleanMacro(IsColumnMajor, bool);
165 
167 
170  void SetActiveScalar(const std::pair<std::string, VarType>& inqVars);
171  std::pair<std::string, VarType>& GetActiveScalar();
172  const std::pair<std::string, VarType>& GetActiveScalar() const;
173 
175 
178  StringToParams& GetAvilableVariables();
179  const StringToParams& GetAvilableVariables() const;
180 
182 
185  StringToParams& GetAvailableAttributes();
186  const StringToParams& GetAvailableAttributes() const;
187 
189 
192  void SetController(vtkMultiProcessController*);
194 
199 
200 protected:
202  ~vtkADIOS2CoreImageReader() override;
203 
204  int RequestDataObjectInternal(vtkInformationVector*);
205 
206  int RequestInformation(
207  vtkInformation* request, vtkInformationVector** input, vtkInformationVector* output) override;
208  int RequestData(
209  vtkInformation* request, vtkInformationVector** input, vtkInformationVector* output) override;
210 
211  std::string FetchTypeStringFromVarName(const std::string& name);
212 
213  void UpdateDimensionFromDimensionArray();
214 
215  // Read available variables and attributes in the file
216  bool OpenAndReadMetaData();
217 
218  // Convert the array selection into inquire variables.
219  void ConvertArraySelectionToInqVar();
220 
221  // Init the workDistribution based on the first inquired variable
222  bool InitWorkDistribution();
223 
224  void ReadImageBlocks(vtkMultiBlockDataSet* mbds);
225 
226  // Gather time steps info from the time step array
227  bool GatherTimeSteps();
228 
229  // Helper function for InitWorkDistribution to calculate how many blocks each process shall read
230  template <typename T>
231  void CalculateWorkDistribution(const std::string& varName);
232 
233  // Helper function for ReadImageBlocks to populate vtk data array from adios variable
234  template <typename T, template <typename...> class U>
235  vtkSmartPointer<vtkAbstractArray> PopulateDataArrayFromVar(
236  const std::string& varName, size_t blockIndex);
237 
238  // Helper function to gather time steps from adios time array
239  template <typename T>
240  void GatherTimeStepsFromADIOSTimeArray();
241 
243 
246 
249 
250  double Origin[3];
251  double Spacing[3];
252  int Dimension[3];
253 
255 
257 
258  struct vtkADIOS2CoreImageReaderImpl;
259  std::unique_ptr<vtkADIOS2CoreImageReaderImpl> Impl;
260 
261 private:
263  void operator=(const vtkADIOS2CoreImageReader&) = delete;
264 };
265 VTK_ABI_NAMESPACE_END
266 #endif
Store vtkAlgorithm input/output information.
std::vector< std::pair< std::string, VarType >> InquireVariablesType
abstract class to specify dataset behavior
Definition: vtkDataSet.h:52
static vtkDataObjectAlgorithm * New()
vtkTypeBool ProcessRequest(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
see vtkAlgorithm for details
a vtkAbstractArray subclass for strings
a simple class to control print indentation
Definition: vtkIndent.h:28
topologically and geometrically regular array of data
Definition: vtkImageData.h:42
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
std::map< std::string, Params > StringToParams
represent and manipulate attribute data in a dataset
#define VTK_FILEPATH
Superclass for algorithms that produce only data object as output.
object to represent cell connectivity
Definition: vtkCellArray.h:175
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
Composite dataset that organizes datasets into blocks.
std::unique_ptr< vtkADIOS2CoreImageReaderImpl > Impl
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
vtkSmartPointer< vtkMultiProcessController > Controller
Store zero or more vtkInformation instances.
std::map< std::string, std::string > Params
general representation of visualization data
Definition: vtkDataObject.h:54
represent and manipulate fields of data
Definition: vtkFieldData.h:51
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Multiprocessing communication superclass.