VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkXMLReader.h 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 "vtkIOXMLModule.h" // For export macro 00027 #include "vtkAlgorithm.h" 00028 00029 class vtkAbstractArray; 00030 class vtkCallbackCommand; 00031 class vtkDataArraySelection; 00032 class vtkDataSet; 00033 class vtkDataSetAttributes; 00034 class vtkXMLDataElement; 00035 class vtkXMLDataParser; 00036 class vtkInformationVector; 00037 class vtkInformation; 00038 00039 class VTKIOXML_EXPORT vtkXMLReader : public vtkAlgorithm 00040 { 00041 public: 00042 vtkTypeMacro(vtkXMLReader,vtkAlgorithm); 00043 void PrintSelf(ostream& os, vtkIndent indent); 00044 00046 00047 vtkSetStringMacro(FileName); 00048 vtkGetStringMacro(FileName); 00050 00052 virtual int CanReadFile(const char* name); 00053 00055 00056 vtkDataSet* GetOutputAsDataSet(); 00057 vtkDataSet* GetOutputAsDataSet(int index); 00059 00061 00063 vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection); 00064 vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection); 00066 00068 00069 int GetNumberOfPointArrays(); 00070 int GetNumberOfCellArrays(); 00072 00074 00076 const char* GetPointArrayName(int index); 00077 const char* GetCellArrayName(int index); 00079 00081 00083 int GetPointArrayStatus(const char* name); 00084 int GetCellArrayStatus(const char* name); 00085 void SetPointArrayStatus(const char* name, int status); 00086 void SetCellArrayStatus(const char* name, int status); 00088 00089 // For the specified port, copy the information this reader sets up in 00090 // SetupOutputInformation to outInfo 00091 virtual void CopyOutputInformation(vtkInformation *vtkNotUsed(outInfo), 00092 int vtkNotUsed(port)) {} 00093 00095 00096 vtkSetMacro(TimeStep, int); 00097 vtkGetMacro(TimeStep, int); 00099 00100 vtkGetMacro(NumberOfTimeSteps, int); 00102 00103 vtkGetVector2Macro(TimeStepRange, int); 00104 vtkSetVector2Macro(TimeStepRange, int); 00106 00108 00110 vtkXMLDataParser* GetXMLParser() 00111 { 00112 return this->XMLParser; 00113 } 00115 00116 virtual int ProcessRequest(vtkInformation *request, 00117 vtkInformationVector **inputVector, 00118 vtkInformationVector *outputVector); 00119 00120 protected: 00121 vtkXMLReader(); 00122 ~vtkXMLReader(); 00123 00124 // Pipeline execution methods to be defined by subclass. Called by 00125 // corresponding RequestData methods after appropriate setup has been 00126 // done. 00127 virtual int ReadXMLInformation(); 00128 virtual void ReadXMLData(); 00129 00130 // Get the name of the data set being read. 00131 virtual const char* GetDataSetName()=0; 00132 00133 // Test if the reader can read a file with the given version number. 00134 virtual int CanReadFileVersion(int major, int minor); 00135 00136 // Setup the output with no data available. Used in error cases. 00137 virtual void SetupEmptyOutput()=0; 00138 00139 // Setup the output's information. 00140 virtual void SetupOutputInformation(vtkInformation *vtkNotUsed(outInfo)) {} 00141 00142 // Setup the output's information for the update extent 00143 virtual void SetupUpdateExtentInformation 00144 (vtkInformation *vtkNotUsed(outInfo)) {} 00145 00146 // Setup the output's data with allocation. 00147 virtual void SetupOutputData(); 00148 00149 // Read the primary element from the file. This is the element 00150 // whose name is the value returned by GetDataSetName(). 00151 virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary); 00152 00153 // Read the top-level element from the file. This is always the 00154 // VTKFile element. 00155 virtual int ReadVTKFile(vtkXMLDataElement* eVTKFile); 00156 00157 // Create a vtkAbstractArray from its cooresponding XML representation. 00158 // Does not allocate. 00159 vtkAbstractArray* CreateArray(vtkXMLDataElement* da); 00160 00161 // Create a vtkInformationKey from its coresponding XML representation. 00162 // Stores it in the instance of vtkInformationProvided. Does not allocate. 00163 int CreateInformationKey(vtkXMLDataElement *eInfoKey, vtkInformation *info); 00164 00165 // Internal utility methods. 00166 virtual int OpenVTKFile(); 00167 virtual void CloseVTKFile(); 00168 virtual void CreateXMLParser(); 00169 virtual void DestroyXMLParser(); 00170 void SetupCompressor(const char* type); 00171 int CanReadFileVersionString(const char* version); 00172 00177 virtual int CanReadFileWithDataType(const char* dsname); 00178 00179 // Returns the major version for the file being read. -1 when invalid. 00180 vtkGetMacro(FileMajorVersion, int); 00181 00182 // Returns the minor version for the file being read. -1 when invalid. 00183 vtkGetMacro(FileMinorVersion, int); 00184 00185 // Utility methods for subclasses. 00186 int IntersectExtents(int* extent1, int* extent2, int* result); 00187 int Min(int a, int b); 00188 int Max(int a, int b); 00189 void ComputePointDimensions(int* extent, int* dimensions); 00190 void ComputePointIncrements(int* extent, vtkIdType* increments); 00191 void ComputeCellDimensions(int* extent, int* dimensions); 00192 void ComputeCellIncrements(int* extent, vtkIdType* increments); 00193 vtkIdType GetStartTuple(int* extent, vtkIdType* increments, 00194 int i, int j, int k); 00195 void ReadAttributeIndices(vtkXMLDataElement* eDSA, 00196 vtkDataSetAttributes* dsa); 00197 char** CreateStringArray(int numStrings); 00198 void DestroyStringArray(int numStrings, char** strings); 00199 00200 // Setup the data array selections for the input's set of arrays. 00201 void SetDataArraySelections(vtkXMLDataElement* eDSA, 00202 vtkDataArraySelection* sel); 00203 00204 //BTX 00205 int SetFieldDataInfo(vtkXMLDataElement *eDSA, int association, 00206 int numTuples, vtkInformationVector *(&infoVector)); 00207 //ETX 00208 00209 // Check whether the given array element is an enabled array. 00210 int PointDataArrayIsEnabled(vtkXMLDataElement* ePDA); 00211 int CellDataArrayIsEnabled(vtkXMLDataElement* eCDA); 00212 00213 // Callback registered with the SelectionObserver. 00214 static void SelectionModifiedCallback(vtkObject* caller, unsigned long eid, 00215 void* clientdata, void* calldata); 00216 00217 // The vtkXMLDataParser instance used to hide XML reading details. 00218 vtkXMLDataParser* XMLParser; 00219 00220 // The FieldData element representation. 00221 vtkXMLDataElement* FieldDataElement; 00222 00223 // The input file's name. 00224 char* FileName; 00225 00226 // The stream used to read the input. 00227 istream* Stream; 00228 00229 // The array selections. 00230 vtkDataArraySelection* PointDataArraySelection; 00231 vtkDataArraySelection* CellDataArraySelection; 00232 00233 // The observer to modify this object when the array selections are 00234 // modified. 00235 vtkCallbackCommand* SelectionObserver; 00236 00237 // Whether there was an error reading the file in RequestInformation. 00238 int InformationError; 00239 00240 // Whether there was an error reading the file in RequestData. 00241 int DataError; 00242 00243 // incrementally fine-tuned progress updates. 00244 virtual void GetProgressRange(float* range); 00245 virtual void SetProgressRange(float* range, int curStep, int numSteps); 00246 virtual void SetProgressRange(float* range, int curStep, float* fractions); 00247 virtual void UpdateProgressDiscrete(float progress); 00248 float ProgressRange[2]; 00249 00250 virtual int RequestData(vtkInformation *request, 00251 vtkInformationVector **inputVector, 00252 vtkInformationVector *outputVector); 00253 virtual int RequestDataObject(vtkInformation *vtkNotUsed(request), 00254 vtkInformationVector **vtkNotUsed(inputVector), 00255 vtkInformationVector *vtkNotUsed(outputVector)) 00256 { return 1; } 00257 virtual int RequestInformation(vtkInformation *request, 00258 vtkInformationVector **inputVector, 00259 vtkInformationVector *outputVector); 00260 virtual int RequestUpdateExtentInformation 00261 (vtkInformation *request, 00262 vtkInformationVector **inputVector, 00263 vtkInformationVector *outputVector); 00264 00265 vtkTimeStamp ReadMTime; 00266 00267 // Whether there was an error reading the XML. 00268 int ReadError; 00269 00270 // For structured data keep track of dimensions empty of cells. For 00271 // unstructured data these are always zero. This is used to support 00272 // 1-D and 2-D cell data. 00273 int AxesEmpty[3]; 00274 00275 // The timestep currently being read. 00276 int TimeStep; 00277 int CurrentTimeStep; 00278 int NumberOfTimeSteps; 00279 void SetNumberOfTimeSteps(int num); 00280 // buffer for reading timestep from the XML file the length is of 00281 // NumberOfTimeSteps and therefore is always long enough 00282 int *TimeSteps; 00283 // Store the range of time steps 00284 int TimeStepRange[2]; 00285 00286 // Now we need to save what was the last time read for each kind of 00287 // data to avoid rereading it that is to say we need a var for 00288 // e.g. PointData/CellData/Points/Cells... 00289 // See SubClass for details with member vars like PointsTimeStep/PointsOffset 00290 00291 // Helper function useful to know if a timestep is found in an array of timestep 00292 static int IsTimeStepInArray(int timestep, int* timesteps, int length); 00293 00294 vtkDataObject* GetCurrentOutput(); 00295 vtkInformation* GetCurrentOutputInformation(); 00296 00297 private: 00298 // The stream used to read the input if it is in a file. 00299 ifstream* FileStream; 00300 int TimeStepWasReadOnce; 00301 00302 int FileMajorVersion; 00303 int FileMinorVersion; 00304 00305 vtkDataObject* CurrentOutput; 00306 vtkInformation* CurrentOutputInformation; 00307 00308 private: 00309 vtkXMLReader(const vtkXMLReader&); // Not implemented. 00310 void operator=(const vtkXMLReader&); // Not implemented. 00311 }; 00312 00313 #endif