Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | 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 =========================================================================*/
00033 #ifndef __vtkXMLReader_h
00034 #define __vtkXMLReader_h
00035 
00036 #include "vtkSource.h"
00037 
00038 class vtkCallbackCommand;
00039 class vtkDataArray;
00040 class vtkDataArraySelection;
00041 class vtkDataSet;
00042 class vtkDataSetAttributes;
00043 class vtkXMLDataElement;
00044 class vtkXMLDataParser;
00045 
00046 class VTK_IO_EXPORT vtkXMLReader : public vtkSource
00047 {
00048 public:
00049   vtkTypeRevisionMacro(vtkXMLReader,vtkSource);
00050   void PrintSelf(ostream& os, vtkIndent indent);
00051   
00053 
00054   vtkSetStringMacro(FileName);
00055   vtkGetStringMacro(FileName);
00057   
00059   virtual int CanReadFile(const char* name);
00060   
00062 
00063   vtkDataSet* GetOutputAsDataSet();
00064   vtkDataSet* GetOutputAsDataSet(int index);
00066   
00068 
00070   vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
00071   vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
00073   
00075 
00076   int GetNumberOfPointArrays();
00077   int GetNumberOfCellArrays();
00079   
00081 
00083   const char* GetPointArrayName(int index);
00084   const char* GetCellArrayName(int index);
00086   
00088 
00090   int GetPointArrayStatus(const char* name);
00091   int GetCellArrayStatus(const char* name);
00092   void SetPointArrayStatus(const char* name, int status);  
00093   void SetCellArrayStatus(const char* name, int status);  
00095   
00096 protected:
00097   vtkXMLReader();
00098   ~vtkXMLReader();
00099   
00100   // Standard pipeline exectution methods.
00101   void ExecuteInformation();
00102   void ExecuteData(vtkDataObject* output);
00103   
00104   // Pipeline execution methods to be defined by subclass.  Called by
00105   // corresponding Execute methods after appropriate setup has been
00106   // done.
00107   virtual void ReadXMLInformation();
00108   virtual void ReadXMLData();
00109   
00110   // Get the name of the data set being read.
00111   virtual const char* GetDataSetName()=0;
00112   
00113   // Test if the reader can read a file with the given version number.
00114   virtual int CanReadFileVersion(int major, int minor);
00115   
00116   // Setup the output with no data available.  Used in error cases.
00117   virtual void SetupEmptyOutput()=0;
00118   
00119   // Setup the output's information and data without allocation.
00120   virtual void SetupOutputInformation();
00121   
00122   // Setup the output's information and data with allocation.
00123   virtual void SetupOutputData();
00124   
00125   // Read the primary element from the file.  This is the element
00126   // whose name is the value returned by GetDataSetName().
00127   virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
00128   
00129   // Read the top-level element from the file.  This is always the
00130   // VTKFile element.
00131   int ReadVTKFile(vtkXMLDataElement* eVTKFile);  
00132   
00133   // Create a vtkDataArray from its cooresponding XML representation.
00134   // Does not allocate.
00135   vtkDataArray* CreateDataArray(vtkXMLDataElement* da);
00136   
00137   // Internal utility methods.
00138   int OpenVTKFile();
00139   void CloseVTKFile();
00140   virtual void CreateXMLParser();
00141   virtual void DestroyXMLParser();
00142   void SetupCompressor(const char* type);
00143   int CanReadFileVersionString(const char* version);
00144   
00145   // Utility methods for subclasses.
00146   int IntersectExtents(int* extent1, int* extent2, int* result);
00147   int Min(int a, int b);
00148   int Max(int a, int b);
00149   void ComputeDimensions(int* extent, int* dimensions, int isPoint);
00150   void ComputeIncrements(int* extent, int* increments, int isPoint);
00151   unsigned int GetStartTuple(int* extent, int* increments,
00152                              int i, int j, int k);
00153   void ReadAttributeIndices(vtkXMLDataElement* eDSA,
00154                             vtkDataSetAttributes* dsa);
00155   char** CreateStringArray(int numStrings);
00156   void DestroyStringArray(int numStrings, char** strings);  
00157   
00158   // Setup the data array selections for the input's set of arrays.
00159   void SetDataArraySelections(vtkXMLDataElement* eDSA,
00160                               vtkDataArraySelection* sel);
00161   
00162   // Check whether the given array element is an enabled array.
00163   int PointDataArrayIsEnabled(vtkXMLDataElement* ePDA);
00164   int CellDataArrayIsEnabled(vtkXMLDataElement* eCDA);
00165   
00166   // Callback registered with the SelectionObserver.
00167   static void SelectionModifiedCallback(vtkObject* caller, unsigned long eid,
00168                                         void* clientdata, void* calldata);
00169   
00170   // The vtkXMLDataParser instance used to hide XML reading details.
00171   vtkXMLDataParser* XMLParser;
00172   
00173   // The input file's name.
00174   char* FileName;
00175   
00176   // The stream used to read the input.
00177   istream* Stream;
00178   
00179   // The array selections.
00180   vtkDataArraySelection* PointDataArraySelection;
00181   vtkDataArraySelection* CellDataArraySelection;
00182   
00183   // The observer to modify this object when the array selections are
00184   // modified.
00185   vtkCallbackCommand* SelectionObserver;
00186   
00187   // Whether there was an error reading the file in ExecuteInformation.
00188   int InformationError;
00189   
00190   // Whether there was an error reading the file in ExecuteData.
00191   int DataError;
00192   
00193   // The index of the output on which ExecuteData is currently
00194   // running.
00195   int CurrentOutput;
00196   
00197   // The current range over which progress is moving.  This allows for
00198   // incrementally fine-tuned progress updates.
00199   virtual void GetProgressRange(float* range);
00200   virtual void SetProgressRange(float* range, int curStep, int numSteps);
00201   virtual void SetProgressRange(float* range, int curStep, float* fractions);
00202   virtual void UpdateProgressDiscrete(float progress);
00203   float ProgressRange[2];
00204 
00205 private:
00206   // The stream used to read the input if it is in a file.
00207   ifstream* FileStream;  
00208   
00209 private:
00210   vtkXMLReader(const vtkXMLReader&);  // Not implemented.
00211   void operator=(const vtkXMLReader&);  // Not implemented.
00212 };
00213 
00214 #endif