VTK  9.2.6
vtkXMLReader.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkXMLReader.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
36 #ifndef vtkXMLReader_h
37 #define vtkXMLReader_h
38 
39 #include "vtkAlgorithm.h"
40 #include "vtkIOXMLModule.h" // For export macro
41 #include "vtkSmartPointer.h" // for vtkSmartPointer.
42 
43 #include <string> // for std::string
44 
45 class vtkAbstractArray;
46 class vtkCallbackCommand;
47 class vtkCommand;
48 class vtkDataArray;
50 class vtkDataSet;
52 class vtkXMLDataElement;
53 class vtkXMLDataParser;
55 class vtkInformation;
56 class vtkStringArray;
57 
58 class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
59 {
60 public:
61  vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
62  void PrintSelf(ostream& os, vtkIndent indent) override;
63 
64  enum FieldType
65  {
68  OTHER
69  };
70 
72 
78 
80 
83  vtkSetMacro(ReadFromInputString, vtkTypeBool);
84  vtkGetMacro(ReadFromInputString, vtkTypeBool);
85  vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
86  void SetInputString(const std::string& s) { this->InputString = s; }
88 
96  virtual int CanReadFile(VTK_FILEPATH const char* name);
97 
99 
105 
107 
111  vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
112  vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
113  vtkGetObjectMacro(ColumnArraySelection, vtkDataArraySelection);
115 
117 
124 
126 
130  const char* GetTimeDataArray(int idx) const;
131  vtkGetObjectMacro(TimeDataStringArray, vtkStringArray);
133 
135 
141  vtkGetStringMacro(ActiveTimeDataArrayName);
142  vtkSetStringMacro(ActiveTimeDataArrayName);
144 
146 
150  const char* GetPointArrayName(int index);
151  const char* GetCellArrayName(int index);
152  const char* GetColumnArrayName(int index);
154 
156 
160  int GetPointArrayStatus(const char* name);
161  int GetCellArrayStatus(const char* name);
162  void SetPointArrayStatus(const char* name, int status);
163  void SetCellArrayStatus(const char* name, int status);
164  int GetColumnArrayStatus(const char* name);
165  void SetColumnArrayStatus(const char* name, int status);
167 
168  // For the specified port, copy the information this reader sets up in
169  // SetupOutputInformation to outInfo
170  virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
171 
173 
176  vtkSetMacro(TimeStep, int);
177  vtkGetMacro(TimeStep, int);
179 
180  vtkGetMacro(NumberOfTimeSteps, int);
182 
185  vtkGetVector2Macro(TimeStepRange, int);
186  vtkSetVector2Macro(TimeStepRange, int);
188 
193  vtkXMLDataParser* GetXMLParser() { return this->XMLParser; }
194 
196  vtkInformationVector* outputVector) override;
197 
199 
204  vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
206 
208 
213  vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
215 
216 protected:
218  ~vtkXMLReader() override;
219 
220  // Pipeline execution methods to be defined by subclass. Called by
221  // corresponding RequestData methods after appropriate setup has been
222  // done.
223  virtual int ReadXMLInformation();
224  virtual void ReadXMLData();
225 
226  // Get the name of the data set being read.
227  virtual const char* GetDataSetName() = 0;
228 
229  // Test if the reader can read a file with the given version number.
230  virtual int CanReadFileVersion(int major, int minor);
231 
232  // Setup the output with no data available. Used in error cases.
233  virtual void SetupEmptyOutput() = 0;
234 
235  // Setup the output's information.
236  virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
237 
238  // Setup the output's data with allocation.
239  virtual void SetupOutputData();
240 
241  // Read the primary element from the file. This is the element
242  // whose name is the value returned by GetDataSetName().
243  virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
244 
245  // Read the top-level element from the file. This is always the
246  // VTKFile element.
247  virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
248 
254  int GetLocalDataType(vtkXMLDataElement* da, int datatype);
255 
256  // Create a vtkAbstractArray from its cooresponding XML representation.
257  // Does not allocate.
259 
260  // Create a vtkInformationKey from its corresponding XML representation.
261  // Stores it in the instance of vtkInformationProvided. Does not allocate.
263 
264  // Populates the info object with the InformationKey children in infoRoot.
265  // Returns false if errors occur.
267 
268  // Internal utility methods.
269  virtual int OpenStream();
270  virtual void CloseStream();
271  virtual int OpenVTKFile();
272  virtual void CloseVTKFile();
273  virtual int OpenVTKString();
274  virtual void CloseVTKString();
275  virtual void CreateXMLParser();
276  virtual void DestroyXMLParser();
277  void SetupCompressor(const char* type);
279 
285  virtual int CanReadFileWithDataType(const char* dsname);
286 
287  // Returns the major version for the file being read. -1 when invalid.
288  vtkGetMacro(FileMajorVersion, int);
289 
290  // Returns the minor version for the file being read. -1 when invalid.
291  vtkGetMacro(FileMinorVersion, int);
292 
293  // Utility methods for subclasses.
294  int IntersectExtents(int* extent1, int* extent2, int* result);
295  int Min(int a, int b);
296  int Max(int a, int b);
297  void ComputePointDimensions(int* extent, int* dimensions);
298  void ComputePointIncrements(int* extent, vtkIdType* increments);
299  void ComputeCellDimensions(int* extent, int* dimensions);
300  void ComputeCellIncrements(int* extent, vtkIdType* increments);
301  vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
303  char** CreateStringArray(int numStrings);
304  void DestroyStringArray(int numStrings, char** strings);
305 
306  // Read an Array values starting at the given index and up to numValues.
307  // This method assumes that the array is of correct size to
308  // accommodate all numValues values. arrayIndex is the value index at which the read
309  // values will be put in the array.
310  virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
311  vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
312 
313  // Setup the data array selections for the input's set of arrays.
315 
316  int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
317  vtkInformationVector*(&infoVector));
318 
319  // Check whether the given array element is an enabled array.
322 
323  // Callback registered with the SelectionObserver.
325  vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
326 
327  // Give concrete classes an option to squeeze any output arrays
328  // at the end of RequestData.
330 
341 
342  // The vtkXMLDataParser instance used to hide XML reading details.
344 
345  // The FieldData element representation.
347 
348  // The input file's name.
349  char* FileName;
350 
351  // The stream used to read the input.
352  istream* Stream;
353 
354  // Whether this object is reading from a string or a file.
355  // Default is 0: read from file.
357 
358  // The input string.
360 
361  // The array selections.
366 
372 
378 
379  // The observer to modify this object when the array selections are
380  // modified.
382 
383  // Whether there was an error reading the file in RequestInformation.
385 
386  // Whether there was an error reading the file in RequestData.
388 
389  // incrementally fine-tuned progress updates.
390  virtual void GetProgressRange(float* range);
391  virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
392  virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
393  virtual void UpdateProgressDiscrete(float progress);
394  float ProgressRange[2];
395 
396  virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
397  vtkInformationVector* outputVector);
398  virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
399  vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
400  {
401  return 1;
402  }
403  virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
404  vtkInformationVector* outputVector);
406 
407  // Whether there was an error reading the XML.
409 
410  // For structured data keep track of dimensions empty of cells. For
411  // unstructured data these are always zero. This is used to support
412  // 1-D and 2-D cell data.
413  int AxesEmpty[3];
414 
415  // The timestep currently being read.
416  int TimeStep;
419  void SetNumberOfTimeSteps(int num);
420  // buffer for reading timestep from the XML file the length is of
421  // NumberOfTimeSteps and therefore is always long enough
422  int* TimeSteps;
423  // Store the range of time steps
424  int TimeStepRange[2];
425 
426  // Now we need to save what was the last time read for each kind of
427  // data to avoid rereading it that is to say we need a var for
428  // e.g. PointData/CellData/Points/Cells...
429  // See SubClass for details with member vars like PointsTimeStep/PointsOffset
430 
431  // Helper function useful to know if a timestep is found in an array of timestep
432  static int IsTimeStepInArray(int timestep, int* timesteps, int length);
433 
436 
437  // Flag for whether DataProgressCallback should actually update
438  // progress.
440 
442 
444 
445 private:
446  // The stream used to read the input if it is in a file.
447  istream* FileStream;
448  // The stream used to read the input if it is in a string.
449  std::istringstream* StringStream;
450  int TimeStepWasReadOnce;
451 
452  int FileMajorVersion;
453  int FileMinorVersion;
454 
455  vtkDataObject* CurrentOutput;
456  vtkInformation* CurrentOutputInformation;
457 
458 private:
459  vtkXMLReader(const vtkXMLReader&) = delete;
460  void operator=(const vtkXMLReader&) = delete;
461 
462  vtkCommand* ReaderErrorObserver;
463  vtkCommand* ParserErrorObserver;
464 };
465 
466 #endif
Abstract superclass for all arrays.
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:72
supports function callbacks
superclass for callback/observer methods
Definition: vtkCommand.h:395
Store on/off settings for data arrays, etc.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:65
general representation of visualization data
Definition: vtkDataObject.h:75
represent and manipulate attribute data in a dataset
abstract class to specify dataset behavior
Definition: vtkDataSet.h:72
a simple class to control print indentation
Definition: vtkIndent.h:49
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:72
a vtkAbstractArray subclass for strings
record modification and/or execution time
Definition: vtkTimeStamp.h:45
Represents an XML element and those nested inside.
Used by vtkXMLReader to parse VTK XML files.
Superclass for VTK's XML format readers.
Definition: vtkXMLReader.h:59
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:346
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:381
virtual void SetProgressRange(const float range[2], int curStep, int numSteps)
virtual void ConvertGhostLevelsToGhostType(FieldType, vtkAbstractArray *, vtkIdType, vtkIdType)
Definition: vtkXMLReader.h:441
int GetColumnArrayStatus(const char *name)
Get/Set whether the point, cell, column or time array with the given name is to be read.
virtual int CanReadFileVersion(int major, int minor)
virtual void GetProgressRange(float *range)
virtual void DestroyXMLParser()
int NumberOfTimeSteps
Definition: vtkXMLReader.h:418
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
istream * Stream
Definition: vtkXMLReader.h:352
void SetColumnArrayStatus(const char *name, int status)
Get/Set whether the point, cell, column or time array with the given name is to be read.
virtual int ReadArrayValues(vtkXMLDataElement *da, vtkIdType arrayIndex, vtkAbstractArray *array, vtkIdType startIndex, vtkIdType numValues, FieldType type=OTHER)
vtkDataSet * GetOutputAsDataSet(int index)
Get the output as a vtkDataSet pointer.
void SetReaderErrorObserver(vtkCommand *)
Set/get the ErrorObserver for the internal reader This is useful for applications that want to catch ...
vtkXMLDataParser * GetXMLParser()
Returns the internal XML parser.
Definition: vtkXMLReader.h:193
vtkDataArraySelection * CellDataArraySelection
Definition: vtkXMLReader.h:363
virtual void SetupOutputData()
void ComputeCellIncrements(int *extent, vtkIdType *increments)
int CreateInformationKey(vtkXMLDataElement *eInfoKey, vtkInformation *info)
void SetDataArraySelections(vtkXMLDataElement *eDSA, vtkDataArraySelection *sel)
void SetParserErrorObserver(vtkCommand *)
Set/get the ErrorObserver for the internal xml parser This is useful for applications that want to ca...
virtual void SetupEmptyOutput()=0
int GetNumberOfTimeDataArrays() const
Getters for time data array candidates.
virtual void SqueezeOutputArrays(vtkDataObject *)
Definition: vtkXMLReader.h:329
vtkDataSet * GetOutputAsDataSet()
Get the output as a vtkDataSet pointer.
int GetNumberOfPointArrays()
Get the number of point, cell or column arrays available in the input.
int Max(int a, int b)
virtual void CreateXMLParser()
vtkSmartPointer< vtkDataArray > TimeDataArray
Populated in ReadXMLInformation from the field data for the array chosen using ActiveTimeDataArrayNam...
Definition: vtkXMLReader.h:377
vtkAbstractArray * CreateArray(vtkXMLDataElement *da)
virtual void CloseStream()
int CanReadFileVersionString(const char *version)
void ReadFieldData()
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:236
vtkIdType GetStartTuple(int *extent, vtkIdType *increments, int i, int j, int k)
virtual const char * GetDataSetName()=0
vtkTypeBool ReadFromInputString
Definition: vtkXMLReader.h:356
void SetupCompressor(const char *type)
vtkDataArraySelection * ColumnArraySelection
Definition: vtkXMLReader.h:364
int InformationError
Definition: vtkXMLReader.h:384
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:343
void SetInputString(const std::string &s)
Enable reading from an InputString instead of the default, a file.
Definition: vtkXMLReader.h:86
void ComputePointIncrements(int *extent, vtkIdType *increments)
virtual int ReadXMLInformation()
int GetNumberOfColumnArrays()
Get the number of point, cell or column arrays available in the input.
void ReadAttributeIndices(vtkXMLDataElement *eDSA, vtkDataSetAttributes *dsa)
int PointDataArrayIsEnabled(vtkXMLDataElement *ePDA)
virtual void CloseVTKFile()
virtual int OpenVTKFile()
vtkTimeStamp ReadMTime
Definition: vtkXMLReader.h:405
void ComputeCellDimensions(int *extent, int *dimensions)
virtual int CanReadFile(VTK_FILEPATH const char *name)
Test whether the file (type) with the given name can be read by this reader.
void SetNumberOfTimeSteps(int num)
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
static void SelectionModifiedCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
static int IsTimeStepInArray(int timestep, int *timesteps, int length)
char ** CreateStringArray(int numStrings)
virtual int RequestDataObject(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *vtkNotUsed(outputVector))
Definition: vtkXMLReader.h:398
void ComputePointDimensions(int *extent, int *dimensions)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int GetNumberOfCellArrays()
Get the number of point, cell or column arrays available in the input.
void MarkIdTypeArrays(vtkXMLDataElement *da)
XML files have not consistently saved out adequate meta-data in past to correctly create vtkIdTypeArr...
~vtkXMLReader() override
virtual int CanReadFileWithDataType(const char *dsname)
This method is used by CanReadFile() to check if the reader can read an XML with the primary element ...
const char * GetCellArrayName(int index)
Get the name of the point, cell, column or time array with the given index in the input.
int IntersectExtents(int *extent1, int *extent2, int *result)
char * ActiveTimeDataArrayName
Name of the field-data array used to determine the time for the dataset being read.
Definition: vtkXMLReader.h:371
virtual int ReadVTKFile(vtkXMLDataElement *eVTKFile)
virtual int OpenVTKString()
virtual int ReadPrimaryElement(vtkXMLDataElement *ePrimary)
vtkGetFilePathMacro(FileName)
Get/Set the name of the input file.
const char * GetPointArrayName(int index)
Get the name of the point, cell, column or time array with the given index in the input.
const char * GetTimeDataArray(int idx) const
Getters for time data array candidates.
int GetLocalDataType(vtkXMLDataElement *da, int datatype)
If the IdType argument is present in the provided XMLDataElement and the provided dataType has the sa...
bool ReadInformation(vtkXMLDataElement *infoRoot, vtkInformation *info)
vtkInformation * GetCurrentOutputInformation()
vtkTypeBool ProcessRequest(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Upstream/Downstream requests form the generalized interface through which executives invoke a algorit...
int GetCellArrayStatus(const char *name)
Get/Set whether the point, cell, column or time array with the given name is to be read.
vtkSetFilePathMacro(FileName)
Get/Set the name of the input file.
int GetPointArrayStatus(const char *name)
Get/Set whether the point, cell, column or time array with the given name is to be read.
char * FileName
Definition: vtkXMLReader.h:349
const char * GetColumnArrayName(int index)
Get the name of the point, cell, column or time array with the given index in the input.
virtual void UpdateProgressDiscrete(float progress)
vtkDataObject * GetCurrentOutput()
virtual void ReadXMLData()
virtual int OpenStream()
vtkStringArray * TimeDataStringArray
Definition: vtkXMLReader.h:365
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
virtual void SetProgressRange(const float range[2], int curStep, const float *fractions)
void DestroyStringArray(int numStrings, char **strings)
void SetCellArrayStatus(const char *name, int status)
Get/Set whether the point, cell, column or time array with the given name is to be read.
virtual void CloseVTKString()
void SetPointArrayStatus(const char *name, int status)
Get/Set whether the point, cell, column or time array with the given name is to be read.
std::string InputString
Definition: vtkXMLReader.h:359
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:362
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:170
int SetFieldDataInfo(vtkXMLDataElement *eDSA, int association, vtkIdType numTuples, vtkInformationVector *(&infoVector))
int Min(int a, int b)
@ info
Definition: vtkX3D.h:382
@ length
Definition: vtkX3D.h:399
@ port
Definition: vtkX3D.h:453
@ range
Definition: vtkX3D.h:244
@ extent
Definition: vtkX3D.h:351
@ type
Definition: vtkX3D.h:522
@ version
Definition: vtkX3D.h:532
@ name
Definition: vtkX3D.h:225
@ index
Definition: vtkX3D.h:252
@ progress
Definition: vtkX3D.h:458
@ string
Definition: vtkX3D.h:496
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:332
#define VTK_FILEPATH