VTK  9.2.6
vtkDataWriter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDataWriter.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 vtkDataWriter_h
30 #define vtkDataWriter_h
31 
32 #include "vtkIOLegacyModule.h" // For export macro
33 #include "vtkWriter.h"
34 
35 #include <locale> // For locale settings
36 
37 class vtkCellArray;
38 class vtkDataArray;
39 class vtkDataSet;
40 class vtkFieldData;
41 class vtkGraph;
42 class vtkInformation;
43 class vtkInformationKey;
44 class vtkPoints;
45 class vtkTable;
46 
47 class VTKIOLEGACY_EXPORT vtkDataWriter : public vtkWriter
48 {
49 public:
51 
54  vtkTypeMacro(vtkDataWriter, vtkWriter);
55  void PrintSelf(ostream& os, vtkIndent indent) override;
57 
62  static vtkDataWriter* New();
63 
65 
68  vtkSetFilePathMacro(FileName);
69  vtkGetFilePathMacro(FileName);
71 
72  // Currently VTK can write out two different versions of file format: files
73  // of VTK reader version 4.2 and previous; and VTK reader version 5.1 and
74  // later. This will likely change in the future. (Note: the major
75  // difference in the two formats is the way cell arrays are written out.)
76  // By default, Version 5.1 files are written out.
78  {
79  VTK_LEGACY_READER_VERSION_4_2 = 42,
80  VTK_LEGACY_READER_VERSION_5_1 = 51
81  };
82 
84 
93  void SetFileVersion(int);
94  vtkGetMacro(FileVersion, int);
95  vtkGetMacro(FileMajorVersion, int);
96  vtkGetMacro(FileMinorVersion, int);
98 
100 
103  vtkSetMacro(WriteToOutputString, vtkTypeBool);
104  vtkGetMacro(WriteToOutputString, vtkTypeBool);
105  vtkBooleanMacro(WriteToOutputString, vtkTypeBool);
107 
109 
114  vtkGetMacro(OutputStringLength, vtkIdType);
115  vtkGetStringMacro(OutputString);
116  unsigned char* GetBinaryOutputString()
117  {
118  return reinterpret_cast<unsigned char*>(this->OutputString);
119  }
121 
126  vtkStdString GetOutputStdString();
127 
133  char* RegisterAndGetOutputString();
134 
136 
139  vtkSetStringMacro(Header);
140  vtkGetStringMacro(Header);
142 
144 
148  vtkSetMacro(WriteArrayMetaData, bool);
149  vtkGetMacro(WriteArrayMetaData, bool);
150  vtkBooleanMacro(WriteArrayMetaData, bool);
152 
154 
157  vtkSetClampMacro(FileType, int, VTK_ASCII, VTK_BINARY);
158  vtkGetMacro(FileType, int);
159  void SetFileTypeToASCII() { this->SetFileType(VTK_ASCII); }
160  void SetFileTypeToBinary() { this->SetFileType(VTK_BINARY); }
162 
164 
168  vtkSetStringMacro(ScalarsName);
169  vtkGetStringMacro(ScalarsName);
171 
173 
177  vtkSetStringMacro(VectorsName);
178  vtkGetStringMacro(VectorsName);
180 
182 
186  vtkSetStringMacro(TensorsName);
187  vtkGetStringMacro(TensorsName);
189 
191 
195  vtkSetStringMacro(NormalsName);
196  vtkGetStringMacro(NormalsName);
198 
200 
204  vtkSetStringMacro(TCoordsName);
205  vtkGetStringMacro(TCoordsName);
207 
209 
213  vtkSetStringMacro(GlobalIdsName);
214  vtkGetStringMacro(GlobalIdsName);
216 
218 
222  vtkSetStringMacro(PedigreeIdsName);
223  vtkGetStringMacro(PedigreeIdsName);
225 
227 
231  vtkSetStringMacro(EdgeFlagsName);
232  vtkGetStringMacro(EdgeFlagsName);
234 
236 
240  vtkSetStringMacro(LookupTableName);
241  vtkGetStringMacro(LookupTableName);
243 
245 
249  vtkSetStringMacro(FieldDataName);
250  vtkGetStringMacro(FieldDataName);
252 
256  virtual ostream* OpenVTKFile();
257 
261  int WriteHeader(ostream* fp);
262 
266  int WritePoints(ostream* fp, vtkPoints* p);
267 
271  int WriteCoordinates(ostream* fp, vtkDataArray* coords, int axes);
272 
276  int WriteCells(ostream* fp, vtkCellArray* cells, const char* label);
277 
282  int WriteCellsLegacy(ostream* fp, vtkCellArray* cells, const char* label);
283 
288  int WriteCellData(ostream* fp, vtkDataSet* ds);
289 
294  int WritePointData(ostream* fp, vtkDataSet* ds);
295 
300  int WriteEdgeData(ostream* fp, vtkGraph* g);
301 
306  int WriteVertexData(ostream* fp, vtkGraph* g);
307 
312  int WriteRowData(ostream* fp, vtkTable* g);
313 
317  int WriteFieldData(ostream* fp, vtkFieldData* f);
318 
323  int WriteDataSetData(ostream* fp, vtkDataSet* ds);
324 
328  void CloseVTKFile(ostream* fp);
329 
330 protected:
331  vtkDataWriter();
332  ~vtkDataWriter() override;
333 
337 
338  void WriteData() override; // dummy method to allow this class to be instantiated and delegated to
339 
340  char* FileName;
344  char* Header;
345  int FileType;
346 
348 
349  char* ScalarsName;
350  char* VectorsName;
351  char* TensorsName;
352  char* TCoordsName;
353  char* NormalsName;
359 
360  std::locale CurrentLocale;
361 
362  int WriteArray(ostream* fp, int dataType, vtkAbstractArray* data, const char* format,
363  vtkIdType num, vtkIdType numComp);
364  int WriteScalarData(ostream* fp, vtkDataArray* s, vtkIdType num);
365  int WriteVectorData(ostream* fp, vtkDataArray* v, vtkIdType num);
366  int WriteNormalData(ostream* fp, vtkDataArray* n, vtkIdType num);
367  int WriteTCoordData(ostream* fp, vtkDataArray* tc, vtkIdType num);
368  int WriteTensorData(ostream* fp, vtkDataArray* t, vtkIdType num);
369  int WriteGlobalIdData(ostream* fp, vtkDataArray* g, vtkIdType num);
370  int WritePedigreeIdData(ostream* fp, vtkAbstractArray* p, vtkIdType num);
371  int WriteEdgeFlagsData(ostream* fp, vtkDataArray* edgeFlags, vtkIdType num);
372 
373  bool CanWriteInformationKey(vtkInformation* info, vtkInformationKey* key);
374 
378  int WriteInformation(ostream* fp, vtkInformation* info);
379 
380 private:
381  vtkDataWriter(const vtkDataWriter&) = delete;
382  void operator=(const vtkDataWriter&) = delete;
383 };
384 
385 #endif
char * FieldDataName
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
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:62
Abstract superclass for all arrays.
helper class for objects that write VTK data files
Definition: vtkDataWriter.h:47
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:332
char * TensorsName
#define VTK_ASCII
Definition: vtkWriter.h:42
char * EdgeFlagsName
int vtkTypeBool
Definition: vtkABI.h:69
Base class for graph data types.
Definition: vtkGraph.h:295
abstract class to write data to file(s)
Definition: vtkWriter.h:45
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:39
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:55
#define VTK_BINARY
Definition: vtkWriter.h:43
char * GlobalIdsName
char * PedigreeIdsName
bool WriteArrayMetaData
object to represent cell connectivity
Definition: vtkCellArray.h:186
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:73
std::locale CurrentLocale
char * TCoordsName
static vtkAlgorithm * New()
virtual void WriteData()=0
char * VectorsName
represent and manipulate 3D points
Definition: vtkPoints.h:39
represent and manipulate fields of data
Definition: vtkFieldData.h:62