1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkXMLReader.h,v $
6 Date: $Date: 2002/11/27 00:16:04 $
7 Version: $Revision: 1.3 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkXMLReader - Superclass for VTK's XML format readers.
19 // .SECTION Description
20 // vtkXMLReader uses vtkXMLDataParser to parse a VTK XML input file.
21 // Concrete subclasses then traverse the parsed file structure and
24 #ifndef __vtkXMLReader_h
25 #define __vtkXMLReader_h
27 #include "vtkSource.h"
29 class vtkCallbackCommand;
31 class vtkDataArraySelection;
33 class vtkDataSetAttributes;
34 class vtkXMLDataElement;
35 class vtkXMLDataParser;
37 class VTK_IO_EXPORT vtkXMLReader : public vtkSource
40 vtkTypeRevisionMacro(vtkXMLReader,vtkSource);
41 void PrintSelf(ostream& os, vtkIndent indent);
44 // Get/Set the name of the input file.
45 vtkSetStringMacro(FileName);
46 vtkGetStringMacro(FileName);
49 // Test whether the file with the given name can be read by this
51 virtual int CanReadFile(const char* name);
54 // Get the output as a vtkDataSet pointer.
55 vtkDataSet* GetOutputAsDataSet();
58 // Get the data array selection tables used to configure which data
59 // arrays are loaded by the reader.
60 vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
61 vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
64 // Get the number of point or cell arrays available in the input.
65 int GetNumberOfPointArrays();
66 int GetNumberOfCellArrays();
69 // Get the name of the point or cell array with the given index in
71 const char* GetPointArrayName(int index);
72 const char* GetCellArrayName(int index);
75 // Get/Set whether the point or cell array with the given name is to
77 int GetPointArrayStatus(const char* name);
78 int GetCellArrayStatus(const char* name);
79 void SetPointArrayStatus(const char* name, int status);
80 void SetCellArrayStatus(const char* name, int status);
86 // Standard pipeline exectution methods.
87 void ExecuteInformation();
88 void ExecuteData(vtkDataObject* output);
90 // Pipeline execution methods to be defined by subclass. Called by
91 // corresponding Execute methods after appropriate setup has been
93 virtual void ReadXMLInformation();
94 virtual void ReadXMLData();
96 // Get the name of the data set being read.
97 virtual const char* GetDataSetName()=0;
99 // Test if the reader can read a file with the given version number.
100 virtual int CanReadFileVersion(int major, int minor);
102 // Setup the output with no data available. Used in error cases.
103 virtual void SetupEmptyOutput()=0;
105 // Setup the output's information and data without allocation.
106 virtual void SetupOutputInformation();
108 // Setup the output's information and data with allocation.
109 virtual void SetupOutputData();
111 // Read the primary element from the file. This is the element
112 // whose name is the value returned by GetDataSetName().
113 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
115 // Read the top-level element from the file. This is always the
117 int ReadVTKFile(vtkXMLDataElement* eVTKFile);
119 // Create a vtkDataArray from its cooresponding XML representation.
120 // Does not allocate.
121 vtkDataArray* CreateDataArray(vtkXMLDataElement* da);
123 // Internal utility methods.
126 void CreateXMLParser();
127 void DestroyXMLParser();
128 void SetupCompressor(const char* type);
129 int CanReadFileVersionString(const char* version);
131 // Utility methods for subclasses.
132 int IntersectExtents(int* extent1, int* extent2, int* result);
133 int Min(int a, int b);
134 int Max(int a, int b);
135 void ComputeDimensions(int* extent, int* dimensions, int isPoint);
136 void ComputeIncrements(int* extent, int* increments, int isPoint);
137 unsigned int GetStartTuple(int* extent, int* increments,
138 int i, int j, int k);
139 void ReadAttributeIndices(vtkXMLDataElement* eDSA,
140 vtkDataSetAttributes* dsa);
141 char** CreateStringArray(int numStrings);
142 void DestroyStringArray(int numStrings, char** strings);
144 // Setup the data array selections for the input's set of arrays.
145 void SetDataArraySelections(vtkXMLDataElement* eDSA,
146 vtkDataArraySelection* sel);
148 // Check whether the given array element is an enabled array.
149 int PointDataArrayIsEnabled(vtkXMLDataElement* ePDA);
150 int CellDataArrayIsEnabled(vtkXMLDataElement* eCDA);
152 // Callback registered with the SelectionObserver.
153 static void SelectionModifiedCallback(vtkObject* caller, unsigned long eid,
154 void* clientdata, void* calldata);
156 // The vtkXMLDataParser instance used to hide XML reading details.
157 vtkXMLDataParser* XMLParser;
159 // The input file's name.
162 // The file stream used to read the input file.
163 ifstream* FileStream;
165 // The array selections.
166 vtkDataArraySelection* PointDataArraySelection;
167 vtkDataArraySelection* CellDataArraySelection;
169 // The observer to modify this object when the array selections are
171 vtkCallbackCommand* SelectionObserver;
173 // Whether there was an error reading the file in ExecuteInformation.
174 int InformationError;
176 // Whether there was an error reading the file in ExecuteData.
180 vtkXMLReader(const vtkXMLReader&); // Not implemented.
181 void operator=(const vtkXMLReader&); // Not implemented.