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=========================================================================*/
33#ifndef vtkXMLReader_h
34#define vtkXMLReader_h
35
36#include "vtkAlgorithm.h"
37#include "vtkIOXMLModule.h" // For export macro
38#include "vtkSmartPointer.h" // for vtkSmartPointer.
39
40#include <string> // for std::string
41
44class vtkCommand;
45class vtkDataArray;
47class vtkDataSet;
52class vtkInformation;
53class vtkStringArray;
54
55class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
56{
57public:
58 vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
59 void PrintSelf(ostream& os, vtkIndent indent) override;
60
62 {
65 OTHER
66 };
67
69
75
77
80 vtkSetMacro(ReadFromInputString, vtkTypeBool);
81 vtkGetMacro(ReadFromInputString, vtkTypeBool);
82 vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
83 void SetInputString(const std::string& s) { this->InputString = s; }
85
93 virtual int CanReadFile(VTK_FILEPATH const char* name);
94
96
102
104
108 vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
109 vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
110 vtkGetObjectMacro(ColumnArraySelection, vtkDataArraySelection);
112
114
121
123
127 const char* GetTimeDataArray(int idx) const;
128 vtkGetObjectMacro(TimeDataStringArray, vtkStringArray);
130
132
138 vtkGetStringMacro(ActiveTimeDataArrayName);
139 vtkSetStringMacro(ActiveTimeDataArrayName);
141
143
147 const char* GetPointArrayName(int index);
148 const char* GetCellArrayName(int index);
149 const char* GetColumnArrayName(int index);
151
153
157 int GetPointArrayStatus(const char* name);
158 int GetCellArrayStatus(const char* name);
159 void SetPointArrayStatus(const char* name, int status);
160 void SetCellArrayStatus(const char* name, int status);
161 int GetColumnArrayStatus(const char* name);
162 void SetColumnArrayStatus(const char* name, int status);
164
165 // For the specified port, copy the information this reader sets up in
166 // SetupOutputInformation to outInfo
167 virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
168
170
173 vtkSetMacro(TimeStep, int);
174 vtkGetMacro(TimeStep, int);
176
177 vtkGetMacro(NumberOfTimeSteps, int);
179
182 vtkGetVector2Macro(TimeStepRange, int);
183 vtkSetVector2Macro(TimeStepRange, int);
185
190 vtkXMLDataParser* GetXMLParser() { return this->XMLParser; }
191
193 vtkInformationVector* outputVector) override;
194
196
201 vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
203
205
210 vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
212
213protected:
215 ~vtkXMLReader() override;
216
217 // Pipeline execution methods to be defined by subclass. Called by
218 // corresponding RequestData methods after appropriate setup has been
219 // done.
220 virtual int ReadXMLInformation();
221 virtual void ReadXMLData();
222
223 // Get the name of the data set being read.
224 virtual const char* GetDataSetName() = 0;
225
226 // Test if the reader can read a file with the given version number.
227 virtual int CanReadFileVersion(int major, int minor);
228
229 // Setup the output with no data available. Used in error cases.
230 virtual void SetupEmptyOutput() = 0;
231
232 // Setup the output's information.
233 virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
234
235 // Setup the output's data with allocation.
236 virtual void SetupOutputData();
237
238 // Read the primary element from the file. This is the element
239 // whose name is the value returned by GetDataSetName().
240 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
241
242 // Read the top-level element from the file. This is always the
243 // VTKFile element.
244 virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
245
251 int GetLocalDataType(vtkXMLDataElement* da, int datatype);
252
253 // Create a vtkAbstractArray from its cooresponding XML representation.
254 // Does not allocate.
256
257 // Create a vtkInformationKey from its corresponding XML representation.
258 // Stores it in the instance of vtkInformationProvided. Does not allocate.
260
261 // Populates the info object with the InformationKey children in infoRoot.
262 // Returns false if errors occur.
264
265 // Internal utility methods.
266 virtual int OpenStream();
267 virtual void CloseStream();
268 virtual int OpenVTKFile();
269 virtual void CloseVTKFile();
270 virtual int OpenVTKString();
271 virtual void CloseVTKString();
272 virtual void CreateXMLParser();
273 virtual void DestroyXMLParser();
274 void SetupCompressor(const char* type);
276
282 virtual int CanReadFileWithDataType(const char* dsname);
283
284 // Returns the major version for the file being read. -1 when invalid.
285 vtkGetMacro(FileMajorVersion, int);
286
287 // Returns the minor version for the file being read. -1 when invalid.
288 vtkGetMacro(FileMinorVersion, int);
289
290 // Utility methods for subclasses.
291 int IntersectExtents(int* extent1, int* extent2, int* result);
292 int Min(int a, int b);
293 int Max(int a, int b);
294 void ComputePointDimensions(int* extent, int* dimensions);
295 void ComputePointIncrements(int* extent, vtkIdType* increments);
296 void ComputeCellDimensions(int* extent, int* dimensions);
297 void ComputeCellIncrements(int* extent, vtkIdType* increments);
298 vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
300 char** CreateStringArray(int numStrings);
301 void DestroyStringArray(int numStrings, char** strings);
302
303 // Read an Array values starting at the given index and up to numValues.
304 // This method assumes that the array is of correct size to
305 // accommodate all numValues values. arrayIndex is the value index at which the read
306 // values will be put in the array.
307 virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
308 vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
309
310 // Setup the data array selections for the input's set of arrays.
312
313 int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
314 vtkInformationVector*(&infoVector));
315
316 // Check whether the given array element is an enabled array.
319
320 // Callback registered with the SelectionObserver.
322 vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
323
324 // Give concrete classes an option to squeeze any output arrays
325 // at the end of RequestData.
327
338
339 // The vtkXMLDataParser instance used to hide XML reading details.
341
342 // The FieldData element representation.
344
345 // The input file's name.
346 char* FileName;
347
348 // The stream used to read the input.
349 istream* Stream;
350
351 // Whether this object is reading from a string or a file.
352 // Default is 0: read from file.
354
355 // The input string.
357
358 // The array selections.
363
369
375
376 // The observer to modify this object when the array selections are
377 // modified.
379
380 // Whether there was an error reading the file in RequestInformation.
382
383 // Whether there was an error reading the file in RequestData.
385
386 // incrementally fine-tuned progress updates.
387 virtual void GetProgressRange(float* range);
388 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
389 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
390 virtual void UpdateProgressDiscrete(float progress);
391 float ProgressRange[2];
392
393 virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
394 vtkInformationVector* outputVector);
395 virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
396 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
397 {
398 return 1;
399 }
400 virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
401 vtkInformationVector* outputVector);
403
404 // Whether there was an error reading the XML.
406
407 // For structured data keep track of dimensions empty of cells. For
408 // unstructured data these are always zero. This is used to support
409 // 1-D and 2-D cell data.
410 int AxesEmpty[3];
411
412 // The timestep currently being read.
416 void SetNumberOfTimeSteps(int num);
417 // buffer for reading timestep from the XML file the length is of
418 // NumberOfTimeSteps and therefore is always long enough
420 // Store the range of time steps
421 int TimeStepRange[2];
422
423 // Now we need to save what was the last time read for each kind of
424 // data to avoid rereading it that is to say we need a var for
425 // e.g. PointData/CellData/Points/Cells...
426 // See SubClass for details with member vars like PointsTimeStep/PointsOffset
427
428 // Helper function useful to know if a timestep is found in an array of timestep
429 static int IsTimeStepInArray(int timestep, int* timesteps, int length);
430
433
434 // Flag for whether DataProgressCallback should actually update
435 // progress.
437
439
441
442private:
443 // The stream used to read the input if it is in a file.
444 istream* FileStream;
445 // The stream used to read the input if it is in a string.
446 std::istringstream* StringStream;
447 int TimeStepWasReadOnce;
448
449 int FileMajorVersion;
450 int FileMinorVersion;
451
452 vtkDataObject* CurrentOutput;
453 vtkInformation* CurrentOutputInformation;
454
455private:
456 vtkXMLReader(const vtkXMLReader&) = delete;
457 void operator=(const vtkXMLReader&) = delete;
458
459 vtkCommand* ReaderErrorObserver;
460 vtkCommand* ParserErrorObserver;
461};
462
463#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:59
general representation of visualization data
Definition: vtkDataObject.h:69
represent and manipulate attribute data in a dataset
abstract class to specify dataset behavior
Definition: vtkDataSet.h:66
a simple class to control print indentation
Definition: vtkIndent.h:43
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:42
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:56
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:343
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:378
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:438
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:415
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
istream * Stream
Definition: vtkXMLReader.h:349
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:360
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:326
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:374
virtual void CloseStream()
int CanReadFileVersionString(const char *version)
void ReadFieldData()
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:233
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:353
void SetupCompressor(const char *type)
vtkInformation * GetCurrentOutputInformation()
vtkDataArraySelection * ColumnArraySelection
Definition: vtkXMLReader.h:361
int InformationError
Definition: vtkXMLReader.h:381
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:340
virtual const char * GetDataSetName()=0
vtkXMLDataParser * GetXMLParser()
Returns the internal XML parser.
Definition: vtkXMLReader.h:190
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:83
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:402
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:395
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:368
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:346
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:362
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:356
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:359
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:167
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