VTK  9.4.20251007
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
14
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 vtkCharArray;
28class vtkCommand;
29class vtkDataArray;
31class vtkDataSet;
36class vtkInformation;
37class vtkStringArray;
38
39class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
40{
41public:
42 vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
43 void PrintSelf(ostream& os, vtkIndent indent) override;
44
51
53
59
61
68
74 void SetInputString(const char* in);
75 void SetInputString(const char* in, int len);
76 void SetBinaryInputString(const char*, int len);
77 void SetInputString(const std::string& input)
78 {
79 this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length()));
80 }
81
82
84
94
102 virtual int CanReadFile(VTK_FILEPATH const char* name);
103
105
111
113
121
123
130
132
136 const char* GetTimeDataArray(int idx) const;
139
141
147 vtkGetStringMacro(ActiveTimeDataArrayName);
148 vtkSetStringMacro(ActiveTimeDataArrayName);
150
152
156 const char* GetPointArrayName(int index);
157 const char* GetCellArrayName(int index);
158 const char* GetColumnArrayName(int index);
160
162
166 int GetPointArrayStatus(const char* name);
167 int GetCellArrayStatus(const char* name);
168 void SetPointArrayStatus(const char* name, int status);
169 void SetCellArrayStatus(const char* name, int status);
170 int GetColumnArrayStatus(const char* name);
171 void SetColumnArrayStatus(const char* name, int status);
173
174 // For the specified port, copy the information this reader sets up in
175 // SetupOutputInformation to outInfo
176 virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
177
179
182 vtkSetMacro(TimeStep, int);
183 vtkGetMacro(TimeStep, int);
185
186 vtkGetMacro(NumberOfTimeSteps, int);
188
191 vtkGetVector2Macro(TimeStepRange, int);
192 vtkSetVector2Macro(TimeStepRange, int);
194
200
202 vtkInformationVector* outputVector) override;
203
205
210 vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
212
214
219 vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
221
222protected:
224 ~vtkXMLReader() override;
225
227
232 virtual int ReadXMLInformation();
233 virtual void ReadXMLData();
235
239 virtual const char* GetDataSetName() = 0;
240
244 virtual int CanReadFileVersion(int major, int minor);
245
249 virtual void SetupEmptyOutput() = 0;
250
254 virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
255
259 virtual void SetupOutputData();
260
265 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
266
271 virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
272
278 int GetLocalDataType(vtkXMLDataElement* da, int datatype);
279
285
291
297
299
302 virtual int OpenStream();
303 virtual void CloseStream();
304 virtual int OpenVTKFile();
305 virtual void CloseVTKFile();
306 virtual int OpenVTKString();
307 virtual void CloseVTKString();
308 virtual void CreateXMLParser();
309 virtual void DestroyXMLParser();
310 void SetupCompressor(const char* type);
311 int CanReadFileVersionString(const char* version);
313
319 virtual int CanReadFileWithDataType(const char* dsname);
320
324 vtkGetMacro(FileMajorVersion, int);
325
329 vtkGetMacro(FileMinorVersion, int);
330
332
335 int IntersectExtents(int* extent1, int* extent2, int* result);
336 int Min(int a, int b);
337 int Max(int a, int b);
338 void ComputePointDimensions(int* extent, int* dimensions);
339 void ComputePointIncrements(int* extent, vtkIdType* increments);
340 void ComputeCellDimensions(int* extent, int* dimensions);
341 void ComputeCellIncrements(int* extent, vtkIdType* increments);
342 vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
344 char** CreateStringArray(int numStrings);
345 void DestroyStringArray(int numStrings, char** strings);
347
354 virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
355 vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
356
365 virtual int ReadArrayTuples(vtkXMLDataElement* da, vtkIdType arrayTupleIndex,
366 vtkAbstractArray* array, vtkIdType startTupleIndex, vtkIdType numTuples,
367 FieldType type = OTHER);
368
373
374 int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
375 vtkInformationVector*(&infoVector));
376
378
384
389 vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
390
396
407
408 // The vtkXMLDataParser instance used to hide XML reading details.
410
411 // The FieldData element representation.
413
414 // The input file's name.
415 char* FileName;
416
417 // The stream used to read the input.
418 istream* Stream;
419
420 // Whether this object is reading from a string or a file.
421 // Default is 0: read from file.
423
424 // The input string.
425 std::string InputString;
426
427 // The input array. Keeps a low memory footprint by sourcing StringStream from contents of this
428 // array
430
431 // The array selections.
436
442
448
449 // The observer to modify this object when the array selections are
450 // modified.
452
453 // Whether there was an error reading the file in RequestInformation.
455
456 // Whether there was an error reading the file in RequestData.
458
459 // incrementally fine-tuned progress updates.
460 virtual void GetProgressRange(float* range);
461 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
462 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
463 virtual void UpdateProgressDiscrete(float progress);
465
466 virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
467 vtkInformationVector* outputVector);
468 virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
469 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
470 {
471 return 1;
472 }
473 virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
474 vtkInformationVector* outputVector);
476
477 // Whether there was an error reading the XML.
479
480 // For structured data keep track of dimensions empty of cells. For
481 // unstructured data these are always zero. This is used to support
482 // 1-D and 2-D cell data.
483 int AxesEmpty[3];
484
485 // The timestep currently being read.
489 void SetNumberOfTimeSteps(int num);
490 // buffer for reading timestep from the XML file the length is of
491 // NumberOfTimeSteps and therefore is always long enough
493 // Store the range of time steps
495
496 // Now we need to save what was the last time read for each kind of
497 // data to avoid rereading it that is to say we need a var for
498 // e.g. PointData/CellData/Points/Cells...
499 // See SubClass for details with member vars like PointsTimeStep/PointsOffset
500
501 // Helper function useful to know if a timestep is found in an array of timestep
502 static int IsTimeStepInArray(int timestep, int* timesteps, int length);
503
506
507 // Flag for whether DataProgressCallback should actually update
508 // progress.
510
512
513 /*
514 * Populate the output's FieldData with the file's FieldData tags content
515 */
517
518private:
519 // The stream used to read the input if it is in a file.
520 istream* FileStream;
521 // The stream used to read the input if it is in a string.
522 std::istringstream* StringStream;
523 int TimeStepWasReadOnce;
524
525 int FileMajorVersion;
526 int FileMinorVersion;
527
528 vtkDataObject* CurrentOutput;
529 vtkInformation* CurrentOutputInformation;
530
531 vtkXMLReader(const vtkXMLReader&) = delete;
532 void operator=(const vtkXMLReader&) = delete;
533
534 vtkCommand* ReaderErrorObserver;
535 vtkCommand* ParserErrorObserver;
536};
537
538VTK_ABI_NAMESPACE_END
539#endif
Abstract superclass for all arrays.
supports function callbacks
dynamic, self-adjusting array of char
superclass for callback/observer methods
Definition vtkCommand.h:384
Store on/off settings for data arrays, etc.
general representation of visualization data
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:29
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
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.
vtkCharArray * InputArray
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.
void SetInputString(const std::string &input)
Enable reading from an InputString instead of the default, a file.
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()
float ProgressRange[2]
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.
virtual void SetInputArray(vtkCharArray *)
Specify the vtkCharArray to be used when reading from a string.
const char * GetPointArrayName(int index)
Get the name of the point, cell, column or time array with the given index in the input.
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 SetInputString(const char *in, int len)
Enable reading from an InputString instead of the default, a file.
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.
void SetInputString(const char *in)
Specify the InputString for use when reading from a character array.
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.
void SetBinaryInputString(const char *, int len)
Enable reading from an InputString instead of the default, a file.
vtkGetFilePathMacro(FileName)
Get/Set the name of the input file.
int TimeStepRange[2]
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
#define vtkDataArray
int vtkIdType
Definition vtkType.h:315
#define VTK_FILEPATH