VTK  9.7.20261008
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#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
42
43#include <istream> // for IStream
44#include <memory> // for std::unique_ptr
45#include <streambuf> // for Streambuf
46#include <string> // for std::string
47
48VTK_ABI_NAMESPACE_BEGIN
51class vtkCharArray;
52class vtkCommand;
53class vtkDataArray;
55class vtkDataSet;
57class vtkInformation;
60class vtkStringArray;
63
64class VTKIOXML_EXPORT VTK_MARSHALAUTO vtkXMLReader : public vtkAlgorithm
65{
66public:
67 vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
68 void PrintSelf(ostream& os, vtkIndent indent) override;
69
76
78
84
86
94
101 void SetInputString(const char* in);
102 void SetInputString(const char* in, int len);
103 void SetBinaryInputString(const char*, int len);
104 void SetInputString(const std::string& input)
105 {
106 this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length()));
107 }
108
109
111
121
123
128 vtkSetMacro(ReadFromInputStream, bool);
129 vtkGetMacro(ReadFromInputStream, bool);
130 vtkBooleanMacro(ReadFromInputStream, bool);
132
134
143
145
153 virtual int CanReadFile(VTK_FILEPATH const char* name);
156
158
164
166
174
176
183
185
189 const char* GetTimeDataArray(int idx) const;
192
194
200 vtkGetStringMacro(ActiveTimeDataArrayName);
201 vtkSetStringMacro(ActiveTimeDataArrayName);
203
205
209 const char* GetPointArrayName(int index);
210 const char* GetCellArrayName(int index);
211 const char* GetColumnArrayName(int index);
213
215
219 int GetPointArrayStatus(const char* name);
220 int GetCellArrayStatus(const char* name);
221 void SetPointArrayStatus(const char* name, int status);
222 void SetCellArrayStatus(const char* name, int status);
223 int GetColumnArrayStatus(const char* name);
224 void SetColumnArrayStatus(const char* name, int status);
226
227 // For the specified port, copy the information this reader sets up in
228 // SetupOutputInformation to outInfo
229 virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
230
232
235 vtkSetMacro(TimeStep, int);
236 vtkGetMacro(TimeStep, int);
238
239 vtkGetMacro(NumberOfTimeSteps, int);
241
244 vtkGetVector2Macro(TimeStepRange, int);
245 vtkSetVector2Macro(TimeStepRange, int);
247
253
255 vtkInformationVector* outputVector) override;
256
258
263 vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
265
267
272 vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
274
279
280protected:
282 ~vtkXMLReader() override;
283
285
290 virtual int ReadXMLInformation();
291 virtual void ReadXMLData();
293
297 virtual const char* GetDataSetName() = 0;
298
302 virtual int CanReadFileVersion(int major, int minor);
303
307 virtual void SetupEmptyOutput() = 0;
308
312 virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
313
317 virtual void SetupOutputData();
318
323 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
324
329 virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
330
336 int GetLocalDataType(vtkXMLDataElement* da, int datatype);
337
343
349
355
357
360 virtual int OpenStream();
361 virtual void CloseStream();
362 virtual int OpenVTKFile();
363 virtual void CloseVTKFile();
364 virtual int OpenVTKString();
365 virtual void CloseVTKString();
366 virtual void CreateXMLParser();
367 virtual void DestroyXMLParser();
368 void SetupCompressor(const char* type);
369 int CanReadFileVersionString(const char* version);
371
377 virtual int CanReadFileWithDataType(const char* dsname);
378
382 vtkGetMacro(FileMajorVersion, int);
383
387 vtkGetMacro(FileMinorVersion, int);
388
390
394 VTK_FUTURE_CONST int extent1[6], VTK_FUTURE_CONST int extent2[6], int result[6]);
395 void ComputePointDimensions(VTK_FUTURE_CONST int extent[6], int* dimensions);
396 void ComputePointIncrements(VTK_FUTURE_CONST int extent[6], vtkIdType* increments);
397 void ComputeCellDimensions(VTK_FUTURE_CONST int extent[6], int* dimensions);
398 void ComputeCellIncrements(VTK_FUTURE_CONST int extent[6], vtkIdType* increments);
400 VTK_FUTURE_CONST int extent[6], vtkIdType* increments, int i, int j, int k);
402 char** CreateStringArray(int numStrings);
403 void DestroyStringArray(int numStrings, char** strings);
405
412 virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
413 vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
414
423 virtual int ReadArrayTuples(vtkXMLDataElement* da, vtkIdType arrayTupleIndex,
424 vtkAbstractArray* array, vtkIdType startTupleIndex, vtkIdType numTuples,
425 FieldType type = OTHER);
426
431
432 int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
433 vtkInformationVector*(&infoVector));
434
436
442
447 vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
448
454
465
466 // The vtkXMLDataParser instance used to hide XML reading details.
468
469 // The FieldData element representation.
471
472 // The input file's name.
473 char* FileName;
474
475 // The stream used to read the input.
476 std::istream* Stream;
477
478 // Whether this object is reading from a string or a file.
479 // Default is 0: read from file.
481
482 // The input string.
483 std::string InputString;
484
485 // The input array. Keeps a low memory footprint by sourcing StringStream from contents of this
486 // array
488
489 // The array selections.
494
500
506
507 // The observer to modify this object when the array selections are
508 // modified.
510
511 // Whether there was an error reading the file in RequestInformation.
513
514 // Whether there was an error reading the file in RequestData.
516
517 // incrementally fine-tuned progress updates.
518 virtual void GetProgressRange(float* range);
519 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
520 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
521 virtual void UpdateProgressDiscrete(float progress);
523
524 virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
525 vtkInformationVector* outputVector);
526 virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
527 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
528 {
529 return 1;
530 }
531 virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
532 vtkInformationVector* outputVector);
534
535 // Whether there was an error reading the XML.
537
538 // For structured data keep track of dimensions empty of cells. For
539 // unstructured data these are always zero. This is used to support
540 // 1-D and 2-D cell data.
541 int AxesEmpty[3];
542
543 // The timestep currently being read.
547 void SetNumberOfTimeSteps(int num);
548 // buffer for reading timestep from the XML file the length is of
549 // NumberOfTimeSteps and therefore is always long enough
551 // Store the range of time steps
553
554 // Now we need to save what was the last time read for each kind of
555 // data to avoid rereading it that is to say we need a var for
556 // e.g. PointData/CellData/Points/Cells...
557 // See SubClass for details with member vars like PointsTimeStep/PointsOffset
558
559 // Helper function useful to know if a timestep is found in an array of timestep
560 static int IsTimeStepInArray(int timestep, int* timesteps, int length);
561
564
565 // Flag for whether DataProgressCallback should actually update
566 // progress.
568
570
571 /*
572 * Populate the output's FieldData with the file's FieldData tags content
573 */
575
576private:
577 int OpenVTKStream();
578
579 // The stream used to read the input if it is in a resource stream
581
582 bool ReadFromInputStream = false;
583
584 // The stream used to read the input if it is in a file.
585 istream* FileStream;
586 // The stream used to read the input if it is in a string.
587 std::istringstream* StringStream;
588
589 // Used when converting vtkResourceStream into istream
590 std::unique_ptr<std::streambuf> Streambuf;
591 std::unique_ptr<std::istream> StreamBuffer;
592
593 int TimeStepWasReadOnce;
594
595 int FileMajorVersion;
596 int FileMinorVersion;
597
598 vtkDataObject* CurrentOutput;
599 vtkInformation* CurrentOutputInformation;
600
601 vtkXMLReader(const vtkXMLReader&) = delete;
602 void operator=(const vtkXMLReader&) = delete;
603
604 vtkCommand* ReaderErrorObserver;
605 vtkCommand* ParserErrorObserver;
606};
607
608VTK_ABI_NAMESPACE_END
609#endif
int idx
Definition HexCnBasis.h:79
Abstract superclass for all arrays.
supports function callbacks
dynamic, self-adjusting array of char
superclass for callback/observer methods
Definition vtkCommand.h:387
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:165
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.
int IntersectExtents(VTK_FUTURE_CONST int extent1[6], VTK_FUTURE_CONST int extent2[6], int result[6])
Utility methods for subclasses.
vtkDataArraySelection * CellDataArraySelection
virtual void SetupOutputData()
Setup the output's data with allocation.
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...
void ComputePointIncrements(VTK_FUTURE_CONST int extent[6], vtkIdType *increments)
Utility methods for subclasses.
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]
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.
void ComputeCellIncrements(VTK_FUTURE_CONST int extent[6], vtkIdType *increments)
Utility methods for subclasses.
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.
vtkIdType GetStartTuple(VTK_FUTURE_CONST int extent[6], vtkIdType *increments, int i, int j, int k)
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(VTK_FUTURE_CONST int extent[6], 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 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 ...
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.
void ComputePointDimensions(VTK_FUTURE_CONST int extent[6], int *dimensions)
Utility methods for subclasses.
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:363
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:318
#define VTK_FILEPATH
#define VTK_MARSHALAUTO