Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

dox/IO/vtkXMLReader.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkXMLReader.h,v $ 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00023 #ifndef __vtkXMLReader_h 00024 #define __vtkXMLReader_h 00025 00026 #include "vtkSource.h" 00027 00028 class vtkCallbackCommand; 00029 class vtkDataArray; 00030 class vtkDataArraySelection; 00031 class vtkDataSet; 00032 class vtkDataSetAttributes; 00033 class vtkXMLDataElement; 00034 class vtkXMLDataParser; 00035 00036 class VTK_IO_EXPORT vtkXMLReader : public vtkSource 00037 { 00038 public: 00039 vtkTypeRevisionMacro(vtkXMLReader,vtkSource); 00040 void PrintSelf(ostream& os, vtkIndent indent); 00041 00043 00044 vtkSetStringMacro(FileName); 00045 vtkGetStringMacro(FileName); 00047 00049 virtual int CanReadFile(const char* name); 00050 00052 00053 vtkDataSet* GetOutputAsDataSet(); 00054 vtkDataSet* GetOutputAsDataSet(int index); 00056 00058 00060 vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection); 00061 vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection); 00063 00065 00066 int GetNumberOfPointArrays(); 00067 int GetNumberOfCellArrays(); 00069 00071 00073 const char* GetPointArrayName(int index); 00074 const char* GetCellArrayName(int index); 00076 00078 00080 int GetPointArrayStatus(const char* name); 00081 int GetCellArrayStatus(const char* name); 00082 void SetPointArrayStatus(const char* name, int status); 00083 void SetCellArrayStatus(const char* name, int status); 00085 00086 protected: 00087 vtkXMLReader(); 00088 ~vtkXMLReader(); 00089 00090 // Standard pipeline exectution methods. 00091 void ExecuteInformation(); 00092 void ExecuteData(vtkDataObject* output); 00093 00094 // Pipeline execution methods to be defined by subclass. Called by 00095 // corresponding Execute methods after appropriate setup has been 00096 // done. 00097 virtual void ReadXMLInformation(); 00098 virtual void ReadXMLData(); 00099 00100 // Get the name of the data set being read. 00101 virtual const char* GetDataSetName()=0; 00102 00103 // Test if the reader can read a file with the given version number. 00104 virtual int CanReadFileVersion(int major, int minor); 00105 00106 // Setup the output with no data available. Used in error cases. 00107 virtual void SetupEmptyOutput()=0; 00108 00109 // Setup the output's information and data without allocation. 00110 virtual void SetupOutputInformation(); 00111 00112 // Setup the output's information and data with allocation. 00113 virtual void SetupOutputData(); 00114 00115 // Read the primary element from the file. This is the element 00116 // whose name is the value returned by GetDataSetName(). 00117 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary); 00118 00119 // Read the top-level element from the file. This is always the 00120 // VTKFile element. 00121 int ReadVTKFile(vtkXMLDataElement* eVTKFile); 00122 00123 // Create a vtkDataArray from its cooresponding XML representation. 00124 // Does not allocate. 00125 vtkDataArray* CreateDataArray(vtkXMLDataElement* da); 00126 00127 // Internal utility methods. 00128 int OpenVTKFile(); 00129 void CloseVTKFile(); 00130 virtual void CreateXMLParser(); 00131 virtual void DestroyXMLParser(); 00132 void SetupCompressor(const char* type); 00133 int CanReadFileVersionString(const char* version); 00134 00135 // Utility methods for subclasses. 00136 int IntersectExtents(int* extent1, int* extent2, int* result); 00137 int Min(int a, int b); 00138 int Max(int a, int b); 00139 void ComputeDimensions(int* extent, int* dimensions, int isPoint); 00140 void ComputeIncrements(int* extent, int* increments, int isPoint); 00141 unsigned int GetStartTuple(int* extent, int* increments, 00142 int i, int j, int k); 00143 void ReadAttributeIndices(vtkXMLDataElement* eDSA, 00144 vtkDataSetAttributes* dsa); 00145 char** CreateStringArray(int numStrings); 00146 void DestroyStringArray(int numStrings, char** strings); 00147 00148 // Setup the data array selections for the input's set of arrays. 00149 void SetDataArraySelections(vtkXMLDataElement* eDSA, 00150 vtkDataArraySelection* sel); 00151 00152 // Check whether the given array element is an enabled array. 00153 int PointDataArrayIsEnabled(vtkXMLDataElement* ePDA); 00154 int CellDataArrayIsEnabled(vtkXMLDataElement* eCDA); 00155 00156 // Callback registered with the SelectionObserver. 00157 static void SelectionModifiedCallback(vtkObject* caller, unsigned long eid, 00158 void* clientdata, void* calldata); 00159 00160 // The vtkXMLDataParser instance used to hide XML reading details. 00161 vtkXMLDataParser* XMLParser; 00162 00163 // The input file's name. 00164 char* FileName; 00165 00166 // The stream used to read the input. 00167 istream* Stream; 00168 00169 // The array selections. 00170 vtkDataArraySelection* PointDataArraySelection; 00171 vtkDataArraySelection* CellDataArraySelection; 00172 00173 // The observer to modify this object when the array selections are 00174 // modified. 00175 vtkCallbackCommand* SelectionObserver; 00176 00177 // Whether there was an error reading the file in ExecuteInformation. 00178 int InformationError; 00179 00180 // Whether there was an error reading the file in ExecuteData. 00181 int DataError; 00182 00183 // The index of the output on which ExecuteData is currently 00184 // running. 00185 int CurrentOutput; 00186 00187 // The current range over which progress is moving. This allows for 00188 // incrementally fine-tuned progress updates. 00189 virtual void GetProgressRange(float* range); 00190 virtual void SetProgressRange(float* range, int curStep, int numSteps); 00191 virtual void SetProgressRange(float* range, int curStep, float* fractions); 00192 virtual void UpdateProgressDiscrete(float progress); 00193 float ProgressRange[2]; 00194 00195 private: 00196 // The stream used to read the input if it is in a file. 00197 ifstream* FileStream; 00198 00199 private: 00200 vtkXMLReader(const vtkXMLReader&); // Not implemented. 00201 void operator=(const vtkXMLReader&); // Not implemented. 00202 }; 00203 00204 #endif