VTK  9.1.0
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
44class vtkCharArray;
45class vtkCellArray;
46class vtkDataSet;
48class vtkFieldData;
49class vtkGraph;
50class vtkPointSet;
52class vtkTable;
53
54class VTKIOLEGACY_EXPORT vtkDataReader : public vtkSimpleReader
55{
56public:
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
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
362
369
374
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
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
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
524protected:
526 ~vtkDataReader() override;
527
528 std::string CurrentFileName;
533 istream* IS;
534
543
548
549 void SetScalarLut(const char* lut);
550 vtkGetStringMacro(ScalarLut);
551
552 char* Header;
553
564
569
571
572 // This supports getting additional information from vtk files
592
600
601 std::locale CurrentLocale;
602
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
616private:
617 vtkDataReader(const vtkDataReader&) = delete;
618 void operator=(const vtkDataReader&) = delete;
619
620 void ConvertGhostLevelsToGhostType(FieldType fieldType, vtkAbstractArray* data) const;
621};
622
623#endif
Abstract superclass for all arrays.
object to represent cell connectivity
Definition: vtkCellArray.h:290
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:68
general representation of visualization data
helper superclass for objects that read vtk data files
Definition: vtkDataReader.h:55
char * InputString
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.
Definition: vtkDataReader.h:76
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,...
int ReadString(char result[256])
Internal function to read in a string up to 256 characters.
void SetScalarLut(const char *lut)
char * LowerCase(char *str, const size_t len=256)
Helper method for reading in data.
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 TCoordsNameAllocSize
int ScalarsNameAllocSize
int ReadTimeDependentMetaData(int timestep, vtkInformation *metadata) override
Overridden to handle reading from a string.
char * VectorsName
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.
int NumberOfTensorsInFile
vtkTimeStamp CharacteristicsTime
int ReadDataSetData(vtkDataSet *ds)
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
char * TCoordsName
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 NumberOfVectorsInFile
int Read(float *)
Internal function to read in a value.
char * NormalsName
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 NormalsNameAllocSize
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...
char * TensorsName
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()
int NumberOfNormalsInFile
char ** ScalarsNameInFile
vtkFieldData * ReadFieldData(FieldType fieldType=FIELD_DATA)
Helper functions for reading data.
int TensorsNameAllocSize
char * FieldDataName
int NumberOfScalarsInFile
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 VectorsNameAllocSize
istream * IS
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...
char * ScalarsName
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 NumberOfTCoordsInFile
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 FieldDataNameAllocSize
int ReadInformation(vtkInformation *info, vtkIdType numKeys)
Format is detailed here.
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
Definition: vtkFieldData.h:164
Base class for graph data types.
Definition: vtkGraph.h:339
a simple class to control print indentation
Definition: vtkIndent.h:113
Store vtkAlgorithm input/output information.
concrete class for storing a set of points
Definition: vtkPointSet.h:106
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.
Definition: vtkStdString.h:105
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:172
record modification and/or execution time
Definition: vtkTimeStamp.h:52
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:332
#define IS
#define VTK_FILEPATH