VTK  9.2.6
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 #include <vtkSmartPointer.h> // for smart pointer
37 
38 #include <locale> // For locale settings
39 
40 #define VTK_ASCII 1
41 #define VTK_BINARY 2
42 
43 class vtkAbstractArray;
44 class vtkCharArray;
45 class vtkCellArray;
46 class vtkDataSet;
48 class vtkFieldData;
49 class vtkGraph;
50 class vtkPointSet;
51 class vtkRectilinearGrid;
52 class vtkTable;
53 
54 class VTKIOLEGACY_EXPORT vtkDataReader : public vtkSimpleReader
55 {
56 public:
57  enum FieldType
58  {
61  FIELD_DATA
62  };
63 
64  static vtkDataReader* New();
66  void PrintSelf(ostream& os, vtkIndent indent) override;
67 
69 
74  void SetFileName(VTK_FILEPATH const char* fname);
75  VTK_FILEPATH const char* GetFileName() const;
76  VTK_FILEPATH const char* GetFileName(int i) const
77  {
78  return this->vtkSimpleReader::GetFileName(i);
79  }
81 
83 
94  vtkGetMacro(FileVersion, int);
95  vtkGetMacro(FileMajorVersion, int);
96  vtkGetMacro(FileMinorVersion, int);
98 
100 
104  int IsFileValid(const char* dstype);
105  int IsFileStructuredPoints() { return this->IsFileValid("structured_points"); }
106  int IsFilePolyData() { return this->IsFileValid("polydata"); }
107  int IsFileStructuredGrid() { return this->IsFileValid("structured_grid"); }
108  int IsFileUnstructuredGrid() { return this->IsFileValid("unstructured_grid"); }
109  int IsFileRectilinearGrid() { return this->IsFileValid("rectilinear_grid"); }
111 
113 
119  void SetInputString(const char* in);
120  vtkGetStringMacro(InputString);
121  void SetInputString(const char* in, int len);
122  vtkGetMacro(InputStringLength, int);
123  void SetBinaryInputString(const char*, int len);
124  void SetInputString(const vtkStdString& input)
125  {
126  this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length()));
127  }
129 
131 
139  virtual void SetInputArray(vtkCharArray*);
140  vtkGetObjectMacro(InputArray, vtkCharArray);
142 
144 
147  vtkGetStringMacro(Header);
149 
151 
155  vtkSetMacro(ReadFromInputString, vtkTypeBool);
156  vtkGetMacro(ReadFromInputString, vtkTypeBool);
157  vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
159 
161 
165  vtkGetMacro(FileType, int);
167 
176  {
177  this->CharacterizeFile();
178  return this->NumberOfScalarsInFile;
179  }
181  {
182  this->CharacterizeFile();
183  return this->NumberOfVectorsInFile;
184  }
186  {
187  this->CharacterizeFile();
188  return this->NumberOfTensorsInFile;
189  }
191  {
192  this->CharacterizeFile();
193  return this->NumberOfNormalsInFile;
194  }
196  {
197  this->CharacterizeFile();
198  return this->NumberOfTCoordsInFile;
199  }
201  {
202  this->CharacterizeFile();
203  return this->NumberOfFieldDataInFile;
204  }
205 
207 
212  const char* GetScalarsNameInFile(int i);
213  const char* GetVectorsNameInFile(int i);
214  const char* GetTensorsNameInFile(int i);
215  const char* GetNormalsNameInFile(int i);
216  const char* GetTCoordsNameInFile(int i);
217  const char* GetFieldDataNameInFile(int i);
219 
221 
225  vtkSetStringMacro(ScalarsName);
226  vtkGetStringMacro(ScalarsName);
228 
230 
234  vtkSetStringMacro(VectorsName);
235  vtkGetStringMacro(VectorsName);
237 
239 
243  vtkSetStringMacro(TensorsName);
244  vtkGetStringMacro(TensorsName);
246 
248 
252  vtkSetStringMacro(NormalsName);
253  vtkGetStringMacro(NormalsName);
255 
257 
261  vtkSetStringMacro(TCoordsName);
262  vtkGetStringMacro(TCoordsName);
264 
266 
270  vtkSetStringMacro(LookupTableName);
271  vtkGetStringMacro(LookupTableName);
273 
275 
279  vtkSetStringMacro(FieldDataName);
280  vtkGetStringMacro(FieldDataName);
282 
284 
287  vtkSetMacro(ReadAllScalars, vtkTypeBool);
288  vtkGetMacro(ReadAllScalars, vtkTypeBool);
289  vtkBooleanMacro(ReadAllScalars, vtkTypeBool);
291 
293 
296  vtkSetMacro(ReadAllVectors, vtkTypeBool);
297  vtkGetMacro(ReadAllVectors, vtkTypeBool);
298  vtkBooleanMacro(ReadAllVectors, vtkTypeBool);
300 
302 
305  vtkSetMacro(ReadAllNormals, vtkTypeBool);
306  vtkGetMacro(ReadAllNormals, vtkTypeBool);
307  vtkBooleanMacro(ReadAllNormals, vtkTypeBool);
309 
311 
314  vtkSetMacro(ReadAllTensors, vtkTypeBool);
315  vtkGetMacro(ReadAllTensors, vtkTypeBool);
316  vtkBooleanMacro(ReadAllTensors, vtkTypeBool);
318 
320 
323  vtkSetMacro(ReadAllColorScalars, vtkTypeBool);
324  vtkGetMacro(ReadAllColorScalars, vtkTypeBool);
325  vtkBooleanMacro(ReadAllColorScalars, vtkTypeBool);
327 
329 
332  vtkSetMacro(ReadAllTCoords, vtkTypeBool);
333  vtkGetMacro(ReadAllTCoords, vtkTypeBool);
334  vtkBooleanMacro(ReadAllTCoords, vtkTypeBool);
336 
338 
341  vtkSetMacro(ReadAllFields, vtkTypeBool);
342  vtkGetMacro(ReadAllFields, vtkTypeBool);
343  vtkBooleanMacro(ReadAllFields, vtkTypeBool);
345 
349  int OpenVTKFile(VTK_FILEPATH const char* fname = nullptr);
350 
354  int ReadHeader(VTK_FILEPATH const char* fname = nullptr);
355 
361  int ReadCellData(vtkDataSet* ds, vtkIdType numCells);
362 
368  int ReadPointData(vtkDataSet* ds, vtkIdType numPts);
369 
373  int ReadPointCoordinates(vtkPointSet* ps, vtkIdType numPts);
374 
378  int ReadPointCoordinates(vtkGraph* g, vtkIdType numPts);
379 
385  int ReadVertexData(vtkGraph* g, vtkIdType numVertices);
386 
392  int ReadEdgeData(vtkGraph* g, vtkIdType numEdges);
393 
397  int ReadRowData(vtkTable* t, vtkIdType numEdges);
398 
404  int ReadCells(vtkSmartPointer<vtkCellArray>& cellArray);
405 
410  int ReadCellsLegacy(vtkIdType size, int* data);
411 
415  int ReadCellsLegacy(vtkIdType size, int* data, int skip1, int read2, int skip3);
416 
421  int ReadCoordinates(vtkRectilinearGrid* rg, int axes, int numCoords);
422 
424 
427  vtkAbstractArray* ReadArray(const char* dataType, vtkIdType numTuples, vtkIdType numComp);
428  vtkFieldData* ReadFieldData(FieldType fieldType = FIELD_DATA);
430 
432 
436  int Read(char*);
437  int Read(unsigned char*);
438  int Read(short*);
439  int Read(unsigned short*);
440  int Read(int*);
441  int Read(unsigned int*);
442  int Read(long*);
443  int Read(unsigned long*);
444  int Read(long long* result);
445  int Read(unsigned long long* result);
446  int Read(float*);
447  int Read(double*);
449 
454  size_t Peek(char* str, size_t n);
455 
459  void CloseVTKFile();
460 
465  int ReadLine(char result[256]);
466 
471  int ReadString(char result[256]);
472 
476  char* LowerCase(char* str, const size_t len = 256);
477 
481  istream* GetIStream() { return this->IS; }
482 
484 
488  int ReadTimeDependentMetaData(int timestep, vtkInformation* metadata) override;
489  int ReadMesh(int piece, int npieces, int nghosts, int timestep, vtkDataObject* output) override;
490  int ReadPoints(int /*piece*/, int /*npieces*/, int /*nghosts*/, int /*timestep*/,
491  vtkDataObject* /*output*/) override
492  {
493  return 1;
494  }
495  int ReadArrays(int /*piece*/, int /*npieces*/, int /*nghosts*/, int /*timestep*/,
496  vtkDataObject* /*output*/) override
497  {
498  return 1;
499  }
501 
503 
508  int ReadMeshSimple(VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
509  {
510  return 1;
511  }
513  VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
514  {
515  return 1;
516  }
518  VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
519  {
520  return 1;
521  }
523 
524 protected:
525  vtkDataReader();
526  ~vtkDataReader() override;
527 
532  int FileType;
533  istream* IS;
534 
535  char* ScalarsName;
536  char* VectorsName;
537  char* TensorsName;
538  char* TCoordsName;
539  char* NormalsName;
542  char* ScalarLut;
543 
545  char* InputString;
548 
549  void SetScalarLut(const char* lut);
550  vtkGetStringMacro(ScalarLut);
551 
552  char* Header;
553 
554  int ReadScalarData(vtkDataSetAttributes* a, vtkIdType num);
555  int ReadVectorData(vtkDataSetAttributes* a, vtkIdType num);
556  int ReadNormalData(vtkDataSetAttributes* a, vtkIdType num);
557  int ReadTensorData(vtkDataSetAttributes* a, vtkIdType num, vtkIdType numComp = 9);
558  int ReadCoScalarData(vtkDataSetAttributes* a, vtkIdType num);
559  int ReadLutData(vtkDataSetAttributes* a);
560  int ReadTCoordsData(vtkDataSetAttributes* a, vtkIdType num);
561  int ReadGlobalIds(vtkDataSetAttributes* a, vtkIdType num);
562  int ReadPedigreeIds(vtkDataSetAttributes* a, vtkIdType num);
563  int ReadEdgeFlags(vtkDataSetAttributes* a, vtkIdType num);
564 
568  int ReadInformation(vtkInformation* info, vtkIdType numKeys);
569 
570  int ReadDataSetData(vtkDataSet* ds);
571 
572  // This supports getting additional information from vtk files
592 
600 
601  std::locale CurrentLocale;
602 
603  void InitializeCharacteristics();
604  int CharacterizeFile(); // read entire file, storing important characteristics
605  void CheckFor(const char* name, char* line, int& num, char**& array, int& allocSize);
606 
608 
614  int DecodeString(char* resname, const char* name);
615 
616 private:
617  vtkDataReader(const vtkDataReader&) = delete;
618  void operator=(const vtkDataReader&) = delete;
619 
620  void ConvertGhostLevelsToGhostType(FieldType fieldType, vtkAbstractArray* data) const;
621 };
622 
623 #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:38
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: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 ...
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:35
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:69
int NormalsNameAllocSize
vtkTypeBool ReadAllScalars
int vtkIdType
Definition: vtkType.h:332
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 vtkTypeBool
Definition: vtkABI.h:69
Base class for graph data types.
Definition: vtkGraph.h:295
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:51
std::string CurrentFileName
helper superclass for objects that read vtk data files
Definition: vtkDataReader.h:54
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 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:76
char * TensorsName
#define VTK_FILEPATH
int GetNumberOfVectorsInFile()
object to represent cell connectivity
Definition: vtkCellArray.h:186
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:73
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 VectorsNameAllocSize
char ** NormalsNameInFile
vtkTypeBool ReadAllTCoords
vtkCharArray * InputArray
istream * IS
char * VectorsName
char ** TCoordsNameInFile
int FieldDataNameAllocSize
general representation of visualization data
Definition: vtkDataObject.h:65
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:62
int NumberOfVectorsInFile