VTK  9.0.1
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(const char* fname);
75  const char* GetFileName() const;
76  const char* GetFileName(int i) const { return this->vtkSimpleReader::GetFileName(i); }
78 
80 
84  int IsFileValid(const char* dstype);
85  int IsFileStructuredPoints() { return this->IsFileValid("structured_points"); }
86  int IsFilePolyData() { return this->IsFileValid("polydata"); }
87  int IsFileStructuredGrid() { return this->IsFileValid("structured_grid"); }
88  int IsFileUnstructuredGrid() { return this->IsFileValid("unstructured_grid"); }
89  int IsFileRectilinearGrid() { return this->IsFileValid("rectilinear_grid"); }
91 
93 
99  void SetInputString(const char* in);
100  vtkGetStringMacro(InputString);
101  void SetInputString(const char* in, int len);
102  vtkGetMacro(InputStringLength, int);
103  void SetBinaryInputString(const char*, int len);
104  void SetInputString(const vtkStdString& input)
105  {
106  this->SetBinaryInputString(input.c_str(), static_cast<int>(input.length()));
107  }
109 
111 
119  virtual void SetInputArray(vtkCharArray*);
120  vtkGetObjectMacro(InputArray, vtkCharArray);
122 
124 
127  vtkGetStringMacro(Header);
129 
131 
135  vtkSetMacro(ReadFromInputString, vtkTypeBool);
136  vtkGetMacro(ReadFromInputString, vtkTypeBool);
137  vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
139 
141 
145  vtkGetMacro(FileType, int);
147 
156  {
157  this->CharacterizeFile();
158  return this->NumberOfScalarsInFile;
159  }
161  {
162  this->CharacterizeFile();
163  return this->NumberOfVectorsInFile;
164  }
166  {
167  this->CharacterizeFile();
168  return this->NumberOfTensorsInFile;
169  }
171  {
172  this->CharacterizeFile();
173  return this->NumberOfNormalsInFile;
174  }
176  {
177  this->CharacterizeFile();
178  return this->NumberOfTCoordsInFile;
179  }
181  {
182  this->CharacterizeFile();
183  return this->NumberOfFieldDataInFile;
184  }
185 
187 
192  const char* GetScalarsNameInFile(int i);
193  const char* GetVectorsNameInFile(int i);
194  const char* GetTensorsNameInFile(int i);
195  const char* GetNormalsNameInFile(int i);
196  const char* GetTCoordsNameInFile(int i);
197  const char* GetFieldDataNameInFile(int i);
199 
201 
205  vtkSetStringMacro(ScalarsName);
206  vtkGetStringMacro(ScalarsName);
208 
210 
214  vtkSetStringMacro(VectorsName);
215  vtkGetStringMacro(VectorsName);
217 
219 
223  vtkSetStringMacro(TensorsName);
224  vtkGetStringMacro(TensorsName);
226 
228 
232  vtkSetStringMacro(NormalsName);
233  vtkGetStringMacro(NormalsName);
235 
237 
241  vtkSetStringMacro(TCoordsName);
242  vtkGetStringMacro(TCoordsName);
244 
246 
250  vtkSetStringMacro(LookupTableName);
251  vtkGetStringMacro(LookupTableName);
253 
255 
259  vtkSetStringMacro(FieldDataName);
260  vtkGetStringMacro(FieldDataName);
262 
264 
267  vtkSetMacro(ReadAllScalars, vtkTypeBool);
268  vtkGetMacro(ReadAllScalars, vtkTypeBool);
269  vtkBooleanMacro(ReadAllScalars, vtkTypeBool);
271 
273 
276  vtkSetMacro(ReadAllVectors, vtkTypeBool);
277  vtkGetMacro(ReadAllVectors, vtkTypeBool);
278  vtkBooleanMacro(ReadAllVectors, vtkTypeBool);
280 
282 
285  vtkSetMacro(ReadAllNormals, vtkTypeBool);
286  vtkGetMacro(ReadAllNormals, vtkTypeBool);
287  vtkBooleanMacro(ReadAllNormals, vtkTypeBool);
289 
291 
294  vtkSetMacro(ReadAllTensors, vtkTypeBool);
295  vtkGetMacro(ReadAllTensors, vtkTypeBool);
296  vtkBooleanMacro(ReadAllTensors, vtkTypeBool);
298 
300 
303  vtkSetMacro(ReadAllColorScalars, vtkTypeBool);
304  vtkGetMacro(ReadAllColorScalars, vtkTypeBool);
305  vtkBooleanMacro(ReadAllColorScalars, vtkTypeBool);
307 
309 
312  vtkSetMacro(ReadAllTCoords, vtkTypeBool);
313  vtkGetMacro(ReadAllTCoords, vtkTypeBool);
314  vtkBooleanMacro(ReadAllTCoords, vtkTypeBool);
316 
318 
321  vtkSetMacro(ReadAllFields, vtkTypeBool);
322  vtkGetMacro(ReadAllFields, vtkTypeBool);
323  vtkBooleanMacro(ReadAllFields, vtkTypeBool);
325 
329  int OpenVTKFile(const char* fname = nullptr);
330 
334  int ReadHeader(const char* fname = nullptr);
335 
341  int ReadCellData(vtkDataSet* ds, vtkIdType numCells);
342 
348  int ReadPointData(vtkDataSet* ds, vtkIdType numPts);
349 
353  int ReadPointCoordinates(vtkPointSet* ps, vtkIdType numPts);
354 
358  int ReadPointCoordinates(vtkGraph* g, vtkIdType numPts);
359 
365  int ReadVertexData(vtkGraph* g, vtkIdType numVertices);
366 
372  int ReadEdgeData(vtkGraph* g, vtkIdType numEdges);
373 
377  int ReadRowData(vtkTable* t, vtkIdType numEdges);
378 
384  int ReadCells(vtkSmartPointer<vtkCellArray>& cellArray);
385 
390  int ReadCellsLegacy(vtkIdType size, int* data);
391 
395  int ReadCellsLegacy(vtkIdType size, int* data, int skip1, int read2, int skip3);
396 
401  int ReadCoordinates(vtkRectilinearGrid* rg, int axes, int numCoords);
402 
404 
407  vtkAbstractArray* ReadArray(const char* dataType, vtkIdType numTuples, vtkIdType numComp);
408  vtkFieldData* ReadFieldData(FieldType fieldType = FIELD_DATA);
410 
412 
416  vtkGetMacro(FileMajorVersion, int);
417  vtkGetMacro(FileMinorVersion, int);
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 
448  void CloseVTKFile();
449 
454  int ReadLine(char result[256]);
455 
460  int ReadString(char result[256]);
461 
465  char* LowerCase(char* str, const 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(const std::string& /*fname*/, vtkDataObject* /*output*/) override { return 1; }
498  int ReadPointsSimple(const std::string& /*fname*/, vtkDataObject* /*output*/) override
499  {
500  return 1;
501  }
502  int ReadArraysSimple(const std::string& /*fname*/, vtkDataObject* /*output*/) override
503  {
504  return 1;
505  }
507 
508 protected:
509  vtkDataReader();
510  ~vtkDataReader() override;
511 
513  int FileType;
514  istream* IS;
515 
516  char* ScalarsName;
517  char* VectorsName;
518  char* TensorsName;
519  char* TCoordsName;
520  char* NormalsName;
523  char* ScalarLut;
524 
526  char* InputString;
529 
530  void SetScalarLut(const char* lut);
531  vtkGetStringMacro(ScalarLut);
532 
533  char* Header;
534 
535  int ReadScalarData(vtkDataSetAttributes* a, vtkIdType num);
536  int ReadVectorData(vtkDataSetAttributes* a, vtkIdType num);
537  int ReadNormalData(vtkDataSetAttributes* a, vtkIdType num);
538  int ReadTensorData(vtkDataSetAttributes* a, vtkIdType num, vtkIdType numComp = 9);
539  int ReadCoScalarData(vtkDataSetAttributes* a, vtkIdType num);
540  int ReadLutData(vtkDataSetAttributes* a);
541  int ReadTCoordsData(vtkDataSetAttributes* a, vtkIdType num);
542  int ReadGlobalIds(vtkDataSetAttributes* a, vtkIdType num);
543  int ReadPedigreeIds(vtkDataSetAttributes* a, vtkIdType num);
544  int ReadEdgeFlags(vtkDataSetAttributes* a, vtkIdType num);
545 
549  int ReadInformation(vtkInformation* info, vtkIdType numKeys);
550 
551  int ReadDataSetData(vtkDataSet* ds);
552 
553  // This supports getting additional information from vtk files
573 
583 
584  std::locale CurrentLocale;
585 
586  void InitializeCharacteristics();
587  int CharacterizeFile(); // read entire file, storing important characteristics
588  void CheckFor(const char* name, char* line, int& num, char**& array, int& allocSize);
589 
591 
597  int DecodeString(char* resname, const char* name);
598 
602  {
603  return 1;
604  }
606  {
607  return 1;
608  }
610  {
611  return 1;
612  }
613 
614 private:
615  vtkDataReader(const vtkDataReader&) = delete;
616  void operator=(const vtkDataReader&) = delete;
617 
618  void ConvertGhostLevelsToGhostType(FieldType fieldType, vtkAbstractArray* data) const;
619 };
620 
621 #endif
vtkTypeBool ReadAllTensors
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
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
char * FieldDataName
vtkTypeBool ReadAllFields
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
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 ...
Definition: vtkDataReader.h:86
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 ...
Definition: vtkDataReader.h:89
record modification and/or execution time
Definition: vtkTimeStamp.h:32
int NumberOfTensorsInFile
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
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()
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:62
int NormalsNameAllocSize
vtkTypeBool ReadAllScalars
int vtkIdType
Definition: vtkType.h:338
int IsFileStructuredGrid()
Is the file a valid vtk file of the passed dataset type ? The dataset type is passed as a lower case ...
Definition: vtkDataReader.h:87
int TensorsNameAllocSize
vtkTimeStamp CharacteristicsTime
const char * GetFileName(int i) const
Specify file name of vtk data file to read.
Definition: vtkDataReader.h:76
const char * GetFileName(int i) const
Returns a particular filename stored by the reader.
char ** TensorsNameInFile
int GetNumberOfFieldDataInFile()
int ReadMeshSimple(const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
int vtkTypeBool
Definition: vtkABI.h:69
virtual vtkTypeBool ProcessRequest(vtkInformation *request, vtkInformationVector **inInfo, vtkInformationVector *outInfo)
Upstream/Downstream requests form the generalized interface through which executives invoke a algorit...
Base class for graph data types.
Definition: vtkGraph.h:289
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:35
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:33
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 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
virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
char * TensorsName
int GetNumberOfVectorsInFile()
object to represent cell connectivity
Definition: vtkCellArray.h:179
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:62
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 ...
Definition: vtkDataReader.h:88
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 ...
Definition: vtkDataReader.h:85
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
Store zero or more vtkInformation instances.
static vtkAlgorithm * New()
int ReadArraysSimple(const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
int VectorsNameAllocSize
int ReadPointsSimple(const std::string &, vtkDataObject *) override
Overridden with default implementation of doing nothing so that subclasses only override what is need...
char ** NormalsNameInFile
vtkTypeBool ReadAllTCoords
vtkCharArray * InputArray
istream * IS
char * VectorsName
char ** TCoordsNameInFile
int FieldDataNameAllocSize
general representation of visualization data
Definition: vtkDataObject.h:59
int GetNumberOfTensorsInFile()
int NumberOfTCoordsInFile
#define IS
represent and manipulate fields of data
Definition: vtkFieldData.h:53
int NumberOfVectorsInFile