VTK  9.1.0
vtkXMLWriterBase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkXMLWriterBase.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 =========================================================================*/
28 #ifndef vtkXMLWriterBase_h
29 #define vtkXMLWriterBase_h
30 
31 #include "vtkAlgorithm.h"
32 #include "vtkIOXMLModule.h" // For export macro
33 
34 #include <string> // for std::string
35 
36 class vtkDataCompressor;
37 
38 class VTKIOXML_EXPORT vtkXMLWriterBase : public vtkAlgorithm
39 {
40 public:
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
47  enum
48  {
50  LittleEndian
51  };
52 
59  enum
60  {
63  Appended
64  };
65 
71  enum
72  {
73  Int32 = 32,
74  Int64 = 64
75  };
76 
82  enum
83  {
84  UInt32 = 32,
85  UInt64 = 64
86  };
87 
89 
93  vtkSetMacro(ByteOrder, int);
94  vtkGetMacro(ByteOrder, int);
95  void SetByteOrderToBigEndian() { this->SetByteOrder(BigEndian); }
96  void SetByteOrderToLittleEndian() { this->SetByteOrder(LittleEndian); }
98 
100 
104  virtual void SetHeaderType(int);
105  vtkGetMacro(HeaderType, int);
106  void SetHeaderTypeToUInt32() { this->SetHeaderType(UInt32); }
107  void SetHeaderTypeToUInt64() { this->SetHeaderType(UInt64); }
109 
111 
115  virtual void SetIdType(int);
116  vtkGetMacro(IdType, int);
117  void SetIdTypeToInt32() { this->SetIdType(Int32); }
118  void SetIdTypeToInt64() { this->SetIdType(Int64); }
120 
122 
128 
130 
133  vtkSetMacro(WriteToOutputString, bool);
134  vtkGetMacro(WriteToOutputString, bool);
135  vtkBooleanMacro(WriteToOutputString, bool);
136  std::string GetOutputString() { return this->OutputString; }
138 
140 
145  vtkGetObjectMacro(Compressor, vtkDataCompressor);
147 
149  {
153  LZMA
154  };
155 
157 
160  void SetCompressorType(int compressorType);
161  void SetCompressorTypeToNone() { this->SetCompressorType(NONE); }
162  void SetCompressorTypeToLZ4() { this->SetCompressorType(LZ4); }
163  void SetCompressorTypeToZLib() { this->SetCompressorType(ZLIB); }
164  void SetCompressorTypeToLZMA() { this->SetCompressorType(LZMA); }
166 
168 
172  void SetCompressionLevel(int compressorLevel);
173  vtkGetMacro(CompressionLevel, int);
175 
177 
183  virtual void SetBlockSize(size_t blockSize);
184  vtkGetMacro(BlockSize, size_t);
186 
188 
193  vtkSetMacro(DataMode, int);
194  vtkGetMacro(DataMode, int);
195  void SetDataModeToAscii() { this->SetDataMode(Ascii); }
196  void SetDataModeToBinary() { this->SetDataMode(Binary); }
197  void SetDataModeToAppended() { this->SetDataMode(Appended); }
199 
201 
208  vtkSetMacro(EncodeAppendedData, bool);
209  vtkGetMacro(EncodeAppendedData, bool);
210  vtkBooleanMacro(EncodeAppendedData, bool);
212 
216  virtual const char* GetDefaultFileExtension() = 0;
217 
221  int Write();
222 
223 protected:
225  ~vtkXMLWriterBase() override;
226 
227  // Methods to define the file's major and minor version numbers.
228  virtual int GetDataSetMajorVersion();
229  virtual int GetDataSetMinorVersion();
230 
231  // The name of the output file.
232  char* FileName;
233 
234  // Whether this object is writing to a string or a file.
235  // Default is 0: write to file.
237 
238  // The output string.
240 
241  // The output byte order.
243 
244  // The output binary header word type.
246 
247  // The output vtkIdType.
248  int IdType;
249 
250  // The form of binary data to write. Used by subclasses to choose
251  // how to write data.
252  int DataMode;
253 
254  // Whether to base64-encode the appended data section.
256 
257  // Compression information.
259  size_t BlockSize;
260 
261  // Compression Level for vtkDataCompressor objects
262  // 1 (worst compression, fastest) ... 9 (best compression, slowest)
264 
265  // This variable is used to ease transition to new versions of VTK XML files.
266  // If data that needs to be written satisfies certain conditions,
267  // the writer can use the previous file version version.
268  // For version change 0.1 -> 2.0 (UInt32 header) and 1.0 -> 2.0
269  // (UInt64 header), if data does not have a vtkGhostType array,
270  // the file is written with version: 0.1/1.0.
272 
273 private:
274  vtkXMLWriterBase(const vtkXMLWriterBase&) = delete;
275  void operator=(const vtkXMLWriterBase&) = delete;
276 };
277 
278 #endif
vtkXMLWriterBase::UsePreviousVersion
bool UsePreviousVersion
Definition: vtkXMLWriterBase.h:271
vtkXMLWriterBase::SetHeaderTypeToUInt32
void SetHeaderTypeToUInt32()
Get/Set the binary data header word type.
Definition: vtkXMLWriterBase.h:106
vtkXMLWriterBase::DataMode
int DataMode
Definition: vtkXMLWriterBase.h:252
vtkXMLWriterBase::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkXMLWriterBase::Ascii
@ Ascii
Definition: vtkXMLWriterBase.h:61
vtkXMLWriterBase::CompressionLevel
int CompressionLevel
Definition: vtkXMLWriterBase.h:263
vtkXMLWriterBase::BigEndian
@ BigEndian
Definition: vtkXMLWriterBase.h:49
vtkAlgorithm
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:123
vtkXMLWriterBase::SetHeaderTypeToUInt64
void SetHeaderTypeToUInt64()
Get/Set the binary data header word type.
Definition: vtkXMLWriterBase.h:107
vtkXMLWriterBase::ZLIB
@ ZLIB
Definition: vtkXMLWriterBase.h:151
vtkXMLWriterBase::IdType
int IdType
Definition: vtkXMLWriterBase.h:248
vtkXMLWriterBase::~vtkXMLWriterBase
~vtkXMLWriterBase() override
vtkXMLWriterBase::HeaderType
int HeaderType
Definition: vtkXMLWriterBase.h:245
vtkXMLWriterBase::EncodeAppendedData
bool EncodeAppendedData
Definition: vtkXMLWriterBase.h:255
vtkXMLWriterBase::SetCompressorType
void SetCompressorType(int compressorType)
Convenience functions to set the compressor to certain known types.
vtkXMLWriterBase::vtkSetFilePathMacro
vtkSetFilePathMacro(FileName)
Get/Set the name of the output file.
vtkXMLWriterBase::SetByteOrderToBigEndian
void SetByteOrderToBigEndian()
Get/Set the byte order of data written to the file.
Definition: vtkXMLWriterBase.h:95
vtkXMLWriterBase::GetDefaultFileExtension
virtual const char * GetDefaultFileExtension()=0
Get the default file extension for files written by this writer.
vtkXMLWriterBase::vtkGetFilePathMacro
vtkGetFilePathMacro(FileName)
Get/Set the name of the output file.
vtkXMLWriterBase
Abstract base class for VTK-XML writers.
Definition: vtkXMLWriterBase.h:39
vtkXMLWriterBase::vtkXMLWriterBase
vtkXMLWriterBase()
vtkXMLWriterBase::SetIdTypeToInt32
void SetIdTypeToInt32()
Get/Set the size of the vtkIdType values stored in the file.
Definition: vtkXMLWriterBase.h:117
vtkAlgorithm.h
vtkXMLWriterBase::SetCompressor
virtual void SetCompressor(vtkDataCompressor *)
Get/Set the compressor used to compress binary and appended data before writing to the file.
vtkXMLWriterBase::Binary
@ Binary
Definition: vtkXMLWriterBase.h:62
vtkXMLWriterBase::Compressor
vtkDataCompressor * Compressor
Definition: vtkXMLWriterBase.h:258
vtkXMLWriterBase::Write
int Write()
Invoke the writer.
vtkXMLWriterBase::SetCompressorTypeToLZ4
void SetCompressorTypeToLZ4()
Convenience functions to set the compressor to certain known types.
Definition: vtkXMLWriterBase.h:162
vtkXMLWriterBase::SetHeaderType
virtual void SetHeaderType(int)
Get/Set the binary data header word type.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkXMLWriterBase::SetCompressorTypeToNone
void SetCompressorTypeToNone()
Convenience functions to set the compressor to certain known types.
Definition: vtkXMLWriterBase.h:161
vtkXMLWriterBase::SetCompressionLevel
void SetCompressionLevel(int compressorLevel)
Get/Set compression level.
vtkDataCompressor
Abstract interface for data compression classes.
Definition: vtkDataCompressor.h:46
vtkXMLWriterBase::LZ4
@ LZ4
Definition: vtkXMLWriterBase.h:152
vtkXMLWriterBase::CompressorType
CompressorType
Definition: vtkXMLWriterBase.h:149
vtkXMLWriterBase::GetOutputString
std::string GetOutputString()
Enable writing to an OutputString instead of the default, a file.
Definition: vtkXMLWriterBase.h:136
vtkXMLWriterBase::SetCompressorTypeToZLib
void SetCompressorTypeToZLib()
Convenience functions to set the compressor to certain known types.
Definition: vtkXMLWriterBase.h:163
vtkXMLWriterBase::WriteToOutputString
bool WriteToOutputString
Definition: vtkXMLWriterBase.h:236
vtkXMLWriterBase::OutputString
std::string OutputString
Definition: vtkXMLWriterBase.h:239
vtkXMLWriterBase::FileName
char * FileName
Definition: vtkXMLWriterBase.h:232
vtkXMLWriterBase::SetDataModeToBinary
void SetDataModeToBinary()
Get/Set the data mode used for the file's data.
Definition: vtkXMLWriterBase.h:196
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkXMLWriterBase::SetDataModeToAppended
void SetDataModeToAppended()
Get/Set the data mode used for the file's data.
Definition: vtkXMLWriterBase.h:197
vtkXMLWriterBase::SetCompressorTypeToLZMA
void SetCompressorTypeToLZMA()
Convenience functions to set the compressor to certain known types.
Definition: vtkXMLWriterBase.h:164
vtkXMLWriterBase::SetByteOrderToLittleEndian
void SetByteOrderToLittleEndian()
Get/Set the byte order of data written to the file.
Definition: vtkXMLWriterBase.h:96
vtkXMLWriterBase::ByteOrder
int ByteOrder
Definition: vtkXMLWriterBase.h:242
vtkXMLWriterBase::SetBlockSize
virtual void SetBlockSize(size_t blockSize)
Get/Set the block size used in compression.
vtkXMLWriterBase::GetDataSetMinorVersion
virtual int GetDataSetMinorVersion()
vtkXMLWriterBase::GetDataSetMajorVersion
virtual int GetDataSetMajorVersion()
vtkXMLWriterBase::NONE
@ NONE
Definition: vtkXMLWriterBase.h:150
vtkXMLWriterBase::BlockSize
size_t BlockSize
Definition: vtkXMLWriterBase.h:259
vtkXMLWriterBase::SetDataModeToAscii
void SetDataModeToAscii()
Get/Set the data mode used for the file's data.
Definition: vtkXMLWriterBase.h:195
vtkXMLWriterBase::SetIdType
virtual void SetIdType(int)
Get/Set the size of the vtkIdType values stored in the file.
vtkXMLWriterBase::SetIdTypeToInt64
void SetIdTypeToInt64()
Get/Set the size of the vtkIdType values stored in the file.
Definition: vtkXMLWriterBase.h:118