VTK  9.1.0
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 
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 
127 
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:
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 
374 
379 
380 private:
381  vtkDataWriter(const vtkDataWriter&) = delete;
382  void operator=(const vtkDataWriter&) = delete;
383 };
384 
385 #endif
vtkDataWriter::WritePointData
int WritePointData(ostream *fp, vtkDataSet *ds)
Write the point data (e.g., scalars, vectors, ...) of a vtk dataset.
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:143
vtkDataWriter::WritePedigreeIdData
int WritePedigreeIdData(ostream *fp, vtkAbstractArray *p, vtkIdType num)
vtkDataWriter::WriteEdgeFlagsData
int WriteEdgeFlagsData(ostream *fp, vtkDataArray *edgeFlags, vtkIdType num)
vtkDataWriter::NormalsName
char * NormalsName
Definition: vtkDataWriter.h:353
vtkDataWriter::vtkDataWriter
vtkDataWriter()
vtkDataWriter::WriteArray
int WriteArray(ostream *fp, int dataType, vtkAbstractArray *data, const char *format, vtkIdType num, vtkIdType numComp)
vtkDataWriter::WriteGlobalIdData
int WriteGlobalIdData(ostream *fp, vtkDataArray *g, vtkIdType num)
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkDataWriter::FieldDataName
char * FieldDataName
Definition: vtkDataWriter.h:355
vtkX3D::data
@ data
Definition: vtkX3D.h:321
vtkDataWriter::OutputStringLength
vtkIdType OutputStringLength
Definition: vtkDataWriter.h:336
vtkTable
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:172
vtkDataWriter::WritePoints
int WritePoints(ostream *fp, vtkPoints *p)
Write out the points of the data set.
vtkX3D::key
@ key
Definition: vtkX3D.h:263
vtkDataWriter::WriteCellsLegacy
int WriteCellsLegacy(ostream *fp, vtkCellArray *cells, const char *label)
Write out the cells of the data set.
vtkDataWriter::WriteVertexData
int WriteVertexData(ostream *fp, vtkGraph *g)
Write the vertex data (e.g., scalars, vectors, ...) of a vtk graph.
vtkDataWriter::SetFileTypeToASCII
void SetFileTypeToASCII()
Specify the file type (ASCII or BINARY) of the VTK data file.
Definition: vtkDataWriter.h:159
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
vtkDataWriter::OutputString
char * OutputString
Definition: vtkDataWriter.h:335
vtkDataWriter::SetFileTypeToBinary
void SetFileTypeToBinary()
Specify the file type (ASCII or BINARY) of the VTK data file.
Definition: vtkDataWriter.h:160
vtkFieldData
represent and manipulate fields of data
Definition: vtkFieldData.h:164
vtkDataWriter::WriteArrayMetaData
bool WriteArrayMetaData
Definition: vtkDataWriter.h:347
vtkDataWriter::Header
char * Header
Definition: vtkDataWriter.h:344
vtkDataWriter::WriteTensorData
int WriteTensorData(ostream *fp, vtkDataArray *t, vtkIdType num)
vtkDataWriter::VTKFileVersion
VTKFileVersion
Definition: vtkDataWriter.h:78
vtkDataWriter::GetOutputStdString
vtkStdString GetOutputStdString()
When WriteToOutputString is on, this method returns a copy of the output string in a vtkStdString.
vtkDataWriter::vtkSetFilePathMacro
vtkSetFilePathMacro(FileName)
Specify the file name of VTK data file to write.
vtkDataWriter::WriteToOutputString
vtkTypeBool WriteToOutputString
Definition: vtkDataWriter.h:334
vtkDataWriter::WriteCells
int WriteCells(ostream *fp, vtkCellArray *cells, const char *label)
Write out the cells of the data set.
vtkDataWriter::WriteNormalData
int WriteNormalData(ostream *fp, vtkDataArray *n, vtkIdType num)
vtkDataWriter::New
static vtkDataWriter * New()
Create object with default header, ASCII format, and default names for scalars, vectors,...
vtkDataWriter::ScalarsName
char * ScalarsName
Definition: vtkDataWriter.h:349
vtkDataWriter::CurrentLocale
std::locale CurrentLocale
Definition: vtkDataWriter.h:360
vtkDataWriter::WriteCoordinates
int WriteCoordinates(ostream *fp, vtkDataArray *coords, int axes)
Write out coordinates for rectilinear grids.
vtkDataWriter::FileVersion
int FileVersion
Definition: vtkDataWriter.h:341
vtkDataWriter::GetBinaryOutputString
unsigned char * GetBinaryOutputString()
When WriteToOutputString in on, then a string is allocated, written to, and can be retrieved with the...
Definition: vtkDataWriter.h:116
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:290
vtkDataWriter::WriteHeader
int WriteHeader(ostream *fp)
Write the header of a vtk data file.
vtkDataWriter::FileMinorVersion
int FileMinorVersion
Definition: vtkDataWriter.h:343
vtkDataWriter::WriteInformation
int WriteInformation(ostream *fp, vtkInformation *info)
Format is detailed here.
vtkDataWriter::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for type information and printing.
vtkDataWriter::WriteVectorData
int WriteVectorData(ostream *fp, vtkDataArray *v, vtkIdType num)
vtkWriter
abstract class to write data to file(s)
Definition: vtkWriter.h:46
vtkDataWriter::WriteTCoordData
int WriteTCoordData(ostream *fp, vtkDataArray *tc, vtkIdType num)
VTK_ASCII
#define VTK_ASCII
Definition: vtkWriter.h:42
vtkDataWriter::PedigreeIdsName
char * PedigreeIdsName
Definition: vtkDataWriter.h:357
vtkDataWriter::TCoordsName
char * TCoordsName
Definition: vtkDataWriter.h:352
vtkDataWriter::EdgeFlagsName
char * EdgeFlagsName
Definition: vtkDataWriter.h:358
vtkDataWriter::OpenVTKFile
virtual ostream * OpenVTKFile()
Open a vtk data file.
vtkDataWriter::vtkGetFilePathMacro
vtkGetFilePathMacro(FileName)
Specify the file name of VTK data file to write.
vtkDataSet
abstract class to specify dataset behavior
Definition: vtkDataSet.h:166
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:76
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:183
vtkX3D::info
@ info
Definition: vtkX3D.h:382
vtkDataWriter::SetFileVersion
void SetFileVersion(int)
Specify the VTK file version to write.
vtkDataWriter::FileType
int FileType
Definition: vtkDataWriter.h:345
vtkDataWriter::LookupTableName
char * LookupTableName
Definition: vtkDataWriter.h:354
vtkWriter.h
vtkDataWriter::CloseVTKFile
void CloseVTKFile(ostream *fp)
Close a vtk file.
vtkDataWriter::WriteEdgeData
int WriteEdgeData(ostream *fp, vtkGraph *g)
Write the edge data (e.g., scalars, vectors, ...) of a vtk graph.
vtkDataWriter::CanWriteInformationKey
bool CanWriteInformationKey(vtkInformation *info, vtkInformationKey *key)
vtkDataWriter::FileMajorVersion
int FileMajorVersion
Definition: vtkDataWriter.h:342
vtkDataWriter::GlobalIdsName
char * GlobalIdsName
Definition: vtkDataWriter.h:356
vtkDataWriter::TensorsName
char * TensorsName
Definition: vtkDataWriter.h:351
vtkDataWriter::WriteData
void WriteData() override
vtkDataWriter::FileName
char * FileName
Definition: vtkDataWriter.h:340
vtkDataWriter::RegisterAndGetOutputString
char * RegisterAndGetOutputString()
This convenience method returns the string, sets the IVAR to nullptr, so that the user is responsible...
vtkDataWriter::WriteCellData
int WriteCellData(ostream *fp, vtkDataSet *ds)
Write the cell data (e.g., scalars, vectors, ...) of a vtk dataset.
vtkDataWriter
helper class for objects that write VTK data files
Definition: vtkDataWriter.h:48
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:105
vtkGraph
Base class for graph data types.
Definition: vtkGraph.h:339
vtkDataWriter::WriteDataSetData
int WriteDataSetData(ostream *fp, vtkDataSet *ds)
Write out the data associated with the dataset (i.e.
vtkDataWriter::WriteFieldData
int WriteFieldData(ostream *fp, vtkFieldData *f)
Write out the field data.
vtkDataWriter::WriteRowData
int WriteRowData(ostream *fp, vtkTable *g)
Write the row data (e.g., scalars, vectors, ...) of a vtk table.
VTK_BINARY
#define VTK_BINARY
Definition: vtkWriter.h:43
vtkDataWriter::VectorsName
char * VectorsName
Definition: vtkDataWriter.h:350
vtkInformationKey
Superclass for vtkInformation keys.
Definition: vtkInformationKey.h:39
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkDataWriter::WriteScalarData
int WriteScalarData(ostream *fp, vtkDataArray *s, vtkIdType num)
vtkDataWriter::~vtkDataWriter
~vtkDataWriter() override