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 =========================================================================*/
23 #ifndef vtkXMLReader_h
24 #define vtkXMLReader_h
25 
26 #include "vtkIOXMLModule.h" // For export macro
27 #include "vtkAlgorithm.h"
28 
29 #include <string> // for std::string
30 
31 class vtkAbstractArray;
32 class vtkCallbackCommand;
34 class vtkDataSet;
36 class vtkXMLDataElement;
37 class vtkXMLDataParser;
39 class vtkInformation;
40 class vtkCommand;
41 
43 {
44 public:
45  vtkTypeMacro(vtkXMLReader, vtkAlgorithm);
46  void PrintSelf(ostream& os, vtkIndent indent);
47 
49 
50  vtkSetStringMacro(FileName);
51  vtkGetStringMacro(FileName);
53 
55 
56  vtkSetMacro(ReadFromInputString,int);
57  vtkGetMacro(ReadFromInputString,int);
58  vtkBooleanMacro(ReadFromInputString,int);
59  void SetInputString(std::string s) { this->InputString = s; }
61 
67  virtual int CanReadFile(const char* name);
68 
70 
71  vtkDataSet* GetOutputAsDataSet();
72  vtkDataSet* GetOutputAsDataSet(int index);
74 
76 
78  vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
79  vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
81 
83 
84  int GetNumberOfPointArrays();
85  int GetNumberOfCellArrays();
87 
89 
91  const char* GetPointArrayName(int index);
92  const char* GetCellArrayName(int index);
94 
96 
98  int GetPointArrayStatus(const char* name);
99  int GetCellArrayStatus(const char* name);
100  void SetPointArrayStatus(const char* name, int status);
101  void SetCellArrayStatus(const char* name, int status);
103 
104  // For the specified port, copy the information this reader sets up in
105  // SetupOutputInformation to outInfo
106  virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo),
107  int vtkNotUsed(port)) {}
108 
110 
111  vtkSetMacro(TimeStep, int);
112  vtkGetMacro(TimeStep, int);
114 
115  vtkGetMacro(NumberOfTimeSteps, int);
117 
118  vtkGetVector2Macro(TimeStepRange, int);
119  vtkSetVector2Macro(TimeStepRange, int);
121 
123 
126  {
127  return this->XMLParser;
128  }
130 
131  virtual int ProcessRequest(vtkInformation *request,
132  vtkInformationVector **inputVector,
133  vtkInformationVector *outputVector);
134 
136 
138  void SetReaderErrorObserver(vtkCommand *);
139  vtkGetObjectMacro(ReaderErrorObserver,vtkCommand);
141 
143 
145  void SetParserErrorObserver(vtkCommand *);
146  vtkGetObjectMacro(ParserErrorObserver,vtkCommand);
148 
149 protected:
150  vtkXMLReader();
151  ~vtkXMLReader();
152 
153  // Pipeline execution methods to be defined by subclass. Called by
154  // corresponding RequestData methods after appropriate setup has been
155  // done.
156  virtual int ReadXMLInformation();
157  virtual void ReadXMLData();
158 
159  // Get the name of the data set being read.
160  virtual const char* GetDataSetName()=0;
161 
162  // Test if the reader can read a file with the given version number.
163  virtual int CanReadFileVersion(int major, int minor);
164 
165  // Setup the output with no data available. Used in error cases.
166  virtual void SetupEmptyOutput()=0;
167 
168  // Setup the output's information.
169  virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo)) {}
170 
171  // Setup the output's data with allocation.
172  virtual void SetupOutputData();
173 
174  // Read the primary element from the file. This is the element
175  // whose name is the value returned by GetDataSetName().
176  virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
177 
178  // Read the top-level element from the file. This is always the
179  // VTKFile element.
180  virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile);
181 
182  // Create a vtkAbstractArray from its cooresponding XML representation.
183  // Does not allocate.
184  vtkAbstractArray* CreateArray(vtkXMLDataElement* da);
185 
186  // Create a vtkInformationKey from its coresponding XML representation.
187  // Stores it in the instance of vtkInformationProvided. Does not allocate.
188  int CreateInformationKey(vtkXMLDataElement *eInfoKey, vtkInformation *info);
189 
190  // Internal utility methods.
191  virtual int OpenStream();
192  virtual void CloseStream();
193  virtual int OpenVTKFile();
194  virtual void CloseVTKFile();
195  virtual int OpenVTKString();
196  virtual void CloseVTKString();
197  virtual void CreateXMLParser();
198  virtual void DestroyXMLParser();
199  void SetupCompressor(const char* type);
200  int CanReadFileVersionString(const char* version);
201 
206  virtual int CanReadFileWithDataType(const char* dsname);
207 
208  // Returns the major version for the file being read. -1 when invalid.
209  vtkGetMacro(FileMajorVersion, int);
210 
211  // Returns the minor version for the file being read. -1 when invalid.
212  vtkGetMacro(FileMinorVersion, int);
213 
214  // Utility methods for subclasses.
215  int IntersectExtents(int* extent1, int* extent2, int* result);
216  int Min(int a, int b);
217  int Max(int a, int b);
218  void ComputePointDimensions(int* extent, int* dimensions);
219  void ComputePointIncrements(int* extent, vtkIdType* increments);
220  void ComputeCellDimensions(int* extent, int* dimensions);
221  void ComputeCellIncrements(int* extent, vtkIdType* increments);
222  vtkIdType GetStartTuple(int* extent, vtkIdType* increments,
223  int i, int j, int k);
224  void ReadAttributeIndices(vtkXMLDataElement* eDSA,
225  vtkDataSetAttributes* dsa);
226  char** CreateStringArray(int numStrings);
227  void DestroyStringArray(int numStrings, char** strings);
228 
229  // Setup the data array selections for the input's set of arrays.
230  void SetDataArraySelections(vtkXMLDataElement* eDSA,
231  vtkDataArraySelection* sel);
232 
233 //BTX
234  int SetFieldDataInfo(vtkXMLDataElement *eDSA, int association,
235  int numTuples, vtkInformationVector *(&infoVector));
236 //ETX
237 
238  // Check whether the given array element is an enabled array.
239  int PointDataArrayIsEnabled(vtkXMLDataElement* ePDA);
240  int CellDataArrayIsEnabled(vtkXMLDataElement* eCDA);
241 
242  // Callback registered with the SelectionObserver.
243  static void SelectionModifiedCallback(vtkObject* caller, unsigned long eid,
244  void* clientdata, void* calldata);
245 
246  // The vtkXMLDataParser instance used to hide XML reading details.
248 
249  // The FieldData element representation.
251 
252  // The input file's name.
253  char* FileName;
254 
255  // The stream used to read the input.
256  istream* Stream;
257 
258  // Whether this object is reading from a string or a file.
259  // Default is 0: read from file.
261 
262  // The input string.
264 
265  // The array selections.
268 
269  // The observer to modify this object when the array selections are
270  // modified.
272 
273  // Whether there was an error reading the file in RequestInformation.
275 
276  // Whether there was an error reading the file in RequestData.
278 
279  // incrementally fine-tuned progress updates.
280  virtual void GetProgressRange(float* range);
281  virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
282  virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
283  virtual void UpdateProgressDiscrete(float progress);
284  float ProgressRange[2];
285 
286  virtual int RequestData(vtkInformation *request,
287  vtkInformationVector **inputVector,
288  vtkInformationVector *outputVector);
289  virtual int RequestDataObject(vtkInformation *vtkNotUsed(request),
290  vtkInformationVector **vtkNotUsed(inputVector),
291  vtkInformationVector *vtkNotUsed(outputVector))
292  { return 1; }
293  virtual int RequestInformation(vtkInformation *request,
294  vtkInformationVector **inputVector,
295  vtkInformationVector *outputVector);
297 
298  // Whether there was an error reading the XML.
300 
301  // For structured data keep track of dimensions empty of cells. For
302  // unstructured data these are always zero. This is used to support
303  // 1-D and 2-D cell data.
304  int AxesEmpty[3];
305 
306  // The timestep currently being read.
307  int TimeStep;
310  void SetNumberOfTimeSteps(int num);
311  // buffer for reading timestep from the XML file the length is of
312  // NumberOfTimeSteps and therefore is always long enough
313  int *TimeSteps;
314  // Store the range of time steps
315  int TimeStepRange[2];
316 
317  // Now we need to save what was the last time read for each kind of
318  // data to avoid rereading it that is to say we need a var for
319  // e.g. PointData/CellData/Points/Cells...
320  // See SubClass for details with member vars like PointsTimeStep/PointsOffset
321 
322  // Helper function useful to know if a timestep is found in an array of timestep
323  static int IsTimeStepInArray(int timestep, int* timesteps, int length);
324 
325  vtkDataObject* GetCurrentOutput();
326  vtkInformation* GetCurrentOutputInformation();
327 
328 private:
329  // The stream used to read the input if it is in a file.
330  ifstream* FileStream;
331  // The stream used to read the input if it is in a string.
332  std::istringstream* StringStream;
333  int TimeStepWasReadOnce;
334 
335  int FileMajorVersion;
336  int FileMinorVersion;
337 
338  vtkDataObject* CurrentOutput;
339  vtkInformation* CurrentOutputInformation;
340 
341 private:
342  vtkXMLReader(const vtkXMLReader&); // Not implemented.
343  void operator=(const vtkXMLReader&); // Not implemented.
344 
345  vtkCommand *ReaderErrorObserver;
346  vtkCommand *ParserErrorObserver;
347 };
348 
349 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:61
Represents an XML element and those nested inside.
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:61
Abstract superclass for all arrays.
record modification and/or execution time
Definition: vtkTimeStamp.h:34
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:250
virtual int ProcessRequest(vtkInformation *request, vtkInformationVector **inInfo, vtkInformationVector *outInfo)
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:271
int vtkIdType
Definition: vtkType.h:247
char * FileName
Definition: vtkXMLReader.h:253
superclass for callback/observer methods
Definition: vtkCommand.h:328
supports function callbacks
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:61
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkTimeStamp ReadMTime
Definition: vtkXMLReader.h:296
#define VTKIOXML_EXPORT
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:266
vtkDataArraySelection * CellDataArraySelection
Definition: vtkXMLReader.h:267
Store on/off settings for data arrays for a vtkSource.
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:169
int NumberOfTimeSteps
Definition: vtkXMLReader.h:309
represent and manipulate attribute data in a dataset
std::string InputString
Definition: vtkXMLReader.h:263
int InformationError
Definition: vtkXMLReader.h:274
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:106
Used by vtkXMLReader to parse VTK XML files.
int ReadFromInputString
Definition: vtkXMLReader.h:260
virtual int RequestDataObject(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *vtkNotUsed(outputVector))
Definition: vtkXMLReader.h:289
void SetInputString(std::string s)
Definition: vtkXMLReader.h:59
istream * Stream
Definition: vtkXMLReader.h:256
vtkXMLDataParser * GetXMLParser()
Definition: vtkXMLReader.h:125
Store zero or more vtkInformation instances.
general representation of visualization data
Definition: vtkDataObject.h:64
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:247
Superclass for VTK's XML format readers.
Definition: vtkXMLReader.h:42
void PrintSelf(ostream &os, vtkIndent indent)