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