VTK  9.7.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
22 #ifndef vtkDataReader_h
23 #define vtkDataReader_h
24 
25 #include "vtkIOLegacyModule.h" // For export macro
26 #include "vtkSimpleReader.h"
27 #include "vtkStdString.h" // For API using strings
28 
29 #include <vtkSmartPointer.h> // for smart pointer
30 
31 #include <istream> // for IStream
32 #include <locale> // For locale settings
33 #include <memory> // for unique_ptr
34 #include <streambuf> // for Streambuf
35 
36 #define VTK_ASCII 1
37 #define VTK_BINARY 2
38 
39 VTK_ABI_NAMESPACE_BEGIN
40 class vtkAbstractArray;
41 class vtkCharArray;
42 class vtkCellArray;
43 class vtkDataSet;
45 class vtkFieldData;
46 class vtkGraph;
47 class vtkPointSet;
48 class vtkRectilinearGrid;
49 class vtkResourceStream;
50 class vtkTable;
51 
52 class VTKIOLEGACY_EXPORT vtkDataReader : public vtkSimpleReader
53 {
54 public:
55  enum FieldType
56  {
59  FIELD_DATA
60  };
61 
62  static vtkDataReader* New();
64  void PrintSelf(ostream& os, vtkIndent indent) override;
65 
67 
72  void SetFileName(VTK_FILEPATH const char* fname);
73  VTK_FILEPATH const char* GetFileName() const;
74  VTK_FILEPATH const char* GetFileName(int i) const
75  {
76  return this->vtkSimpleReader::GetFileName(i);
77  }
79 
81 
92  vtkGetMacro(FileVersion, int);
93  vtkGetMacro(FileMajorVersion, int);
94  vtkGetMacro(FileMinorVersion, int);
96 
98 
102  int IsFileValid(const char* dstype);
103  int IsFileStructuredPoints() { return this->IsFileValid("structured_points"); }
104  int IsFilePolyData() { return this->IsFileValid("polydata"); }
105  int IsFileStructuredGrid() { return this->IsFileValid("structured_grid"); }
106  int IsFileUnstructuredGrid() { return this->IsFileValid("unstructured_grid"); }
107  int IsFileRectilinearGrid() { return this->IsFileValid("rectilinear_grid"); }
109 
111 
118  void SetInputString(const char* in);
119  vtkGetStringMacro(InputString);
120  void SetInputString(const char* in, int len);
121  vtkGetMacro(InputStringLength, int);
122  void SetBinaryInputString(const char*, int len);
123  void SetInputString(const vtkStdString& input)
124  {
125  this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length()));
126  }
128 
130 
134  void SetStream(vtkResourceStream* stream);
135  vtkResourceStream* GetStream();
137 
139 
147  virtual void SetInputArray(vtkCharArray*);
148  vtkGetObjectMacro(InputArray, vtkCharArray);
150 
152 
155  vtkGetStringMacro(Header);
157 
159 
164  vtkSetMacro(ReadFromInputString, vtkTypeBool);
165  vtkGetMacro(ReadFromInputString, vtkTypeBool);
166  vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
168 
170 
175  vtkSetMacro(ReadFromInputStream, bool);
176  vtkGetMacro(ReadFromInputStream, bool);
177  vtkBooleanMacro(ReadFromInputStream, bool);
179 
181 
185  vtkGetMacro(FileType, int);
187 
196  {
197  this->CharacterizeFile();
198  return this->NumberOfScalarsInFile;
199  }
201  {
202  this->CharacterizeFile();
203  return this->NumberOfVectorsInFile;
204  }
206  {
207  this->CharacterizeFile();
208  return this->NumberOfTensorsInFile;
209  }
211  {
212  this->CharacterizeFile();
213  return this->NumberOfNormalsInFile;
214  }
216  {
217  this->CharacterizeFile();
218  return this->NumberOfTCoordsInFile;
219  }
221  {
222  this->CharacterizeFile();
223  return this->NumberOfFieldDataInFile;
224  }
225 
227 
232  const char* GetScalarsNameInFile(int i);
233  const char* GetVectorsNameInFile(int i);
234  const char* GetTensorsNameInFile(int i);
235  const char* GetNormalsNameInFile(int i);
236  const char* GetTCoordsNameInFile(int i);
237  const char* GetFieldDataNameInFile(int i);
239 
241 
245  vtkSetStringMacro(ScalarsName);
246  vtkGetStringMacro(ScalarsName);
248 
250 
254  vtkSetStringMacro(VectorsName);
255  vtkGetStringMacro(VectorsName);
257 
259 
263  vtkSetStringMacro(TensorsName);
264  vtkGetStringMacro(TensorsName);
266 
268 
272  vtkSetStringMacro(NormalsName);
273  vtkGetStringMacro(NormalsName);
275 
277 
281  vtkSetStringMacro(TCoordsName);
282  vtkGetStringMacro(TCoordsName);
284 
286 
290  vtkSetStringMacro(LookupTableName);
291  vtkGetStringMacro(LookupTableName);
293 
295 
299  vtkSetStringMacro(FieldDataName);
300  vtkGetStringMacro(FieldDataName);
302 
304 
307  vtkSetMacro(ReadAllScalars, vtkTypeBool);
308  vtkGetMacro(ReadAllScalars, vtkTypeBool);
309  vtkBooleanMacro(ReadAllScalars, vtkTypeBool);
311 
313 
316  vtkSetMacro(ReadAllVectors, vtkTypeBool);
317  vtkGetMacro(ReadAllVectors, vtkTypeBool);
318  vtkBooleanMacro(ReadAllVectors, vtkTypeBool);
320 
322 
325  vtkSetMacro(ReadAllNormals, vtkTypeBool);
326  vtkGetMacro(ReadAllNormals, vtkTypeBool);
327  vtkBooleanMacro(ReadAllNormals, vtkTypeBool);
329 
331 
334  vtkSetMacro(ReadAllTensors, vtkTypeBool);
335  vtkGetMacro(ReadAllTensors, vtkTypeBool);
336  vtkBooleanMacro(ReadAllTensors, vtkTypeBool);
338 
340 
343  vtkSetMacro(ReadAllColorScalars, vtkTypeBool);
344  vtkGetMacro(ReadAllColorScalars, vtkTypeBool);
345  vtkBooleanMacro(ReadAllColorScalars, vtkTypeBool);
347 
349 
352  vtkSetMacro(ReadAllTCoords, vtkTypeBool);
353  vtkGetMacro(ReadAllTCoords, vtkTypeBool);
354  vtkBooleanMacro(ReadAllTCoords, vtkTypeBool);
356 
358 
361  vtkSetMacro(ReadAllFields, vtkTypeBool);
362  vtkGetMacro(ReadAllFields, vtkTypeBool);
363  vtkBooleanMacro(ReadAllFields, vtkTypeBool);
365 
369  int OpenVTKFile(VTK_FILEPATH const char* fname = nullptr);
370 
374  int ReadHeader(VTK_FILEPATH const char* fname = nullptr, bool quiet = false);
375 
381  int ReadCellData(vtkDataSet* ds, vtkIdType numCells);
382 
388  int ReadPointData(vtkDataSet* ds, vtkIdType numPts);
389 
393  int ReadPointCoordinates(vtkPointSet* ps, vtkIdType numPts);
394 
398  int ReadPointCoordinates(vtkGraph* g, vtkIdType numPts);
399 
405  int ReadVertexData(vtkGraph* g, vtkIdType numVertices);
406 
412  int ReadEdgeData(vtkGraph* g, vtkIdType numEdges);
413 
417  int ReadRowData(vtkTable* t, vtkIdType numEdges);
418 
424  int ReadCells(vtkSmartPointer<vtkCellArray>& cellArray);
425 
430  int ReadCellsLegacy(vtkIdType size, int* data);
431 
435  int ReadCellsLegacy(vtkIdType size, int* data, int skip1, int read2, int skip3);
436 
441  int ReadCoordinates(vtkRectilinearGrid* rg, int axes, int numCoords);
442 
444 
447  vtkAbstractArray* ReadArray(const char* dataType, vtkIdType numTuples, vtkIdType numComp);
448  vtkFieldData* ReadFieldData(FieldType fieldType = FIELD_DATA);
450 
452 
456  int Read(char*);
457  int Read(unsigned char*);
458  int Read(short*);
459  int Read(unsigned short*);
460  int Read(int*);
461  int Read(unsigned int*);
462  int Read(long*);
463  int Read(unsigned long*);
464  int Read(long long* result);
465  int Read(unsigned long long* result);
466  int Read(float*);
467  int Read(double*);
469 
474  size_t Peek(char* str, size_t n);
475 
479  void CloseVTKFile();
480 
485  int ReadLine(char result[256]);
486 
491  int ReadString(char (&result)[256]);
492 
496  char* LowerCase(char* str, size_t len = 256);
497 
501  istream* GetIStream() { return this->IS; }
502 
504 
508  int ReadTimeDependentMetaData(int timestep, vtkInformation* metadata) override;
509  int ReadMesh(int piece, int npieces, int nghosts, int timestep, vtkDataObject* output) override;
510  int ReadPoints(int /*piece*/, int /*npieces*/, int /*nghosts*/, int /*timestep*/,
511  vtkDataObject* /*output*/) override
512  {
513  return 1;
514  }
515  int ReadArrays(int /*piece*/, int /*npieces*/, int /*nghosts*/, int /*timestep*/,
516  vtkDataObject* /*output*/) override
517  {
518  return 1;
519  }
521 
523 
528  int ReadMeshSimple(VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
529  {
530  return 1;
531  }
533  VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
534  {
535  return 1;
536  }
538  VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
539  {
540  return 1;
541  }
543 
547  vtkMTimeType GetMTime() override;
548 
549 protected:
550  vtkDataReader();
551  ~vtkDataReader() override;
552 
557  int FileType;
558  istream* IS;
559 
560  char* ScalarsName;
561  char* VectorsName;
562  char* TensorsName;
563  char* TCoordsName;
564  char* NormalsName;
567  char* ScalarLut;
568 
570  char* InputString;
573 
574  void SetScalarLut(const char* lut);
575  vtkGetStringMacro(ScalarLut);
576 
577  char* Header;
578 
579  int ReadScalarData(vtkDataSetAttributes* a, vtkIdType num);
580  int ReadVectorData(vtkDataSetAttributes* a, vtkIdType num);
581  int ReadNormalData(vtkDataSetAttributes* a, vtkIdType num);
582  int ReadTensorData(vtkDataSetAttributes* a, vtkIdType num, vtkIdType numComp = 9);
583  int ReadCoScalarData(vtkDataSetAttributes* a, vtkIdType num);
584  int ReadLutData(vtkDataSetAttributes* a);
585  int ReadTCoordsData(vtkDataSetAttributes* a, vtkIdType num);
586  int ReadGlobalIds(vtkDataSetAttributes* a, vtkIdType num);
587  int ReadPedigreeIds(vtkDataSetAttributes* a, vtkIdType num);
588  int ReadEdgeFlags(vtkDataSetAttributes* a, vtkIdType num);
589 
594  int ReadInformation(vtkInformation* info, vtkIdType numKeys);
595 
596  int ReadDataSetData(vtkDataSet* ds);
597 
598  // This supports getting additional information from vtk files
618 
626 
627  std::locale OriginalStreamLocale;
628 
629  void InitializeCharacteristics();
630  int CharacterizeFile(); // read entire file, storing important characteristics
631  void CheckFor(const char* name, char* line, int& num, char**& array, int& allocSize);
632 
634 
640  int DecodeString(char* resname, const char* name);
641 
642 private:
643  vtkDataReader(const vtkDataReader&) = delete;
644  void operator=(const vtkDataReader&) = delete;
645 
646  void ConvertGhostLevelsToGhostType(FieldType fieldType, vtkAbstractArray* data) const;
647 
648  // The stream used to read the input if it is in a resource stream
650  bool ReadFromInputStream = false;
651 
652  // Used when converting vtkResourceStream into istream
653  std::unique_ptr<std::streambuf> Streambuf;
654 };
655 
656 VTK_ABI_NAMESPACE_END
657 #endif
vtkTypeBool ReadAllTensors
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
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
Abstract class used for custom streams.
vtkTypeBool ReadAllFields
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
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 ...
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 ...
record modification and/or execution time
Definition: vtkTimeStamp.h:24
int NumberOfTensorsInFile
std::locale OriginalStreamLocale
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.
int GetNumberOfNormalsInFile()
concrete class for storing a set of points
Definition: vtkPointSet.h:58
int NormalsNameAllocSize
vtkTypeBool ReadAllScalars
int vtkIdType
Definition: vtkType.h:363
int IsFileStructuredGrid()
Is the file a valid vtk file of the passed dataset type ? The dataset type is passed as a lower case ...
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:64
Base class for graph data types.
Definition: vtkGraph.h:282
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:44
std::string CurrentFileName
helper superclass for objects that read vtk data files
Definition: vtkDataReader.h:52
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.
virtual vtkMTimeType GetMTime()
Return this object's modified time.
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
char * TensorsName
#define VTK_FILEPATH
int GetNumberOfVectorsInFile()
object to represent cell connectivity
Definition: vtkCellArray.h:177
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:59
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 ...
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 ...
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 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:74
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:55
int GetNumberOfTensorsInFile()
int NumberOfTCoordsInFile
#define IS
Represents and manipulates a collection of data arrays.
Definition: vtkFieldData.h:51
int NumberOfVectorsInFile