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 
66  virtual int CanReadFile(const char* name);
67 
69 
73 
75 
77  vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
78  vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
80 
82 
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
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:
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.
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.
170 
171  // Create a vtkInformationKey from its coresponding XML representation.
172  // Stores it in the instance of vtkInformationProvided. Does not allocate.
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);
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);
208  int i, int j, int k);
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.
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.
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);
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;
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 
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
vtkXMLReader::ReadMTime
vtkTimeStamp ReadMTime
Definition: vtkXMLReader.h:281
VTKIOXML_EXPORT
#define VTKIOXML_EXPORT
Definition: vtkIOXMLModule.h:15
vtkXMLReader::RequestInformation
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
vtkGetObjectMacro
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:232
vtkXMLReader::GetStartTuple
vtkIdType GetStartTuple(int *extent, vtkIdType *increments, int i, int j, int k)
vtkXMLReader::CurrentTimeStep
int CurrentTimeStep
Definition: vtkXMLReader.h:293
vtkXMLReader::GetProgressRange
virtual void GetProgressRange(float *range)
vtkSetVector2Macro
#define vtkSetVector2Macro(name, type)
Definition: vtkSetGet.h:254
vtkXMLReader::GetPointArrayName
const char * GetPointArrayName(int index)
vtkXMLReader::FieldDataElement
vtkXMLDataElement * FieldDataElement
Definition: vtkXMLReader.h:235
vtkXMLReader::GetNumberOfCellArrays
int GetNumberOfCellArrays()
vtkXMLReader::PointDataArraySelection
vtkDataArraySelection * PointDataArraySelection
Definition: vtkXMLReader.h:251
vtkgl::b
GLboolean GLboolean GLboolean b
Definition: vtkgl.h:12312
vtkXMLReader::SelectionModifiedCallback
static void SelectionModifiedCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
vtkXMLReader::ReadPrimaryElement
virtual int ReadPrimaryElement(vtkXMLDataElement *ePrimary)
vtkGetVector2Macro
#define vtkGetVector2Macro(name, type)
Definition: vtkSetGet.h:270
vtkXMLReader::DestroyStringArray
void DestroyStringArray(int numStrings, char **strings)
vtkXMLReader::SetDataArraySelections
void SetDataArraySelections(vtkXMLDataElement *eDSA, vtkDataArraySelection *sel)
vtkXMLReader::TimeSteps
int * TimeSteps
Definition: vtkXMLReader.h:298
vtkXMLReader::ComputePointIncrements
void ComputePointIncrements(int *extent, vtkIdType *increments)
vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkXMLReader::XMLParser
vtkXMLDataParser * XMLParser
Definition: vtkXMLReader.h:232
vtkXMLReader::CloseStream
virtual void CloseStream()
vtkAlgorithm
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:62
vtkDataSetAttributes
represent and manipulate attribute data in a dataset
Definition: vtkDataSetAttributes.h:58
vtkXMLReader::CanReadFileWithDataType
virtual int CanReadFileWithDataType(const char *dsname)
vtkXMLReader::InformationError
int InformationError
Definition: vtkXMLReader.h:259
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:41
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkXMLReader::CanReadFileVersionString
int CanReadFileVersionString(const char *version)
vtkgl::s
GLdouble s
Definition: vtkgl.h:11594
vtkXMLReader::ReadVTKFile
virtual int ReadVTKFile(vtkXMLDataElement *eVTKFile)
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkXMLReader::SetupCompressor
void SetupCompressor(const char *type)
vtkXMLReader::FileName
char * FileName
Definition: vtkXMLReader.h:238
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkXMLReader::SetNumberOfTimeSteps
void SetNumberOfTimeSteps(int num)
vtkXMLReader::RequestDataObject
virtual int RequestDataObject(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *vtkNotUsed(outputVector))
Definition: vtkXMLReader.h:274
vtkXMLReader::SetCellArrayStatus
void SetCellArrayStatus(const char *name, int status)
vtkXMLReader::GetCellArrayName
const char * GetCellArrayName(int index)
vtkXMLReader::SetProgressRange
virtual void SetProgressRange(const float range[2], int curStep, const float *fractions)
vtkXMLReader::UpdateProgressDiscrete
virtual void UpdateProgressDiscrete(float progress)
vtkXMLReader::Stream
istream * Stream
Definition: vtkXMLReader.h:241
vtkgl::range
GLenum GLint * range
Definition: vtkgl.h:14180
vtkgl::length
GLuint GLsizei GLsizei * length
Definition: vtkgl.h:11992
vtkXMLReader::OpenStream
virtual int OpenStream()
vtkXMLReader::OpenVTKString
virtual int OpenVTKString()
vtkXMLReader::RequestData
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
vtkXMLReader::DataError
int DataError
Definition: vtkXMLReader.h:262
vtkXMLReader::PointDataArrayIsEnabled
int PointDataArrayIsEnabled(vtkXMLDataElement *ePDA)
vtkDataArraySelection
Store on/off settings for data arrays for a vtkSource.
Definition: vtkDataArraySelection.h:34
vtkXMLReader::GetPointArrayStatus
int GetPointArrayStatus(const char *name)
vtkAlgorithm.h
vtkXMLReader::OpenVTKFile
virtual int OpenVTKFile()
vtkXMLReader::GetNumberOfPointArrays
int GetNumberOfPointArrays()
vtkIOXMLModule.h
vtkX3D::port
@ port
Definition: vtkX3D.h:447
vtkgl::name
GLuint const GLchar * name
Definition: vtkgl.h:11983
vtkNotUsed
#define vtkNotUsed(x)
Definition: vtkSetGet.h:557
vtkgl::strings
GLsizei const GLchar ** strings
Definition: vtkgl.h:14213
vtkXMLReader::SetupOutputData
virtual void SetupOutputData()
vtkXMLReader::GetCurrentOutputInformation
vtkInformation * GetCurrentOutputInformation()
vtkXMLReader::InputString
std::string InputString
Definition: vtkXMLReader.h:248
vtkXMLReader::vtkXMLReader
vtkXMLReader()
vtkXMLReader::ReadXMLData
virtual void ReadXMLData()
vtkXMLReader::ComputeCellDimensions
void ComputeCellDimensions(int *extent, int *dimensions)
vtkgl::num
GLuint GLuint num
Definition: vtkgl.h:16907
vtkXMLReader::SetupEmptyOutput
virtual void SetupEmptyOutput()=0
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkSetStringMacro
#define vtkSetStringMacro(name)
Definition: vtkSetGet.h:104
vtkXMLReader::ReadAttributeIndices
void ReadAttributeIndices(vtkXMLDataElement *eDSA, vtkDataSetAttributes *dsa)
vtkXMLReader::~vtkXMLReader
~vtkXMLReader()
vtkXMLReader::IntersectExtents
int IntersectExtents(int *extent1, int *extent2, int *result)
vtkXMLReader::CreateXMLParser
virtual void CreateXMLParser()
vtkXMLReader::CreateArray
vtkAbstractArray * CreateArray(vtkXMLDataElement *da)
vtkXMLReader::GetDataSetName
virtual const char * GetDataSetName()=0
vtkXMLDataElement
Represents an XML element and those nested inside.
Definition: vtkXMLDataElement.h:36
vtkGetMacro
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:93
vtkGetStringMacro
vtkGetStringMacro(ExtensionsString)
vtkgl::a
GLboolean GLboolean GLboolean GLboolean a
Definition: vtkgl.h:12312
vtkXMLReader::GetXMLParser
vtkXMLDataParser * GetXMLParser()
Definition: vtkXMLReader.h:124
vtkXMLReader::GetOutputAsDataSet
vtkDataSet * GetOutputAsDataSet()
vtkXMLReader::CreateStringArray
char ** CreateStringArray(int numStrings)
vtkDataSet
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:65
vtkBooleanMacro
vtkBooleanMacro(IgnoreDriverBugs, bool)
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:86
vtkXMLReader::ComputeCellIncrements
void ComputeCellIncrements(int *extent, vtkIdType *increments)
vtkXMLReader::ComputePointDimensions
void ComputePointDimensions(int *extent, int *dimensions)
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
vtkX3D::info
@ info
Definition: vtkX3D.h:376
vtkgl::index
GLuint index
Definition: vtkgl.h:11983
vtkXMLReader::IsTimeStepInArray
static int IsTimeStepInArray(int timestep, int *timesteps, int length)
vtkXMLReader::CellDataArraySelection
vtkDataArraySelection * CellDataArraySelection
Definition: vtkXMLReader.h:252
vtkgl::result
GLuint64EXT * result
Definition: vtkgl.h:18868
vtkXMLReader::CloseVTKFile
virtual void CloseVTKFile()
vtkXMLReader::GetCurrentOutput
vtkDataObject * GetCurrentOutput()
vtkXMLReader::TimeStep
int TimeStep
Definition: vtkXMLReader.h:292
vtkXMLReader::SetProgressRange
virtual void SetProgressRange(const float range[2], int curStep, int numSteps)
vtkXMLReader::CellDataArrayIsEnabled
int CellDataArrayIsEnabled(vtkXMLDataElement *eCDA)
vtkCallbackCommand
supports function callbacks
Definition: vtkCallbackCommand.h:50
vtkXMLReader::SetupOutputInformation
virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo))
Definition: vtkXMLReader.h:154
vtkXMLReader::CreateInformationKey
int CreateInformationKey(vtkXMLDataElement *eInfoKey, vtkInformation *info)
vtkXMLReader::SetPointArrayStatus
void SetPointArrayStatus(const char *name, int status)
vtkXMLReader::NumberOfTimeSteps
int NumberOfTimeSteps
Definition: vtkXMLReader.h:294
vtkXMLReader::SelectionObserver
vtkCallbackCommand * SelectionObserver
Definition: vtkXMLReader.h:256
vtkX3D::progress
@ progress
Definition: vtkX3D.h:452
vtkX3D::version
@ version
Definition: vtkX3D.h:526
vtkX3D::extent
@ extent
Definition: vtkX3D.h:345
vtkXMLReader::ReadXMLInformation
virtual int ReadXMLInformation()
vtkXMLReader::Max
int Max(int a, int b)
vtkXMLReader::DestroyXMLParser
virtual void DestroyXMLParser()
vtkXMLReader::CanReadFile
virtual int CanReadFile(const char *name)
vtkXMLReader::GetCellArrayStatus
int GetCellArrayStatus(const char *name)
vtkDataObject
general representation of visualization data
Definition: vtkDataObject.h:65
vtkXMLReader::CloseVTKString
virtual void CloseVTKString()
vtkXMLReader::CopyOutputInformation
virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), int vtkNotUsed(port))
Definition: vtkXMLReader.h:105
vtkXMLReader::ReadError
int ReadError
Definition: vtkXMLReader.h:284
vtkgl::type
GLuint GLuint GLsizei GLenum type
Definition: vtkgl.h:11315
vtkXMLReader::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
vtkXMLReader::SetFieldDataInfo
int SetFieldDataInfo(vtkXMLDataElement *eDSA, int association, int numTuples, vtkInformationVector *(&infoVector))
vtkXMLReader::ReadFromInputString
int ReadFromInputString
Definition: vtkXMLReader.h:245
vtkXMLReader::Min
int Min(int a, int b)
vtkgl::string
GLsizei const GLchar ** string
Definition: vtkgl.h:12011
vtkXMLReader
Superclass for VTK's XML format readers.
Definition: vtkXMLReader.h:42
vtkXMLReader::CanReadFileVersion
virtual int CanReadFileVersion(int major, int minor)
vtkXMLDataParser
Used by vtkXMLReader to parse VTK XML files.
Definition: vtkXMLDataParser.h:42
vtkXMLReader::ProcessRequest
virtual int ProcessRequest(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
vtkXMLReader::GetOutputAsDataSet
vtkDataSet * GetOutputAsDataSet(int index)
vtkXMLReader::SetInputString
void SetInputString(std::string s)
Definition: vtkXMLReader.h:58