VTK  9.3.0
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
24VTK_ABI_NAMESPACE_BEGIN
27class vtkCommand;
28class vtkDataArray;
30class vtkDataSet;
35class vtkInformation;
36class vtkStringArray;
37
38class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
39{
40public:
41 vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
42 void PrintSelf(ostream& os, vtkIndent indent) override;
43
45 {
48 OTHER
49 };
50
52
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
85
87
91 vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
92 vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
93 vtkGetObjectMacro(ColumnArraySelection, vtkDataArraySelection);
95
97
104
106
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
184 vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
186
188
193 vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
195
196protected:
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
265
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);
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
347
348 int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
349 vtkInformationVector*(&infoVector));
350
352
358
363 vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
364
370
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.
399 std::string InputString;
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.
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
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
476
477 // Flag for whether DataProgressCallback should actually update
478 // progress.
480
482
484
485private:
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
505VTK_ABI_NAMESPACE_END
506#endif
Abstract superclass for all arrays.
Superclass for all sources, filters, and sinks in VTK.
supports function callbacks
superclass for callback/observer methods
Definition vtkCommand.h:384
Store on/off settings for data arrays, etc.
abstract superclass for arrays of numeric data
general representation of visualization data
represent and manipulate attribute data in a dataset
abstract class to specify dataset behavior
Definition vtkDataSet.h:53
a simple class to control print indentation
Definition vtkIndent.h:29
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition vtkObject.h:49
Hold a reference to a vtkObjectBase instance.
a vtkAbstractArray subclass for strings
record modification and/or execution time
Represents an XML element and those nested inside.
Used by vtkXMLReader to parse VTK XML files.
Superclass for VTK's XML format readers.
virtual int ReadArrayTuples(vtkXMLDataElement *da, vtkIdType arrayTupleIndex, vtkAbstractArray *array, vtkIdType startTupleIndex, vtkIdType numTuples, FieldType type=OTHER)
Read an Array values starting at the given tuple index and up to numTuples taking into account the nu...
vtkXMLDataElement * FieldDataElement
vtkCallbackCommand * SelectionObserver
char ** CreateStringArray(int numStrings)
Utility methods for subclasses.
virtual void SetProgressRange(const float range[2], int curStep, int numSteps)
virtual void ConvertGhostLevelsToGhostType(FieldType, vtkAbstractArray *, vtkIdType, vtkIdType)
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)
Test if the reader can read a file with the given version number.
virtual void GetProgressRange(float *range)
virtual void DestroyXMLParser()
Internal utility methods.
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
Check whether the given array element is an enabled array.
istream * Stream
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)
Read an Array values starting at the given index and up to numValues.
void SetReaderErrorObserver(vtkCommand *)
Set/get the ErrorObserver for the internal reader This is useful for applications that want to catch ...
const char * GetCellArrayName(int index)
Get the name of the point, cell, column or time array with the given index in the input.
vtkDataArraySelection * CellDataArraySelection
virtual void SetupOutputData()
Setup the output's data with allocation.
void ComputeCellIncrements(int *extent, vtkIdType *increments)
Utility methods for subclasses.
int CreateInformationKey(vtkXMLDataElement *eInfoKey, vtkInformation *info)
Create a vtkInformationKey from its corresponding XML representation.
void SetDataArraySelections(vtkXMLDataElement *eDSA, vtkDataArraySelection *sel)
Setup the data array selections for the input's set of arrays.
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
Setup the output with no data available.
int GetNumberOfTimeDataArrays() const
Getters for time data array candidates.
virtual void SqueezeOutputArrays(vtkDataObject *)
Give concrete classes an option to squeeze any output arrays at the end of RequestData.
int GetNumberOfPointArrays()
Get the number of point, cell or column arrays available in the input.
int Max(int a, int b)
Utility methods for subclasses.
virtual void CreateXMLParser()
Internal utility methods.
vtkSmartPointer< vtkDataArray > TimeDataArray
Populated in ReadXMLInformation from the field data for the array chosen using ActiveTimeDataArrayNam...
virtual void CloseStream()
Internal utility methods.
int CanReadFileVersionString(const char *version)
Internal utility methods.
void ReadFieldData()
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Setup the output's information.
vtkIdType GetStartTuple(int *extent, vtkIdType *increments, int i, int j, int k)
Utility methods for subclasses.
const char * GetColumnArrayName(int index)
Get the name of the point, cell, column or time array with the given index in the input.
vtkTypeBool ReadFromInputString
void SetupCompressor(const char *type)
Internal utility methods.
vtkInformation * GetCurrentOutputInformation()
vtkDataArraySelection * ColumnArraySelection
vtkXMLDataParser * XMLParser
virtual const char * GetDataSetName()=0
Get the name of the data set being read.
vtkXMLDataParser * GetXMLParser()
Returns the internal XML parser.
const char * GetPointArrayName(int index)
Get the name of the point, cell, column or time array with the given index in the input.
void SetInputString(const std::string &s)
Enable reading from an InputString instead of the default, a file.
void ComputePointIncrements(int *extent, vtkIdType *increments)
Utility methods for subclasses.
virtual int ReadXMLInformation()
Pipeline execution methods to be defined by subclass.
vtkAbstractArray * CreateArray(vtkXMLDataElement *da)
Create a vtkAbstractArray from its corresponding XML representation.
int GetNumberOfColumnArrays()
Get the number of point, cell or column arrays available in the input.
void ReadAttributeIndices(vtkXMLDataElement *eDSA, vtkDataSetAttributes *dsa)
Utility methods for subclasses.
int PointDataArrayIsEnabled(vtkXMLDataElement *ePDA)
Check whether the given array element is an enabled array.
vtkDataSet * GetOutputAsDataSet()
Get the output as a vtkDataSet pointer.
virtual void CloseVTKFile()
Internal utility methods.
virtual int OpenVTKFile()
Internal utility methods.
vtkTimeStamp ReadMTime
void ComputeCellDimensions(int *extent, int *dimensions)
Utility methods for subclasses.
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)
Callback registered with the SelectionObserver.
static int IsTimeStepInArray(int timestep, int *timesteps, int length)
virtual int RequestDataObject(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *vtkNotUsed(outputVector))
void ComputePointDimensions(int *extent, int *dimensions)
Utility methods for subclasses.
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 ...
int IntersectExtents(int *extent1, int *extent2, int *result)
Utility methods for subclasses.
char * ActiveTimeDataArrayName
Name of the field-data array used to determine the time for the dataset being read.
virtual int ReadVTKFile(vtkXMLDataElement *eVTKFile)
Read the top-level element from the file.
virtual int OpenVTKString()
Internal utility methods.
virtual int ReadPrimaryElement(vtkXMLDataElement *ePrimary)
Read the primary element from the file.
vtkGetFilePathMacro(FileName)
Get/Set the name of the input file.
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)
Populates the info object with the InformationKey children in infoRoot.
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.
vtkDataObject * GetCurrentOutput()
int GetPointArrayStatus(const char *name)
Get/Set whether the point, cell, column or time array with the given name is to be read.
const char * GetTimeDataArray(int idx) const
Getters for time data array candidates.
virtual void UpdateProgressDiscrete(float progress)
virtual void ReadXMLData()
Pipeline execution methods to be defined by subclass.
virtual int OpenStream()
Internal utility methods.
vtkStringArray * TimeDataStringArray
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)
Utility methods for subclasses.
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()
Internal utility methods.
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
vtkDataArraySelection * PointDataArraySelection
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
vtkDataSet * GetOutputAsDataSet(int index)
Get the output as a vtkDataSet pointer.
int SetFieldDataInfo(vtkXMLDataElement *eDSA, int association, vtkIdType numTuples, vtkInformationVector *(&infoVector))
int Min(int a, int b)
Utility methods for subclasses.
int vtkTypeBool
Definition vtkABI.h:64
int vtkIdType
Definition vtkType.h:315
#define VTK_FILEPATH