VTK  9.0.1
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 =========================================================================*/
24 #ifndef vtkXMLReader_h
25 #define vtkXMLReader_h
26 
27 #include "vtkAlgorithm.h"
28 #include "vtkIOXMLModule.h" // For export macro
29 
30 #include <string> // for std::string
31 
32 class vtkAbstractArray;
33 class vtkCallbackCommand;
35 class vtkDataSet;
37 class vtkXMLDataElement;
38 class vtkXMLDataParser;
40 class vtkInformation;
41 class vtkCommand;
42 
43 class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
44 {
45 public:
46  vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
47  void PrintSelf(ostream& os, vtkIndent indent) override;
48 
49  enum FieldType
50  {
53  OTHER
54  };
55 
57 
60  vtkSetStringMacro(FileName);
61  vtkGetStringMacro(FileName);
63 
65 
68  vtkSetMacro(ReadFromInputString, vtkTypeBool);
69  vtkGetMacro(ReadFromInputString, vtkTypeBool);
70  vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
71  void SetInputString(const std::string& s) { this->InputString = s; }
73 
81  virtual int CanReadFile(const char* name);
82 
84 
90 
92 
96  vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
97  vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
98  vtkGetObjectMacro(ColumnArraySelection, vtkDataArraySelection);
100 
102 
109 
111 
115  const char* GetPointArrayName(int index);
116  const char* GetCellArrayName(int index);
117  const char* GetColumnArrayName(int index);
119 
121 
125  int GetPointArrayStatus(const char* name);
126  int GetCellArrayStatus(const char* name);
127  void SetPointArrayStatus(const char* name, int status);
128  void SetCellArrayStatus(const char* name, int status);
129  int GetColumnArrayStatus(const char* name);
130  void SetColumnArrayStatus(const char* name, int status);
132 
133  // For the specified port, copy the information this reader sets up in
134  // SetupOutputInformation to outInfo
135  virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
136 
138 
141  vtkSetMacro(TimeStep, int);
142  vtkGetMacro(TimeStep, int);
144 
145  vtkGetMacro(NumberOfTimeSteps, int);
147 
150  vtkGetVector2Macro(TimeStepRange, int);
151  vtkSetVector2Macro(TimeStepRange, int);
153 
158  vtkXMLDataParser* GetXMLParser() { return this->XMLParser; }
159 
161  vtkInformationVector* outputVector) override;
162 
164 
169  vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
171 
173 
178  vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
180 
181 protected:
183  ~vtkXMLReader() override;
184 
185  // Pipeline execution methods to be defined by subclass. Called by
186  // corresponding RequestData methods after appropriate setup has been
187  // done.
188  virtual int ReadXMLInformation();
189  virtual void ReadXMLData();
190 
191  // Get the name of the data set being read.
192  virtual const char* GetDataSetName() = 0;
193 
194  // Test if the reader can read a file with the given version number.
195  virtual int CanReadFileVersion(int major, int minor);
196 
197  // Setup the output with no data available. Used in error cases.
198  virtual void SetupEmptyOutput() = 0;
199 
200  // Setup the output's information.
201  virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
202 
203  // Setup the output's data with allocation.
204  virtual void SetupOutputData();
205 
206  // Read the primary element from the file. This is the element
207  // whose name is the value returned by GetDataSetName().
208  virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
209 
210  // Read the top-level element from the file. This is always the
211  // VTKFile element.
212  virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
213 
219  int GetLocalDataType(vtkXMLDataElement* da, int datatype);
220 
221  // Create a vtkAbstractArray from its cooresponding XML representation.
222  // Does not allocate.
224 
225  // Create a vtkInformationKey from its corresponding XML representation.
226  // Stores it in the instance of vtkInformationProvided. Does not allocate.
228 
229  // Populates the info object with the InformationKey children in infoRoot.
230  // Returns false if errors occur.
232 
233  // Internal utility methods.
234  virtual int OpenStream();
235  virtual void CloseStream();
236  virtual int OpenVTKFile();
237  virtual void CloseVTKFile();
238  virtual int OpenVTKString();
239  virtual void CloseVTKString();
240  virtual void CreateXMLParser();
241  virtual void DestroyXMLParser();
242  void SetupCompressor(const char* type);
244 
250  virtual int CanReadFileWithDataType(const char* dsname);
251 
252  // Returns the major version for the file being read. -1 when invalid.
253  vtkGetMacro(FileMajorVersion, int);
254 
255  // Returns the minor version for the file being read. -1 when invalid.
256  vtkGetMacro(FileMinorVersion, int);
257 
258  // Utility methods for subclasses.
259  int IntersectExtents(int* extent1, int* extent2, int* result);
260  int Min(int a, int b);
261  int Max(int a, int b);
262  void ComputePointDimensions(int* extent, int* dimensions);
263  void ComputePointIncrements(int* extent, vtkIdType* increments);
264  void ComputeCellDimensions(int* extent, int* dimensions);
265  void ComputeCellIncrements(int* extent, vtkIdType* increments);
266  vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
268  char** CreateStringArray(int numStrings);
269  void DestroyStringArray(int numStrings, char** strings);
270 
271  // Read an Array values starting at the given index and up to numValues.
272  // This method assumes that the array is of correct size to
273  // accommodate all numValues values. arrayIndex is the value index at which the read
274  // values will be put in the array.
275  virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
276  vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
277 
278  // Setup the data array selections for the input's set of arrays.
280 
281  int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
282  vtkInformationVector*(&infoVector));
283 
284  // Check whether the given array element is an enabled array.
287 
288  // Callback registered with the SelectionObserver.
290  vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
291 
292  // Give concrete classes an option to squeeze any output arrays
293  // at the end of RequestData.
295 
296  // The vtkXMLDataParser instance used to hide XML reading details.
298 
299  // The FieldData element representation.
301 
302  // The input file's name.
303  char* FileName;
304 
305  // The stream used to read the input.
306  istream* Stream;
307 
308  // Whether this object is reading from a string or a file.
309  // Default is 0: read from file.
311 
312  // The input string.
314 
315  // The array selections.
319 
320  // The observer to modify this object when the array selections are
321  // modified.
323 
324  // Whether there was an error reading the file in RequestInformation.
326 
327  // Whether there was an error reading the file in RequestData.
329 
330  // incrementally fine-tuned progress updates.
331  virtual void GetProgressRange(float* range);
332  virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
333  virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
334  virtual void UpdateProgressDiscrete(float progress);
335  float ProgressRange[2];
336 
337  virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
338  vtkInformationVector* outputVector);
339  virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
340  vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
341  {
342  return 1;
343  }
344  virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
345  vtkInformationVector* outputVector);
347 
348  // Whether there was an error reading the XML.
350 
351  // For structured data keep track of dimensions empty of cells. For
352  // unstructured data these are always zero. This is used to support
353  // 1-D and 2-D cell data.
354  int AxesEmpty[3];
355 
356  // The timestep currently being read.
357  int TimeStep;
360  void SetNumberOfTimeSteps(int num);
361  // buffer for reading timestep from the XML file the length is of
362  // NumberOfTimeSteps and therefore is always long enough
363  int* TimeSteps;
364  // Store the range of time steps
365  int TimeStepRange[2];
366 
367  // Now we need to save what was the last time read for each kind of
368  // data to avoid rereading it that is to say we need a var for
369  // e.g. PointData/CellData/Points/Cells...
370  // See SubClass for details with member vars like PointsTimeStep/PointsOffset
371 
372  // Helper function useful to know if a timestep is found in an array of timestep
373  static int IsTimeStepInArray(int timestep, int* timesteps, int length);
374 
377 
378  // Flag for whether DataProgressCallback should actually update
379  // progress.
381 
383 
385 
386 private:
387  // The stream used to read the input if it is in a file.
388  istream* FileStream;
389  // The stream used to read the input if it is in a string.
390  std::istringstream* StringStream;
391  int TimeStepWasReadOnce;
392 
393  int FileMajorVersion;
394  int FileMinorVersion;
395 
396  vtkDataObject* CurrentOutput;
397  vtkInformation* CurrentOutputInformation;
398 
399 private:
400  vtkXMLReader(const vtkXMLReader&) = delete;
401  void operator=(const vtkXMLReader&) = delete;
402 
403  vtkCommand* ReaderErrorObserver;
404  vtkCommand* ParserErrorObserver;
405 };
406 
407 #endif
Abstract superclass for all arrays.
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:54
supports function callbacks
superclass for callback/observer methods
Definition: vtkCommand.h:378
Store on/off settings for data arrays for a vtkSource.
general representation of visualization data
Definition: vtkDataObject.h:60
represent and manipulate attribute data in a dataset
abstract class to specify dataset behavior
Definition: vtkDataSet.h:57
a simple class to control print indentation
Definition: vtkIndent.h:34
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:54
record modification and/or execution time
Definition: vtkTimeStamp.h:33
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:44
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:300
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:322
virtual void SetProgressRange(const float range[2], int curStep, int numSteps)
virtual void ConvertGhostLevelsToGhostType(FieldType, vtkAbstractArray *, vtkIdType, vtkIdType)
Definition: vtkXMLReader.h:382
int GetColumnArrayStatus(const char *name)
virtual int CanReadFileVersion(int major, int minor)
virtual void GetProgressRange(float *range)
virtual void DestroyXMLParser()
int NumberOfTimeSteps
Definition: vtkXMLReader.h:359
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
istream * Stream
Definition: vtkXMLReader.h:306
void SetColumnArrayStatus(const char *name, int status)
virtual int ReadArrayValues(vtkXMLDataElement *da, vtkIdType arrayIndex, vtkAbstractArray *array, vtkIdType startIndex, vtkIdType numValues, FieldType type=OTHER)
vtkDataSet * GetOutputAsDataSet(int index)
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:158
vtkDataArraySelection * CellDataArraySelection
Definition: vtkXMLReader.h:317
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
virtual void SqueezeOutputArrays(vtkDataObject *)
Definition: vtkXMLReader.h:294
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()
vtkAbstractArray * CreateArray(vtkXMLDataElement *da)
virtual void CloseStream()
int CanReadFileVersionString(const char *version)
void ReadFieldData()
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:201
vtkIdType GetStartTuple(int *extent, vtkIdType *increments, int i, int j, int k)
virtual const char * GetDataSetName()=0
vtkTypeBool ReadFromInputString
Definition: vtkXMLReader.h:310
void SetupCompressor(const char *type)
vtkDataArraySelection * ColumnArraySelection
Definition: vtkXMLReader.h:318
int InformationError
Definition: vtkXMLReader.h:325
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:297
void SetInputString(const std::string &s)
Definition: vtkXMLReader.h:71
void ComputePointIncrements(int *extent, vtkIdType *increments)
virtual int ReadXMLInformation()
int GetNumberOfColumnArrays()
void ReadAttributeIndices(vtkXMLDataElement *eDSA, vtkDataSetAttributes *dsa)
virtual int CanReadFile(const char *name)
Test whether the file (type) with the given name can be read by this reader.
int PointDataArrayIsEnabled(vtkXMLDataElement *ePDA)
virtual void CloseVTKFile()
virtual int OpenVTKFile()
vtkTimeStamp ReadMTime
Definition: vtkXMLReader.h:346
void ComputeCellDimensions(int *extent, int *dimensions)
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:339
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()
~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)
int IntersectExtents(int *extent1, int *extent2, int *result)
virtual int ReadVTKFile(vtkXMLDataElement *eVTKFile)
virtual int OpenVTKString()
virtual int ReadPrimaryElement(vtkXMLDataElement *ePrimary)
const char * GetPointArrayName(int index)
Get the name of the point, cell or column array with the given index in the input.
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)
int GetPointArrayStatus(const char *name)
Get/Set whether the point, cell or column array with the given name is to be read.
char * FileName
Definition: vtkXMLReader.h:303
const char * GetColumnArrayName(int index)
virtual void UpdateProgressDiscrete(float progress)
vtkDataObject * GetCurrentOutput()
virtual void ReadXMLData()
virtual int OpenStream()
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)
virtual void CloseVTKString()
void SetPointArrayStatus(const char *name, int status)
std::string InputString
Definition: vtkXMLReader.h:313
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:316
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:135
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:338