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 
32 class vtkAbstractArray;
33 class vtkCallbackCommand;
35 class vtkDataSet;
37 class vtkXMLDataElement;
38 class vtkXMLDataParser;
40 class vtkInformation;
41 class vtkCommand;
42 
43 class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm
44 {
45 public:
46  vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
47  void PrintSelf(ostream& os, vtkIndent indent);
48 
50 
53  vtkSetStringMacro(FileName);
54  vtkGetStringMacro(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 
80  vtkDataSet* GetOutputAsDataSet();
81  vtkDataSet* GetOutputAsDataSet(int index);
83 
85 
89  vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
90  vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
92 
94 
97  int GetNumberOfPointArrays();
98  int GetNumberOfCellArrays();
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 
161  void SetReaderErrorObserver(vtkCommand *);
162  vtkGetObjectMacro(ReaderErrorObserver, vtkCommand);
164 
166 
170  void SetParserErrorObserver(vtkCommand *);
171  vtkGetObjectMacro(ParserErrorObserver, vtkCommand);
173 
174 protected:
175  vtkXMLReader();
176  ~vtkXMLReader();
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.
209  vtkAbstractArray* CreateArray(vtkXMLDataElement* da);
210 
211  // Create a vtkInformationKey from its coresponding XML representation.
212  // Stores it in the instance of vtkInformationProvided. Does not allocate.
213  int CreateInformationKey(vtkXMLDataElement *eInfoKey, vtkInformation *info);
214 
215  // Populates the info object with the InformationKey children in infoRoot.
216  // Returns false if errors occur.
217  bool ReadInformation(vtkXMLDataElement *infoRoot, vtkInformation *info);
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);
229  int CanReadFileVersionString(const char* version);
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);
252  vtkIdType GetStartTuple(int* extent, vtkIdType* increments,
253  int i, int j, int k);
254  void ReadAttributeIndices(vtkXMLDataElement* eDSA,
255  vtkDataSetAttributes* dsa);
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.
260  void SetDataArraySelections(vtkXMLDataElement* eDSA,
261  vtkDataArraySelection* sel);
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.
267  int PointDataArrayIsEnabled(vtkXMLDataElement* ePDA);
268  int CellDataArrayIsEnabled(vtkXMLDataElement* eCDA);
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.
339  int TimeStep;
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
345  int *TimeSteps;
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 
357  vtkDataObject* GetCurrentOutput();
358  vtkInformation* GetCurrentOutputInformation();
359 
360 private:
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 
373 private:
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
virtual void SqueezeOutputArrays(vtkDataObject *)
Definition: vtkXMLReader.h:276
abstract base class for most VTK objects
Definition: vtkObject.h:59
Represents an XML element and those nested inside.
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
Abstract superclass for all arrays.
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:282
virtual int ProcessRequest(vtkInformation *request, vtkInformationVector **inInfo, vtkInformationVector *outInfo)
Upstream/Downstream requests form the generalized interface through which executives invoke a algorit...
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:303
int vtkIdType
Definition: vtkType.h:287
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
char * FileName
Definition: vtkXMLReader.h:285
superclass for callback/observer methods
Definition: vtkCommand.h:341
supports function callbacks
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:59
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkTimeStamp ReadMTime
Definition: vtkXMLReader.h:328
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:298
vtkDataArraySelection * CellDataArraySelection
Definition: vtkXMLReader.h:299
Store on/off settings for data arrays for a vtkSource.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:194
int NumberOfTimeSteps
Definition: vtkXMLReader.h:341
represent and manipulate attribute data in a dataset
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
std::string InputString
Definition: vtkXMLReader.h:295
int InformationError
Definition: vtkXMLReader.h:306
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:123
Used by vtkXMLReader to parse VTK XML files.
int ReadFromInputString
Definition: vtkXMLReader.h:292
virtual int RequestDataObject(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *vtkNotUsed(outputVector))
Definition: vtkXMLReader.h:321
void SetInputString(std::string s)
Enable reading from an InputString instead of the default, a file.
Definition: vtkXMLReader.h:64
istream * Stream
Definition: vtkXMLReader.h:288
vtkXMLDataParser * GetXMLParser()
Returns the internal XML parser.
Definition: vtkXMLReader.h:147
Store zero or more vtkInformation instances.
vtkBooleanMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
general representation of visualization data
Definition: vtkDataObject.h:64
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:279
Superclass for VTK's XML format readers.
Definition: vtkXMLReader.h:43