VTK  9.3.1
vtkXMLReader.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
15 #ifndef vtkXMLReader_h
16 #define vtkXMLReader_h
17 
18 #include "vtkAlgorithm.h"
19 #include "vtkIOXMLModule.h" // For export macro
20 #include "vtkSmartPointer.h" // for vtkSmartPointer.
21 
22 #include <string> // for std::string
23 
24 VTK_ABI_NAMESPACE_BEGIN
25 class vtkAbstractArray;
26 class vtkCallbackCommand;
27 class vtkCommand;
28 class vtkDataArray;
30 class vtkDataSet;
32 class vtkXMLDataElement;
33 class vtkXMLDataParser;
35 class vtkInformation;
36 class vtkStringArray;
37 
38 class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
39 {
40 public:
41  vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
44  enum FieldType
45  {
48  OTHER
49  };
50 
52 
55  vtkSetFilePathMacro(FileName);
56  vtkGetFilePathMacro(FileName);
58 
60 
63  vtkSetMacro(ReadFromInputString, vtkTypeBool);
64  vtkGetMacro(ReadFromInputString, vtkTypeBool);
65  vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
66  void SetInputString(const std::string& s) { this->InputString = s; }
68 
76  virtual int CanReadFile(VTK_FILEPATH const char* name);
77 
79 
82  vtkDataSet* GetOutputAsDataSet();
83  vtkDataSet* GetOutputAsDataSet(int index);
85 
87 
91  vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
92  vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
93  vtkGetObjectMacro(ColumnArraySelection, vtkDataArraySelection);
95 
97 
100  int GetNumberOfPointArrays();
101  int GetNumberOfCellArrays();
102  int GetNumberOfColumnArrays();
104 
106 
109  int GetNumberOfTimeDataArrays() const;
110  const char* GetTimeDataArray(int idx) const;
111  vtkGetObjectMacro(TimeDataStringArray, vtkStringArray);
113 
115 
121  vtkGetStringMacro(ActiveTimeDataArrayName);
122  vtkSetStringMacro(ActiveTimeDataArrayName);
124 
126 
130  const char* GetPointArrayName(int index);
131  const char* GetCellArrayName(int index);
132  const char* GetColumnArrayName(int index);
134 
136 
140  int GetPointArrayStatus(const char* name);
141  int GetCellArrayStatus(const char* name);
142  void SetPointArrayStatus(const char* name, int status);
143  void SetCellArrayStatus(const char* name, int status);
144  int GetColumnArrayStatus(const char* name);
145  void SetColumnArrayStatus(const char* name, int status);
147 
148  // For the specified port, copy the information this reader sets up in
149  // SetupOutputInformation to outInfo
150  virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
151 
153 
156  vtkSetMacro(TimeStep, int);
157  vtkGetMacro(TimeStep, int);
159 
160  vtkGetMacro(NumberOfTimeSteps, int);
162 
165  vtkGetVector2Macro(TimeStepRange, int);
166  vtkSetVector2Macro(TimeStepRange, int);
168 
173  vtkXMLDataParser* GetXMLParser() { return this->XMLParser; }
174 
176  vtkInformationVector* outputVector) override;
177 
179 
183  void SetReaderErrorObserver(vtkCommand*);
184  vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
186 
188 
192  void SetParserErrorObserver(vtkCommand*);
193  vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
195 
196 protected:
197  vtkXMLReader();
198  ~vtkXMLReader() override;
199 
201 
206  virtual int ReadXMLInformation();
207  virtual void ReadXMLData();
209 
213  virtual const char* GetDataSetName() = 0;
214 
218  virtual int CanReadFileVersion(int major, int minor);
219 
223  virtual void SetupEmptyOutput() = 0;
224 
228  virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
229 
233  virtual void SetupOutputData();
234 
239  virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
240 
245  virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
246 
252  int GetLocalDataType(vtkXMLDataElement* da, int datatype);
253 
259 
264  int CreateInformationKey(vtkXMLDataElement* eInfoKey, vtkInformation* info);
265 
270  bool ReadInformation(vtkXMLDataElement* infoRoot, vtkInformation* info);
271 
273 
276  virtual int OpenStream();
277  virtual void CloseStream();
278  virtual int OpenVTKFile();
279  virtual void CloseVTKFile();
280  virtual int OpenVTKString();
281  virtual void CloseVTKString();
282  virtual void CreateXMLParser();
283  virtual void DestroyXMLParser();
284  void SetupCompressor(const char* type);
285  int CanReadFileVersionString(const char* version);
287 
293  virtual int CanReadFileWithDataType(const char* dsname);
294 
298  vtkGetMacro(FileMajorVersion, int);
299 
303  vtkGetMacro(FileMinorVersion, int);
304 
306 
309  int IntersectExtents(int* extent1, int* extent2, int* result);
310  int Min(int a, int b);
311  int Max(int a, int b);
312  void ComputePointDimensions(int* extent, int* dimensions);
313  void ComputePointIncrements(int* extent, vtkIdType* increments);
314  void ComputeCellDimensions(int* extent, int* dimensions);
315  void ComputeCellIncrements(int* extent, vtkIdType* increments);
316  vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
317  void ReadAttributeIndices(vtkXMLDataElement* eDSA, vtkDataSetAttributes* dsa);
318  char** CreateStringArray(int numStrings);
319  void DestroyStringArray(int numStrings, char** strings);
321 
328  virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
329  vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
330 
339  virtual int ReadArrayTuples(vtkXMLDataElement* da, vtkIdType arrayTupleIndex,
340  vtkAbstractArray* array, vtkIdType startTupleIndex, vtkIdType numTuples,
341  FieldType type = OTHER);
342 
346  void SetDataArraySelections(vtkXMLDataElement* eDSA, vtkDataArraySelection* sel);
347 
348  int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
349  vtkInformationVector*(&infoVector));
350 
352 
355  int PointDataArrayIsEnabled(vtkXMLDataElement* ePDA);
356  int CellDataArrayIsEnabled(vtkXMLDataElement* eCDA);
358 
362  static void SelectionModifiedCallback(
363  vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
364 
370 
380  void MarkIdTypeArrays(vtkXMLDataElement* da);
381 
382  // The vtkXMLDataParser instance used to hide XML reading details.
384 
385  // The FieldData element representation.
387 
388  // The input file's name.
389  char* FileName;
390 
391  // The stream used to read the input.
392  istream* Stream;
393 
394  // Whether this object is reading from a string or a file.
395  // Default is 0: read from file.
397 
398  // The input string.
400 
401  // The array selections.
406 
412 
418 
419  // The observer to modify this object when the array selections are
420  // modified.
422 
423  // Whether there was an error reading the file in RequestInformation.
425 
426  // Whether there was an error reading the file in RequestData.
428 
429  // incrementally fine-tuned progress updates.
430  virtual void GetProgressRange(float* range);
431  virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
432  virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
433  virtual void UpdateProgressDiscrete(float progress);
434  float ProgressRange[2];
435 
436  virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
437  vtkInformationVector* outputVector);
438  virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
439  vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
440  {
441  return 1;
442  }
443  virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
444  vtkInformationVector* outputVector);
446 
447  // Whether there was an error reading the XML.
449 
450  // For structured data keep track of dimensions empty of cells. For
451  // unstructured data these are always zero. This is used to support
452  // 1-D and 2-D cell data.
453  int AxesEmpty[3];
454 
455  // The timestep currently being read.
456  int TimeStep;
459  void SetNumberOfTimeSteps(int num);
460  // buffer for reading timestep from the XML file the length is of
461  // NumberOfTimeSteps and therefore is always long enough
462  int* TimeSteps;
463  // Store the range of time steps
464  int TimeStepRange[2];
465 
466  // Now we need to save what was the last time read for each kind of
467  // data to avoid rereading it that is to say we need a var for
468  // e.g. PointData/CellData/Points/Cells...
469  // See SubClass for details with member vars like PointsTimeStep/PointsOffset
470 
471  // Helper function useful to know if a timestep is found in an array of timestep
472  static int IsTimeStepInArray(int timestep, int* timesteps, int length);
473 
474  vtkDataObject* GetCurrentOutput();
475  vtkInformation* GetCurrentOutputInformation();
476 
477  // Flag for whether DataProgressCallback should actually update
478  // progress.
480 
482 
483  void ReadFieldData();
484 
485 private:
486  // The stream used to read the input if it is in a file.
487  istream* FileStream;
488  // The stream used to read the input if it is in a string.
489  std::istringstream* StringStream;
490  int TimeStepWasReadOnce;
491 
492  int FileMajorVersion;
493  int FileMinorVersion;
494 
495  vtkDataObject* CurrentOutput;
496  vtkInformation* CurrentOutputInformation;
497 
498  vtkXMLReader(const vtkXMLReader&) = delete;
499  void operator=(const vtkXMLReader&) = delete;
500 
501  vtkCommand* ReaderErrorObserver;
502  vtkCommand* ParserErrorObserver;
503 };
504 
505 VTK_ABI_NAMESPACE_END
506 #endif
virtual void SqueezeOutputArrays(vtkDataObject *)
Give concrete classes an option to squeeze any output arrays at the end of RequestData.
Definition: vtkXMLReader.h:369
abstract base class for most VTK objects
Definition: vtkObject.h:51
Represents an XML element and those nested inside.
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:52
Abstract superclass for all arrays.
record modification and/or execution time
Definition: vtkTimeStamp.h:24
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:386
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:421
a vtkAbstractArray subclass for strings
int vtkIdType
Definition: vtkType.h:315
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
char * ActiveTimeDataArrayName
Name of the field-data array used to determine the time for the dataset being read.
Definition: vtkXMLReader.h:411
char * FileName
Definition: vtkXMLReader.h:389
int vtkTypeBool
Definition: vtkABI.h:64
virtual vtkTypeBool ProcessRequest(vtkInformation *request, vtkInformationVector **inInfo, vtkInformationVector *outInfo)
Upstream/Downstream requests form the generalized interface through which executives invoke a algorit...
vtkSmartPointer< vtkDataArray > TimeDataArray
Populated in ReadXMLInformation from the field data for the array chosen using ActiveTimeDataArrayNam...
Definition: vtkXMLReader.h:417
superclass for callback/observer methods
Definition: vtkCommand.h:383
supports function callbacks
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:51
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkTimeStamp ReadMTime
Definition: vtkXMLReader.h:445
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:402
vtkDataArraySelection * CellDataArraySelection
Definition: vtkXMLReader.h:403
Store on/off settings for data arrays, etc.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Setup the output's information.
Definition: vtkXMLReader.h:228
int NumberOfTimeSteps
Definition: vtkXMLReader.h:458
represent and manipulate attribute data in a dataset
vtkStringArray * TimeDataStringArray
Definition: vtkXMLReader.h:405
vtkTypeBool ReadFromInputString
Definition: vtkXMLReader.h:396
virtual void ConvertGhostLevelsToGhostType(FieldType, vtkAbstractArray *, vtkIdType, vtkIdType)
Definition: vtkXMLReader.h:481
std::string InputString
Definition: vtkXMLReader.h:399
#define VTK_FILEPATH
int InformationError
Definition: vtkXMLReader.h:424
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:150
vtkDataArraySelection * ColumnArraySelection
Definition: vtkXMLReader.h:404
Used by vtkXMLReader to parse VTK XML files.
virtual int RequestDataObject(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *vtkNotUsed(outputVector))
Definition: vtkXMLReader.h:438
istream * Stream
Definition: vtkXMLReader.h:392
vtkXMLDataParser * GetXMLParser()
Returns the internal XML parser.
Definition: vtkXMLReader.h:173
Store zero or more vtkInformation instances.
general representation of visualization data
Definition: vtkDataObject.h:54
vtkSmartPointer< vtkDataArray > CreateArray(const Ioss::Field &field)
Create an array for the given field.
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:383
Superclass for VTK's XML format readers.
Definition: vtkXMLReader.h:38
void SetInputString(const std::string &s)
Enable reading from an InputString instead of the default, a file.
Definition: vtkXMLReader.h:66