VTK  9.2.5
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 =========================================================================*/
46 #ifndef vtkXMLReader_h
47 #define vtkXMLReader_h
48 
49 #include "vtkAlgorithm.h"
50 #include "vtkIOXMLModule.h" // For export macro
51 #include "vtkSmartPointer.h" // for vtkSmartPointer.
52 
53 #include <string> // for std::string
54 
55 class vtkAbstractArray;
56 class vtkCallbackCommand;
57 class vtkCommand;
58 class vtkDataArray;
60 class vtkDataSet;
62 class vtkXMLDataElement;
63 class vtkXMLDataParser;
65 class vtkInformation;
66 class vtkStringArray;
67 
68 class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
69 {
70 public:
71  vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
72  void PrintSelf(ostream& os, vtkIndent indent) override;
73 
74  enum FieldType
75  {
78  OTHER
79  };
80 
82 
88 
90 
93  vtkSetMacro(ReadFromInputString, vtkTypeBool);
94  vtkGetMacro(ReadFromInputString, vtkTypeBool);
95  vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
96  void SetInputString(const std::string& s) { this->InputString = s; }
98 
106  virtual int CanReadFile(VTK_FILEPATH const char* name);
107 
109 
115 
117 
121  vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
122  vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
123  vtkGetObjectMacro(ColumnArraySelection, vtkDataArraySelection);
125 
127 
134 
136 
140  const char* GetTimeDataArray(int idx) const;
141  vtkGetObjectMacro(TimeDataStringArray, vtkStringArray);
143 
145 
151  vtkGetStringMacro(ActiveTimeDataArrayName);
152  vtkSetStringMacro(ActiveTimeDataArrayName);
154 
156 
160  const char* GetPointArrayName(int index);
161  const char* GetCellArrayName(int index);
162  const char* GetColumnArrayName(int index);
164 
166 
170  int GetPointArrayStatus(const char* name);
171  int GetCellArrayStatus(const char* name);
172  void SetPointArrayStatus(const char* name, int status);
173  void SetCellArrayStatus(const char* name, int status);
174  int GetColumnArrayStatus(const char* name);
175  void SetColumnArrayStatus(const char* name, int status);
177 
178  // For the specified port, copy the information this reader sets up in
179  // SetupOutputInformation to outInfo
180  virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
181 
183 
186  vtkSetMacro(TimeStep, int);
187  vtkGetMacro(TimeStep, int);
189 
190  vtkGetMacro(NumberOfTimeSteps, int);
192 
195  vtkGetVector2Macro(TimeStepRange, int);
196  vtkSetVector2Macro(TimeStepRange, int);
198 
203  vtkXMLDataParser* GetXMLParser() { return this->XMLParser; }
204 
206  vtkInformationVector* outputVector) override;
207 
209 
214  vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
216 
218 
223  vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
225 
226 protected:
228  ~vtkXMLReader() override;
229 
230  // Pipeline execution methods to be defined by subclass. Called by
231  // corresponding RequestData methods after appropriate setup has been
232  // done.
233  virtual int ReadXMLInformation();
234  virtual void ReadXMLData();
235 
236  // Get the name of the data set being read.
237  virtual const char* GetDataSetName() = 0;
238 
239  // Test if the reader can read a file with the given version number.
240  virtual int CanReadFileVersion(int major, int minor);
241 
242  // Setup the output with no data available. Used in error cases.
243  virtual void SetupEmptyOutput() = 0;
244 
245  // Setup the output's information.
246  virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
247 
248  // Setup the output's data with allocation.
249  virtual void SetupOutputData();
250 
251  // Read the primary element from the file. This is the element
252  // whose name is the value returned by GetDataSetName().
253  virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
254 
255  // Read the top-level element from the file. This is always the
256  // VTKFile element.
257  virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
258 
264  int GetLocalDataType(vtkXMLDataElement* da, int datatype);
265 
266  // Create a vtkAbstractArray from its cooresponding XML representation.
267  // Does not allocate.
269 
270  // Create a vtkInformationKey from its corresponding XML representation.
271  // Stores it in the instance of vtkInformationProvided. Does not allocate.
273 
274  // Populates the info object with the InformationKey children in infoRoot.
275  // Returns false if errors occur.
277 
278  // Internal utility methods.
279  virtual int OpenStream();
280  virtual void CloseStream();
281  virtual int OpenVTKFile();
282  virtual void CloseVTKFile();
283  virtual int OpenVTKString();
284  virtual void CloseVTKString();
285  virtual void CreateXMLParser();
286  virtual void DestroyXMLParser();
287  void SetupCompressor(const char* type);
289 
295  virtual int CanReadFileWithDataType(const char* dsname);
296 
297  // Returns the major version for the file being read. -1 when invalid.
298  vtkGetMacro(FileMajorVersion, int);
299 
300  // Returns the minor version for the file being read. -1 when invalid.
301  vtkGetMacro(FileMinorVersion, int);
302 
303  // Utility methods for subclasses.
304  int IntersectExtents(int* extent1, int* extent2, int* result);
305  int Min(int a, int b);
306  int Max(int a, int b);
307  void ComputePointDimensions(int* extent, int* dimensions);
308  void ComputePointIncrements(int* extent, vtkIdType* increments);
309  void ComputeCellDimensions(int* extent, int* dimensions);
310  void ComputeCellIncrements(int* extent, vtkIdType* increments);
311  vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
313  char** CreateStringArray(int numStrings);
314  void DestroyStringArray(int numStrings, char** strings);
315 
316  // Read an Array values starting at the given index and up to numValues.
317  // This method assumes that the array is of correct size to
318  // accommodate all numValues values. arrayIndex is the value index at which the read
319  // values will be put in the array.
320  virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
321  vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
322 
323  // Setup the data array selections for the input's set of arrays.
325 
326  int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
327  vtkInformationVector*(&infoVector));
328 
329  // Check whether the given array element is an enabled array.
332 
333  // Callback registered with the SelectionObserver.
335  vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
336 
337  // Give concrete classes an option to squeeze any output arrays
338  // at the end of RequestData.
340 
351 
352  // The vtkXMLDataParser instance used to hide XML reading details.
354 
355  // The FieldData element representation.
357 
358  // The input file's name.
359  char* FileName;
360 
361  // The stream used to read the input.
362  istream* Stream;
363 
364  // Whether this object is reading from a string or a file.
365  // Default is 0: read from file.
367 
368  // The input string.
370 
371  // The array selections.
376 
382 
388 
389  // The observer to modify this object when the array selections are
390  // modified.
392 
393  // Whether there was an error reading the file in RequestInformation.
395 
396  // Whether there was an error reading the file in RequestData.
398 
399  // incrementally fine-tuned progress updates.
400  virtual void GetProgressRange(float* range);
401  virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
402  virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
403  virtual void UpdateProgressDiscrete(float progress);
404  float ProgressRange[2];
405 
406  virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
407  vtkInformationVector* outputVector);
408  virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
409  vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
410  {
411  return 1;
412  }
413  virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
414  vtkInformationVector* outputVector);
416 
417  // Whether there was an error reading the XML.
419 
420  // For structured data keep track of dimensions empty of cells. For
421  // unstructured data these are always zero. This is used to support
422  // 1-D and 2-D cell data.
423  int AxesEmpty[3];
424 
425  // The timestep currently being read.
426  int TimeStep;
429  void SetNumberOfTimeSteps(int num);
430  // buffer for reading timestep from the XML file the length is of
431  // NumberOfTimeSteps and therefore is always long enough
432  int* TimeSteps;
433  // Store the range of time steps
434  int TimeStepRange[2];
435 
436  // Now we need to save what was the last time read for each kind of
437  // data to avoid rereading it that is to say we need a var for
438  // e.g. PointData/CellData/Points/Cells...
439  // See SubClass for details with member vars like PointsTimeStep/PointsOffset
440 
441  // Helper function useful to know if a timestep is found in an array of timestep
442  static int IsTimeStepInArray(int timestep, int* timesteps, int length);
443 
446 
447  // Flag for whether DataProgressCallback should actually update
448  // progress.
450 
452 
454 
455 private:
456  // The stream used to read the input if it is in a file.
457  istream* FileStream;
458  // The stream used to read the input if it is in a string.
459  std::istringstream* StringStream;
460  int TimeStepWasReadOnce;
461 
462  int FileMajorVersion;
463  int FileMinorVersion;
464 
465  vtkDataObject* CurrentOutput;
466  vtkInformation* CurrentOutputInformation;
467 
468 private:
469  vtkXMLReader(const vtkXMLReader&) = delete;
470  void operator=(const vtkXMLReader&) = delete;
471 
472  vtkCommand* ReaderErrorObserver;
473  vtkCommand* ParserErrorObserver;
474 };
475 
476 #endif
Abstract superclass for all arrays.
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:122
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:165
general representation of visualization data
represent and manipulate attribute data in a dataset
abstract class to specify dataset behavior
Definition: vtkDataSet.h:172
a simple class to control print indentation
Definition: vtkIndent.h:119
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:82
a vtkAbstractArray subclass for strings
record modification and/or execution time
Definition: vtkTimeStamp.h:55
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:69
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:356
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:391
virtual void SetProgressRange(const float range[2], int curStep, int numSteps)
virtual void ConvertGhostLevelsToGhostType(FieldType, vtkAbstractArray *, vtkIdType, vtkIdType)
Definition: vtkXMLReader.h:451
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:428
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
istream * Stream
Definition: vtkXMLReader.h:362
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:203
vtkDataArraySelection * CellDataArraySelection
Definition: vtkXMLReader.h:373
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:339
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:387
vtkAbstractArray * CreateArray(vtkXMLDataElement *da)
virtual void CloseStream()
int CanReadFileVersionString(const char *version)
void ReadFieldData()
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:246
vtkIdType GetStartTuple(int *extent, vtkIdType *increments, int i, int j, int k)
virtual const char * GetDataSetName()=0
vtkTypeBool ReadFromInputString
Definition: vtkXMLReader.h:366
void SetupCompressor(const char *type)
vtkDataArraySelection * ColumnArraySelection
Definition: vtkXMLReader.h:374
int InformationError
Definition: vtkXMLReader.h:394
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:353
void SetInputString(const std::string &s)
Enable reading from an InputString instead of the default, a file.
Definition: vtkXMLReader.h:96
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:415
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:408
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:381
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:359
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:375
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:369
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:372
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:180
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