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=========================================================================*/
43#ifndef vtkXMLReader_h
44#define vtkXMLReader_h
45
46#include "vtkAlgorithm.h"
47#include "vtkIOXMLModule.h" // For export macro
48#include "vtkSmartPointer.h" // for vtkSmartPointer.
49
50#include <string> // for std::string
51
54class vtkCommand;
55class vtkDataArray;
57class vtkDataSet;
62class vtkInformation;
63class vtkStringArray;
64
65class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
66{
67public:
68 vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
69 void PrintSelf(ostream& os, vtkIndent indent) override;
70
72 {
75 OTHER
76 };
77
79
85
87
90 vtkSetMacro(ReadFromInputString, vtkTypeBool);
91 vtkGetMacro(ReadFromInputString, vtkTypeBool);
92 vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
93 void SetInputString(const std::string& s) { this->InputString = s; }
95
103 virtual int CanReadFile(VTK_FILEPATH const char* name);
104
106
112
114
118 vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
119 vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
120 vtkGetObjectMacro(ColumnArraySelection, vtkDataArraySelection);
122
124
131
133
137 const char* GetTimeDataArray(int idx) const;
138 vtkGetObjectMacro(TimeDataStringArray, vtkStringArray);
140
142
148 vtkGetStringMacro(ActiveTimeDataArrayName);
149 vtkSetStringMacro(ActiveTimeDataArrayName);
151
153
157 const char* GetPointArrayName(int index);
158 const char* GetCellArrayName(int index);
159 const char* GetColumnArrayName(int index);
161
163
167 int GetPointArrayStatus(const char* name);
168 int GetCellArrayStatus(const char* name);
169 void SetPointArrayStatus(const char* name, int status);
170 void SetCellArrayStatus(const char* name, int status);
171 int GetColumnArrayStatus(const char* name);
172 void SetColumnArrayStatus(const char* name, int status);
174
175 // For the specified port, copy the information this reader sets up in
176 // SetupOutputInformation to outInfo
177 virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
178
180
183 vtkSetMacro(TimeStep, int);
184 vtkGetMacro(TimeStep, int);
186
187 vtkGetMacro(NumberOfTimeSteps, int);
189
192 vtkGetVector2Macro(TimeStepRange, int);
193 vtkSetVector2Macro(TimeStepRange, int);
195
200 vtkXMLDataParser* GetXMLParser() { return this->XMLParser; }
201
203 vtkInformationVector* outputVector) override;
204
206
211 vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
213
215
220 vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
222
223protected:
225 ~vtkXMLReader() override;
226
227 // Pipeline execution methods to be defined by subclass. Called by
228 // corresponding RequestData methods after appropriate setup has been
229 // done.
230 virtual int ReadXMLInformation();
231 virtual void ReadXMLData();
232
233 // Get the name of the data set being read.
234 virtual const char* GetDataSetName() = 0;
235
236 // Test if the reader can read a file with the given version number.
237 virtual int CanReadFileVersion(int major, int minor);
238
239 // Setup the output with no data available. Used in error cases.
240 virtual void SetupEmptyOutput() = 0;
241
242 // Setup the output's information.
243 virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
244
245 // Setup the output's data with allocation.
246 virtual void SetupOutputData();
247
248 // Read the primary element from the file. This is the element
249 // whose name is the value returned by GetDataSetName().
250 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
251
252 // Read the top-level element from the file. This is always the
253 // VTKFile element.
254 virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
255
261 int GetLocalDataType(vtkXMLDataElement* da, int datatype);
262
263 // Create a vtkAbstractArray from its cooresponding XML representation.
264 // Does not allocate.
266
267 // Create a vtkInformationKey from its corresponding XML representation.
268 // Stores it in the instance of vtkInformationProvided. Does not allocate.
270
271 // Populates the info object with the InformationKey children in infoRoot.
272 // Returns false if errors occur.
274
275 // Internal utility methods.
276 virtual int OpenStream();
277 virtual void CloseStream();
278 virtual int OpenVTKFile();
279 virtual void CloseVTKFile();
280 virtual int OpenVTKString();
281 virtual void CloseVTKString();
282 virtual void CreateXMLParser();
283 virtual void DestroyXMLParser();
284 void SetupCompressor(const char* type);
286
292 virtual int CanReadFileWithDataType(const char* dsname);
293
294 // Returns the major version for the file being read. -1 when invalid.
295 vtkGetMacro(FileMajorVersion, int);
296
297 // Returns the minor version for the file being read. -1 when invalid.
298 vtkGetMacro(FileMinorVersion, int);
299
300 // Utility methods for subclasses.
301 int IntersectExtents(int* extent1, int* extent2, int* result);
302 int Min(int a, int b);
303 int Max(int a, int b);
304 void ComputePointDimensions(int* extent, int* dimensions);
305 void ComputePointIncrements(int* extent, vtkIdType* increments);
306 void ComputeCellDimensions(int* extent, int* dimensions);
307 void ComputeCellIncrements(int* extent, vtkIdType* increments);
308 vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
310 char** CreateStringArray(int numStrings);
311 void DestroyStringArray(int numStrings, char** strings);
312
313 // Read an Array values starting at the given index and up to numValues.
314 // This method assumes that the array is of correct size to
315 // accommodate all numValues values. arrayIndex is the value index at which the read
316 // values will be put in the array.
317 virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
318 vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
319
320 // Setup the data array selections for the input's set of arrays.
322
323 int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
324 vtkInformationVector*(&infoVector));
325
326 // Check whether the given array element is an enabled array.
329
330 // Callback registered with the SelectionObserver.
332 vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
333
334 // Give concrete classes an option to squeeze any output arrays
335 // at the end of RequestData.
337
348
349 // The vtkXMLDataParser instance used to hide XML reading details.
351
352 // The FieldData element representation.
354
355 // The input file's name.
356 char* FileName;
357
358 // The stream used to read the input.
359 istream* Stream;
360
361 // Whether this object is reading from a string or a file.
362 // Default is 0: read from file.
364
365 // The input string.
367
368 // The array selections.
373
379
385
386 // The observer to modify this object when the array selections are
387 // modified.
389
390 // Whether there was an error reading the file in RequestInformation.
392
393 // Whether there was an error reading the file in RequestData.
395
396 // incrementally fine-tuned progress updates.
397 virtual void GetProgressRange(float* range);
398 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
399 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
400 virtual void UpdateProgressDiscrete(float progress);
401 float ProgressRange[2];
402
403 virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
404 vtkInformationVector* outputVector);
405 virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
406 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
407 {
408 return 1;
409 }
410 virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
411 vtkInformationVector* outputVector);
413
414 // Whether there was an error reading the XML.
416
417 // For structured data keep track of dimensions empty of cells. For
418 // unstructured data these are always zero. This is used to support
419 // 1-D and 2-D cell data.
420 int AxesEmpty[3];
421
422 // The timestep currently being read.
426 void SetNumberOfTimeSteps(int num);
427 // buffer for reading timestep from the XML file the length is of
428 // NumberOfTimeSteps and therefore is always long enough
430 // Store the range of time steps
431 int TimeStepRange[2];
432
433 // Now we need to save what was the last time read for each kind of
434 // data to avoid rereading it that is to say we need a var for
435 // e.g. PointData/CellData/Points/Cells...
436 // See SubClass for details with member vars like PointsTimeStep/PointsOffset
437
438 // Helper function useful to know if a timestep is found in an array of timestep
439 static int IsTimeStepInArray(int timestep, int* timesteps, int length);
440
443
444 // Flag for whether DataProgressCallback should actually update
445 // progress.
447
449
451
452private:
453 // The stream used to read the input if it is in a file.
454 istream* FileStream;
455 // The stream used to read the input if it is in a string.
456 std::istringstream* StringStream;
457 int TimeStepWasReadOnce;
458
459 int FileMajorVersion;
460 int FileMinorVersion;
461
462 vtkDataObject* CurrentOutput;
463 vtkInformation* CurrentOutputInformation;
464
465private:
466 vtkXMLReader(const vtkXMLReader&) = delete;
467 void operator=(const vtkXMLReader&) = delete;
468
469 vtkCommand* ReaderErrorObserver;
470 vtkCommand* ParserErrorObserver;
471};
472
473#endif
Abstract superclass for all arrays.
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:114
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:159
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:113
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:73
a vtkAbstractArray subclass for strings
record modification and/or execution time
Definition: vtkTimeStamp.h:52
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:66
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:353
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:388
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:448
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:425
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
istream * Stream
Definition: vtkXMLReader.h:359
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:370
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:336
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:384
virtual void CloseStream()
int CanReadFileVersionString(const char *version)
void ReadFieldData()
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:243
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:363
void SetupCompressor(const char *type)
vtkInformation * GetCurrentOutputInformation()
vtkDataArraySelection * ColumnArraySelection
Definition: vtkXMLReader.h:371
int InformationError
Definition: vtkXMLReader.h:391
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:350
virtual const char * GetDataSetName()=0
vtkXMLDataParser * GetXMLParser()
Returns the internal XML parser.
Definition: vtkXMLReader.h:200
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:93
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:412
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:405
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:378
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:356
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:372
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:366
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:369
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:177
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