VTK
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 "vtkIOXMLModule.h" // For export macro
28#include "vtkAlgorithm.h"
29
30#include <string> // for std::string
31
35class vtkDataSet;
40class vtkInformation;
41class vtkCommand;
42
43class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
44{
45public:
46 vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
47 void PrintSelf(ostream& os, vtkIndent indent);
48
50
53 vtkSetStringMacro(FileName);
56
58
61 vtkSetMacro(ReadFromInputString, int);
62 vtkGetMacro(ReadFromInputString, int);
63 vtkBooleanMacro(ReadFromInputString, int);
64 void SetInputString(std::string s) { this->InputString = s; }
66
74 virtual int CanReadFile(const char* name);
75
77
83
85
89 vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
90 vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
92
94
100
102
106 const char* GetPointArrayName(int index);
107 const char* GetCellArrayName(int index);
109
111
115 int GetPointArrayStatus(const char* name);
116 int GetCellArrayStatus(const char* name);
117 void SetPointArrayStatus(const char* name, int status);
118 void SetCellArrayStatus(const char* name, int status);
120
121 // For the specified port, copy the information this reader sets up in
122 // SetupOutputInformation to outInfo
123 virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo),
124 int vtkNotUsed(port)) {}
125
127
130 vtkSetMacro(TimeStep, int);
131 vtkGetMacro(TimeStep, int);
133
134 vtkGetMacro(NumberOfTimeSteps, int);
136
139 vtkGetVector2Macro(TimeStepRange, int);
140 vtkSetVector2Macro(TimeStepRange, int);
142
148 {
149 return this->XMLParser;
150 }
151
152 virtual int ProcessRequest(vtkInformation *request,
153 vtkInformationVector **inputVector,
154 vtkInformationVector *outputVector);
155
157
162 vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
164
166
171 vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
173
174protected:
177
178 // Pipeline execution methods to be defined by subclass. Called by
179 // corresponding RequestData methods after appropriate setup has been
180 // done.
181 virtual int ReadXMLInformation();
182 virtual void ReadXMLData();
183
184 // Get the name of the data set being read.
185 virtual const char* GetDataSetName()=0;
186
187 // Test if the reader can read a file with the given version number.
188 virtual int CanReadFileVersion(int major, int minor);
189
190 // Setup the output with no data available. Used in error cases.
191 virtual void SetupEmptyOutput()=0;
192
193 // Setup the output's information.
194 virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo)) {}
195
196 // Setup the output's data with allocation.
197 virtual void SetupOutputData();
198
199 // Read the primary element from the file. This is the element
200 // whose name is the value returned by GetDataSetName().
201 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
202
203 // Read the top-level element from the file. This is always the
204 // VTKFile element.
205 virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
206
207 // Create a vtkAbstractArray from its cooresponding XML representation.
208 // Does not allocate.
210
211 // Create a vtkInformationKey from its coresponding XML representation.
212 // Stores it in the instance of vtkInformationProvided. Does not allocate.
214
215 // Populates the info object with the InformationKey children in infoRoot.
216 // Returns false if errors occur.
218
219 // Internal utility methods.
220 virtual int OpenStream();
221 virtual void CloseStream();
222 virtual int OpenVTKFile();
223 virtual void CloseVTKFile();
224 virtual int OpenVTKString();
225 virtual void CloseVTKString();
226 virtual void CreateXMLParser();
227 virtual void DestroyXMLParser();
228 void SetupCompressor(const char* type);
230
236 virtual int CanReadFileWithDataType(const char* dsname);
237
238 // Returns the major version for the file being read. -1 when invalid.
239 vtkGetMacro(FileMajorVersion, int);
240
241 // Returns the minor version for the file being read. -1 when invalid.
242 vtkGetMacro(FileMinorVersion, int);
243
244 // Utility methods for subclasses.
245 int IntersectExtents(int* extent1, int* extent2, int* result);
246 int Min(int a, int b);
247 int Max(int a, int b);
248 void ComputePointDimensions(int* extent, int* dimensions);
249 void ComputePointIncrements(int* extent, vtkIdType* increments);
250 void ComputeCellDimensions(int* extent, int* dimensions);
251 void ComputeCellIncrements(int* extent, vtkIdType* increments);
253 int i, int j, int k);
256 char** CreateStringArray(int numStrings);
257 void DestroyStringArray(int numStrings, char** strings);
258
259 // Setup the data array selections for the input's set of arrays.
262
263 int SetFieldDataInfo(vtkXMLDataElement *eDSA, int association,
264 int numTuples, vtkInformationVector *(&infoVector));
265
266 // Check whether the given array element is an enabled array.
269
270 // Callback registered with the SelectionObserver.
271 static void SelectionModifiedCallback(vtkObject* caller, unsigned long eid,
272 void* clientdata, void* calldata);
273
274 // Give concrete classes an option to squeeze any output arrays
275 // at the end of RequestData.
277
278 // The vtkXMLDataParser instance used to hide XML reading details.
280
281 // The FieldData element representation.
283
284 // The input file's name.
285 char* FileName;
286
287 // The stream used to read the input.
288 istream* Stream;
289
290 // Whether this object is reading from a string or a file.
291 // Default is 0: read from file.
293
294 // The input string.
296
297 // The array selections.
300
301 // The observer to modify this object when the array selections are
302 // modified.
304
305 // Whether there was an error reading the file in RequestInformation.
307
308 // Whether there was an error reading the file in RequestData.
310
311 // incrementally fine-tuned progress updates.
312 virtual void GetProgressRange(float* range);
313 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
314 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
315 virtual void UpdateProgressDiscrete(float progress);
316 float ProgressRange[2];
317
318 virtual int RequestData(vtkInformation *request,
319 vtkInformationVector **inputVector,
320 vtkInformationVector *outputVector);
321 virtual int RequestDataObject(vtkInformation *vtkNotUsed(request),
322 vtkInformationVector **vtkNotUsed(inputVector),
323 vtkInformationVector *vtkNotUsed(outputVector))
324 { return 1; }
325 virtual int RequestInformation(vtkInformation *request,
326 vtkInformationVector **inputVector,
327 vtkInformationVector *outputVector);
329
330 // Whether there was an error reading the XML.
332
333 // For structured data keep track of dimensions empty of cells. For
334 // unstructured data these are always zero. This is used to support
335 // 1-D and 2-D cell data.
336 int AxesEmpty[3];
337
338 // The timestep currently being read.
342 void SetNumberOfTimeSteps(int num);
343 // buffer for reading timestep from the XML file the length is of
344 // NumberOfTimeSteps and therefore is always long enough
346 // Store the range of time steps
347 int TimeStepRange[2];
348
349 // Now we need to save what was the last time read for each kind of
350 // data to avoid rereading it that is to say we need a var for
351 // e.g. PointData/CellData/Points/Cells...
352 // See SubClass for details with member vars like PointsTimeStep/PointsOffset
353
354 // Helper function useful to know if a timestep is found in an array of timestep
355 static int IsTimeStepInArray(int timestep, int* timesteps, int length);
356
359
360private:
361 // The stream used to read the input if it is in a file.
362 ifstream* FileStream;
363 // The stream used to read the input if it is in a string.
364 std::istringstream* StringStream;
365 int TimeStepWasReadOnce;
366
367 int FileMajorVersion;
368 int FileMinorVersion;
369
370 vtkDataObject* CurrentOutput;
371 vtkInformation* CurrentOutputInformation;
372
373private:
374 vtkXMLReader(const vtkXMLReader&) VTK_DELETE_FUNCTION;
375 void operator=(const vtkXMLReader&) VTK_DELETE_FUNCTION;
376
377 vtkCommand *ReaderErrorObserver;
378 vtkCommand *ParserErrorObserver;
379};
380
381#endif
Abstract superclass for all arrays.
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:60
supports function callbacks
superclass for callback/observer methods
Definition: vtkCommand.h:342
Store on/off settings for data arrays for a vtkSource.
general representation of visualization data
Definition: vtkDataObject.h:65
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.
abstract base class for most VTK objects
Definition: vtkObject.h:60
record modification and/or execution time
Definition: vtkTimeStamp.h:36
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:44
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:282
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:303
char ** CreateStringArray(int numStrings)
virtual void SetProgressRange(const float range[2], int curStep, int numSteps)
virtual int CanReadFileVersion(int major, int minor)
virtual void GetProgressRange(float *range)
virtual void DestroyXMLParser()
int NumberOfTimeSteps
Definition: vtkXMLReader.h:341
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
istream * Stream
Definition: vtkXMLReader.h:288
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)
vtkDataArraySelection * CellDataArraySelection
Definition: vtkXMLReader.h:299
virtual void SetupOutputData()
void ComputeCellIncrements(int *extent, vtkIdType *increments)
int CreateInformationKey(vtkXMLDataElement *eInfoKey, vtkInformation *info)
void SetDataArraySelections(vtkXMLDataElement *eDSA, vtkDataArraySelection *sel)
int SetFieldDataInfo(vtkXMLDataElement *eDSA, int association, int numTuples, vtkInformationVector *(&infoVector))
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
virtual void SqueezeOutputArrays(vtkDataObject *)
Definition: vtkXMLReader.h:276
void SetInputString(std::string s)
Definition: vtkXMLReader.h:64
int GetNumberOfPointArrays()
Get the number of point or cell arrays available in the input.
int Max(int a, int b)
virtual void CreateXMLParser()
virtual void CloseStream()
int CanReadFileVersionString(const char *version)
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:194
vtkIdType GetStartTuple(int *extent, vtkIdType *increments, int i, int j, int k)
void SetupCompressor(const char *type)
vtkInformation * GetCurrentOutputInformation()
virtual int ProcessRequest(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
Upstream/Downstream requests form the generalized interface through which executives invoke a algorit...
int InformationError
Definition: vtkXMLReader.h:306
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:279
virtual const char * GetDataSetName()=0
vtkXMLDataParser * GetXMLParser()
Returns the internal XML parser.
Definition: vtkXMLReader.h:147
const char * GetPointArrayName(int index)
Get the name of the point or cell array with the given index in the input.
void ComputePointIncrements(int *extent, vtkIdType *increments)
virtual int ReadXMLInformation()
vtkAbstractArray * CreateArray(vtkXMLDataElement *da)
void ReadAttributeIndices(vtkXMLDataElement *eDSA, vtkDataSetAttributes *dsa)
virtual int CanReadFile(const char *name)
Test whether the file (type) with the given name can be read by this reader.
int PointDataArrayIsEnabled(vtkXMLDataElement *ePDA)
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkDataSet * GetOutputAsDataSet()
Get the output as a vtkDataSet pointer.
virtual void CloseVTKFile()
virtual int OpenVTKFile()
vtkTimeStamp ReadMTime
Definition: vtkXMLReader.h:328
void ComputeCellDimensions(int *extent, int *dimensions)
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:321
void ComputePointDimensions(int *extent, int *dimensions)
int GetNumberOfCellArrays()
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)
virtual int ReadVTKFile(vtkXMLDataElement *eVTKFile)
virtual int OpenVTKString()
virtual int ReadPrimaryElement(vtkXMLDataElement *ePrimary)
bool ReadInformation(vtkXMLDataElement *infoRoot, vtkInformation *info)
int GetCellArrayStatus(const char *name)
vtkDataObject * GetCurrentOutput()
int GetPointArrayStatus(const char *name)
Get/Set whether the point or cell array with the given name is to be read.
char * FileName
Definition: vtkXMLReader.h:285
virtual void UpdateProgressDiscrete(float progress)
int ReadFromInputString
Definition: vtkXMLReader.h:292
virtual void ReadXMLData()
virtual int OpenStream()
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)
virtual void CloseVTKString()
void SetPointArrayStatus(const char *name, int status)
std::string InputString
Definition: vtkXMLReader.h:295
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:298
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:123
vtkDataSet * GetOutputAsDataSet(int index)
int Min(int a, int b)
@ info
Definition: vtkX3D.h:376
@ length
Definition: vtkX3D.h:393
@ port
Definition: vtkX3D.h:447
@ range
Definition: vtkX3D.h:238
@ extent
Definition: vtkX3D.h:345
@ type
Definition: vtkX3D.h:516
@ version
Definition: vtkX3D.h:526
@ name
Definition: vtkX3D.h:219
@ index
Definition: vtkX3D.h:246
@ progress
Definition: vtkX3D.h:452
@ string
Definition: vtkX3D.h:490
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkBooleanMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
int vtkIdType
Definition: vtkType.h:287