VTK  9.6.20260315
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
21
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
39VTK_ABI_NAMESPACE_BEGIN
41class vtkCharArray;
42class vtkCellArray;
43class vtkDataSet;
45class vtkFieldData;
46class vtkGraph;
47class vtkPointSet;
50class vtkTable;
51
52class VTKIOLEGACY_EXPORT vtkDataReader : public vtkSimpleReader
53{
54public:
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 }
78
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 }
127
128
130
137
139
148 vtkGetObjectMacro(InputArray, vtkCharArray);
150
152
155 vtkGetStringMacro(Header);
157
159
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
309 vtkBooleanMacro(ReadAllScalars, vtkTypeBool);
311
313
318 vtkBooleanMacro(ReadAllVectors, vtkTypeBool);
320
322
327 vtkBooleanMacro(ReadAllNormals, vtkTypeBool);
329
331
336 vtkBooleanMacro(ReadAllTensors, vtkTypeBool);
338
340
347
349
354 vtkBooleanMacro(ReadAllTCoords, vtkTypeBool);
356
358
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
382
389
394
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
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);
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
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 }
520
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 }
542
543
548
549protected:
551 ~vtkDataReader() override;
552
553 std::string CurrentFileName;
558 istream* IS;
559
568
573
574 void SetScalarLut(const char* lut);
575 vtkGetStringMacro(ScalarLut);
576
577 char* Header;
578
589
595
597
598 // This supports getting additional information from vtk files
618
626
628
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
642private:
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
656VTK_ABI_NAMESPACE_END
657#endif
Abstract superclass for all arrays.
object to represent cell connectivity
dynamic, self-adjusting array of char
general representation of visualization data
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()
const char * GetFieldDataNameInFile(int i)
What is the name of the ith attribute of a certain type in this file?
const char * GetScalarsNameInFile(int i)
What is the name of the ith attribute of a certain type in this 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 ReadMeshSimple(const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
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.
void CheckFor(const char *name, char *line, int &num, char **&array, int &allocSize)
int ReadHeader(const char *fname=nullptr, bool quiet=false)
Read the header of a vtk data file.
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 ?
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.
char ** TensorsNameInFile
const char * GetFileName() const
Specify file name of vtk data file to read.
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?
int ReadArraysSimple(const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
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 OpenVTKFile(const char *fname=nullptr)
Open a vtk data file.
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?
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.
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.
vtkResourceStream * GetStream()
Specify resource stream to read from Set ReadFromInputStream to true to read from this stream.
vtkTypeBool ReadFromInputString
int IsFileStructuredGrid()
Is the file a valid vtk file of the passed dataset type ?
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 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.
vtkMTimeType GetMTime() override
Overridden to take into account mtime from the internal vtkResourceStream.
int IsFileValid(const char *dstype)
Is the file a valid vtk file of the passed dataset type ?
~vtkDataReader() override
void SetStream(vtkResourceStream *stream)
Specify resource stream to read from Set ReadFromInputStream to true to read from this stream.
int ReadPointsSimple(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)
std::locale OriginalStreamLocale
int NumberOfFieldDataInFile
void SetFileName(const char *fname)
Specify file name of vtk data file to read.
int IsFileStructuredPoints()
Is the file a valid vtk file of the passed dataset type ?
vtkTypeBool ReadAllScalars
int GetNumberOfTCoordsInFile()
const char * GetVectorsNameInFile(int i)
What is the name of the ith attribute of a certain type in this 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 * GetFileName(int i) const
Specify file name of vtk data file to read.
const char * GetTensorsNameInFile(int i)
What is the name of the ith attribute of a certain type in this 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 ?
int GetNumberOfScalarsInFile()
How many attributes of various types are in this 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 ?
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
Represents and manipulates a collection of data arrays.
Base class for graph data types.
Definition vtkGraph.h:342
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
Abstract class used for custom streams.
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:169
record modification and/or execution time
int vtkTypeBool
Definition vtkABI.h:64
int vtkIdType
Definition vtkType.h:363
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:318
#define VTK_FILEPATH