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