VTK  9.3.20240423
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
31VTK_ABI_NAMESPACE_BEGIN
33class vtkCharArray;
34class vtkCellArray;
35class vtkDataSet;
37class vtkFieldData;
38class vtkGraph;
39class vtkPointSet;
41class vtkTable;
42
43class VTKIOLEGACY_EXPORT vtkDataReader : public vtkSimpleReader
44{
45public:
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
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
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
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
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
513protected:
515 ~vtkDataReader() override;
516
517 std::string CurrentFileName;
522 istream* IS;
523
532
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
606private:
607 vtkDataReader(const vtkDataReader&) = delete;
608 void operator=(const vtkDataReader&) = delete;
609
610 void ConvertGhostLevelsToGhostType(FieldType fieldType, vtkAbstractArray* data) const;
611};
612
613VTK_ABI_NAMESPACE_END
614#endif
Abstract superclass for all arrays.
object to represent cell connectivity
dynamic, self-adjusting array of char
general representation of visualization data
helper superclass for objects that read vtk data files
VTK_FILEPATH const char * GetFileName() const
Specify file name of vtk data file to read.
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()
VTK_FILEPATH const char * GetFileName(int i) const
Specify file name of vtk data file to read.
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,...
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,...
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
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 ReadTimeDependentMetaData(int timestep, vtkInformation *metadata) override
Overridden to handle reading from a string.
int IsFileRectilinearGrid()
Is the file a valid vtk file of the passed dataset type ? The dataset type is passed as a lower case ...
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.
vtkTimeStamp CharacteristicsTime
int ReadDataSetData(vtkDataSet *ds)
char * LowerCase(char *str, size_t len=256)
Helper method for reading in data.
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...
char ** TensorsNameInFile
void InitializeCharacteristics()
int Read(unsigned long *)
Internal function to read in a value.
istream * GetIStream()
Return the istream being used to read in the data.
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,...
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 Read(float *)
Internal function to read in a value.
int GetNumberOfTensorsInFile()
vtkTypeBool ReadAllNormals
int CharacterizeFile()
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,...
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.
vtkAbstractArray * ReadArray(const char *dataType, vtkIdType numTuples, vtkIdType numComp)
Helper functions for reading data.
int Read(double *)
Internal function to read in a value.
int ReadScalarData(vtkDataSetAttributes *a, vtkIdType num)
vtkTypeBool ReadAllFields
std::string CurrentFileName
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.
static vtkDataReader * New()
char * LookupTableName
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...
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 ...
int GetNumberOfNormalsInFile()
char ** ScalarsNameInFile
vtkFieldData * ReadFieldData(FieldType fieldType=FIELD_DATA)
Helper functions for reading data.
int ReadString(char(&result)[256])
Internal function to read in a string up to 256 characters.
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 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...
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 ...
vtkTypeBool ReadAllScalars
int GetNumberOfTCoordsInFile()
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,...
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 * GetTensorsNameInFile(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.
char ** TCoordsNameInFile
int ReadTensorData(vtkDataSetAttributes *a, vtkIdType num, vtkIdType numComp=9)
int ReadNormalData(vtkDataSetAttributes *a, vtkIdType num)
int ReadGlobalIds(vtkDataSetAttributes *a, vtkIdType num)
int IsFilePolyData()
Is the file a valid vtk file of the passed dataset type ? The dataset type is passed as a lower case ...
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 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 ...
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:166
represent and manipulate fields of data
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:98
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.
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
A table, which contains similar-typed columns of data.
Definition vtkTable.h:168
record modification and/or execution time
int vtkTypeBool
Definition vtkABI.h:64
int vtkIdType
Definition vtkType.h:315
#define IS
#define VTK_FILEPATH