VTK  9.3.1
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 
357  int ReadPointData(vtkDataSet* ds, vtkIdType numPts);
358 
362  int ReadPointCoordinates(vtkPointSet* ps, vtkIdType numPts);
363 
367  int ReadPointCoordinates(vtkGraph* g, vtkIdType numPts);
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 
393  int ReadCells(vtkSmartPointer<vtkCellArray>& cellArray);
394 
399  int ReadCellsLegacy(vtkIdType size, int* data);
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:
514  vtkDataReader();
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 
543  int ReadScalarData(vtkDataSetAttributes* a, vtkIdType num);
544  int ReadVectorData(vtkDataSetAttributes* a, vtkIdType num);
545  int ReadNormalData(vtkDataSetAttributes* a, vtkIdType num);
546  int ReadTensorData(vtkDataSetAttributes* a, vtkIdType num, vtkIdType numComp = 9);
547  int ReadCoScalarData(vtkDataSetAttributes* a, vtkIdType num);
548  int ReadLutData(vtkDataSetAttributes* a);
549  int ReadTCoordsData(vtkDataSetAttributes* a, vtkIdType num);
550  int ReadGlobalIds(vtkDataSetAttributes* a, vtkIdType num);
551  int ReadPedigreeIds(vtkDataSetAttributes* a, vtkIdType num);
552  int ReadEdgeFlags(vtkDataSetAttributes* a, vtkIdType num);
553 
558  int ReadInformation(vtkInformation* info, vtkIdType numKeys);
559 
560  int ReadDataSetData(vtkDataSet* ds);
561 
562  // This supports getting additional information from vtk files
582 
590 
591  std::locale CurrentLocale;
592 
593  void InitializeCharacteristics();
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
int ReadMeshSimple(VTK_FILEPATH const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
vtkTypeBool ReadAllTensors
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
vtkTypeBool ReadFromInputString
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
VTK_FILEPATH const char * GetFileName(int i) const
Returns a particular filename stored by the reader.
char * FieldDataName
vtkTypeBool ReadAllFields
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:52
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:95
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:98
record modification and/or execution time
Definition: vtkTimeStamp.h:24
int NumberOfTensorsInFile
int NumberOfFieldDataInFile
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.
std::locale CurrentLocale
int GetNumberOfNormalsInFile()
concrete class for storing a set of points
Definition: vtkPointSet.h:58
int NormalsNameAllocSize
vtkTypeBool ReadAllScalars
int vtkIdType
Definition: vtkType.h:315
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 TensorsNameAllocSize
vtkTimeStamp CharacteristicsTime
char ** TensorsNameInFile
int GetNumberOfFieldDataInFile()
int vtkTypeBool
Definition: vtkABI.h:64
Base class for graph data types.
Definition: vtkGraph.h:280
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:40
std::string CurrentFileName
helper superclass for objects that read vtk data files
Definition: vtkDataReader.h:43
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:28
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 ReadPointsSimple(VTK_FILEPATH const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
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
VTK_FILEPATH const char * GetFileName(int i) const
Specify file name of vtk data file to read.
Definition: vtkDataReader.h:65
char * TensorsName
#define VTK_FILEPATH
int GetNumberOfVectorsInFile()
object to represent cell connectivity
Definition: vtkCellArray.h:175
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:58
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:97
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:94
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
static vtkAlgorithm * New()
int VectorsNameAllocSize
char ** NormalsNameInFile
vtkTypeBool ReadAllTCoords
vtkCharArray * InputArray
istream * IS
char * VectorsName
char ** TCoordsNameInFile
int FieldDataNameAllocSize
general representation of visualization data
Definition: vtkDataObject.h:54
int GetNumberOfTensorsInFile()
int ReadArraysSimple(VTK_FILEPATH const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
int NumberOfTCoordsInFile
#define IS
represent and manipulate fields of data
Definition: vtkFieldData.h:51
int NumberOfVectorsInFile