VTK  9.3.20240327
vtkDataWriter.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 vtkDataWriter_h
18 #define vtkDataWriter_h
19 
20 #include "vtkIOLegacyModule.h" // For export macro
21 #include "vtkWriter.h"
22 
23 #include <locale> // For locale settings
24 
25 VTK_ABI_NAMESPACE_BEGIN
26 class vtkCellArray;
27 class vtkDataArray;
28 class vtkDataSet;
29 class vtkFieldData;
30 class vtkGraph;
31 class vtkInformation;
32 class vtkInformationKey;
33 class vtkPoints;
34 class vtkTable;
35 
36 class VTKIOLEGACY_EXPORT vtkDataWriter : public vtkWriter
37 {
38 public:
40 
43  vtkTypeMacro(vtkDataWriter, vtkWriter);
44  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
51  static vtkDataWriter* New();
52 
54 
60 
61  // Currently VTK can write out two different versions of file format: files
62  // of VTK reader version 4.2 and previous; and VTK reader version 5.1 and
63  // later. This will likely change in the future. (Note: the major
64  // difference in the two formats is the way cell arrays are written out.)
65  // By default, Version 5.1 files are written out.
67  {
68  VTK_LEGACY_READER_VERSION_4_2 = 42,
69  VTK_LEGACY_READER_VERSION_5_1 = 51
70  };
71 
73 
82  void SetFileVersion(int);
83  vtkGetMacro(FileVersion, int);
84  vtkGetMacro(FileMajorVersion, int);
85  vtkGetMacro(FileMinorVersion, int);
87 
89 
92  vtkSetMacro(WriteToOutputString, vtkTypeBool);
93  vtkGetMacro(WriteToOutputString, vtkTypeBool);
94  vtkBooleanMacro(WriteToOutputString, vtkTypeBool);
96 
98 
103  vtkGetMacro(OutputStringLength, vtkIdType);
104  vtkGetStringMacro(OutputString);
105  unsigned char* GetBinaryOutputString()
106  {
107  return reinterpret_cast<unsigned char*>(this->OutputString);
108  }
110 
116 
123 
125 
128  vtkSetStringMacro(Header);
129  vtkGetStringMacro(Header);
131 
133 
137  vtkSetMacro(WriteArrayMetaData, bool);
138  vtkGetMacro(WriteArrayMetaData, bool);
139  vtkBooleanMacro(WriteArrayMetaData, bool);
141 
143 
146  vtkSetClampMacro(FileType, int, VTK_ASCII, VTK_BINARY);
147  vtkGetMacro(FileType, int);
148  void SetFileTypeToASCII() { this->SetFileType(VTK_ASCII); }
149  void SetFileTypeToBinary() { this->SetFileType(VTK_BINARY); }
151 
153 
157  vtkSetStringMacro(ScalarsName);
158  vtkGetStringMacro(ScalarsName);
160 
162 
166  vtkSetStringMacro(VectorsName);
167  vtkGetStringMacro(VectorsName);
169 
171 
175  vtkSetStringMacro(TensorsName);
176  vtkGetStringMacro(TensorsName);
178 
180 
184  vtkSetStringMacro(NormalsName);
185  vtkGetStringMacro(NormalsName);
187 
189 
193  vtkSetStringMacro(TCoordsName);
194  vtkGetStringMacro(TCoordsName);
196 
198 
202  vtkSetStringMacro(GlobalIdsName);
203  vtkGetStringMacro(GlobalIdsName);
205 
207 
211  vtkSetStringMacro(PedigreeIdsName);
212  vtkGetStringMacro(PedigreeIdsName);
214 
216 
220  vtkSetStringMacro(EdgeFlagsName);
221  vtkGetStringMacro(EdgeFlagsName);
223 
225 
229  vtkSetStringMacro(LookupTableName);
230  vtkGetStringMacro(LookupTableName);
232 
234 
238  vtkSetStringMacro(FieldDataName);
239  vtkGetStringMacro(FieldDataName);
241 
245  virtual ostream* OpenVTKFile();
246 
250  int WriteHeader(ostream* fp);
251 
255  int WritePoints(ostream* fp, vtkPoints* p);
256 
260  int WriteCoordinates(ostream* fp, vtkDataArray* coords, int axes);
261 
265  int WriteCells(ostream* fp, vtkCellArray* cells, const char* label);
266 
271  int WriteCellsLegacy(ostream* fp, vtkCellArray* cells, const char* label);
272 
277  int WriteCellData(ostream* fp, vtkDataSet* ds);
278 
283  int WritePointData(ostream* fp, vtkDataSet* ds);
284 
289  int WriteEdgeData(ostream* fp, vtkGraph* g);
290 
295  int WriteVertexData(ostream* fp, vtkGraph* g);
296 
301  int WriteRowData(ostream* fp, vtkTable* g);
302 
306  int WriteFieldData(ostream* fp, vtkFieldData* f);
307 
312  int WriteDataSetData(ostream* fp, vtkDataSet* ds);
313 
317  void CloseVTKFile(ostream* fp);
318 
319 protected:
321  ~vtkDataWriter() override;
322 
326 
327  void WriteData() override; // dummy method to allow this class to be instantiated and delegated to
328 
329  char* FileName;
333  char* Header;
334  int FileType;
335 
337 
338  char* ScalarsName;
339  char* VectorsName;
340  char* TensorsName;
341  char* TCoordsName;
342  char* NormalsName;
348 
349  std::locale CurrentLocale;
350 
351  int WriteArray(ostream* fp, int dataType, vtkAbstractArray* data, const char* format,
352  vtkIdType num, vtkIdType numComp);
353  int WriteScalarData(ostream* fp, vtkDataArray* s, vtkIdType num);
354  int WriteVectorData(ostream* fp, vtkDataArray* v, vtkIdType num);
355  int WriteNormalData(ostream* fp, vtkDataArray* n, vtkIdType num);
356  int WriteTCoordData(ostream* fp, vtkDataArray* tc, vtkIdType num);
357  int WriteTensorData(ostream* fp, vtkDataArray* t, vtkIdType num);
358  int WriteGlobalIdData(ostream* fp, vtkDataArray* g, vtkIdType num);
359  int WritePedigreeIdData(ostream* fp, vtkAbstractArray* p, vtkIdType num);
360  int WriteEdgeFlagsData(ostream* fp, vtkDataArray* edgeFlags, vtkIdType num);
361 
363 
369 
370 private:
371  vtkDataWriter(const vtkDataWriter&) = delete;
372  void operator=(const vtkDataWriter&) = delete;
373 };
374 
375 VTK_ABI_NAMESPACE_END
376 #endif
Abstract superclass for all arrays.
object to represent cell connectivity
Definition: vtkCellArray.h:285
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:154
abstract class to specify dataset behavior
Definition: vtkDataSet.h:165
helper class for objects that write VTK data files
Definition: vtkDataWriter.h:37
vtkSetFilePathMacro(FileName)
Specify the file name of VTK data file to write.
int WriteEdgeData(ostream *fp, vtkGraph *g)
Write the edge data (e.g., scalars, vectors, ...) of a vtk graph.
int WriteTCoordData(ostream *fp, vtkDataArray *tc, vtkIdType num)
int WritePointData(ostream *fp, vtkDataSet *ds)
Write the point data (e.g., scalars, vectors, ...) of a vtk dataset.
int WriteDataSetData(ostream *fp, vtkDataSet *ds)
Write out the data associated with the dataset (i.e.
char * LookupTableName
void SetFileVersion(int)
Specify the VTK file version to write.
char * EdgeFlagsName
vtkStdString GetOutputStdString()
When WriteToOutputString is on, this method returns a copy of the output string in a vtkStdString.
void WriteData() override
char * VectorsName
void SetFileTypeToBinary()
Specify the file type (ASCII or BINARY) of the VTK data file.
int WriteGlobalIdData(ostream *fp, vtkDataArray *g, vtkIdType num)
char * TCoordsName
char * NormalsName
int WriteInformation(ostream *fp, vtkInformation *info)
Format is detailed at https://docs.vtk.org/en/latest/design_documents/IOLegacyInformationFormat....
char * ScalarsName
int WriteVertexData(ostream *fp, vtkGraph *g)
Write the vertex data (e.g., scalars, vectors, ...) of a vtk graph.
vtkIdType OutputStringLength
int WriteTensorData(ostream *fp, vtkDataArray *t, vtkIdType num)
int WriteHeader(ostream *fp)
Write the header of a vtk data file.
int WriteCells(ostream *fp, vtkCellArray *cells, const char *label)
Write out the cells of the data set.
int WriteCoordinates(ostream *fp, vtkDataArray *coords, int axes)
Write out coordinates for rectilinear grids.
char * FieldDataName
char * PedigreeIdsName
void CloseVTKFile(ostream *fp)
Close a vtk file.
virtual ostream * OpenVTKFile()
Open a vtk data file.
char * OutputString
char * GlobalIdsName
static vtkDataWriter * New()
Create object with default header, ASCII format, and default names for scalars, vectors,...
int WriteEdgeFlagsData(ostream *fp, vtkDataArray *edgeFlags, vtkIdType num)
int WriteNormalData(ostream *fp, vtkDataArray *n, vtkIdType num)
unsigned char * GetBinaryOutputString()
When WriteToOutputString in on, then a string is allocated, written to, and can be retrieved with the...
int WriteArray(ostream *fp, int dataType, vtkAbstractArray *data, const char *format, vtkIdType num, vtkIdType numComp)
int WriteScalarData(ostream *fp, vtkDataArray *s, vtkIdType num)
char * RegisterAndGetOutputString()
This convenience method returns the string, sets the IVAR to nullptr, so that the user is responsible...
int WritePoints(ostream *fp, vtkPoints *p)
Write out the points of the data set.
int WriteFieldData(ostream *fp, vtkFieldData *f)
Write out the field data.
void SetFileTypeToASCII()
Specify the file type (ASCII or BINARY) of the VTK data file.
std::locale CurrentLocale
char * TensorsName
~vtkDataWriter() override
int WriteCellsLegacy(ostream *fp, vtkCellArray *cells, const char *label)
Write out the cells of the data set.
int WriteVectorData(ostream *fp, vtkDataArray *v, vtkIdType num)
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for type information and printing.
vtkGetFilePathMacro(FileName)
Specify the file name of VTK data file to write.
bool WriteArrayMetaData
int WriteCellData(ostream *fp, vtkDataSet *ds)
Write the cell data (e.g., scalars, vectors, ...) of a vtk dataset.
vtkTypeBool WriteToOutputString
int WriteRowData(ostream *fp, vtkTable *g)
Write the row data (e.g., scalars, vectors, ...) of a vtk table.
bool CanWriteInformationKey(vtkInformation *info, vtkInformationKey *key)
int WritePedigreeIdData(ostream *fp, vtkAbstractArray *p, vtkIdType num)
represent and manipulate fields of data
Definition: vtkFieldData.h:161
Base class for graph data types.
Definition: vtkGraph.h:340
a simple class to control print indentation
Definition: vtkIndent.h:108
Superclass for vtkInformation keys.
Store vtkAlgorithm input/output information.
represent and manipulate 3D points
Definition: vtkPoints.h:138
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:78
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:168
abstract class to write data to file(s)
Definition: vtkWriter.h:35
@ key
Definition: vtkX3D.h:257
@ info
Definition: vtkX3D.h:376
@ data
Definition: vtkX3D.h:315
int vtkTypeBool
Definition: vtkABI.h:64
int vtkIdType
Definition: vtkType.h:315
#define VTK_BINARY
Definition: vtkWriter.h:32
#define VTK_ASCII
Definition: vtkWriter.h:31