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

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

Generated on Mon Jan 21 23:07:32 2008 for VTK by  doxygen 1.4.3-20050530