VTK  9.2.6
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=========================================================================*/
26
27#ifndef vtkXMLReader_h
28#define vtkXMLReader_h
29
30#include "vtkAlgorithm.h"
31#include "vtkIOXMLModule.h" // For export macro
32#include "vtkSmartPointer.h" // for vtkSmartPointer.
33
34#include <string> // for std::string
35
38class vtkCommand;
39class vtkDataArray;
41class vtkDataSet;
46class vtkInformation;
47class vtkStringArray;
48
49class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
50{
51public:
52 vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
53 void PrintSelf(ostream& os, vtkIndent indent) override;
54
61
63
69
71
77 void SetInputString(const std::string& s) { this->InputString = s; }
79
87 virtual int CanReadFile(VTK_FILEPATH const char* name);
88
90
96
98
106
108
115
117
121 const char* GetTimeDataArray(int idx) const;
124
126
132 vtkGetStringMacro(ActiveTimeDataArrayName);
133 vtkSetStringMacro(ActiveTimeDataArrayName);
135
137
141 const char* GetPointArrayName(int index);
142 const char* GetCellArrayName(int index);
143 const char* GetColumnArrayName(int index);
145
147
151 int GetPointArrayStatus(const char* name);
152 int GetCellArrayStatus(const char* name);
153 void SetPointArrayStatus(const char* name, int status);
154 void SetCellArrayStatus(const char* name, int status);
155 int GetColumnArrayStatus(const char* name);
156 void SetColumnArrayStatus(const char* name, int status);
158
159 // For the specified port, copy the information this reader sets up in
160 // SetupOutputInformation to outInfo
161 virtual void CopyOutputInformation(vtkInformation* vtkNotUsed(outInfo), int vtkNotUsed(port)) {}
162
164
167 vtkSetMacro(TimeStep, int);
168 vtkGetMacro(TimeStep, int);
170
171 vtkGetMacro(NumberOfTimeSteps, int);
173
176 vtkGetVector2Macro(TimeStepRange, int);
177 vtkSetVector2Macro(TimeStepRange, int);
179
185
187 vtkInformationVector* outputVector) override;
188
190
195 vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
197
199
204 vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
206
207protected:
209 ~vtkXMLReader() override;
210
211 // Pipeline execution methods to be defined by subclass. Called by
212 // corresponding RequestData methods after appropriate setup has been
213 // done.
214 virtual int ReadXMLInformation();
215 virtual void ReadXMLData();
216
217 // Get the name of the data set being read.
218 virtual const char* GetDataSetName() = 0;
219
220 // Test if the reader can read a file with the given version number.
221 virtual int CanReadFileVersion(int major, int minor);
222
223 // Setup the output with no data available. Used in error cases.
224 virtual void SetupEmptyOutput() = 0;
225
226 // Setup the output's information.
227 virtual void SetupOutputInformation(vtkInformation* vtkNotUsed(outInfo)) {}
228
229 // Setup the output's data with allocation.
230 virtual void SetupOutputData();
231
232 // Read the primary element from the file. This is the element
233 // whose name is the value returned by GetDataSetName().
234 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
235
236 // Read the top-level element from the file. This is always the
237 // VTKFile element.
238 virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
239
245 int GetLocalDataType(vtkXMLDataElement* da, int datatype);
246
247 // Create a vtkAbstractArray from its cooresponding XML representation.
248 // Does not allocate.
250
251 // Create a vtkInformationKey from its corresponding XML representation.
252 // Stores it in the instance of vtkInformationProvided. Does not allocate.
254
255 // Populates the info object with the InformationKey children in infoRoot.
256 // Returns false if errors occur.
258
259 // Internal utility methods.
260 virtual int OpenStream();
261 virtual void CloseStream();
262 virtual int OpenVTKFile();
263 virtual void CloseVTKFile();
264 virtual int OpenVTKString();
265 virtual void CloseVTKString();
266 virtual void CreateXMLParser();
267 virtual void DestroyXMLParser();
268 void SetupCompressor(const char* type);
269 int CanReadFileVersionString(const char* version);
270
276 virtual int CanReadFileWithDataType(const char* dsname);
277
278 // Returns the major version for the file being read. -1 when invalid.
279 vtkGetMacro(FileMajorVersion, int);
280
281 // Returns the minor version for the file being read. -1 when invalid.
282 vtkGetMacro(FileMinorVersion, int);
283
284 // Utility methods for subclasses.
285 int IntersectExtents(int* extent1, int* extent2, int* result);
286 int Min(int a, int b);
287 int Max(int a, int b);
288 void ComputePointDimensions(int* extent, int* dimensions);
289 void ComputePointIncrements(int* extent, vtkIdType* increments);
290 void ComputeCellDimensions(int* extent, int* dimensions);
291 void ComputeCellIncrements(int* extent, vtkIdType* increments);
292 vtkIdType GetStartTuple(int* extent, vtkIdType* increments, int i, int j, int k);
294 char** CreateStringArray(int numStrings);
295 void DestroyStringArray(int numStrings, char** strings);
296
297 // Read an Array values starting at the given index and up to numValues.
298 // This method assumes that the array is of correct size to
299 // accommodate all numValues values. arrayIndex is the value index at which the read
300 // values will be put in the array.
301 virtual int ReadArrayValues(vtkXMLDataElement* da, vtkIdType arrayIndex, vtkAbstractArray* array,
302 vtkIdType startIndex, vtkIdType numValues, FieldType type = OTHER);
303
304 // Setup the data array selections for the input's set of arrays.
306
307 int SetFieldDataInfo(vtkXMLDataElement* eDSA, int association, vtkIdType numTuples,
308 vtkInformationVector*(&infoVector));
309
310 // Check whether the given array element is an enabled array.
313
314 // Callback registered with the SelectionObserver.
316 vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);
317
318 // Give concrete classes an option to squeeze any output arrays
319 // at the end of RequestData.
321
332
333 // The vtkXMLDataParser instance used to hide XML reading details.
335
336 // The FieldData element representation.
338
339 // The input file's name.
340 char* FileName;
341
342 // The stream used to read the input.
343 istream* Stream;
344
345 // Whether this object is reading from a string or a file.
346 // Default is 0: read from file.
348
349 // The input string.
350 std::string InputString;
351
352 // The array selections.
357
363
369
370 // The observer to modify this object when the array selections are
371 // modified.
373
374 // Whether there was an error reading the file in RequestInformation.
376
377 // Whether there was an error reading the file in RequestData.
379
380 // incrementally fine-tuned progress updates.
381 virtual void GetProgressRange(float* range);
382 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
383 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
384 virtual void UpdateProgressDiscrete(float progress);
386
387 virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
388 vtkInformationVector* outputVector);
389 virtual int RequestDataObject(vtkInformation* vtkNotUsed(request),
390 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
391 {
392 return 1;
393 }
394 virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
395 vtkInformationVector* outputVector);
397
398 // Whether there was an error reading the XML.
400
401 // For structured data keep track of dimensions empty of cells. For
402 // unstructured data these are always zero. This is used to support
403 // 1-D and 2-D cell data.
404 int AxesEmpty[3];
405
406 // The timestep currently being read.
410 void SetNumberOfTimeSteps(int num);
411 // buffer for reading timestep from the XML file the length is of
412 // NumberOfTimeSteps and therefore is always long enough
414 // Store the range of time steps
416
417 // Now we need to save what was the last time read for each kind of
418 // data to avoid rereading it that is to say we need a var for
419 // e.g. PointData/CellData/Points/Cells...
420 // See SubClass for details with member vars like PointsTimeStep/PointsOffset
421
422 // Helper function useful to know if a timestep is found in an array of timestep
423 static int IsTimeStepInArray(int timestep, int* timesteps, int length);
424
427
428 // Flag for whether DataProgressCallback should actually update
429 // progress.
431
433
435
436private:
437 // The stream used to read the input if it is in a file.
438 istream* FileStream;
439 // The stream used to read the input if it is in a string.
440 std::istringstream* StringStream;
441 int TimeStepWasReadOnce;
442
443 int FileMajorVersion;
444 int FileMinorVersion;
445
446 vtkDataObject* CurrentOutput;
447 vtkInformation* CurrentOutputInformation;
448
449private:
450 vtkXMLReader(const vtkXMLReader&) = delete;
451 void operator=(const vtkXMLReader&) = delete;
452
453 vtkCommand* ReaderErrorObserver;
454 vtkCommand* ParserErrorObserver;
455};
456
457#endif
Abstract superclass for all arrays.
supports function callbacks
superclass for callback/observer methods
Definition vtkCommand.h:395
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:63
a simple class to control print indentation
Definition vtkIndent.h:40
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
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.
vtkXMLDataElement * FieldDataElement
vtkCallbackCommand * SelectionObserver
char ** CreateStringArray(int numStrings)
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)
virtual void GetProgressRange(float *range)
virtual void DestroyXMLParser()
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
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.
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
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 *)
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...
virtual void CloseStream()
int CanReadFileVersionString(const char *version)
void ReadFieldData()
float ProgressRange[2]
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
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
void SetupCompressor(const char *type)
vtkInformation * GetCurrentOutputInformation()
vtkDataArraySelection * ColumnArraySelection
vtkXMLDataParser * XMLParser
virtual const char * GetDataSetName()=0
vtkXMLDataParser * GetXMLParser()
Returns the internal XML parser.
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.
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
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))
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.
virtual int ReadVTKFile(vtkXMLDataElement *eVTKFile)
virtual int OpenVTKString()
virtual int ReadPrimaryElement(vtkXMLDataElement *ePrimary)
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...
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.
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
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
vtkDataArraySelection * PointDataArraySelection
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
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)
int vtkTypeBool
Definition vtkABI.h:69
#define vtkDataArray
int vtkIdType
Definition vtkType.h:332
#define VTK_FILEPATH