VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/IO/Legacy/vtkDataReader.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkDataReader.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 =========================================================================*/
00028 #ifndef vtkDataReader_h
00029 #define vtkDataReader_h
00030 
00031 #include "vtkIOLegacyModule.h" // For export macro
00032 #include "vtkAlgorithm.h"
00033 #include "vtkStdString.h" // For API using strings
00034 
00035 #define VTK_ASCII 1
00036 #define VTK_BINARY 2
00037 
00038 class vtkAbstractArray;
00039 class vtkCharArray;
00040 class vtkDataSet;
00041 class vtkDataSetAttributes;
00042 class vtkFieldData;
00043 class vtkGraph;
00044 class vtkPointSet;
00045 class vtkRectilinearGrid;
00046 class vtkTable;
00047 
00048 class VTKIOLEGACY_EXPORT vtkDataReader : public vtkAlgorithm
00049 {
00050 public:
00051   static vtkDataReader *New();
00052   vtkTypeMacro(vtkDataReader,vtkAlgorithm);
00053   void PrintSelf(ostream& os, vtkIndent indent);
00054 
00056 
00057   vtkSetStringMacro(FileName);
00058   vtkGetStringMacro(FileName);
00060 
00062 
00064   int IsFileValid(const char *dstype);
00065   int IsFileStructuredPoints() {
00066     return this->IsFileValid("structured_points");};
00067   int IsFilePolyData() {
00068     return this->IsFileValid("polydata");};
00069   int IsFileStructuredGrid() {
00070     return this->IsFileValid("structured_grid");};
00071   int IsFileUnstructuredGrid() {
00072     return this->IsFileValid("unstructured_grid");};
00073   int IsFileRectilinearGrid() {
00074     return this->IsFileValid("rectilinear_grid");};
00076 
00078 
00082   void SetInputString(const char *in);
00083   vtkGetStringMacro(InputString);
00084   void SetInputString(const char *in, int len);
00085   vtkGetMacro(InputStringLength, int);
00086   void SetBinaryInputString(const char *, int len);
00087   void SetInputString(const vtkStdString& input)
00088     { this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length())); }
00090 
00092 
00098   virtual void SetInputArray(vtkCharArray*);
00099   vtkGetObjectMacro(InputArray, vtkCharArray);
00101 
00103 
00104   vtkGetStringMacro(Header);
00106 
00108 
00110   vtkSetMacro(ReadFromInputString,int);
00111   vtkGetMacro(ReadFromInputString,int);
00112   vtkBooleanMacro(ReadFromInputString,int);
00114 
00116 
00118   vtkGetMacro(FileType,int);
00120 
00122 
00126   int GetNumberOfScalarsInFile()
00127     {this->CharacterizeFile(); return this->NumberOfScalarsInFile;}
00128   int GetNumberOfVectorsInFile()
00129     {this->CharacterizeFile(); return this->NumberOfVectorsInFile;}
00130   int GetNumberOfTensorsInFile()
00131     {this->CharacterizeFile(); return this->NumberOfTensorsInFile;}
00132   int GetNumberOfNormalsInFile()
00133     {this->CharacterizeFile(); return this->NumberOfNormalsInFile;}
00134   int GetNumberOfTCoordsInFile()
00135     {this->CharacterizeFile(); return this->NumberOfTCoordsInFile;}
00136   int GetNumberOfFieldDataInFile()
00137     {this->CharacterizeFile(); return this->NumberOfFieldDataInFile;}
00139 
00141 
00144   const char *GetScalarsNameInFile(int i);
00145   const char *GetVectorsNameInFile(int i);
00146   const char *GetTensorsNameInFile(int i);
00147   const char *GetNormalsNameInFile(int i);
00148   const char *GetTCoordsNameInFile(int i);
00149   const char *GetFieldDataNameInFile(int i);
00151 
00153 
00155   vtkSetStringMacro(ScalarsName);
00156   vtkGetStringMacro(ScalarsName);
00158 
00160 
00162   vtkSetStringMacro(VectorsName);
00163   vtkGetStringMacro(VectorsName);
00165 
00167 
00169   vtkSetStringMacro(TensorsName);
00170   vtkGetStringMacro(TensorsName);
00172 
00174 
00176   vtkSetStringMacro(NormalsName);
00177   vtkGetStringMacro(NormalsName);
00179 
00181 
00183   vtkSetStringMacro(TCoordsName);
00184   vtkGetStringMacro(TCoordsName);
00186 
00188 
00191   vtkSetStringMacro(LookupTableName);
00192   vtkGetStringMacro(LookupTableName);
00194 
00196 
00198   vtkSetStringMacro(FieldDataName);
00199   vtkGetStringMacro(FieldDataName);
00201 
00203 
00204   vtkSetMacro(ReadAllScalars,int);
00205   vtkGetMacro(ReadAllScalars,int);
00206   vtkBooleanMacro(ReadAllScalars,int);
00208 
00210 
00211   vtkSetMacro(ReadAllVectors,int);
00212   vtkGetMacro(ReadAllVectors,int);
00213   vtkBooleanMacro(ReadAllVectors,int);
00215 
00217 
00218   vtkSetMacro(ReadAllNormals,int);
00219   vtkGetMacro(ReadAllNormals,int);
00220   vtkBooleanMacro(ReadAllNormals,int);
00222 
00224 
00225   vtkSetMacro(ReadAllTensors,int);
00226   vtkGetMacro(ReadAllTensors,int);
00227   vtkBooleanMacro(ReadAllTensors,int);
00229 
00231 
00232   vtkSetMacro(ReadAllColorScalars,int);
00233   vtkGetMacro(ReadAllColorScalars,int);
00234   vtkBooleanMacro(ReadAllColorScalars,int);
00236 
00238 
00239   vtkSetMacro(ReadAllTCoords,int);
00240   vtkGetMacro(ReadAllTCoords,int);
00241   vtkBooleanMacro(ReadAllTCoords,int);
00243 
00245 
00246   vtkSetMacro(ReadAllFields,int);
00247   vtkGetMacro(ReadAllFields,int);
00248   vtkBooleanMacro(ReadAllFields,int);
00250 
00252   int OpenVTKFile();
00253 
00255   int ReadHeader();
00256 
00260   int ReadCellData(vtkDataSet *ds, int numCells);
00261 
00265   int ReadPointData(vtkDataSet *ds, int numPts);
00266 
00268   int ReadPoints(vtkPointSet *ps, int numPts);
00269 
00271   int ReadPoints(vtkGraph *g, int numPts);
00272 
00276   int ReadVertexData(vtkGraph *g, int numVertices);
00277 
00281   int ReadEdgeData(vtkGraph *g, int numEdges);
00282 
00284   int ReadRowData(vtkTable *t, int numEdges);
00285 
00287   int ReadCells(int size, int *data);
00288 
00290   int ReadCells(int size, int *data, int skip1, int read2, int skip3);
00291 
00294   int ReadCoordinates(vtkRectilinearGrid *rg, int axes, int numCoords);
00295 
00297 
00298   vtkAbstractArray *ReadArray(const char *dataType, int numTuples, int numComp);
00299   vtkFieldData *ReadFieldData();
00301 
00302 //BTX
00304 
00306   int Read(char *);
00307   int Read(unsigned char *);
00308   int Read(short *);
00309   int Read(unsigned short *);
00310   int Read(int *);
00311   int Read(unsigned int *);
00312   int Read(long *);
00313   int Read(unsigned long *);
00314 #if defined(VTK_TYPE_USE___INT64)
00315   int Read(__int64 *result);
00316   int Read(unsigned __int64 *result);
00317 #endif
00318 #if defined(VTK_TYPE_USE_LONG_LONG)
00319   int Read(long long *result);
00320   int Read(unsigned long long *result);
00321 #endif
00322   int Read(float *);
00323   int Read(double *);
00324 //ETX
00326 
00328   void CloseVTKFile();
00329 
00330 //BTX
00333   int ReadLine(char result[256]);
00334 
00337   int ReadString(char result[256]);
00338 
00340   char *LowerCase(char *str, const size_t len=256);
00341 
00343 
00344   istream *GetIStream() {return this->IS;};
00345 //ETX
00347 
00350   virtual int ReadMetaData(vtkInformation *) { return 1; }
00351 
00352 protected:
00353   vtkDataReader();
00354   ~vtkDataReader();
00355 
00356   char *FileName;
00357   int FileType;
00358   istream *IS;
00359 
00360   char *ScalarsName;
00361   char *VectorsName;
00362   char *TensorsName;
00363   char *TCoordsName;
00364   char *NormalsName;
00365   char *LookupTableName;
00366   char *FieldDataName;
00367   char *ScalarLut;
00368 
00369   int ReadFromInputString;
00370   char *InputString;
00371   int InputStringLength;
00372   int InputStringPos;
00373 
00374   void SetScalarLut(const char* lut);
00375   vtkGetStringMacro(ScalarLut);
00376 
00377   char *Header;
00378 
00379   int ReadScalarData(vtkDataSetAttributes *a, int num);
00380   int ReadVectorData(vtkDataSetAttributes *a, int num);
00381   int ReadNormalData(vtkDataSetAttributes *a, int num);
00382   int ReadTensorData(vtkDataSetAttributes *a, int num);
00383   int ReadCoScalarData(vtkDataSetAttributes *a, int num);
00384   int ReadLutData(vtkDataSetAttributes *a);
00385   int ReadTCoordsData(vtkDataSetAttributes *a, int num);
00386   int ReadGlobalIds(vtkDataSetAttributes *a, int num);
00387   int ReadPedigreeIds(vtkDataSetAttributes *a, int num);
00388   int ReadEdgeFlags(vtkDataSetAttributes *a, int num);
00389 
00390   int ReadDataSetData(vtkDataSet *ds);
00391 
00392   // This supports getting additional information from vtk files
00393   int  NumberOfScalarsInFile;
00394   char **ScalarsNameInFile;
00395   int ScalarsNameAllocSize;
00396   int  NumberOfVectorsInFile;
00397   char **VectorsNameInFile;
00398   int VectorsNameAllocSize;
00399   int  NumberOfTensorsInFile;
00400   char **TensorsNameInFile;
00401   int TensorsNameAllocSize;
00402   int  NumberOfTCoordsInFile;
00403   char **TCoordsNameInFile;
00404   int TCoordsNameAllocSize;
00405   int  NumberOfNormalsInFile;
00406   char **NormalsNameInFile;
00407   int NormalsNameAllocSize;
00408   int  NumberOfFieldDataInFile;
00409   char **FieldDataNameInFile;
00410   int FieldDataNameAllocSize;
00411   vtkTimeStamp CharacteristicsTime;
00412 
00413   int ReadAllScalars;
00414   int ReadAllVectors;
00415   int ReadAllNormals;
00416   int ReadAllTensors;
00417   int ReadAllColorScalars;
00418   int ReadAllTCoords;
00419   int ReadAllFields;
00420 
00421   void InitializeCharacteristics();
00422   int CharacterizeFile(); //read entire file, storing important characteristics
00423   void CheckFor(const char* name, char *line, int &num, char** &array,
00424                 int& allocSize);
00425 
00426   vtkCharArray* InputArray;
00427 
00430   int DecodeString(char *resname, const char* name);
00431 
00432   virtual int ProcessRequest(vtkInformation *, vtkInformationVector **,
00433                              vtkInformationVector *);
00434   virtual int RequestData(vtkInformation *, vtkInformationVector **,
00435                           vtkInformationVector *)
00436     { return 1; }
00437   virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **,
00438                                   vtkInformationVector *)
00439     { return 1; }
00440   virtual int RequestInformation(vtkInformation *, vtkInformationVector **,
00441                                  vtkInformationVector *)
00442     { return 1; }
00443 
00444 private:
00445   vtkDataReader(const vtkDataReader&);  // Not implemented.
00446   void operator=(const vtkDataReader&);  // Not implemented.
00447 };
00448 
00449 #endif