1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
/**
* @class vtkXMLWriterBase
* @brief Abstract base class for VTK-XML writers.
*
* vtkXMLWriterBase class was created to help refactor XML writers
* (vtkXMLWriter and subclasses). Get/Set API on vtkXMLWriter is moved here while
* all the gory implementation details are left in vtkXMLWriter. This enables use to create
* a sibling hierarchy to vtkXMLWriter that uses a cleaner design to implement
* the IO capabilities. Eventually, we vtkXMLWriter and its children will be
* substituted by a parallel hierarchy at which point this class may merge with
* it's new subclass.
*/
#ifndef vtkXMLWriterBase_h
#define vtkXMLWriterBase_h
#include "vtkAlgorithm.h"
#include "vtkIOXMLModule.h" // For export macro
#include <string> // for std::string
VTK_ABI_NAMESPACE_BEGIN
class vtkDataCompressor;
class VTKIOXML_EXPORT vtkXMLWriterBase : public vtkAlgorithm
{
public:
vtkTypeMacro(vtkXMLWriterBase, vtkAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Enumerate big and little endian byte order settings.
*/
enum
{
BigEndian,
LittleEndian
};
/**
* Enumerate the supported data modes.
* Ascii = Inline ascii data.
* Binary = Inline binary data (base64 encoded, possibly compressed).
* Appended = Appended binary data (possibly compressed and/or base64).
*/
enum
{
Ascii,
Binary,
Appended
};
/**
* Enumerate the supported vtkIdType bit lengths.
* Int32 = File stores 32-bit values for vtkIdType.
* Int64 = File stores 64-bit values for vtkIdType.
*/
enum
{
Int32 = 32,
Int64 = 64
};
/**
* Enumerate the supported binary data header bit lengths.
* UInt32 = File stores 32-bit binary data header elements.
* UInt64 = File stores 64-bit binary data header elements.
*/
enum
{
UInt32 = 32,
UInt64 = 64
};
///@{
/**
* Get/Set the byte order of data written to the file. The default
* is the machine's hardware byte order.
*/
vtkSetMacro(ByteOrder, int);
vtkGetMacro(ByteOrder, int);
void SetByteOrderToBigEndian() { this->SetByteOrder(BigEndian); }
void SetByteOrderToLittleEndian() { this->SetByteOrder(LittleEndian); }
///@}
///@{
/**
* Get/Set the binary data header word type. The default is UInt32.
* Set to UInt64 when storing arrays requiring 64-bit indexing.
*/
virtual void SetHeaderType(int);
vtkGetMacro(HeaderType, int);
void SetHeaderTypeToUInt32() { this->SetHeaderType(UInt32); }
void SetHeaderTypeToUInt64() { this->SetHeaderType(UInt64); }
///@}
///@{
/**
* Get/Set the size of the vtkIdType values stored in the file. The
* default is the real size of vtkIdType.
*/
virtual void SetIdType(int);
vtkGetMacro(IdType, int);
void SetIdTypeToInt32() { this->SetIdType(Int32); }
void SetIdTypeToInt64() { this->SetIdType(Int64); }
///@}
///@{
/**
* Get/Set the name of the output file.
*/
vtkSetFilePathMacro(FileName);
vtkGetFilePathMacro(FileName);
///@}
///@{
/**
* Enable writing to an OutputString instead of the default, a file.
*/
vtkSetMacro(WriteToOutputString, bool);
vtkGetMacro(WriteToOutputString, bool);
vtkBooleanMacro(WriteToOutputString, bool);
std::string GetOutputString() { return this->OutputString; }
///@}
///@{
/**
* Get/Set the compressor used to compress binary and appended data
* before writing to the file. Default is a vtkZLibDataCompressor.
*/
virtual void SetCompressor(vtkDataCompressor*);
vtkGetObjectMacro(Compressor, vtkDataCompressor);
///@}
enum CompressorType
{
NONE,
ZLIB,
LZ4,
LZMA
};
///@{
/**
* Convenience functions to set the compressor to certain known types.
*/
void SetCompressorType(int compressorType);
void SetCompressorTypeToNone() { this->SetCompressorType(NONE); }
void SetCompressorTypeToLZ4() { this->SetCompressorType(LZ4); }
void SetCompressorTypeToZLib() { this->SetCompressorType(ZLIB); }
void SetCompressorTypeToLZMA() { this->SetCompressorType(LZMA); }
///@}
///@{
/**
* Get/Set compression level.
* 1 (worst compression, fastest) ... 9 (best compression, slowest).
*/
void SetCompressionLevel(int compressorLevel);
vtkGetMacro(CompressionLevel, int);
///@}
///@{
/**
* Get/Set the block size used in compression. When reading, this
* controls the granularity of how much extra information must be
* read when only part of the data are requested. The value should
* be a multiple of the largest scalar data type.
*/
virtual void SetBlockSize(size_t blockSize);
vtkGetMacro(BlockSize, size_t);
///@}
///@{
/**
* Get/Set the data mode used for the file's data. The options are
* vtkXMLWriter::Ascii, vtkXMLWriter::Binary, and
* vtkXMLWriter::Appended.
*/
vtkSetMacro(DataMode, int);
vtkGetMacro(DataMode, int);
void SetDataModeToAscii() { this->SetDataMode(Ascii); }
void SetDataModeToBinary() { this->SetDataMode(Binary); }
void SetDataModeToAppended() { this->SetDataMode(Appended); }
///@}
///@{
/**
* Get/Set whether the appended data section is base64 encoded. If
* encoded, reading and writing will be slower, but the file will be
* fully valid XML and text-only. If not encoded, the XML
* specification will be violated, but reading and writing will be
* fast. The default is to do the encoding.
*/
vtkSetMacro(EncodeAppendedData, bool);
vtkGetMacro(EncodeAppendedData, bool);
vtkBooleanMacro(EncodeAppendedData, bool);
///@}
///@{
/**
* Control whether to write "TimeValue" field data.
* This TimeValue is the current time value in the pipeline information
* key at the time of writing. Default to true.
*/
vtkGetMacro(WriteTimeValue, bool);
vtkSetMacro(WriteTimeValue, bool);
vtkBooleanMacro(WriteTimeValue, bool);
///@}
/**
* Get the default file extension for files written by this writer.
*/
virtual const char* GetDefaultFileExtension() = 0;
/**
* Invoke the writer. Returns 1 for success, 0 for failure.
*/
VTK_UNBLOCKTHREADS
int Write();
protected:
vtkXMLWriterBase();
~vtkXMLWriterBase() override;
// Methods to define the file's major and minor version numbers.
virtual int GetDataSetMajorVersion();
virtual int GetDataSetMinorVersion();
// The name of the output file.
char* FileName;
// Whether this object is writing to a string or a file.
// Default is 0: write to file.
bool WriteToOutputString;
// The output string.
std::string OutputString;
// The output byte order.
int ByteOrder;
// The output binary header word type.
int HeaderType;
// The output vtkIdType.
int IdType;
// The form of binary data to write. Used by subclasses to choose
// how to write data.
int DataMode;
// Whether to base64-encode the appended data section.
bool EncodeAppendedData;
// Compression information.
vtkDataCompressor* Compressor;
size_t BlockSize;
// Compression Level for vtkDataCompressor objects
// 1 (worst compression, fastest) ... 9 (best compression, slowest)
int CompressionLevel;
// This variable is used to ease transition to new versions of VTK XML files.
// If data that needs to be written satisfies certain conditions,
// the writer can use the previous file version version.
// For version change 0.1 -> 2.0 (UInt32 header) and 1.0 -> 2.0
// (UInt64 header), if data does not have a vtkGhostType array,
// the file is written with version: 0.1/1.0.
bool UsePreviousVersion;
private:
vtkXMLWriterBase(const vtkXMLWriterBase&) = delete;
void operator=(const vtkXMLWriterBase&) = delete;
bool WriteTimeValue = true;
};
VTK_ABI_NAMESPACE_END
#endif
|