VTK
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 "vtkIOXMLModule.h" // For export macro
28 #include "vtkAlgorithm.h"
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 
56 
58 
61  vtkSetStringMacro(FileName);
62  vtkGetStringMacro(FileName);
64 
66 
69  vtkSetMacro(ReadFromInputString, vtkTypeBool);
70  vtkGetMacro(ReadFromInputString, vtkTypeBool);
71  vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
72  void SetInputString(const std::string& s) { this->InputString = s; }
74 
82  virtual int CanReadFile(const char* name);
83 
85 
91 
93 
97  vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
98  vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
99  vtkGetObjectMacro(ColumnArraySelection, vtkDataArraySelection);
101 
103 
110 
112 
116  const char* GetPointArrayName(int index);
117  const char* GetCellArrayName(int index);
118  const char* GetColumnArrayName(int index);
120 
122 
126  int GetPointArrayStatus(const char* name);
127  int GetCellArrayStatus(const char* name);
128  void SetPointArrayStatus(const char* name, int status);
129  void SetCellArrayStatus(const char* name, int status);
130  int GetColumnArrayStatus(const char* name);
131  void SetColumnArrayStatus(const char* name, int status);
133 
134  // For the specified port, copy the information this reader sets up in
135  // SetupOutputInformation to outInfo
136  virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo),
137  int vtkNotUsed(port)) {}
138 
140 
143  vtkSetMacro(TimeStep, int);
144  vtkGetMacro(TimeStep, int);
146 
147  vtkGetMacro(NumberOfTimeSteps, int);
149 
152  vtkGetVector2Macro(TimeStepRange, int);
153  vtkSetVector2Macro(TimeStepRange, int);
155 
161  {
162  return this->XMLParser;
163  }
164 
166  vtkInformationVector **inputVector,
167  vtkInformationVector *outputVector) override;
168 
170 
175  vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
177 
179 
184  vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
186 
187 protected:
189  ~vtkXMLReader() override;
190 
191  // Pipeline execution methods to be defined by subclass. Called by
192  // corresponding RequestData methods after appropriate setup has been
193  // done.
194  virtual int ReadXMLInformation();
195  virtual void ReadXMLData();
196 
197  // Get the name of the data set being read.
198  virtual const char* GetDataSetName()=0;
199 
200  // Test if the reader can read a file with the given version number.
201  virtual int CanReadFileVersion(int major, int minor);
202 
203  // Setup the output with no data available. Used in error cases.
204  virtual void SetupEmptyOutput()=0;
205 
206  // Setup the output's information.
207  virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo)) {}
208 
209  // Setup the output's data with allocation.
210  virtual void SetupOutputData();
211 
212  // Read the primary element from the file. This is the element
213  // whose name is the value returned by GetDataSetName().
214  virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
215 
216  // Read the top-level element from the file. This is always the
217  // VTKFile element.
218  virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
219 
220  // Create a vtkAbstractArray from its cooresponding XML representation.
221  // Does not allocate.
223 
224  // Create a vtkInformationKey from its corresponding XML representation.
225  // Stores it in the instance of vtkInformationProvided. Does not allocate.
227 
228  // Populates the info object with the InformationKey children in infoRoot.
229  // Returns false if errors occur.
231 
232  // Internal utility methods.
233  virtual int OpenStream();
234  virtual void CloseStream();
235  virtual int OpenVTKFile();
236  virtual void CloseVTKFile();
237  virtual int OpenVTKString();
238  virtual void CloseVTKString();
239  virtual void CreateXMLParser();
240  virtual void DestroyXMLParser();
241  void SetupCompressor(const char* type);
243 
249  virtual int CanReadFileWithDataType(const char* dsname);
250 
251  // Returns the major version for the file being read. -1 when invalid.
252  vtkGetMacro(FileMajorVersion, int);
253 
254  // Returns the minor version for the file being read. -1 when invalid.
255  vtkGetMacro(FileMinorVersion, int);
256 
257  // Utility methods for subclasses.
258  int IntersectExtents(int* extent1, int* extent2, int* result);
259  int Min(int a, int b);
260  int Max(int a, int b);
261  void ComputePointDimensions(int* extent, int* dimensions);
262  void ComputePointIncrements(int* extent, vtkIdType* increments);
263  void ComputeCellDimensions(int* extent, int* dimensions);
264  void ComputeCellIncrements(int* extent, vtkIdType* increments);
266  int i, int j, int k);
268  vtkDataSetAttributes* dsa);
269  char** CreateStringArray(int numStrings);
270  void DestroyStringArray(int numStrings, char** strings);
271 
272  // Read an Array values starting at the given index and up to numValues.
273  // This method assumes that the array is of correct size to
274  // accommodate all numValues values. arrayIndex is the value index at which the read
275  // values will be put in the array.
276  virtual int ReadArrayValues(
277  vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
278  vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
279 
280  // Setup the data array selections for the input's set of arrays.
282  vtkDataArraySelection* sel);
283 
284  int SetFieldDataInfo(vtkXMLDataElement *eDSA, int association,
285  int numTuples, vtkInformationVector *(&infoVector));
286 
287  // Check whether the given array element is an enabled array.
290 
291  // Callback registered with the SelectionObserver.
292  static void SelectionModifiedCallback(vtkObject* caller, unsigned long eid,
293  void* clientdata, void* calldata);
294 
295  // Give concrete classes an option to squeeze any output arrays
296  // at the end of RequestData.
298 
299  // The vtkXMLDataParser instance used to hide XML reading details.
301 
302  // The FieldData element representation.
304 
305  // The input file's name.
306  char* FileName;
307 
308  // The stream used to read the input.
309  istream* Stream;
310 
311  // Whether this object is reading from a string or a file.
312  // Default is 0: read from file.
314 
315  // The input string.
317 
318  // The array selections.
322 
323  // The observer to modify this object when the array selections are
324  // modified.
326 
327  // Whether there was an error reading the file in RequestInformation.
329 
330  // Whether there was an error reading the file in RequestData.
332 
333  // incrementally fine-tuned progress updates.
334  virtual void GetProgressRange(float* range);
335  virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
336  virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
337  virtual void UpdateProgressDiscrete(float progress);
338  float ProgressRange[2];
339 
340  virtual int RequestData(vtkInformation *request,
341  vtkInformationVector **inputVector,
342  vtkInformationVector *outputVector);
343  virtual int RequestDataObject(vtkInformation *vtkNotUsed(request),
344  vtkInformationVector **vtkNotUsed(inputVector),
345  vtkInformationVector *vtkNotUsed(outputVector))
346  { return 1; }
347  virtual int RequestInformation(vtkInformation *request,
348  vtkInformationVector **inputVector,
349  vtkInformationVector *outputVector);
351 
352  // Whether there was an error reading the XML.
354 
355  // For structured data keep track of dimensions empty of cells. For
356  // unstructured data these are always zero. This is used to support
357  // 1-D and 2-D cell data.
358  int AxesEmpty[3];
359 
360  // The timestep currently being read.
361  int TimeStep;
364  void SetNumberOfTimeSteps(int num);
365  // buffer for reading timestep from the XML file the length is of
366  // NumberOfTimeSteps and therefore is always long enough
367  int *TimeSteps;
368  // Store the range of time steps
369  int TimeStepRange[2];
370 
371  // Now we need to save what was the last time read for each kind of
372  // data to avoid rereading it that is to say we need a var for
373  // e.g. PointData/CellData/Points/Cells...
374  // See SubClass for details with member vars like PointsTimeStep/PointsOffset
375 
376  // Helper function useful to know if a timestep is found in an array of timestep
377  static int IsTimeStepInArray(int timestep, int* timesteps, int length);
378 
381 
382  // Flag for whether DataProgressCallback should actually update
383  // progress.
385 
388 
390 
391 private:
392  // The stream used to read the input if it is in a file.
393  ifstream* FileStream;
394  // The stream used to read the input if it is in a string.
395  std::istringstream* StringStream;
396  int TimeStepWasReadOnce;
397 
398  int FileMajorVersion;
399  int FileMinorVersion;
400 
401  vtkDataObject* CurrentOutput;
402  vtkInformation* CurrentOutputInformation;
403 
404 private:
405  vtkXMLReader(const vtkXMLReader&) = delete;
406  void operator=(const vtkXMLReader&) = delete;
407 
408  vtkCommand *ReaderErrorObserver;
409  vtkCommand *ParserErrorObserver;
410 };
411 
412 #endif
vtkXMLReader::ReadMTime
vtkTimeStamp ReadMTime
Definition: vtkXMLReader.h:350
vtkCommand
superclass for callback/observer methods
Definition: vtkCommand.h:371
vtkXMLReader::RequestInformation
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
vtkXMLReader::GetStartTuple
vtkIdType GetStartTuple(int *extent, vtkIdType *increments, int i, int j, int k)
vtkXMLReader::POINT_DATA
@ POINT_DATA
Definition: vtkXMLReader.h:51
vtkXMLReader::CurrentTimeStep
int CurrentTimeStep
Definition: vtkXMLReader.h:362
vtkXMLReader::GetProgressRange
virtual void GetProgressRange(float *range)
vtkXMLReader::GetPointArrayName
const char * GetPointArrayName(int index)
Get the name of the point, cell or column array with the given index in the input.
vtkXMLReader::FieldDataElement
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:303
vtkXMLReader::GetNumberOfCellArrays
int GetNumberOfCellArrays()
vtkXMLReader::PointDataArraySelection
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:319
vtkXMLReader::SelectionModifiedCallback
static void SelectionModifiedCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
vtkXMLReader::ReadPrimaryElement
virtual int ReadPrimaryElement(vtkXMLDataElement *ePrimary)
vtkXMLReader::SetParserErrorObserver
void SetParserErrorObserver(vtkCommand *)
Set/get the ErrorObserver for the internal xml parser This is useful for applications that want to ca...
vtkXMLReader::DestroyStringArray
void DestroyStringArray(int numStrings, char **strings)
vtkXMLReader::SetDataArraySelections
void SetDataArraySelections(vtkXMLDataElement *eDSA, vtkDataArraySelection *sel)
vtkXMLReader::TimeSteps
int * TimeSteps
Definition: vtkXMLReader.h:367
vtkXMLReader::ComputePointIncrements
void ComputePointIncrements(int *extent, vtkIdType *increments)
vtkXMLReader::ReadFromInputString
vtkTypeBool ReadFromInputString
Definition: vtkXMLReader.h:313
vtkXMLReader::SetInputString
void SetInputString(const std::string &s)
Definition: vtkXMLReader.h:72
vtkX3D::type
@ type
Definition: vtkX3D.h:516
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkXMLReader::XMLParser
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:300
vtkXMLReader::CloseStream
virtual void CloseStream()
vtkAlgorithm
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:60
vtkDataSetAttributes
represent and manipulate attribute data in a dataset
Definition: vtkDataSetAttributes.h:60
vtkXMLReader::ConvertGhostLevelsToGhostType
virtual void ConvertGhostLevelsToGhostType(FieldType, vtkAbstractArray *, vtkIdType, vtkIdType)
Definition: vtkXMLReader.h:386
vtkXMLReader::CanReadFileWithDataType
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 ...
vtkXMLReader::InformationError
int InformationError
Definition: vtkXMLReader.h:328
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:42
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:36
vtkXMLReader::CanReadFileVersionString
int CanReadFileVersionString(const char *version)
vtkXMLReader::ReadVTKFile
virtual int ReadVTKFile(vtkXMLDataElement *eVTKFile)
vtkXMLReader::SetupCompressor
void SetupCompressor(const char *type)
vtkXMLReader::FileName
char * FileName
Definition: vtkXMLReader.h:306
vtkX3D::range
@ range
Definition: vtkX3D.h:238
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkXMLReader::SetNumberOfTimeSteps
void SetNumberOfTimeSteps(int num)
vtkXMLReader::~vtkXMLReader
~vtkXMLReader() override
vtkXMLReader::RequestDataObject
virtual int RequestDataObject(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *vtkNotUsed(outputVector))
Definition: vtkXMLReader.h:343
vtkXMLReader::GetColumnArrayStatus
int GetColumnArrayStatus(const char *name)
vtkX3D::length
@ length
Definition: vtkX3D.h:393
vtkXMLReader::SetCellArrayStatus
void SetCellArrayStatus(const char *name, int status)
vtkXMLReader::GetCellArrayName
const char * GetCellArrayName(int index)
vtkXMLReader::SetProgressRange
virtual void SetProgressRange(const float range[2], int curStep, const float *fractions)
vtkXMLReader::ReadArrayValues
virtual int ReadArrayValues(vtkXMLDataElement *da, vtkIdType arrayIndex, vtkAbstractArray *array, vtkIdType startIndex, vtkIdType numValues, FieldType type=OTHER)
vtkXMLReader::UpdateProgressDiscrete
virtual void UpdateProgressDiscrete(float progress)
vtkXMLReader::Stream
istream * Stream
Definition: vtkXMLReader.h:309
vtkXMLReader::GetNumberOfColumnArrays
int GetNumberOfColumnArrays()
vtkXMLReader::OpenStream
virtual int OpenStream()
vtkXMLReader::OpenVTKString
virtual int OpenVTKString()
vtkXMLReader::RequestData
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
vtkXMLReader::DataError
int DataError
Definition: vtkXMLReader.h:331
vtkXMLReader::PointDataArrayIsEnabled
int PointDataArrayIsEnabled(vtkXMLDataElement *ePDA)
vtkDataArraySelection
Store on/off settings for data arrays for a vtkSource.
Definition: vtkDataArraySelection.h:38
vtkXMLReader::GetPointArrayStatus
int GetPointArrayStatus(const char *name)
Get/Set whether the point, cell or column array with the given name is to be read.
vtkAlgorithm.h
vtkXMLReader::OpenVTKFile
virtual int OpenVTKFile()
vtkXMLReader::GetNumberOfPointArrays
int GetNumberOfPointArrays()
Get the number of point, cell or column arrays available in the input.
vtkX3D::port
@ port
Definition: vtkX3D.h:447
vtkXMLReader::ProcessRequest
int ProcessRequest(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Upstream/Downstream requests form the generalized interface through which executives invoke a algorit...
vtkXMLReader::InReadData
int InReadData
Definition: vtkXMLReader.h:384
vtkXMLReader::SetupOutputData
virtual void SetupOutputData()
vtkXMLReader::GetCurrentOutputInformation
vtkInformation * GetCurrentOutputInformation()
vtkXMLReader::InputString
std::string InputString
Definition: vtkXMLReader.h:316
vtkXMLReader::vtkXMLReader
vtkXMLReader()
vtkXMLReader::SqueezeOutputArrays
virtual void SqueezeOutputArrays(vtkDataObject *)
Definition: vtkXMLReader.h:297
vtkXMLReader::ReadXMLData
virtual void ReadXMLData()
vtkXMLReader::ComputeCellDimensions
void ComputeCellDimensions(int *extent, int *dimensions)
vtkXMLReader::SetupEmptyOutput
virtual void SetupEmptyOutput()=0
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkXMLReader::ReadAttributeIndices
void ReadAttributeIndices(vtkXMLDataElement *eDSA, vtkDataSetAttributes *dsa)
vtkXMLReader::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkXMLReader::IntersectExtents
int IntersectExtents(int *extent1, int *extent2, int *result)
vtkXMLReader::CreateXMLParser
virtual void CreateXMLParser()
vtkXMLReader::CreateArray
vtkAbstractArray * CreateArray(vtkXMLDataElement *da)
vtkXMLReader::ReadInformation
bool ReadInformation(vtkXMLDataElement *infoRoot, vtkInformation *info)
vtkXMLReader::GetDataSetName
virtual const char * GetDataSetName()=0
vtkXMLReader::CELL_DATA
@ CELL_DATA
Definition: vtkXMLReader.h:52
vtkXMLDataElement
Represents an XML element and those nested inside.
Definition: vtkXMLDataElement.h:37
vtkXMLReader::GetXMLParser
vtkXMLDataParser * GetXMLParser()
Returns the internal XML parser.
Definition: vtkXMLReader.h:160
vtkX3D::name
@ name
Definition: vtkX3D.h:219
vtkXMLReader::GetOutputAsDataSet
vtkDataSet * GetOutputAsDataSet()
Get the output as a vtkDataSet pointer.
vtkXMLReader::CreateStringArray
char ** CreateStringArray(int numStrings)
vtkDataSet
abstract class to specify dataset behavior
Definition: vtkDataSet.h:63
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:79
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:87
vtkXMLReader::ComputeCellIncrements
void ComputeCellIncrements(int *extent, vtkIdType *increments)
vtkXMLReader::ComputePointDimensions
void ComputePointDimensions(int *extent, int *dimensions)
vtkX3D::info
@ info
Definition: vtkX3D.h:376
vtkX3D::string
@ string
Definition: vtkX3D.h:490
vtkXMLReader::ReadFieldData
void ReadFieldData()
vtkXMLReader::IsTimeStepInArray
static int IsTimeStepInArray(int timestep, int *timesteps, int length)
vtkXMLReader::CellDataArraySelection
vtkDataArraySelection * CellDataArraySelection
Definition: vtkXMLReader.h:320
vtkXMLReader::CloseVTKFile
virtual void CloseVTKFile()
vtkXMLReader::GetCurrentOutput
vtkDataObject * GetCurrentOutput()
vtkXMLReader::TimeStep
int TimeStep
Definition: vtkXMLReader.h:361
vtkXMLReader::GetColumnArrayName
const char * GetColumnArrayName(int index)
vtkXMLReader::FieldType
FieldType
Definition: vtkXMLReader.h:50
vtkXMLReader::SetProgressRange
virtual void SetProgressRange(const float range[2], int curStep, int numSteps)
vtkXMLReader::CellDataArrayIsEnabled
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
vtkCallbackCommand
supports function callbacks
Definition: vtkCallbackCommand.h:51
vtkXMLReader::SetupOutputInformation
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:207
vtkXMLReader::CreateInformationKey
int CreateInformationKey(vtkXMLDataElement *eInfoKey, vtkInformation *info)
vtkXMLReader::SetPointArrayStatus
void SetPointArrayStatus(const char *name, int status)
vtkXMLReader::NumberOfTimeSteps
int NumberOfTimeSteps
Definition: vtkXMLReader.h:363
vtkXMLReader::SelectionObserver
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:325
vtkX3D::progress
@ progress
Definition: vtkX3D.h:452
vtkX3D::version
@ version
Definition: vtkX3D.h:526
vtkX3D::extent
@ extent
Definition: vtkX3D.h:345
vtkXMLReader::ReadXMLInformation
virtual int ReadXMLInformation()
vtkXMLReader::Max
int Max(int a, int b)
vtkXMLReader::DestroyXMLParser
virtual void DestroyXMLParser()
vtkXMLReader::SetReaderErrorObserver
void SetReaderErrorObserver(vtkCommand *)
Set/get the ErrorObserver for the internal reader This is useful for applications that want to catch ...
vtkXMLReader::CanReadFile
virtual int CanReadFile(const char *name)
Test whether the file (type) with the given name can be read by this reader.
vtkXMLReader::GetCellArrayStatus
int GetCellArrayStatus(const char *name)
vtkDataObject
general representation of visualization data
Definition: vtkDataObject.h:65
vtkXMLReader::CloseVTKString
virtual void CloseVTKString()
vtkXMLReader::CopyOutputInformation
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:136
vtkXMLReader::ReadError
int ReadError
Definition: vtkXMLReader.h:353
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkXMLReader::SetFieldDataInfo
int SetFieldDataInfo(vtkXMLDataElement *eDSA, int association, int numTuples, vtkInformationVector *(&infoVector))
vtkXMLReader::Min
int Min(int a, int b)
vtkXMLReader
Superclass for VTK's XML format readers.
Definition: vtkXMLReader.h:44
vtkXMLReader::SetColumnArrayStatus
void SetColumnArrayStatus(const char *name, int status)
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkXMLReader::CanReadFileVersion
virtual int CanReadFileVersion(int major, int minor)
vtkXMLReader::ColumnArraySelection
vtkDataArraySelection * ColumnArraySelection
Definition: vtkXMLReader.h:321
vtkXMLDataParser
Used by vtkXMLReader to parse VTK XML files.
Definition: vtkXMLDataParser.h:40
vtkXMLReader::GetOutputAsDataSet
vtkDataSet * GetOutputAsDataSet(int index)