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