VTK  9.6.20260109
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
18
19#ifndef vtkDataReader_h
20#define vtkDataReader_h
21
22#include "vtkIOLegacyModule.h" // For export macro
23#include "vtkSimpleReader.h"
24#include "vtkStdString.h" // For API using strings
25
26#include <vtkSmartPointer.h> // for smart pointer
27
28#include <istream> // for IStream
29#include <locale> // For locale settings
30#include <memory> // for unique_ptr
31#include <streambuf> // for Streambuf
32
33#define VTK_ASCII 1
34#define VTK_BINARY 2
35
36VTK_ABI_NAMESPACE_BEGIN
38class vtkCharArray;
39class vtkCellArray;
40class vtkDataSet;
42class vtkFieldData;
43class vtkGraph;
44class vtkPointSet;
47class vtkTable;
48
49class VTKIOLEGACY_EXPORT vtkDataReader : public vtkSimpleReader
50{
51public:
58
59 static vtkDataReader* New();
61 void PrintSelf(ostream& os, vtkIndent indent) override;
62
64
69 void SetFileName(VTK_FILEPATH const char* fname);
70 VTK_FILEPATH const char* GetFileName() const;
71 VTK_FILEPATH const char* GetFileName(int i) const
72 {
73 return this->vtkSimpleReader::GetFileName(i);
74 }
75
76
78
89 vtkGetMacro(FileVersion, int);
90 vtkGetMacro(FileMajorVersion, int);
91 vtkGetMacro(FileMinorVersion, int);
93
95
99 int IsFileValid(const char* dstype);
100 int IsFileStructuredPoints() { return this->IsFileValid("structured_points"); }
101 int IsFilePolyData() { return this->IsFileValid("polydata"); }
102 int IsFileStructuredGrid() { return this->IsFileValid("structured_grid"); }
103 int IsFileUnstructuredGrid() { return this->IsFileValid("unstructured_grid"); }
104 int IsFileRectilinearGrid() { return this->IsFileValid("rectilinear_grid"); }
106
108
115 void SetInputString(const char* in);
116 vtkGetStringMacro(InputString);
117 void SetInputString(const char* in, int len);
118 vtkGetMacro(InputStringLength, int);
119 void SetBinaryInputString(const char*, int len);
120 void SetInputString(const vtkStdString& input)
121 {
122 this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length()));
123 }
124
125
127
134
136
145 vtkGetObjectMacro(InputArray, vtkCharArray);
147
149
152 vtkGetStringMacro(Header);
154
156
165
167
172 vtkSetMacro(ReadFromInputStream, bool);
173 vtkGetMacro(ReadFromInputStream, bool);
174 vtkBooleanMacro(ReadFromInputStream, bool);
176
178
182 vtkGetMacro(FileType, int);
184
193 {
194 this->CharacterizeFile();
195 return this->NumberOfScalarsInFile;
196 }
198 {
199 this->CharacterizeFile();
200 return this->NumberOfVectorsInFile;
201 }
203 {
204 this->CharacterizeFile();
205 return this->NumberOfTensorsInFile;
206 }
208 {
209 this->CharacterizeFile();
210 return this->NumberOfNormalsInFile;
211 }
213 {
214 this->CharacterizeFile();
215 return this->NumberOfTCoordsInFile;
216 }
218 {
219 this->CharacterizeFile();
220 return this->NumberOfFieldDataInFile;
221 }
222
224
229 const char* GetScalarsNameInFile(int i);
230 const char* GetVectorsNameInFile(int i);
231 const char* GetTensorsNameInFile(int i);
232 const char* GetNormalsNameInFile(int i);
233 const char* GetTCoordsNameInFile(int i);
234 const char* GetFieldDataNameInFile(int i);
236
238
242 vtkSetStringMacro(ScalarsName);
243 vtkGetStringMacro(ScalarsName);
245
247
251 vtkSetStringMacro(VectorsName);
252 vtkGetStringMacro(VectorsName);
254
256
260 vtkSetStringMacro(TensorsName);
261 vtkGetStringMacro(TensorsName);
263
265
269 vtkSetStringMacro(NormalsName);
270 vtkGetStringMacro(NormalsName);
272
274
278 vtkSetStringMacro(TCoordsName);
279 vtkGetStringMacro(TCoordsName);
281
283
287 vtkSetStringMacro(LookupTableName);
288 vtkGetStringMacro(LookupTableName);
290
292
296 vtkSetStringMacro(FieldDataName);
297 vtkGetStringMacro(FieldDataName);
299
301
306 vtkBooleanMacro(ReadAllScalars, vtkTypeBool);
308
310
315 vtkBooleanMacro(ReadAllVectors, vtkTypeBool);
317
319
324 vtkBooleanMacro(ReadAllNormals, vtkTypeBool);
326
328
333 vtkBooleanMacro(ReadAllTensors, vtkTypeBool);
335
337
344
346
351 vtkBooleanMacro(ReadAllTCoords, vtkTypeBool);
353
355
360 vtkBooleanMacro(ReadAllFields, vtkTypeBool);
362
366 int OpenVTKFile(VTK_FILEPATH const char* fname = nullptr);
367
371 int ReadHeader(VTK_FILEPATH const char* fname = nullptr);
372
379
386
391
396
402 int ReadVertexData(vtkGraph* g, vtkIdType numVertices);
403
409 int ReadEdgeData(vtkGraph* g, vtkIdType numEdges);
410
414 int ReadRowData(vtkTable* t, vtkIdType numEdges);
415
422
427 int ReadCellsLegacy(vtkIdType size, int* data);
428
432 int ReadCellsLegacy(vtkIdType size, int* data, int skip1, int read2, int skip3);
433
438 int ReadCoordinates(vtkRectilinearGrid* rg, int axes, int numCoords);
439
441
444 vtkAbstractArray* ReadArray(const char* dataType, vtkIdType numTuples, vtkIdType numComp);
447
449
453 int Read(char*);
454 int Read(unsigned char*);
455 int Read(short*);
456 int Read(unsigned short*);
457 int Read(int*);
458 int Read(unsigned int*);
459 int Read(long*);
460 int Read(unsigned long*);
461 int Read(long long* result);
462 int Read(unsigned long long* result);
463 int Read(float*);
464 int Read(double*);
466
471 size_t Peek(char* str, size_t n);
472
477
482 int ReadLine(char result[256]);
483
488 int ReadString(char (&result)[256]);
489
493 char* LowerCase(char* str, size_t len = 256);
494
498 istream* GetIStream() { return this->IS; }
499
501
505 int ReadTimeDependentMetaData(int timestep, vtkInformation* metadata) override;
506 int ReadMesh(int piece, int npieces, int nghosts, int timestep, vtkDataObject* output) override;
507 int ReadPoints(int /*piece*/, int /*npieces*/, int /*nghosts*/, int /*timestep*/,
508 vtkDataObject* /*output*/) override
509 {
510 return 1;
511 }
512 int ReadArrays(int /*piece*/, int /*npieces*/, int /*nghosts*/, int /*timestep*/,
513 vtkDataObject* /*output*/) override
514 {
515 return 1;
516 }
517
518
520
525 int ReadMeshSimple(VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
526 {
527 return 1;
528 }
530 VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
531 {
532 return 1;
533 }
535 VTK_FILEPATH const std::string& /*fname*/, vtkDataObject* /*output*/) override
536 {
537 return 1;
538 }
539
540
545
546protected:
548 ~vtkDataReader() override;
549
550 std::string CurrentFileName;
555 istream* IS;
556
565
570
571 void SetScalarLut(const char* lut);
572 vtkGetStringMacro(ScalarLut);
573
574 char* Header;
575
586
592
594
595 // This supports getting additional information from vtk files
615
623
624 std::locale CurrentLocale;
625
627 int CharacterizeFile(); // read entire file, storing important characteristics
628 void CheckFor(const char* name, char* line, int& num, char**& array, int& allocSize);
629
631
637 int DecodeString(char* resname, const char* name);
638
639private:
640 vtkDataReader(const vtkDataReader&) = delete;
641 void operator=(const vtkDataReader&) = delete;
642
643 void ConvertGhostLevelsToGhostType(FieldType fieldType, vtkAbstractArray* data) const;
644
645 // The stream used to read the input if it is in a resource stream
647 bool ReadFromInputStream = false;
648
649 // Used when converting vtkResourceStream into istream
650 std::unique_ptr<std::streambuf> Streambuf;
651};
652
653VTK_ABI_NAMESPACE_END
654#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 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.
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.
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)
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 ReadHeader(const char *fname=nullptr)
Read the header of a vtk data file.
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:368
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:323
#define VTK_FILEPATH