• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

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

Generated by  doxygen 1.7.1