VTK  9.5.20250625
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#ifndef vtkXMLReader_h
35#define vtkXMLReader_h
36
37#include "vtkAlgorithm.h"
38#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_5_0
39#include "vtkIOXMLModule.h" // For export macro
40#include "vtkSmartPointer.h" // for vtkSmartPointer.
41
42#include <string> // for std::string
43
44VTK_ABI_NAMESPACE_BEGIN
47class vtkCharArray;
48class vtkCommand;
49class vtkDataArray;
51class vtkDataSet;
56class vtkInformation;
57class vtkStringArray;
58
59class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
60{
61public:
62 vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
63 void PrintSelf(ostream& os, vtkIndent indent) override;
64
66 {
69 OTHER
70 };
71
73
79
81
84 vtkSetMacro(ReadFromInputString, vtkTypeBool);
85 vtkGetMacro(ReadFromInputString, vtkTypeBool);
86 vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
88
94 void SetInputString(const char* in);
95 void SetInputString(const char* in, int len);
96 void SetBinaryInputString(const char*, int len);
97 void SetInputString(const std::string& input)
98 {
99 this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length()));
100 }
102
104
114
122 virtual int CanReadFile(VTK_FILEPATH const char* name);
123
125
131
133
137 vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
138 vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
139 vtkGetObjectMacro(ColumnArraySelection, vtkDataArraySelection);
141
143
150
152
156 const char* GetTimeDataArray(int idx) const;
157 vtkGetObjectMacro(TimeDataStringArray, vtkStringArray);
159
161
167 vtkGetStringMacro(ActiveTimeDataArrayName);
168 vtkSetStringMacro(ActiveTimeDataArrayName);
170
172
176 const char* GetPointArrayName(int index);
177 const char* GetCellArrayName(int index);
178 const char* GetColumnArrayName(int index);
180
182
186 int GetPointArrayStatus(const char* name);
187 int GetCellArrayStatus(const char* name);
188 void SetPointArrayStatus(const char* name, int status);
189 void SetCellArrayStatus(const char* name, int status);
190 int GetColumnArrayStatus(const char* name);
191 void SetColumnArrayStatus(const char* name, int status);
193
194 // For the specified port, copy the information this reader sets up in
195 // SetupOutputInformation to outInfo
196 virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
197
199
202 vtkSetMacro(TimeStep, int);
203 vtkGetMacro(TimeStep, int);
205
206 vtkGetMacro(NumberOfTimeSteps, int);
208
211 vtkGetVector2Macro(TimeStepRange, int);
212 vtkSetVector2Macro(TimeStepRange, int);
214
219 vtkXMLDataParser* GetXMLParser() { return this->XMLParser; }
220
222 vtkInformationVector* outputVector) override;
223
225
230 vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
232
234
239 vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
241
242protected:
244 ~vtkXMLReader() override;
245
247
252 virtual int ReadXMLInformation();
253 virtual void ReadXMLData();
255
259 virtual const char* GetDataSetName() = 0;
260
264 virtual int CanReadFileVersion(int major, int minor);
265
269 virtual void SetupEmptyOutput() = 0;
270
274 virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
275
279 virtual void SetupOutputData();
280
285 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
286
291 virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
292
298 int GetLocalDataType(vtkXMLDataElement* da, int datatype);
299
305
311
317
319
322 virtual int OpenStream();
323 virtual void CloseStream();
324 virtual int OpenVTKFile();
325 virtual void CloseVTKFile();
326 virtual int OpenVTKString();
327 virtual void CloseVTKString();
328 virtual void CreateXMLParser();
329 virtual void DestroyXMLParser();
330 void SetupCompressor(const char* type);
331 int CanReadFileVersionString(const char* version);
333
339 virtual int CanReadFileWithDataType(const char* dsname);
340
344 vtkGetMacro(FileMajorVersion, int);
345
349 vtkGetMacro(FileMinorVersion, int);
350
352
355 int IntersectExtents(int* extent1, int* extent2, int* result);
356 VTK_DEPRECATED_IN_9_5_0("Use std::min instead")
357 int Min(int a, int b);
358 VTK_DEPRECATED_IN_9_5_0("Use std::max instead")
359 int Max(int a, int b);
360 void ComputePointDimensions(int* extent, int* dimensions);
361 void ComputePointIncrements(int* extent, vtkIdType* increments);
362 void ComputeCellDimensions(int* extent, int* dimensions);
363 void ComputeCellIncrements(int* extent, vtkIdType* increments);
364 vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
365 void ReadAttributeIndices(vtkXMLDataElement* eDSA, vtkDataSetAttributes* dsa);
366 char** CreateStringArray(int numStrings);
367 void DestroyStringArray(int numStrings, char** strings);
369
376 virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
377 vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
378
387 virtual int ReadArrayTuples(vtkXMLDataElement* da, vtkIdType arrayTupleIndex,
388 vtkAbstractArray* array, vtkIdType startTupleIndex, vtkIdType numTuples,
389 FieldType type = OTHER);
390
394 void SetDataArraySelections(vtkXMLDataElement* eDSA, vtkDataArraySelection* sel);
395
396 int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
397 vtkInformationVector*(&infoVector));
398
400
403 int PointDataArrayIsEnabled(vtkXMLDataElement* ePDA);
404 int CellDataArrayIsEnabled(vtkXMLDataElement* eCDA);
406
410 static void SelectionModifiedCallback(
411 vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
412
417 virtual void SqueezeOutputArrays(vtkDataObject*) {}
418
429
430 // The vtkXMLDataParser instance used to hide XML reading details.
432
433 // The FieldData element representation.
435
436 // The input file's name.
437 char* FileName;
438
439 // The stream used to read the input.
440 istream* Stream;
441
442 // Whether this object is reading from a string or a file.
443 // Default is 0: read from file.
445
446 // The input string.
447 std::string InputString;
448
449 // The input array. Keeps a low memory footprint by sourcing StringStream from contents of this
450 // array
452
453 // The array selections.
458
464
470
471 // The observer to modify this object when the array selections are
472 // modified.
474
475 // Whether there was an error reading the file in RequestInformation.
477
478 // Whether there was an error reading the file in RequestData.
480
481 // incrementally fine-tuned progress updates.
482 virtual void GetProgressRange(float* range);
483 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
484 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
485 virtual void UpdateProgressDiscrete(float progress);
486 float ProgressRange[2];
487
488 virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
489 vtkInformationVector* outputVector);
490 virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
491 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
492 {
493 return 1;
494 }
495 virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
496 vtkInformationVector* outputVector);
498
499 // Whether there was an error reading the XML.
501
502 // For structured data keep track of dimensions empty of cells. For
503 // unstructured data these are always zero. This is used to support
504 // 1-D and 2-D cell data.
505 int AxesEmpty[3];
506
507 // The timestep currently being read.
511 void SetNumberOfTimeSteps(int num);
512 // buffer for reading timestep from the XML file the length is of
513 // NumberOfTimeSteps and therefore is always long enough
515 // Store the range of time steps
516 int TimeStepRange[2];
517
518 // Now we need to save what was the last time read for each kind of
519 // data to avoid rereading it that is to say we need a var for
520 // e.g. PointData/CellData/Points/Cells...
521 // See SubClass for details with member vars like PointsTimeStep/PointsOffset
522
523 // Helper function useful to know if a timestep is found in an array of timestep
524 static int IsTimeStepInArray(int timestep, int* timesteps, int length);
525
528
529 // Flag for whether DataProgressCallback should actually update
530 // progress.
532
534
535 /*
536 * Populate the output's FieldData with the file's FieldData tags content
537 */
539
540private:
541 // The stream used to read the input if it is in a file.
542 istream* FileStream;
543 // The stream used to read the input if it is in a string.
544 std::istringstream* StringStream;
545 int TimeStepWasReadOnce;
546
547 int FileMajorVersion;
548 int FileMinorVersion;
549
550 vtkDataObject* CurrentOutput;
551 vtkInformation* CurrentOutputInformation;
552
553 vtkXMLReader(const vtkXMLReader&) = delete;
554 void operator=(const vtkXMLReader&) = delete;
555
556 vtkCommand* ReaderErrorObserver;
557 vtkCommand* ParserErrorObserver;
558};
559
560VTK_ABI_NAMESPACE_END
561#endif
Abstract superclass for all arrays.
Superclass for all sources, filters, and sinks in VTK.
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.
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:165
a simple class to control print indentation
Definition vtkIndent.h:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition vtkObject.h:162
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.
vtkCharArray * InputArray
vtkXMLDataElement * FieldDataElement
vtkCallbackCommand * SelectionObserver
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.
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.
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.
int CreateInformationKey(vtkXMLDataElement *eInfoKey, vtkInformation *info)
Create a vtkInformationKey from its corresponding XML representation.
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 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...
virtual void CloseStream()
Internal utility methods.
int CanReadFileVersionString(const char *version)
Internal utility methods.
void ReadFieldData()
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.
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.
virtual int CanReadFile(const char *name)
Test whether the file (type) with the given name can be read by this reader.
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 SetNumberOfTimeSteps(int num)
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
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 ...
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 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 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
vtkDataSet * GetOutputAsDataSet(int index)
Get the output as a vtkDataSet pointer.
virtual int RequestDataObject(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_DEPRECATED_IN_9_5_0(reason)
int vtkIdType
Definition vtkType.h:332
#define VTK_FILEPATH
#define max(a, b)