VTK  9.7.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::map<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 
156  vtkMTimeType GetMTime() override;
157 
159 
166  vtkSetMacro(IsColumnMajor, bool);
167  vtkGetMacro(IsColumnMajor, bool);
168  vtkBooleanMacro(IsColumnMajor, bool);
170 
172 
175  void SetActiveScalar(const std::pair<std::string, VarType>& inqVars);
176  std::pair<std::string, VarType>& GetActiveScalar();
177  const std::pair<std::string, VarType>& GetActiveScalar() const;
178 
180 
183  StringToParams& GetAvilableVariables();
184  const StringToParams& GetAvilableVariables() const;
185 
187 
190  StringToParams& GetAvailableAttributes();
191  const StringToParams& GetAvailableAttributes() const;
192 
194 
197  void SetController(vtkMultiProcessController*);
199 
204 
205 protected:
207  ~vtkADIOS2CoreImageReader() override;
208 
209  int RequestDataObjectInternal(vtkInformationVector*);
210 
211  int RequestInformation(
212  vtkInformation* request, vtkInformationVector** input, vtkInformationVector* output) override;
213  int RequestData(
214  vtkInformation* request, vtkInformationVector** input, vtkInformationVector* output) override;
215 
216  std::string FetchTypeStringFromVarName(const std::string& name);
217 
218  void UpdateDimensionFromDimensionArray();
219 
220  // Read available variables and attributes in the file
221  bool OpenAndReadMetaData();
222 
223  // Convert the array selection into inquire variables.
224  void ConvertArraySelectionToInqVar();
225 
226  // Init the workDistribution based on the first inquired variable
227  bool InitWorkDistribution();
228 
229  void ReadImageBlocks(vtkMultiBlockDataSet* mbds);
230 
231  // Gather time steps info from the time step array
232  bool GatherTimeSteps();
233 
234  // Helper function for InitWorkDistribution to calculate how many blocks each process shall read
235  template <typename T>
236  void CalculateWorkDistribution(const std::string& varName);
237 
238  // Helper function for ReadImageBlocks to populate vtk data array from adios variable
239  template <typename T>
240  vtkSmartPointer<vtkAbstractArray> PopulateDataArrayFromVar(
241  const std::string& varName, size_t blockIndex);
242 
243  // Helper function to gather time steps from adios time array
244  template <typename T>
245  void GatherTimeStepsFromADIOSTimeArray();
246 
248 
251 
254 
255  double Origin[3];
256  double Spacing[3];
257  int Dimension[3];
258 
260 
262 
263  struct vtkADIOS2CoreImageReaderImpl;
264  std::unique_ptr<vtkADIOS2CoreImageReaderImpl> Impl;
265 
266 private:
268  void operator=(const vtkADIOS2CoreImageReader&) = delete;
269 };
270 VTK_ABI_NAMESPACE_END
271 #endif
std::map< std::string, VarType > InquireVariablesType
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
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:45
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
virtual vtkMTimeType GetMTime()
Return this object's modified time.
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:177
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:55
Represents and manipulates a collection of data arrays.
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.