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