VTK
vtkDataReader.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDataReader.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
28 #ifndef vtkDataReader_h
29 #define vtkDataReader_h
30 
31 #include "vtkIOLegacyModule.h" // For export macro
32 #include "vtkAlgorithm.h"
33 #include "vtkStdString.h" // For API using strings
34 
35 #define VTK_ASCII 1
36 #define VTK_BINARY 2
37 
38 class vtkAbstractArray;
39 class vtkCharArray;
40 class vtkDataSet;
42 class vtkFieldData;
43 class vtkGraph;
44 class vtkPointSet;
45 class vtkRectilinearGrid;
46 class vtkTable;
47 
49 {
50 public:
51  enum FieldType
52  {
56  };
57 
58 
59 
60  static vtkDataReader *New();
61  vtkTypeMacro(vtkDataReader,vtkAlgorithm);
62  void PrintSelf(ostream& os, vtkIndent indent);
63 
65 
66  vtkSetStringMacro(FileName);
67  vtkGetStringMacro(FileName);
69 
71 
73  int IsFileValid(const char *dstype);
75  return this->IsFileValid("structured_points");};
77  return this->IsFileValid("polydata");};
79  return this->IsFileValid("structured_grid");};
81  return this->IsFileValid("unstructured_grid");};
83  return this->IsFileValid("rectilinear_grid");};
85 
87 
91  void SetInputString(const char *in);
92  vtkGetStringMacro(InputString);
93  void SetInputString(const char *in, int len);
94  vtkGetMacro(InputStringLength, int);
95  void SetBinaryInputString(const char *, int len);
96  void SetInputString(const vtkStdString& input)
97  { this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length())); }
99 
101 
107  virtual void SetInputArray(vtkCharArray*);
108  vtkGetObjectMacro(InputArray, vtkCharArray);
110 
112 
113  vtkGetStringMacro(Header);
115 
117 
119  vtkSetMacro(ReadFromInputString,int);
120  vtkGetMacro(ReadFromInputString,int);
121  vtkBooleanMacro(ReadFromInputString,int);
123 
125 
127  vtkGetMacro(FileType,int);
129 
131 
136  {this->CharacterizeFile(); return this->NumberOfScalarsInFile;}
138  {this->CharacterizeFile(); return this->NumberOfVectorsInFile;}
140  {this->CharacterizeFile(); return this->NumberOfTensorsInFile;}
142  {this->CharacterizeFile(); return this->NumberOfNormalsInFile;}
144  {this->CharacterizeFile(); return this->NumberOfTCoordsInFile;}
146  {this->CharacterizeFile(); return this->NumberOfFieldDataInFile;}
148 
150 
153  const char *GetScalarsNameInFile(int i);
154  const char *GetVectorsNameInFile(int i);
155  const char *GetTensorsNameInFile(int i);
156  const char *GetNormalsNameInFile(int i);
157  const char *GetTCoordsNameInFile(int i);
158  const char *GetFieldDataNameInFile(int i);
160 
162 
164  vtkSetStringMacro(ScalarsName);
165  vtkGetStringMacro(ScalarsName);
167 
169 
171  vtkSetStringMacro(VectorsName);
172  vtkGetStringMacro(VectorsName);
174 
176 
178  vtkSetStringMacro(TensorsName);
179  vtkGetStringMacro(TensorsName);
181 
183 
185  vtkSetStringMacro(NormalsName);
186  vtkGetStringMacro(NormalsName);
188 
190 
192  vtkSetStringMacro(TCoordsName);
193  vtkGetStringMacro(TCoordsName);
195 
197 
200  vtkSetStringMacro(LookupTableName);
201  vtkGetStringMacro(LookupTableName);
203 
205 
207  vtkSetStringMacro(FieldDataName);
208  vtkGetStringMacro(FieldDataName);
210 
212 
213  vtkSetMacro(ReadAllScalars,int);
214  vtkGetMacro(ReadAllScalars,int);
215  vtkBooleanMacro(ReadAllScalars,int);
217 
219 
220  vtkSetMacro(ReadAllVectors,int);
221  vtkGetMacro(ReadAllVectors,int);
222  vtkBooleanMacro(ReadAllVectors,int);
224 
226 
227  vtkSetMacro(ReadAllNormals,int);
228  vtkGetMacro(ReadAllNormals,int);
229  vtkBooleanMacro(ReadAllNormals,int);
231 
233 
234  vtkSetMacro(ReadAllTensors,int);
235  vtkGetMacro(ReadAllTensors,int);
236  vtkBooleanMacro(ReadAllTensors,int);
238 
240 
241  vtkSetMacro(ReadAllColorScalars,int);
242  vtkGetMacro(ReadAllColorScalars,int);
243  vtkBooleanMacro(ReadAllColorScalars,int);
245 
247 
248  vtkSetMacro(ReadAllTCoords,int);
249  vtkGetMacro(ReadAllTCoords,int);
250  vtkBooleanMacro(ReadAllTCoords,int);
252 
254 
255  vtkSetMacro(ReadAllFields,int);
256  vtkGetMacro(ReadAllFields,int);
257  vtkBooleanMacro(ReadAllFields,int);
259 
261  int OpenVTKFile();
262 
264  int ReadHeader();
265 
269  int ReadCellData(vtkDataSet *ds, int numCells);
270 
274  int ReadPointData(vtkDataSet *ds, int numPts);
275 
277  int ReadPoints(vtkPointSet *ps, int numPts);
278 
280  int ReadPoints(vtkGraph *g, int numPts);
281 
285  int ReadVertexData(vtkGraph *g, int numVertices);
286 
290  int ReadEdgeData(vtkGraph *g, int numEdges);
291 
293  int ReadRowData(vtkTable *t, int numEdges);
294 
296  int ReadCells(int size, int *data);
297 
299  int ReadCells(int size, int *data, int skip1, int read2, int skip3);
300 
303  int ReadCoordinates(vtkRectilinearGrid *rg, int axes, int numCoords);
304 
306 
307  vtkAbstractArray *ReadArray(const char *dataType, int numTuples, int numComp);
308  vtkFieldData *ReadFieldData(FieldType fieldType = FIELD_DATA);
310 
312 
314  vtkGetMacro(FileMajorVersion, int);
315  vtkGetMacro(FileMinorVersion, int);
317 
318 //BTX
320 
322  int Read(char *);
323  int Read(unsigned char *);
324  int Read(short *);
325  int Read(unsigned short *);
326  int Read(int *);
327  int Read(unsigned int *);
328  int Read(long *);
329  int Read(unsigned long *);
330 #if defined(VTK_TYPE_USE___INT64)
331  int Read(__int64 *result);
332  int Read(unsigned __int64 *result);
333 #endif
334 #if defined(VTK_TYPE_USE_LONG_LONG)
335  int Read(long long *result);
336  int Read(unsigned long long *result);
337 #endif
338  int Read(float *);
339  int Read(double *);
340 //ETX
342 
344  void CloseVTKFile();
345 
346 //BTX
349  int ReadLine(char result[256]);
350 
353  int ReadString(char result[256]);
354 
356  char *LowerCase(char *str, const size_t len=256);
357 
359 
360  istream *GetIStream() {return this->IS;};
361 //ETX
363 
366  virtual int ReadMetaData(vtkInformation *) { return 1; }
367 
368 protected:
369  vtkDataReader();
370  ~vtkDataReader();
371 
372  char *FileName;
373  int FileType;
374  istream *IS;
375 
376  char *ScalarsName;
377  char *VectorsName;
378  char *TensorsName;
379  char *TCoordsName;
380  char *NormalsName;
383  char *ScalarLut;
384 
386  char *InputString;
389 
390  void SetScalarLut(const char* lut);
391  vtkGetStringMacro(ScalarLut);
392 
393  char *Header;
394 
395  int ReadScalarData(vtkDataSetAttributes *a, int num);
396  int ReadVectorData(vtkDataSetAttributes *a, int num);
397  int ReadNormalData(vtkDataSetAttributes *a, int num);
398  int ReadTensorData(vtkDataSetAttributes *a, int num);
399  int ReadCoScalarData(vtkDataSetAttributes *a, int num);
400  int ReadLutData(vtkDataSetAttributes *a);
401  int ReadTCoordsData(vtkDataSetAttributes *a, int num);
402  int ReadGlobalIds(vtkDataSetAttributes *a, int num);
403  int ReadPedigreeIds(vtkDataSetAttributes *a, int num);
404  int ReadEdgeFlags(vtkDataSetAttributes *a, int num);
405 
406  int ReadDataSetData(vtkDataSet *ds);
407 
408  // This supports getting additional information from vtk files
428 
438 
439  void InitializeCharacteristics();
440  int CharacterizeFile(); //read entire file, storing important characteristics
441  void CheckFor(const char* name, char *line, int &num, char** &array,
442  int& allocSize);
443 
445 
448  int DecodeString(char *resname, const char* name);
449 
454  { return 1; }
457  { return 1; }
460  { return 1; }
461 
462 private:
463  vtkDataReader(const vtkDataReader&); // Not implemented.
464  void operator=(const vtkDataReader&); // Not implemented.
465 
466  void ConvertGhostLevelsToGhostType(
467  FieldType fieldType, vtkAbstractArray *data) const;
468 };
469 
470 #endif
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
int GetNumberOfScalarsInFile()
a dataset that is topologically regular with variable spacing in the three coordinate directions ...
int NumberOfScalarsInFile
char * FieldDataName
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:61
Abstract superclass for all arrays.
void SetInputString(const vtkStdString &input)
Definition: vtkDataReader.h:96
int IsFilePolyData()
Definition: vtkDataReader.h:76
char ** ScalarsNameInFile
int IsFileRectilinearGrid()
Definition: vtkDataReader.h:82
record modification and/or execution time
Definition: vtkTimeStamp.h:34
int NumberOfTensorsInFile
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
int NumberOfFieldDataInFile
virtual int ProcessRequest(vtkInformation *request, vtkInformationVector **inInfo, vtkInformationVector *outInfo)
int GetNumberOfTCoordsInFile()
char * LookupTableName
char * NormalsName
int GetNumberOfNormalsInFile()
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:44
int NormalsNameAllocSize
int IsFileStructuredGrid()
Definition: vtkDataReader.h:78
int TensorsNameAllocSize
#define VTKIOLEGACY_EXPORT
vtkTimeStamp CharacteristicsTime
char ** TensorsNameInFile
int GetNumberOfFieldDataInFile()
Base class for graph data types.
Definition: vtkGraph.h:288
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:42
helper superclass for objects that read vtk data files
Definition: vtkDataReader.h:48
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:61
char * ScalarsName
int TCoordsNameAllocSize
a simple class to control print indentation
Definition: vtkIndent.h:38
istream * GetIStream()
char ** FieldDataNameInFile
int ScalarsNameAllocSize
represent and manipulate attribute data in a dataset
int NumberOfNormalsInFile
virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
char * TensorsName
int GetNumberOfVectorsInFile()
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:67
char * TCoordsName
char * InputString
int IsFileUnstructuredGrid()
Definition: vtkDataReader.h:80
char ** VectorsNameInFile
int IsFileStructuredPoints()
Definition: vtkDataReader.h:74
Store zero or more vtkInformation instances.
static vtkAlgorithm * New()
int VectorsNameAllocSize
char ** NormalsNameInFile
virtual int ReadMetaData(vtkInformation *)
vtkCharArray * InputArray
istream * IS
char * VectorsName
char ** TCoordsNameInFile
int FieldDataNameAllocSize
int GetNumberOfTensorsInFile()
int NumberOfTCoordsInFile
#define IS
represent and manipulate fields of data
Definition: vtkFieldData.h:55
int NumberOfVectorsInFile
void PrintSelf(ostream &os, vtkIndent indent)