VTK  9.6.20260201
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
34
35#ifndef vtkXMLReader_h
36#define vtkXMLReader_h
37
38#include "vtkAlgorithm.h"
39#include "vtkIOXMLModule.h" // For export macro
40#include "vtkSmartPointer.h" // for vtkSmartPointer.
41
42#include <istream> // for IStream
43#include <memory> // for std::unique_ptr
44#include <streambuf> // for Streambuf
45#include <string> // for std::string
46
47VTK_ABI_NAMESPACE_BEGIN
50class vtkCharArray;
51class vtkCommand;
52class vtkDataArray;
54class vtkDataSet;
56class vtkInformation;
59class vtkStringArray;
62
63class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
64{
65public:
66 vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
67 void PrintSelf(ostream& os, vtkIndent indent) override;
68
75
77
83
85
93
100 void SetInputString(const char* in);
101 void SetInputString(const char* in, int len);
102 void SetBinaryInputString(const char*, int len);
103 void SetInputString(const std::string& input)
104 {
105 this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length()));
106 }
107
108
110
120
122
127 vtkSetMacro(ReadFromInputStream, bool);
128 vtkGetMacro(ReadFromInputStream, bool);
129 vtkBooleanMacro(ReadFromInputStream, bool);
131
133
142
144
152 virtual int CanReadFile(VTK_FILEPATH const char* name);
155
157
163
165
173
175
182
184
188 const char* GetTimeDataArray(int idx) const;
191
193
199 vtkGetStringMacro(ActiveTimeDataArrayName);
200 vtkSetStringMacro(ActiveTimeDataArrayName);
202
204
208 const char* GetPointArrayName(int index);
209 const char* GetCellArrayName(int index);
210 const char* GetColumnArrayName(int index);
212
214
218 int GetPointArrayStatus(const char* name);
219 int GetCellArrayStatus(const char* name);
220 void SetPointArrayStatus(const char* name, int status);
221 void SetCellArrayStatus(const char* name, int status);
222 int GetColumnArrayStatus(const char* name);
223 void SetColumnArrayStatus(const char* name, int status);
225
226 // For the specified port, copy the information this reader sets up in
227 // SetupOutputInformation to outInfo
228 virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
229
231
234 vtkSetMacro(TimeStep, int);
235 vtkGetMacro(TimeStep, int);
237
238 vtkGetMacro(NumberOfTimeSteps, int);
240
243 vtkGetVector2Macro(TimeStepRange, int);
244 vtkSetVector2Macro(TimeStepRange, int);
246
252
254 vtkInformationVector* outputVector) override;
255
257
262 vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
264
266
271 vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
273
278
279protected:
281 ~vtkXMLReader() override;
282
284
289 virtual int ReadXMLInformation();
290 virtual void ReadXMLData();
292
296 virtual const char* GetDataSetName() = 0;
297
301 virtual int CanReadFileVersion(int major, int minor);
302
306 virtual void SetupEmptyOutput() = 0;
307
311 virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
312
316 virtual void SetupOutputData();
317
322 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
323
328 virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
329
335 int GetLocalDataType(vtkXMLDataElement* da, int datatype);
336
342
348
354
356
359 virtual int OpenStream();
360 virtual void CloseStream();
361 virtual int OpenVTKFile();
362 virtual void CloseVTKFile();
363 virtual int OpenVTKString();
364 virtual void CloseVTKString();
365 virtual void CreateXMLParser();
366 virtual void DestroyXMLParser();
367 void SetupCompressor(const char* type);
368 int CanReadFileVersionString(const char* version);
370
376 virtual int CanReadFileWithDataType(const char* dsname);
377
381 vtkGetMacro(FileMajorVersion, int);
382
386 vtkGetMacro(FileMinorVersion, int);
387
389
392 int IntersectExtents(int* extent1, int* extent2, int* result);
393 void ComputePointDimensions(int* extent, int* dimensions);
394 void ComputePointIncrements(int* extent, vtkIdType* increments);
395 void ComputeCellDimensions(int* extent, int* dimensions);
396 void ComputeCellIncrements(int* extent, vtkIdType* increments);
397 vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
399 char** CreateStringArray(int numStrings);
400 void DestroyStringArray(int numStrings, char** strings);
402
409 virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
410 vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
411
420 virtual int ReadArrayTuples(vtkXMLDataElement* da, vtkIdType arrayTupleIndex,
421 vtkAbstractArray* array, vtkIdType startTupleIndex, vtkIdType numTuples,
422 FieldType type = OTHER);
423
428
429 int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
430 vtkInformationVector*(&infoVector));
431
433
439
444 vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
445
451
462
463 // The vtkXMLDataParser instance used to hide XML reading details.
465
466 // The FieldData element representation.
468
469 // The input file's name.
470 char* FileName;
471
472 // The stream used to read the input.
473 std::istream* Stream;
474
475 // Whether this object is reading from a string or a file.
476 // Default is 0: read from file.
478
479 // The input string.
480 std::string InputString;
481
482 // The input array. Keeps a low memory footprint by sourcing StringStream from contents of this
483 // array
485
486 // The array selections.
491
497
503
504 // The observer to modify this object when the array selections are
505 // modified.
507
508 // Whether there was an error reading the file in RequestInformation.
510
511 // Whether there was an error reading the file in RequestData.
513
514 // incrementally fine-tuned progress updates.
515 virtual void GetProgressRange(float* range);
516 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
517 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
518 virtual void UpdateProgressDiscrete(float progress);
520
521 virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
522 vtkInformationVector* outputVector);
523 virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
524 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
525 {
526 return 1;
527 }
528 virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
529 vtkInformationVector* outputVector);
531
532 // Whether there was an error reading the XML.
534
535 // For structured data keep track of dimensions empty of cells. For
536 // unstructured data these are always zero. This is used to support
537 // 1-D and 2-D cell data.
538 int AxesEmpty[3];
539
540 // The timestep currently being read.
544 void SetNumberOfTimeSteps(int num);
545 // buffer for reading timestep from the XML file the length is of
546 // NumberOfTimeSteps and therefore is always long enough
548 // Store the range of time steps
550
551 // Now we need to save what was the last time read for each kind of
552 // data to avoid rereading it that is to say we need a var for
553 // e.g. PointData/CellData/Points/Cells...
554 // See SubClass for details with member vars like PointsTimeStep/PointsOffset
555
556 // Helper function useful to know if a timestep is found in an array of timestep
557 static int IsTimeStepInArray(int timestep, int* timesteps, int length);
558
561
562 // Flag for whether DataProgressCallback should actually update
563 // progress.
565
567
568 /*
569 * Populate the output's FieldData with the file's FieldData tags content
570 */
572
573private:
574 int OpenVTKStream();
575
576 // The stream used to read the input if it is in a resource stream
578
579 bool ReadFromInputStream = false;
580
581 // The stream used to read the input if it is in a file.
582 istream* FileStream;
583 // The stream used to read the input if it is in a string.
584 std::istringstream* StringStream;
585
586 // Used when converting vtkResourceStream into istream
587 std::unique_ptr<std::streambuf> Streambuf;
588 std::unique_ptr<std::istream> StreamBuffer;
589
590 int TimeStepWasReadOnce;
591
592 int FileMajorVersion;
593 int FileMinorVersion;
594
595 vtkDataObject* CurrentOutput;
596 vtkInformation* CurrentOutputInformation;
597
598 vtkXMLReader(const vtkXMLReader&) = delete;
599 void operator=(const vtkXMLReader&) = delete;
600
601 vtkCommand* ReaderErrorObserver;
602 vtkCommand* ParserErrorObserver;
603};
604
605VTK_ABI_NAMESPACE_END
606#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:166
a simple class to control print indentation
Definition vtkIndent.h:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Abstract class used for custom streams.
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.
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 ...
virtual void SetupOutputInformation(vtkInformation *outInfo)
Setup the output's information.
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.
vtkMTimeType GetMTime() override
Overridden to take into account mtime from the internal vtkResourceStream.
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.
virtual void CopyOutputInformation(vtkInformation *outInfo, int port)
int GetNumberOfPointArrays()
Get the number of point, cell or column arrays available in the input.
virtual void CreateXMLParser()
Internal utility methods.
vtkSmartPointer< vtkDataArray > TimeDataArray
Populated in ReadXMLInformation from the field data for the array chosen using ActiveTimeDataArrayNam...
vtkResourceStream * GetStream()
Specify resource stream to read from When both Stream and Filename or InputString are set,...
virtual void CloseStream()
Internal utility methods.
int CanReadFileVersionString(const char *version)
Internal utility methods.
void ReadFieldData()
float ProgressRange[2]
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
std::istream * Stream
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.
virtual int CanReadFile(const char *name)
Return 1 if, after a quick check of file header, it looks like the provided file or stream can be rea...
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.
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)
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...
void SetStream(vtkResourceStream *stream)
Specify resource stream to read from When both Stream and Filename or InputString are set,...
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.
bool CanReadFile(vtkResourceStream *stream)
Return 1 if, after a quick check of file header, it looks like the provided file or stream can be rea...
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
vtkDataSet * GetOutputAsDataSet(int index)
Get the output as a vtkDataSet pointer.
int SetFieldDataInfo(vtkXMLDataElement *eDSA, int association, vtkIdType numTuples, vtkInformationVector *(&infoVector))
virtual int RequestDataObject(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
int vtkTypeBool
Definition vtkABI.h:64
#define vtkDataArray
int vtkIdType
Definition vtkType.h:354
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:309
#define VTK_FILEPATH