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

vtkDataReader.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkDataReader.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 =========================================================================*/
00040 #ifndef __vtkDataReader_h
00041 #define __vtkDataReader_h
00042 
00043 #include "vtkSource.h"
00044 
00045 #define VTK_ASCII 1
00046 #define VTK_BINARY 2
00047 
00048 class vtkCharArray;
00049 class vtkDataArray;
00050 class vtkDataSet;
00051 class vtkDataSetAttributes;
00052 class vtkFieldData;
00053 class vtkPointSet;
00054 class vtkRectilinearGrid;
00055 
00056 class VTK_IO_EXPORT vtkDataReader : public vtkSource
00057 {
00058 public:
00059   static vtkDataReader *New();
00060   vtkTypeRevisionMacro(vtkDataReader,vtkSource);
00061   void PrintSelf(ostream& os, vtkIndent indent);
00062 
00064 
00065   vtkSetStringMacro(FileName);
00066   vtkGetStringMacro(FileName);
00068 
00070 
00072   int IsFileValid(const char *dstype);
00073   int IsFileStructuredPoints() {
00074     return this->IsFileValid("structured_points");};  
00075   int IsFilePolyData() {
00076     return this->IsFileValid("polydata");};  
00077   int IsFileStructuredGrid() {
00078     return this->IsFileValid("structured_grid");};  
00079   int IsFileUnstructuredGrid() {
00080     return this->IsFileValid("unstructured_grid");};  
00081   int IsFileRectilinearGrid() {
00082     return this->IsFileValid("rectilinear_grid");};
00084   
00086 
00090   void SetInputString(const char *in);
00091   vtkGetStringMacro(InputString);
00092   void SetInputString(const char *in, int len);
00093   vtkGetMacro(InputStringLength, int);
00094   void SetBinaryInputString(const char *, int len);
00096 
00098 
00104   virtual void SetInputArray(vtkCharArray*);
00105   vtkGetObjectMacro(InputArray, vtkCharArray);
00107     
00109 
00110   vtkGetStringMacro(Header);
00112 
00114 
00116   vtkSetMacro(ReadFromInputString,int);
00117   vtkGetMacro(ReadFromInputString,int);
00118   vtkBooleanMacro(ReadFromInputString,int);
00120 
00122 
00124   vtkGetMacro(FileType,int);
00126 
00128 
00132   int GetNumberOfScalarsInFile()
00133     {this->CharacterizeFile(); return this->NumberOfScalarsInFile;}
00134   int GetNumberOfVectorsInFile()
00135     {this->CharacterizeFile(); return this->NumberOfVectorsInFile;}
00136   int GetNumberOfTensorsInFile()
00137     {this->CharacterizeFile(); return this->NumberOfTensorsInFile;}
00138   int GetNumberOfNormalsInFile()
00139     {this->CharacterizeFile(); return this->NumberOfNormalsInFile;}
00140   int GetNumberOfTCoordsInFile()
00141     {this->CharacterizeFile(); return this->NumberOfTCoordsInFile;}
00142   int GetNumberOfFieldDataInFile()
00143     {this->CharacterizeFile(); return this->NumberOfFieldDataInFile;}
00145   
00147 
00150   const char *GetScalarsNameInFile(int i);
00151   const char *GetVectorsNameInFile(int i);
00152   const char *GetTensorsNameInFile(int i);
00153   const char *GetNormalsNameInFile(int i);
00154   const char *GetTCoordsNameInFile(int i);
00155   const char *GetFieldDataNameInFile(int i);
00157   
00159 
00161   vtkSetStringMacro(ScalarsName);
00162   vtkGetStringMacro(ScalarsName);
00164 
00166 
00168   vtkSetStringMacro(VectorsName);
00169   vtkGetStringMacro(VectorsName);
00171 
00173 
00175   vtkSetStringMacro(TensorsName);
00176   vtkGetStringMacro(TensorsName);
00178 
00180 
00182   vtkSetStringMacro(NormalsName);
00183   vtkGetStringMacro(NormalsName);
00185 
00187 
00189   vtkSetStringMacro(TCoordsName);
00190   vtkGetStringMacro(TCoordsName);
00192 
00194 
00197   vtkSetStringMacro(LookupTableName);
00198   vtkGetStringMacro(LookupTableName);
00200 
00202 
00204   vtkSetStringMacro(FieldDataName);
00205   vtkGetStringMacro(FieldDataName);
00207 
00209 
00210   vtkSetMacro(ReadAllScalars,int);
00211   vtkGetMacro(ReadAllScalars,int);
00212   vtkBooleanMacro(ReadAllScalars,int);
00214 
00216 
00217   vtkSetMacro(ReadAllVectors,int);
00218   vtkGetMacro(ReadAllVectors,int);
00219   vtkBooleanMacro(ReadAllVectors,int);
00221 
00223 
00224   vtkSetMacro(ReadAllNormals,int);
00225   vtkGetMacro(ReadAllNormals,int);
00226   vtkBooleanMacro(ReadAllNormals,int);
00228 
00230 
00231   vtkSetMacro(ReadAllTensors,int);
00232   vtkGetMacro(ReadAllTensors,int);
00233   vtkBooleanMacro(ReadAllTensors,int);
00235 
00237 
00238   vtkSetMacro(ReadAllColorScalars,int);
00239   vtkGetMacro(ReadAllColorScalars,int);
00240   vtkBooleanMacro(ReadAllColorScalars,int);
00242 
00244 
00245   vtkSetMacro(ReadAllTCoords,int);
00246   vtkGetMacro(ReadAllTCoords,int);
00247   vtkBooleanMacro(ReadAllTCoords,int);
00249 
00251 
00252   vtkSetMacro(ReadAllFields,int);
00253   vtkGetMacro(ReadAllFields,int);
00254   vtkBooleanMacro(ReadAllFields,int);
00256 
00258   int OpenVTKFile();
00259 
00261   int ReadHeader();
00262 
00266   int ReadCellData(vtkDataSet *ds, int numCells);
00267 
00271   int ReadPointData(vtkDataSet *ds, int numPts);
00272 
00274   int ReadPoints(vtkPointSet *ps, int numPts);
00275 
00277   int ReadCells(int size, int *data);
00278 
00280   int ReadCells(int size, int *data, int skip1, int read2, int skip3);
00281 
00284   int ReadCoordinates(vtkRectilinearGrid *rg, int axes, int numCoords);
00285 
00287 
00288   vtkDataArray *ReadArray(const char *dataType, int numTuples, int numComp);
00289   vtkFieldData *ReadFieldData();
00291 
00293 
00295   int Read(char *);
00296   int Read(unsigned char *);
00297   int Read(short *);
00298   int Read(unsigned short *);
00299   int Read(int *);
00300   int Read(unsigned int *);
00301   int Read(long *);
00302   int Read(unsigned long *);
00303   int Read(float *);
00304   int Read(double *);
00306 
00308   void CloseVTKFile();
00309 
00310 //BTX
00313   int ReadLine(char result[256]);
00314 
00317   int ReadString(char result[256]);
00318 
00320   char *LowerCase(char *str, const size_t len=256);
00321   
00323   istream *GetIStream() {return this->IS;};
00324 //ETX
00325 
00326 protected:
00327   vtkDataReader();
00328   ~vtkDataReader();
00329 
00330   char *FileName;
00331   int FileType;
00332   istream *IS;
00333 
00334   char *ScalarsName;
00335   char *VectorsName;
00336   char *TensorsName;
00337   char *TCoordsName;
00338   char *NormalsName;
00339   char *LookupTableName;
00340   char *FieldDataName;
00341   char *ScalarLut;
00342 
00343   int ReadFromInputString;
00344   char *InputString;
00345   int InputStringLength;
00346   int InputStringPos;
00347 
00348   vtkSetStringMacro(ScalarLut);
00349   vtkGetStringMacro(ScalarLut);
00350 
00351   char *Header;
00352 
00353   int ReadScalarData(vtkDataSetAttributes *a, int num);
00354   int ReadVectorData(vtkDataSetAttributes *a, int num);
00355   int ReadNormalData(vtkDataSetAttributes *a, int num);
00356   int ReadTensorData(vtkDataSetAttributes *a, int num);
00357   int ReadCoScalarData(vtkDataSetAttributes *a, int num);
00358   int ReadLutData(vtkDataSetAttributes *a);
00359   int ReadTCoordsData(vtkDataSetAttributes *a, int num);
00360 
00361   int ReadDataSetData(vtkDataSet *ds);
00362 
00363   // This supports getting additional information from vtk files
00364   int  NumberOfScalarsInFile;
00365   char **ScalarsNameInFile;
00366   int ScalarsNameAllocSize;
00367   int  NumberOfVectorsInFile;
00368   char **VectorsNameInFile;
00369   int VectorsNameAllocSize;
00370   int  NumberOfTensorsInFile;
00371   char **TensorsNameInFile;
00372   int TensorsNameAllocSize;
00373   int  NumberOfTCoordsInFile;
00374   char **TCoordsNameInFile;
00375   int TCoordsNameAllocSize;
00376   int  NumberOfNormalsInFile;
00377   char **NormalsNameInFile;
00378   int NormalsNameAllocSize;
00379   int  NumberOfFieldDataInFile;
00380   char **FieldDataNameInFile;
00381   int FieldDataNameAllocSize;
00382   vtkTimeStamp CharacteristicsTime;
00383  
00384   int ReadAllScalars;
00385   int ReadAllVectors;
00386   int ReadAllNormals;
00387   int ReadAllTensors;
00388   int ReadAllColorScalars;
00389   int ReadAllTCoords;
00390   int ReadAllFields;
00391 
00392   void InitializeCharacteristics();
00393   int CharacterizeFile(); //read entire file, storing important characteristics
00394   void CheckFor(const char* name, char *line, int &num, char** &array, 
00395                 int& allocSize);
00396 
00397   vtkCharArray* InputArray;
00398 
00401   void DecodeArrayName(char *resname, const char* name);
00402 
00403 private:
00404   vtkDataReader(const vtkDataReader&);  // Not implemented.
00405   void operator=(const vtkDataReader&);  // Not implemented.
00406 };
00407 
00408 #endif
00409 
00410