VTK  9.7.1
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 
57  vtkSetFilePathMacro(FileName);
58  vtkGetFilePathMacro(FileName);
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 
115  vtkStdString GetOutputStdString();
116 
122  char* RegisterAndGetOutputString();
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 
320 
327  virtual void SetPrecision(int precision);
328  vtkGetMacro(Precision, int);
330 
331 protected:
332  vtkDataWriter();
333  ~vtkDataWriter() override;
334 
338 
339  bool WriteDataAndReturn()
340  override; // dummy method to allow this class to be instantiated and delegated to
341 
342  char* FileName;
346  char* Header;
347  int FileType;
348 
350 
351  char* ScalarsName;
352  char* VectorsName;
353  char* TensorsName;
354  char* TCoordsName;
355  char* NormalsName;
361 
362  std::locale OriginalStreamLocale;
363 
366 
367  int WriteArray(ostream* fp, int dataType, vtkAbstractArray* data, const char* format,
368  vtkIdType num, vtkIdType numComp);
369  int WriteScalarData(ostream* fp, vtkDataArray* s, vtkIdType num);
370  int WriteVectorData(ostream* fp, vtkDataArray* v, vtkIdType num);
371  int WriteNormalData(ostream* fp, vtkDataArray* n, vtkIdType num);
372  int WriteTCoordData(ostream* fp, vtkDataArray* tc, vtkIdType num);
373  int WriteTensorData(ostream* fp, vtkDataArray* t, vtkIdType num);
374  int WriteGlobalIdData(ostream* fp, vtkDataArray* g, vtkIdType num);
375  int WritePedigreeIdData(ostream* fp, vtkAbstractArray* p, vtkIdType num);
376  int WriteEdgeFlagsData(ostream* fp, vtkDataArray* edgeFlags, vtkIdType num);
377 
378  bool CanWriteInformationKey(vtkInformation* info, vtkInformationKey* key);
379 
384  int WriteInformation(ostream* fp, vtkInformation* info);
385 
386 private:
387  vtkDataWriter(const vtkDataWriter&) = delete;
388  void operator=(const vtkDataWriter&) = delete;
389 };
390 
391 VTK_ABI_NAMESPACE_END
392 #endif
char * FieldDataName
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
vtkIdType OutputStringLength
char * NormalsName
Store vtkAlgorithm input/output information.
void SetFileTypeToASCII()
Specify the file type (ASCII or BINARY) of the VTK data file.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
Abstract superclass for all arrays.
helper class for objects that write VTK data files
Definition: vtkDataWriter.h:36
char * ScalarsName
char * LookupTableName
unsigned char * GetBinaryOutputString()
When WriteToOutputString in on, then a string is allocated, written to, and can be retrieved with the...
char * OutputString
int vtkIdType
Definition: vtkType.h:363
char * TensorsName
#define VTK_ASCII
Definition: vtkWriter.h:32
char * EdgeFlagsName
int vtkTypeBool
Definition: vtkABI.h:64
Base class for graph data types.
Definition: vtkGraph.h:282
abstract class to write data to file(s)
Definition: vtkWriter.h:35
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Superclass for vtkInformation keys.
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkTypeBool WriteToOutputString
std::string PrecisionFormat
void SetFileTypeToBinary()
Specify the file type (ASCII or BINARY) of the VTK data file.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
#define VTK_BINARY
Definition: vtkWriter.h:33
char * GlobalIdsName
std::locale OriginalStreamLocale
char * PedigreeIdsName
bool WriteArrayMetaData
object to represent cell connectivity
Definition: vtkCellArray.h:177
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:59
char * TCoordsName
static vtkAlgorithm * New()
virtual bool WriteDataAndReturn()
char * VectorsName
represent and manipulate 3D points
Definition: vtkPoints.h:30
Represents and manipulates a collection of data arrays.
Definition: vtkFieldData.h:51