VTK  9.3.20240319
vtkDataReader.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
17 #ifndef vtkDataReader_h
18 #define vtkDataReader_h
19 
20 #include "vtkIOLegacyModule.h" // For export macro
21 #include "vtkSimpleReader.h"
22 #include "vtkStdString.h" // For API using strings
23 
24 #include <vtkSmartPointer.h> // for smart pointer
25 
26 #include <locale> // For locale settings
27 
28 #define VTK_ASCII 1
29 #define VTK_BINARY 2
30 
31 VTK_ABI_NAMESPACE_BEGIN
32 class vtkAbstractArray;
33 class vtkCharArray;
34 class vtkCellArray;
35 class vtkDataSet;
37 class vtkFieldData;
38 class vtkGraph;
39 class vtkPointSet;
40 class vtkRectilinearGrid;
41 class vtkTable;
42 
43 class VTKIOLEGACY_EXPORT vtkDataReader : public vtkSimpleReader
44 {
45 public:
46  enum FieldType
47  {
50  FIELD_DATA
51  };
52 
53  static vtkDataReader* New();
55  void PrintSelf(ostream& os, vtkIndent indent) override;
56 
58 
63  void SetFileName(VTK_FILEPATH const char* fname);
64  VTK_FILEPATH const char* GetFileName() const;
65  VTK_FILEPATH const char* GetFileName(int i) const
66  {
67  return this->vtkSimpleReader::GetFileName(i);
68  }
70 
72 
83  vtkGetMacro(FileVersion, int);
84  vtkGetMacro(FileMajorVersion, int);
85  vtkGetMacro(FileMinorVersion, int);
87 
89 
93  int IsFileValid(const char* dstype);
94  int IsFileStructuredPoints() { return this->IsFileValid("structured_points"); }
95  int IsFilePolyData() { return this->IsFileValid("polydata"); }
96  int IsFileStructuredGrid() { return this->IsFileValid("structured_grid"); }
97  int IsFileUnstructuredGrid() { return this->IsFileValid("unstructured_grid"); }
98  int IsFileRectilinearGrid() { return this->IsFileValid("rectilinear_grid"); }
100 
102 
108  void SetInputString(const char* in);
109  vtkGetStringMacro(InputString);
110  void SetInputString(const char* in, int len);
111  vtkGetMacro(InputStringLength, int);
112  void SetBinaryInputString(const char*, int len);
113  void SetInputString(const vtkStdString& input)
114  {
115  this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length()));
116  }
118 
120 
128  virtual void SetInputArray(vtkCharArray*);
129  vtkGetObjectMacro(InputArray, vtkCharArray);
131 
133 
136  vtkGetStringMacro(Header);
138 
140 
144  vtkSetMacro(ReadFromInputString, vtkTypeBool);
145  vtkGetMacro(ReadFromInputString, vtkTypeBool);
146  vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
148 
150 
154  vtkGetMacro(FileType, int);
156 
165  {
166  this->CharacterizeFile();
167  return this->NumberOfScalarsInFile;
168  }
170  {
171  this->CharacterizeFile();
172  return this->NumberOfVectorsInFile;
173  }
175  {
176  this->CharacterizeFile();
177  return this->NumberOfTensorsInFile;
178  }
180  {
181  this->CharacterizeFile();
182  return this->NumberOfNormalsInFile;
183  }
185  {
186  this->CharacterizeFile();
187  return this->NumberOfTCoordsInFile;
188  }
190  {
191  this->CharacterizeFile();
192  return this->NumberOfFieldDataInFile;
193  }
194 
196 
201  const char* GetScalarsNameInFile(int i);
202  const char* GetVectorsNameInFile(int i);
203  const char* GetTensorsNameInFile(int i);
204  const char* GetNormalsNameInFile(int i);
205  const char* GetTCoordsNameInFile(int i);
206  const char* GetFieldDataNameInFile(int i);
208 
210 
214  vtkSetStringMacro(ScalarsName);
215  vtkGetStringMacro(ScalarsName);
217 
219 
223  vtkSetStringMacro(VectorsName);
224  vtkGetStringMacro(VectorsName);
226 
228 
232  vtkSetStringMacro(TensorsName);
233  vtkGetStringMacro(TensorsName);
235 
237 
241  vtkSetStringMacro(NormalsName);
242  vtkGetStringMacro(NormalsName);
244 
246 
250  vtkSetStringMacro(TCoordsName);
251  vtkGetStringMacro(TCoordsName);
253 
255 
259  vtkSetStringMacro(LookupTableName);
260  vtkGetStringMacro(LookupTableName);
262 
264 
268  vtkSetStringMacro(FieldDataName);
269  vtkGetStringMacro(FieldDataName);
271 
273 
276  vtkSetMacro(ReadAllScalars, vtkTypeBool);
277  vtkGetMacro(ReadAllScalars, vtkTypeBool);
278  vtkBooleanMacro(ReadAllScalars, vtkTypeBool);
280 
282 
285  vtkSetMacro(ReadAllVectors, vtkTypeBool);
286  vtkGetMacro(ReadAllVectors, vtkTypeBool);
287  vtkBooleanMacro(ReadAllVectors, vtkTypeBool);
289 
291 
294  vtkSetMacro(ReadAllNormals, vtkTypeBool);
295  vtkGetMacro(ReadAllNormals, vtkTypeBool);
296  vtkBooleanMacro(ReadAllNormals, vtkTypeBool);
298 
300 
303  vtkSetMacro(ReadAllTensors, vtkTypeBool);
304  vtkGetMacro(ReadAllTensors, vtkTypeBool);
305  vtkBooleanMacro(ReadAllTensors, vtkTypeBool);
307 
309 
312  vtkSetMacro(ReadAllColorScalars, vtkTypeBool);
313  vtkGetMacro(ReadAllColorScalars, vtkTypeBool);
314  vtkBooleanMacro(ReadAllColorScalars, vtkTypeBool);
316 
318 
321  vtkSetMacro(ReadAllTCoords, vtkTypeBool);
322  vtkGetMacro(ReadAllTCoords, vtkTypeBool);
323  vtkBooleanMacro(ReadAllTCoords, vtkTypeBool);
325 
327 
330  vtkSetMacro(ReadAllFields, vtkTypeBool);
331  vtkGetMacro(ReadAllFields, vtkTypeBool);
332  vtkBooleanMacro(ReadAllFields, vtkTypeBool);
334 
338  int OpenVTKFile(VTK_FILEPATH const char* fname = nullptr);
339 
343  int ReadHeader(VTK_FILEPATH const char* fname = nullptr);
344 
350  int ReadCellData(vtkDataSet* ds, vtkIdType numCells);
351 
358 
363 
368 
374  int ReadVertexData(vtkGraph* g, vtkIdType numVertices);
375 
381  int ReadEdgeData(vtkGraph* g, vtkIdType numEdges);
382 
386  int ReadRowData(vtkTable* t, vtkIdType numEdges);
387 
394 
400 
404  int ReadCellsLegacy(vtkIdType size, int* data, int skip1, int read2, int skip3);
405 
410  int ReadCoordinates(vtkRectilinearGrid* rg, int axes, int numCoords);
411 
413 
416  vtkAbstractArray* ReadArray(const char* dataType, vtkIdType numTuples, vtkIdType numComp);
417  vtkFieldData* ReadFieldData(FieldType fieldType = FIELD_DATA);
419 
421 
425  int Read(char*);
426  int Read(unsigned char*);
427  int Read(short*);
428  int Read(unsigned short*);
429  int Read(int*);
430  int Read(unsigned int*);
431  int Read(long*);
432  int Read(unsigned long*);
433  int Read(long long* result);
434  int Read(unsigned long long* result);
435  int Read(float*);
436  int Read(double*);
438 
443  size_t Peek(char* str, size_t n);
444 
448  void CloseVTKFile();
449 
454  int ReadLine(char result[256]);
455 
460  int ReadString(char (&result)[256]);
461 
465  char* LowerCase(char* str, size_t len = 256);
466 
470  istream* GetIStream() { return this->IS; }
471 
473 
477  int ReadTimeDependentMetaData(int timestep, vtkInformation* metadata) override;
478  int ReadMesh(int piece, int npieces, int nghosts, int timestep, vtkDataObject* output) override;
479  int ReadPoints(int /*piece*/, int /*npieces*/, int /*nghosts*/, int /*timestep*/,
480  vtkDataObject* /*output*/) override
481  {
482  return 1;
483  }
484  int ReadArrays(int /*piece*/, int /*npieces*/, int /*nghosts*/, int /*timestep*/,
485  vtkDataObject* /*output*/) override
486  {
487  return 1;
488  }
490 
492 
497  int ReadMeshSimple(VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
498  {
499  return 1;
500  }
502  VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
503  {
504  return 1;
505  }
507  VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
508  {
509  return 1;
510  }
512 
513 protected:
515  ~vtkDataReader() override;
516 
521  int FileType;
522  istream* IS;
523 
524  char* ScalarsName;
525  char* VectorsName;
526  char* TensorsName;
527  char* TCoordsName;
528  char* NormalsName;
531  char* ScalarLut;
532 
534  char* InputString;
537 
538  void SetScalarLut(const char* lut);
539  vtkGetStringMacro(ScalarLut);
540 
541  char* Header;
542 
553 
559 
561 
562  // This supports getting additional information from vtk files
582 
590 
591  std::locale CurrentLocale;
592 
594  int CharacterizeFile(); // read entire file, storing important characteristics
595  void CheckFor(const char* name, char* line, int& num, char**& array, int& allocSize);
596 
598 
604  int DecodeString(char* resname, const char* name);
605 
606 private:
607  vtkDataReader(const vtkDataReader&) = delete;
608  void operator=(const vtkDataReader&) = delete;
609 
610  void ConvertGhostLevelsToGhostType(FieldType fieldType, vtkAbstractArray* data) const;
611 };
612 
613 VTK_ABI_NAMESPACE_END
614 #endif
Abstract superclass for all arrays.
object to represent cell connectivity
Definition: vtkCellArray.h:285
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:60
general representation of visualization data
helper superclass for objects that read vtk data files
Definition: vtkDataReader.h:44
char * InputString
int ReadVectorData(vtkDataSetAttributes *a, vtkIdType num)
int Read(char *)
Internal function to read in a value.
int ReadRowData(vtkTable *t, vtkIdType numEdges)
Read the row data of a vtk data file.
int Read(unsigned long long *result)
Internal function to read in a value.
int GetNumberOfVectorsInFile()
void SetScalarLut(const char *lut)
virtual void SetInputArray(vtkCharArray *)
Specify the vtkCharArray to be used when reading from a string.
int ReadPointCoordinates(vtkPointSet *ps, vtkIdType numPts)
Read point coordinates.
char ** NormalsNameInFile
VTK_FILEPATH const char * GetFileName() const
Specify file name of vtk data file to read.
int ReadMesh(int piece, int npieces, int nghosts, int timestep, vtkDataObject *output) override
Overridden to handle reading from a string.
int Read(unsigned short *)
Internal function to read in a value.
int ReadCells(vtkSmartPointer< vtkCellArray > &cellArray)
Read cells in a vtkCellArray, and update the smartpointer reference passed in.
int ReadHeader(VTK_FILEPATH const char *fname=nullptr)
Read the header of a vtk data file.
void CheckFor(const char *name, char *line, int &num, char **&array, int &allocSize)
int ReadCoScalarData(vtkDataSetAttributes *a, vtkIdType num)
int TCoordsNameAllocSize
int ScalarsNameAllocSize
int ReadTimeDependentMetaData(int timestep, vtkInformation *metadata) override
Overridden to handle reading from a string.
char * VectorsName
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:98
const char * GetTCoordsNameInFile(int i)
What is the name of the ith attribute of a certain type in this file? This requires reading the file,...
vtkTypeBool ReadAllVectors
void SetInputString(const char *in)
Specify the InputString for use when reading from a character array.
vtkTypeBool ReadAllTensors
int Read(short *)
Internal function to read in a value.
int NumberOfTensorsInFile
vtkTimeStamp CharacteristicsTime
int ReadDataSetData(vtkDataSet *ds)
int ReadCoordinates(vtkRectilinearGrid *rg, int axes, int numCoords)
Read the coordinates for a rectilinear grid.
int Read(long *)
Internal function to read in a value.
int ReadArraysSimple(VTK_FILEPATH const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
const char * GetScalarsNameInFile(int i)
What is the name of the ith attribute of a certain type in this file? This requires reading the file,...
char ** TensorsNameInFile
char * TCoordsName
void InitializeCharacteristics()
int Read(unsigned long *)
Internal function to read in a value.
vtkFieldData * ReadFieldData(FieldType fieldType=FIELD_DATA)
Helper functions for reading data.
int DecodeString(char *resname, const char *name)
Decode a string.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetBinaryInputString(const char *, int len)
Specify the InputString for use when reading from a character array.
int ReadPointData(vtkDataSet *ds, vtkIdType numPts)
Read the point data of a vtk data file.
int ReadCellsLegacy(vtkIdType size, int *data)
Read a bunch of "cells".
void SetInputString(const char *in, int len)
Specify the InputString for use when reading from a character array.
int NumberOfVectorsInFile
int Read(float *)
Internal function to read in a value.
char * NormalsName
int GetNumberOfTensorsInFile()
vtkTypeBool ReadAllNormals
int CharacterizeFile()
int ReadEdgeData(vtkGraph *g, vtkIdType numEdges)
Read the edge data of a vtk data file.
int ReadPointCoordinates(vtkGraph *g, vtkIdType numPts)
Read point coordinates.
int ReadArrays(int, int, int, int, vtkDataObject *) override
Overridden to handle reading from a string.
int Read(double *)
Internal function to read in a value.
const char * GetTensorsNameInFile(int i)
What is the name of the ith attribute of a certain type in this file? This requires reading the file,...
int NormalsNameAllocSize
int ReadScalarData(vtkDataSetAttributes *a, vtkIdType num)
vtkTypeBool ReadAllFields
VTK_FILEPATH const char * GetFileName(int i) const
Specify file name of vtk data file to read.
Definition: vtkDataReader.h:65
std::string CurrentFileName
char * LowerCase(char *str, size_t len=256)
Helper method for reading in data.
int Read(int *)
Internal function to read in a value.
std::locale CurrentLocale
int ReadCellData(vtkDataSet *ds, vtkIdType numCells)
Read the cell data of a vtk data file.
char * LookupTableName
vtkAbstractArray * ReadArray(const char *dataType, vtkIdType numTuples, vtkIdType numComp)
Helper functions for reading data.
vtkTypeBool ReadAllColorScalars
void CloseVTKFile()
Close the vtk file.
int ReadPointsSimple(VTK_FILEPATH const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
char * TensorsName
vtkTypeBool ReadFromInputString
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:96
int GetNumberOfNormalsInFile()
int NumberOfNormalsInFile
char ** ScalarsNameInFile
int TensorsNameAllocSize
int ReadString(char(&result)[256])
Internal function to read in a string up to 256 characters.
char * FieldDataName
int NumberOfScalarsInFile
vtkTypeBool ReadAllTCoords
int OpenVTKFile(VTK_FILEPATH const char *fname=nullptr)
Open a vtk data file.
void SetFileName(VTK_FILEPATH const char *fname)
Specify file name of vtk data file to read.
int ReadPoints(int, int, int, int, vtkDataObject *) override
Overridden to handle reading from a string.
int ReadLine(char result[256])
Internal function to read in a line up to 256 characters.
int ReadLutData(vtkDataSetAttributes *a)
int ReadVertexData(vtkGraph *g, vtkIdType numVertices)
Read the vertex data of a vtk data file.
size_t Peek(char *str, size_t n)
Read n character from the stream into str, then reset the stream position.
char ** FieldDataNameInFile
int Read(unsigned int *)
Internal function to read in a value.
int VectorsNameAllocSize
const char * GetVectorsNameInFile(int i)
What is the name of the ith attribute of a certain type in this file? This requires reading the file,...
istream * IS
int IsFileValid(const char *dstype)
Is the file a valid vtk file of the passed dataset type ? The dataset type is passed as a lower case ...
~vtkDataReader() override
int ReadMeshSimple(VTK_FILEPATH const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
char * ScalarsName
static vtkDataReader * New()
int ReadEdgeFlags(vtkDataSetAttributes *a, vtkIdType num)
int NumberOfFieldDataInFile
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:94
vtkTypeBool ReadAllScalars
int GetNumberOfTCoordsInFile()
int GetNumberOfFieldDataInFile()
int Read(unsigned char *)
Internal function to read in a value.
int ReadCellsLegacy(vtkIdType size, int *data, int skip1, int read2, int skip3)
Read a piece of the cells (for streaming compliance)
const char * GetFieldDataNameInFile(int i)
What is the name of the ith attribute of a certain type in this file? This requires reading the file,...
char ** VectorsNameInFile
void SetInputString(const vtkStdString &input)
Specify the InputString for use when reading from a character array.
const char * GetNormalsNameInFile(int i)
What is the name of the ith attribute of a certain type in this file? This requires reading the file,...
char ** TCoordsNameInFile
int ReadTensorData(vtkDataSetAttributes *a, vtkIdType num, vtkIdType numComp=9)
int ReadNormalData(vtkDataSetAttributes *a, vtkIdType num)
int ReadGlobalIds(vtkDataSetAttributes *a, vtkIdType num)
istream * GetIStream()
Return the istream being used to read in the data.
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:95
int NumberOfTCoordsInFile
int GetNumberOfScalarsInFile()
How many attributes of various types are in this file? This requires reading the file,...
int Read(long long *result)
Internal function to read in a value.
int FieldDataNameAllocSize
int ReadInformation(vtkInformation *info, vtkIdType numKeys)
Format is detailed at https://docs.vtk.org/en/latest/design_documents/IOLegacyInformationFormat....
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:97
int ReadPedigreeIds(vtkDataSetAttributes *a, vtkIdType num)
int ReadTCoordsData(vtkDataSetAttributes *a, vtkIdType num)
vtkCharArray * InputArray
represent and manipulate attribute data in a dataset
abstract class to specify dataset behavior
Definition: vtkDataSet.h:165
represent and manipulate fields of data
Definition: vtkFieldData.h:161
Base class for graph data types.
Definition: vtkGraph.h:340
a simple class to control print indentation
Definition: vtkIndent.h:108
Store vtkAlgorithm input/output information.
concrete class for storing a set of points
Definition: vtkPointSet.h:97
a dataset that is topologically regular with variable spacing in the three coordinate directions
Superclass for algorithms that are not time or parallel aware.
VTK_FILEPATH const char * GetFileName(int i) const
Returns a particular filename stored by the reader.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:78
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:168
record modification and/or execution time
Definition: vtkTimeStamp.h:44
@ info
Definition: vtkX3D.h:376
@ name
Definition: vtkX3D.h:219
@ size
Definition: vtkX3D.h:253
@ data
Definition: vtkX3D.h:315
@ string
Definition: vtkX3D.h:490
int vtkTypeBool
Definition: vtkABI.h:64
int vtkIdType
Definition: vtkType.h:315
#define IS
#define VTK_FILEPATH