VTK  9.3.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 
319 protected:
320  vtkDataWriter();
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 
362  bool CanWriteInformationKey(vtkInformation* info, vtkInformationKey* key);
363 
368  int WriteInformation(ostream* fp, vtkInformation* info);
369 
370 private:
371  vtkDataWriter(const vtkDataWriter&) = delete;
372  void operator=(const vtkDataWriter&) = delete;
373 };
374 
375 VTK_ABI_NAMESPACE_END
376 #endif
char * FieldDataName
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
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:52
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:315
char * TensorsName
#define VTK_ASCII
Definition: vtkWriter.h:31
char * EdgeFlagsName
int vtkTypeBool
Definition: vtkABI.h:64
Base class for graph data types.
Definition: vtkGraph.h:280
abstract class to write data to file(s)
Definition: vtkWriter.h:34
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
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:32
char * GlobalIdsName
char * PedigreeIdsName
bool WriteArrayMetaData
object to represent cell connectivity
Definition: vtkCellArray.h:175
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:58
std::locale CurrentLocale
char * TCoordsName
static vtkAlgorithm * New()
virtual void WriteData()=0
char * VectorsName
represent and manipulate 3D points
Definition: vtkPoints.h:28
represent and manipulate fields of data
Definition: vtkFieldData.h:51