VTK  9.1.0
vtkXMLReader.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkXMLReader.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
24#ifndef vtkXMLReader_h
25#define vtkXMLReader_h
26
27#include "vtkAlgorithm.h"
28#include "vtkIOXMLModule.h" // For export macro
29#include "vtkSmartPointer.h" // for vtkSmartPointer.
30
31#include <string> // for std::string
32
35class vtkCommand;
36class vtkDataArray;
38class vtkDataSet;
43class vtkInformation;
44class vtkStringArray;
45
46class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
47{
48public:
49 vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
50 void PrintSelf(ostream& os, vtkIndent indent) override;
51
53 {
56 OTHER
57 };
58
60
66
68
71 vtkSetMacro(ReadFromInputString, vtkTypeBool);
72 vtkGetMacro(ReadFromInputString, vtkTypeBool);
73 vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
74 void SetInputString(const std::string& s) { this->InputString = s; }
76
84 virtual int CanReadFile(VTK_FILEPATH const char* name);
85
87
93
95
99 vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
100 vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
101 vtkGetObjectMacro(ColumnArraySelection, vtkDataArraySelection);
103
105
112
114
118 const char* GetTimeDataArray(int idx) const;
119 vtkGetObjectMacro(TimeDataStringArray, vtkStringArray);
121
123
129 vtkGetStringMacro(ActiveTimeDataArrayName);
130 vtkSetStringMacro(ActiveTimeDataArrayName);
132
134
138 const char* GetPointArrayName(int index);
139 const char* GetCellArrayName(int index);
140 const char* GetColumnArrayName(int index);
142
144
148 int GetPointArrayStatus(const char* name);
149 int GetCellArrayStatus(const char* name);
150 void SetPointArrayStatus(const char* name, int status);
151 void SetCellArrayStatus(const char* name, int status);
152 int GetColumnArrayStatus(const char* name);
153 void SetColumnArrayStatus(const char* name, int status);
155
156 // For the specified port, copy the information this reader sets up in
157 // SetupOutputInformation to outInfo
158 virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
159
161
164 vtkSetMacro(TimeStep, int);
165 vtkGetMacro(TimeStep, int);
167
168 vtkGetMacro(NumberOfTimeSteps, int);
170
173 vtkGetVector2Macro(TimeStepRange, int);
174 vtkSetVector2Macro(TimeStepRange, int);
176
181 vtkXMLDataParser* GetXMLParser() { return this->XMLParser; }
182
184 vtkInformationVector* outputVector) override;
185
187
192 vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
194
196
201 vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
203
204protected:
206 ~vtkXMLReader() override;
207
208 // Pipeline execution methods to be defined by subclass. Called by
209 // corresponding RequestData methods after appropriate setup has been
210 // done.
211 virtual int ReadXMLInformation();
212 virtual void ReadXMLData();
213
214 // Get the name of the data set being read.
215 virtual const char* GetDataSetName() = 0;
216
217 // Test if the reader can read a file with the given version number.
218 virtual int CanReadFileVersion(int major, int minor);
219
220 // Setup the output with no data available. Used in error cases.
221 virtual void SetupEmptyOutput() = 0;
222
223 // Setup the output's information.
224 virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
225
226 // Setup the output's data with allocation.
227 virtual void SetupOutputData();
228
229 // Read the primary element from the file. This is the element
230 // whose name is the value returned by GetDataSetName().
231 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
232
233 // Read the top-level element from the file. This is always the
234 // VTKFile element.
235 virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
236
242 int GetLocalDataType(vtkXMLDataElement* da, int datatype);
243
244 // Create a vtkAbstractArray from its cooresponding XML representation.
245 // Does not allocate.
247
248 // Create a vtkInformationKey from its corresponding XML representation.
249 // Stores it in the instance of vtkInformationProvided. Does not allocate.
251
252 // Populates the info object with the InformationKey children in infoRoot.
253 // Returns false if errors occur.
255
256 // Internal utility methods.
257 virtual int OpenStream();
258 virtual void CloseStream();
259 virtual int OpenVTKFile();
260 virtual void CloseVTKFile();
261 virtual int OpenVTKString();
262 virtual void CloseVTKString();
263 virtual void CreateXMLParser();
264 virtual void DestroyXMLParser();
265 void SetupCompressor(const char* type);
267
273 virtual int CanReadFileWithDataType(const char* dsname);
274
275 // Returns the major version for the file being read. -1 when invalid.
276 vtkGetMacro(FileMajorVersion, int);
277
278 // Returns the minor version for the file being read. -1 when invalid.
279 vtkGetMacro(FileMinorVersion, int);
280
281 // Utility methods for subclasses.
282 int IntersectExtents(int* extent1, int* extent2, int* result);
283 int Min(int a, int b);
284 int Max(int a, int b);
285 void ComputePointDimensions(int* extent, int* dimensions);
286 void ComputePointIncrements(int* extent, vtkIdType* increments);
287 void ComputeCellDimensions(int* extent, int* dimensions);
288 void ComputeCellIncrements(int* extent, vtkIdType* increments);
289 vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
291 char** CreateStringArray(int numStrings);
292 void DestroyStringArray(int numStrings, char** strings);
293
294 // Read an Array values starting at the given index and up to numValues.
295 // This method assumes that the array is of correct size to
296 // accommodate all numValues values. arrayIndex is the value index at which the read
297 // values will be put in the array.
298 virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
299 vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
300
301 // Setup the data array selections for the input's set of arrays.
303
304 int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
305 vtkInformationVector*(&infoVector));
306
307 // Check whether the given array element is an enabled array.
310
311 // Callback registered with the SelectionObserver.
313 vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
314
315 // Give concrete classes an option to squeeze any output arrays
316 // at the end of RequestData.
318
329
330 // The vtkXMLDataParser instance used to hide XML reading details.
332
333 // The FieldData element representation.
335
336 // The input file's name.
337 char* FileName;
338
339 // The stream used to read the input.
340 istream* Stream;
341
342 // Whether this object is reading from a string or a file.
343 // Default is 0: read from file.
345
346 // The input string.
348
349 // The array selections.
354
360
366
367 // The observer to modify this object when the array selections are
368 // modified.
370
371 // Whether there was an error reading the file in RequestInformation.
373
374 // Whether there was an error reading the file in RequestData.
376
377 // incrementally fine-tuned progress updates.
378 virtual void GetProgressRange(float* range);
379 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
380 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
381 virtual void UpdateProgressDiscrete(float progress);
382 float ProgressRange[2];
383
384 virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
385 vtkInformationVector* outputVector);
386 virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
387 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
388 {
389 return 1;
390 }
391 virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
392 vtkInformationVector* outputVector);
394
395 // Whether there was an error reading the XML.
397
398 // For structured data keep track of dimensions empty of cells. For
399 // unstructured data these are always zero. This is used to support
400 // 1-D and 2-D cell data.
401 int AxesEmpty[3];
402
403 // The timestep currently being read.
407 void SetNumberOfTimeSteps(int num);
408 // buffer for reading timestep from the XML file the length is of
409 // NumberOfTimeSteps and therefore is always long enough
411 // Store the range of time steps
412 int TimeStepRange[2];
413
414 // Now we need to save what was the last time read for each kind of
415 // data to avoid rereading it that is to say we need a var for
416 // e.g. PointData/CellData/Points/Cells...
417 // See SubClass for details with member vars like PointsTimeStep/PointsOffset
418
419 // Helper function useful to know if a timestep is found in an array of timestep
420 static int IsTimeStepInArray(int timestep, int* timesteps, int length);
421
424
425 // Flag for whether DataProgressCallback should actually update
426 // progress.
428
430
432
433private:
434 // The stream used to read the input if it is in a file.
435 istream* FileStream;
436 // The stream used to read the input if it is in a string.
437 std::istringstream* StringStream;
438 int TimeStepWasReadOnce;
439
440 int FileMajorVersion;
441 int FileMinorVersion;
442
443 vtkDataObject* CurrentOutput;
444 vtkInformation* CurrentOutputInformation;
445
446private:
447 vtkXMLReader(const vtkXMLReader&) = delete;
448 void operator=(const vtkXMLReader&) = delete;
449
450 vtkCommand* ReaderErrorObserver;
451 vtkCommand* ParserErrorObserver;
452};
453
454#endif
Abstract superclass for all arrays.
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:64
supports function callbacks
superclass for callback/observer methods
Definition: vtkCommand.h:394
Store on/off settings for data arrays for a vtkSource.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
general representation of visualization data
Definition: vtkDataObject.h:60
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:34
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:63
a vtkAbstractArray subclass for strings
record modification and/or execution time
Definition: vtkTimeStamp.h:33
Represents an XML element and those nested inside.
Used by vtkXMLReader to parse VTK XML files.
Superclass for VTK's XML format readers.
Definition: vtkXMLReader.h:47
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:334
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:369
char ** CreateStringArray(int numStrings)
virtual void SetProgressRange(const float range[2], int curStep, int numSteps)
virtual void ConvertGhostLevelsToGhostType(FieldType, vtkAbstractArray *, vtkIdType, vtkIdType)
Definition: vtkXMLReader.h:429
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)
virtual void GetProgressRange(float *range)
virtual void DestroyXMLParser()
int NumberOfTimeSteps
Definition: vtkXMLReader.h:406
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
istream * Stream
Definition: vtkXMLReader.h:340
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)
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
Definition: vtkXMLReader.h:351
virtual void SetupOutputData()
void ComputeCellIncrements(int *extent, vtkIdType *increments)
int CreateInformationKey(vtkXMLDataElement *eInfoKey, vtkInformation *info)
void SetDataArraySelections(vtkXMLDataElement *eDSA, vtkDataArraySelection *sel)
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
int GetNumberOfTimeDataArrays() const
Getters for time data array candidates.
virtual void SqueezeOutputArrays(vtkDataObject *)
Definition: vtkXMLReader.h:317
int GetNumberOfPointArrays()
Get the number of point, cell or column arrays available in the input.
int Max(int a, int b)
virtual void CreateXMLParser()
vtkSmartPointer< vtkDataArray > TimeDataArray
Populated in ReadXMLInformation from the field data for the array chosen using ActiveTimeDataArrayNam...
Definition: vtkXMLReader.h:365
virtual void CloseStream()
int CanReadFileVersionString(const char *version)
void ReadFieldData()
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:224
vtkIdType GetStartTuple(int *extent, vtkIdType *increments, int i, int j, int k)
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
Definition: vtkXMLReader.h:344
void SetupCompressor(const char *type)
vtkInformation * GetCurrentOutputInformation()
vtkDataArraySelection * ColumnArraySelection
Definition: vtkXMLReader.h:352
int InformationError
Definition: vtkXMLReader.h:372
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:331
virtual const char * GetDataSetName()=0
vtkXMLDataParser * GetXMLParser()
Returns the internal XML parser.
Definition: vtkXMLReader.h:181
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.
Definition: vtkXMLReader.h:74
void ComputePointIncrements(int *extent, vtkIdType *increments)
virtual int ReadXMLInformation()
vtkAbstractArray * CreateArray(vtkXMLDataElement *da)
int GetNumberOfColumnArrays()
Get the number of point, cell or column arrays available in the input.
void ReadAttributeIndices(vtkXMLDataElement *eDSA, vtkDataSetAttributes *dsa)
int PointDataArrayIsEnabled(vtkXMLDataElement *ePDA)
vtkDataSet * GetOutputAsDataSet()
Get the output as a vtkDataSet pointer.
virtual void CloseVTKFile()
virtual int OpenVTKFile()
vtkTimeStamp ReadMTime
Definition: vtkXMLReader.h:393
void ComputeCellDimensions(int *extent, int *dimensions)
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)
static int IsTimeStepInArray(int timestep, int *timesteps, int length)
virtual int RequestDataObject(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *vtkNotUsed(outputVector))
Definition: vtkXMLReader.h:386
void ComputePointDimensions(int *extent, int *dimensions)
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)
char * ActiveTimeDataArrayName
Name of the field-data array used to determine the time for the dataset being read.
Definition: vtkXMLReader.h:359
virtual int ReadVTKFile(vtkXMLDataElement *eVTKFile)
virtual int OpenVTKString()
virtual int ReadPrimaryElement(vtkXMLDataElement *ePrimary)
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)
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.
char * FileName
Definition: vtkXMLReader.h:337
const char * GetTimeDataArray(int idx) const
Getters for time data array candidates.
virtual void UpdateProgressDiscrete(float progress)
virtual void ReadXMLData()
virtual int OpenStream()
vtkStringArray * TimeDataStringArray
Definition: vtkXMLReader.h:353
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)
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()
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
Definition: vtkXMLReader.h:347
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:350
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:158
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)
@ info
Definition: vtkX3D.h:382
@ length
Definition: vtkX3D.h:399
@ port
Definition: vtkX3D.h:453
@ range
Definition: vtkX3D.h:244
@ extent
Definition: vtkX3D.h:351
@ type
Definition: vtkX3D.h:522
@ version
Definition: vtkX3D.h:532
@ name
Definition: vtkX3D.h:225
@ index
Definition: vtkX3D.h:252
@ progress
Definition: vtkX3D.h:458
@ string
Definition: vtkX3D.h:496
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:332
#define VTK_FILEPATH