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 =========================================================================*/
29 #ifndef vtkDataReader_h
30 #define vtkDataReader_h
31 
32 #include "vtkIOLegacyModule.h" // For export macro
33 #include "vtkSimpleReader.h"
34 #include "vtkStdString.h" // For API using strings
35 
36 #define VTK_ASCII 1
37 #define VTK_BINARY 2
38 
39 class vtkAbstractArray;
40 class vtkCharArray;
41 class vtkDataSet;
43 class vtkFieldData;
44 class vtkGraph;
45 class vtkPointSet;
46 class vtkRectilinearGrid;
47 class vtkTable;
48 
49 class VTKIOLEGACY_EXPORT vtkDataReader : public vtkSimpleReader
50 {
51 public:
52  enum FieldType
53  {
56  FIELD_DATA
57  };
58 
59  static vtkDataReader *New();
61  void PrintSelf(ostream& os, vtkIndent indent) override;
62 
64 
69  void SetFileName(const char* fname);
70  const char* GetFileName() const;
71  const char* GetFileName(int i) const
72  {
73  return this->vtkSimpleReader::GetFileName(i);
74  }
76 
78 
82  int IsFileValid(const char *dstype);
84  return this->IsFileValid("structured_points");};
86  return this->IsFileValid("polydata");};
88  return this->IsFileValid("structured_grid");};
90  return this->IsFileValid("unstructured_grid");};
92  return this->IsFileValid("rectilinear_grid");};
94 
96 
102  void SetInputString(const char *in);
103  vtkGetStringMacro(InputString);
104  void SetInputString(const char *in, int len);
105  vtkGetMacro(InputStringLength, int);
106  void SetBinaryInputString(const char *, int len);
107  void SetInputString(const vtkStdString& input)
108  { this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length())); }
110 
112 
120  virtual void SetInputArray(vtkCharArray*);
121  vtkGetObjectMacro(InputArray, vtkCharArray);
123 
125 
128  vtkGetStringMacro(Header);
130 
132 
136  vtkSetMacro(ReadFromInputString,vtkTypeBool);
137  vtkGetMacro(ReadFromInputString,vtkTypeBool);
138  vtkBooleanMacro(ReadFromInputString,vtkTypeBool);
140 
142 
146  vtkGetMacro(FileType,int);
148 
157  {this->CharacterizeFile(); return this->NumberOfScalarsInFile;}
159  {this->CharacterizeFile(); return this->NumberOfVectorsInFile;}
161  {this->CharacterizeFile(); return this->NumberOfTensorsInFile;}
163  {this->CharacterizeFile(); return this->NumberOfNormalsInFile;}
165  {this->CharacterizeFile(); return this->NumberOfTCoordsInFile;}
167  {this->CharacterizeFile(); return this->NumberOfFieldDataInFile;}
168 
170 
175  const char *GetScalarsNameInFile(int i);
176  const char *GetVectorsNameInFile(int i);
177  const char *GetTensorsNameInFile(int i);
178  const char *GetNormalsNameInFile(int i);
179  const char *GetTCoordsNameInFile(int i);
180  const char *GetFieldDataNameInFile(int i);
182 
184 
188  vtkSetStringMacro(ScalarsName);
189  vtkGetStringMacro(ScalarsName);
191 
193 
197  vtkSetStringMacro(VectorsName);
198  vtkGetStringMacro(VectorsName);
200 
202 
206  vtkSetStringMacro(TensorsName);
207  vtkGetStringMacro(TensorsName);
209 
211 
215  vtkSetStringMacro(NormalsName);
216  vtkGetStringMacro(NormalsName);
218 
220 
224  vtkSetStringMacro(TCoordsName);
225  vtkGetStringMacro(TCoordsName);
227 
229 
233  vtkSetStringMacro(LookupTableName);
234  vtkGetStringMacro(LookupTableName);
236 
238 
242  vtkSetStringMacro(FieldDataName);
243  vtkGetStringMacro(FieldDataName);
245 
247 
250  vtkSetMacro(ReadAllScalars,vtkTypeBool);
251  vtkGetMacro(ReadAllScalars,vtkTypeBool);
252  vtkBooleanMacro(ReadAllScalars,vtkTypeBool);
254 
256 
259  vtkSetMacro(ReadAllVectors,vtkTypeBool);
260  vtkGetMacro(ReadAllVectors,vtkTypeBool);
261  vtkBooleanMacro(ReadAllVectors,vtkTypeBool);
263 
265 
268  vtkSetMacro(ReadAllNormals,vtkTypeBool);
269  vtkGetMacro(ReadAllNormals,vtkTypeBool);
270  vtkBooleanMacro(ReadAllNormals,vtkTypeBool);
272 
274 
277  vtkSetMacro(ReadAllTensors,vtkTypeBool);
278  vtkGetMacro(ReadAllTensors,vtkTypeBool);
279  vtkBooleanMacro(ReadAllTensors,vtkTypeBool);
281 
283 
286  vtkSetMacro(ReadAllColorScalars,vtkTypeBool);
287  vtkGetMacro(ReadAllColorScalars,vtkTypeBool);
288  vtkBooleanMacro(ReadAllColorScalars,vtkTypeBool);
290 
292 
295  vtkSetMacro(ReadAllTCoords,vtkTypeBool);
296  vtkGetMacro(ReadAllTCoords,vtkTypeBool);
297  vtkBooleanMacro(ReadAllTCoords,vtkTypeBool);
299 
301 
304  vtkSetMacro(ReadAllFields,vtkTypeBool);
305  vtkGetMacro(ReadAllFields,vtkTypeBool);
306  vtkBooleanMacro(ReadAllFields,vtkTypeBool);
308 
312  int OpenVTKFile(const char* fname = nullptr);
313 
317  int ReadHeader(const char* fname = nullptr);
318 
324  int ReadCellData(vtkDataSet *ds, vtkIdType numCells);
325 
331  int ReadPointData(vtkDataSet *ds, vtkIdType numPts);
332 
336  int ReadPointCoordinates(vtkPointSet *ps, vtkIdType numPts);
337 
341  int ReadPointCoordinates(vtkGraph *g, vtkIdType numPts);
342 
348  int ReadVertexData(vtkGraph *g, vtkIdType numVertices);
349 
355  int ReadEdgeData(vtkGraph *g, vtkIdType numEdges);
356 
360  int ReadRowData(vtkTable *t, vtkIdType numEdges);
361 
365  int ReadCells(vtkIdType size, int *data);
366 
370  int ReadCells(vtkIdType size, int *data, int skip1, int read2, int skip3);
371 
376  int ReadCoordinates(vtkRectilinearGrid *rg, int axes, int numCoords);
377 
379 
382  vtkAbstractArray *ReadArray(const char *dataType, vtkIdType numTuples, vtkIdType numComp);
383  vtkFieldData *ReadFieldData(FieldType fieldType = FIELD_DATA);
385 
387 
391  vtkGetMacro(FileMajorVersion, int);
392  vtkGetMacro(FileMinorVersion, int);
394 
396 
400  int Read(char *);
401  int Read(unsigned char *);
402  int Read(short *);
403  int Read(unsigned short *);
404  int Read(int *);
405  int Read(unsigned int *);
406  int Read(long *);
407  int Read(unsigned long *);
408  int Read(long long *result);
409  int Read(unsigned long long *result);
410  int Read(float *);
411  int Read(double *);
413 
418  size_t Peek(char *str, size_t n);
419 
420 
424  void CloseVTKFile();
425 
430  int ReadLine(char result[256]);
431 
436  int ReadString(char result[256]);
437 
441  char *LowerCase(char *str, const size_t len=256);
442 
446  istream *GetIStream() {return this->IS;};
447 
449 
454  int timestep, vtkInformation* metadata) override;
455  int ReadMesh(
456  int piece, int npieces, int nghosts, int timestep,
457  vtkDataObject* output) override;
459  int /*piece*/, int /*npieces*/, int /*nghosts*/, int /*timestep*/,
460  vtkDataObject* /*output*/) override {return 1;}
462  int /*piece*/, int /*npieces*/, int /*nghosts*/, int /*timestep*/,
463  vtkDataObject* /*output*/) override {return 1;}
465 
467 
472  int ReadMeshSimple(const std::string& /*fname*/,
473  vtkDataObject* /*output*/) override {return 1;}
474  int ReadPointsSimple(const std::string& /*fname*/,
475  vtkDataObject* /*output*/) override {return 1;}
476  int ReadArraysSimple(const std::string& /*fname*/,
477  vtkDataObject* /*output*/) override {return 1;}
479 
480 
481 protected:
482  vtkDataReader();
483  ~vtkDataReader() override;
484 
486  int FileType;
487  istream *IS;
488 
489  char *ScalarsName;
490  char *VectorsName;
491  char *TensorsName;
492  char *TCoordsName;
493  char *NormalsName;
496  char *ScalarLut;
497 
499  char *InputString;
502 
503  void SetScalarLut(const char* lut);
504  vtkGetStringMacro(ScalarLut);
505 
506  char *Header;
507 
508  int ReadScalarData(vtkDataSetAttributes *a, vtkIdType num);
509  int ReadVectorData(vtkDataSetAttributes *a, vtkIdType num);
510  int ReadNormalData(vtkDataSetAttributes *a, vtkIdType num);
511  int ReadTensorData(vtkDataSetAttributes *a, vtkIdType num, vtkIdType numComp = 9);
512  int ReadCoScalarData(vtkDataSetAttributes *a, vtkIdType num);
513  int ReadLutData(vtkDataSetAttributes *a);
514  int ReadTCoordsData(vtkDataSetAttributes *a, vtkIdType num);
515  int ReadGlobalIds(vtkDataSetAttributes *a, vtkIdType num);
516  int ReadPedigreeIds(vtkDataSetAttributes *a, vtkIdType num);
517  int ReadEdgeFlags(vtkDataSetAttributes *a, vtkIdType num);
518 
522  int ReadInformation(vtkInformation *info, vtkIdType numKeys);
523 
524  int ReadDataSetData(vtkDataSet *ds);
525 
526  // This supports getting additional information from vtk files
546 
556 
557  void InitializeCharacteristics();
558  int CharacterizeFile(); //read entire file, storing important characteristics
559  void CheckFor(const char* name, char *line, int &num, char** &array,
560  int& allocSize);
561 
563 
569  int DecodeString(char *resname, const char* name);
570 
572  vtkInformationVector *) override;
575  { return 1; }
578  { return 1; }
581  { return 1; }
582 
583 private:
584  vtkDataReader(const vtkDataReader&) = delete;
585  void operator=(const vtkDataReader&) = delete;
586 
587  void ConvertGhostLevelsToGhostType(
588  FieldType fieldType, vtkAbstractArray *data) const;
589 };
590 
591 #endif
vtkTypeBool ReadAllTensors
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
vtkTypeBool ReadFromInputString
const char * GetFileName(int i) const
Returns a particular filename stored by the reader.
int GetNumberOfScalarsInFile()
How many attributes of various types are in this file? This requires reading the file, so the filename must be set prior to invoking this operation.
a dataset that is topologically regular with variable spacing in the three coordinate directions ...
int NumberOfScalarsInFile
char * FieldDataName
vtkTypeBool ReadAllFields
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
Abstract superclass for all arrays.
void SetInputString(const vtkStdString &input)
Specify the InputString for use when reading from a character array.
int IsFilePolyData()
Is the file a valid vtk file of the passed dataset type ? The dataset type is passed as a lower case ...
Definition: vtkDataReader.h:85
char ** ScalarsNameInFile
int IsFileRectilinearGrid()
Is the file a valid vtk file of the passed dataset type ? The dataset type is passed as a lower case ...
Definition: vtkDataReader.h:91
record modification and/or execution time
Definition: vtkTimeStamp.h:35
int NumberOfTensorsInFile
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
int NumberOfFieldDataInFile
virtual int ProcessRequest(vtkInformation *request, vtkInformationVector **inInfo, vtkInformationVector *outInfo)
Upstream/Downstream requests form the generalized interface through which executives invoke a algorit...
int GetNumberOfTCoordsInFile()
char * LookupTableName
char * NormalsName
int ReadTimeDependentMetaData(int timestep, vtkInformation *metadata) override
This is the superclass API overridden by this class to provide time support internally.
int GetNumberOfNormalsInFile()
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:42
int NormalsNameAllocSize
vtkTypeBool ReadAllScalars
int vtkIdType
Definition: vtkType.h:347
int IsFileStructuredGrid()
Is the file a valid vtk file of the passed dataset type ? The dataset type is passed as a lower case ...
Definition: vtkDataReader.h:87
int TensorsNameAllocSize
vtkTimeStamp CharacteristicsTime
char ** TensorsNameInFile
int GetNumberOfFieldDataInFile()
int ReadMeshSimple(const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
int vtkTypeBool
Definition: vtkABI.h:69
Base class for graph data types.
Definition: vtkGraph.h:287
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:38
std::string CurrentFileName
helper superclass for objects that read vtk data files
Definition: vtkDataReader.h:49
char * ScalarsName
int TCoordsNameAllocSize
int ReadArrays(int, int, int, int, vtkDataObject *) override
Overridden to handle reading from a string.
a simple class to control print indentation
Definition: vtkIndent.h:39
istream * GetIStream()
Return the istream being used to read in the data.
Superclass for algorithms that are not time or parallel aware.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
char ** FieldDataNameInFile
int ReadPoints(int, int, int, int, vtkDataObject *) override
Overridden to handle reading from a string.
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:68
vtkTypeBool ReadAllColorScalars
char * TCoordsName
char * InputString
int IsFileUnstructuredGrid()
Is the file a valid vtk file of the passed dataset type ? The dataset type is passed as a lower case ...
Definition: vtkDataReader.h:89
char ** VectorsNameInFile
vtkTypeBool ReadAllNormals
int IsFileStructuredPoints()
Is the file a valid vtk file of the passed dataset type ? The dataset type is passed as a lower case ...
Definition: vtkDataReader.h:83
int ReadMesh(int piece, int npieces, int nghosts, int timestep, vtkDataObject *output) override
This is the superclass API overridden by this class to provide time support internally.
vtkTypeBool ReadAllVectors
Store zero or more vtkInformation instances.
static vtkAlgorithm * New()
int ReadArraysSimple(const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
const char * GetFileName(int i) const
Specify file name of vtk data file to read.
Definition: vtkDataReader.h:71
int VectorsNameAllocSize
int ReadPointsSimple(const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
char ** NormalsNameInFile
vtkTypeBool ReadAllTCoords
vtkCharArray * InputArray
istream * IS
char * VectorsName
char ** TCoordsNameInFile
int FieldDataNameAllocSize
general representation of visualization data
Definition: vtkDataObject.h:64
int GetNumberOfTensorsInFile()
int NumberOfTCoordsInFile
#define IS
represent and manipulate fields of data
Definition: vtkFieldData.h:56
int NumberOfVectorsInFile