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