VTK  9.6.1
vtkXMLWriter.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
20
21#ifndef vtkXMLWriter_h
22#define vtkXMLWriter_h
23
24#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_5_0
25#include "vtkIOXMLModule.h" // For export macro
26#include "vtkXMLWriterBase.h"
27
28#include <sstream> // For ostringstream ivar
29
30VTK_ABI_NAMESPACE_BEGIN
33
34template <class T>
36
37class vtkCellData;
38class vtkDataArray;
40class vtkDataSet;
42class vtkFieldData;
43class vtkOutputStream;
44class vtkPointData;
45class vtkPoints;
46class vtkFieldData;
48
49class vtkStdString;
50class OffsetsManager; // one per piece/per time
51class OffsetsManagerGroup; // array of OffsetsManager
52class OffsetsManagerArray; // array of OffsetsManagerGroup
53
54class VTKIOXML_EXPORT vtkXMLWriter : public vtkXMLWriterBase
55{
56public:
58 void PrintSelf(ostream& os, vtkIndent indent) override;
59
61
69 vtkDataObject* GetInput() { return this->GetInput(0); }
71
72 // See the vtkAlgorithm for a description of what these do
74 vtkInformationVector* outputVector) override;
75
77
80 vtkGetMacro(NumberOfTimeSteps, int);
81 vtkSetMacro(NumberOfTimeSteps, int);
83
85
88 void Start();
89 void Stop();
90 void WriteNextTime(double time);
92
94
103 vtkSetClampMacro(Precision, int, 0, 17);
104 vtkGetMacro(Precision, int);
106
107protected:
109 ~vtkXMLWriter() override;
110
111 virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
112 vtkInformationVector* outputVector);
113 virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
114 vtkInformationVector* outputVector);
115
116 // The output stream to which the XML is written.
117 ostream* Stream;
118
119 // The stream position at which appended data starts.
121
122 // appended data offsets for field data
124
125 // We need a 32 bit signed integer type to which vtkIdType will be
126 // converted if Int32 is specified for the IdType parameter to this
127 // writer.
128#if VTK_SIZEOF_SHORT == 4
129 typedef short Int32IdType;
130#elif VTK_SIZEOF_INT == 4
131 typedef int Int32IdType;
132#elif VTK_SIZEOF_LONG == 4
133 typedef long Int32IdType;
134#else
135#error "No native data type can represent a signed 32-bit integer."
136#endif
137
138 // Buffer for vtkIdType conversion.
139 Int32IdType* Int32IdTypeBuffer;
140
141 // The byte swapping buffer.
142 unsigned char* ByteSwapBuffer;
143
144 // Compression information.
148
149 // The output stream used to write binary and appended data. May
150 // transparently encode the data.
152
153 // Allow subclasses to set the data stream.
155 vtkGetObjectMacro(DataStream, vtkOutputStream);
156
157 // Method to drive most of actual writing.
158 virtual int WriteInternal();
159
160 // Method defined by subclasses to write data. Return 1 for
161 // success, 0 for failure.
162 virtual int WriteData() { return 1; }
163
164 // Method defined by subclasses to specify the data set's type name.
165 virtual const char* GetDataSetName() = 0;
166
167 // Utility methods for subclasses.
169 VTK_DEPRECATED_IN_9_5_0("Use GetDataSetInput() instead.")
171 virtual int StartFile();
172 virtual void WriteFileAttributes();
173 virtual int EndFile();
175 void DeleteAFile(const char* name);
176
177 virtual int WritePrimaryElement(ostream& os, vtkIndent indent);
178 virtual void WritePrimaryElementAttributes(ostream& os, vtkIndent indent);
181
182 // Write enough space to go back and write the given attribute with
183 // at most "length" characters in the value. Returns the stream
184 // position at which attribute should be later written. The default
185 // length of 20 is enough for a 64-bit integer written in decimal or
186 // a double-precision floating point value written to 13 digits of
187 // precision (the other 7 come from a minus sign, decimal place, and
188 // a big exponent like "e+300").
189 vtkTypeInt64 ReserveAttributeSpace(const char* attr, size_t length = 20);
190
191 vtkTypeInt64 GetAppendedDataOffset();
193 vtkTypeInt64 streamPos, vtkTypeInt64& lastoffset, const char* attr = nullptr);
195 vtkTypeInt64 streamPos, vtkTypeInt64 offset, const char* attr = nullptr);
196 void ForwardAppendedDataDouble(vtkTypeInt64 streamPos, double value, const char* attr);
197
198 int WriteScalarAttribute(const char* name, int data);
199 int WriteScalarAttribute(const char* name, float data);
200 int WriteScalarAttribute(const char* name, double data);
201#ifdef VTK_USE_64BIT_IDS
202 int WriteScalarAttribute(const char* name, vtkIdType data);
203#endif
204
205 int WriteVectorAttribute(const char* name, int length, int* data);
206 int WriteVectorAttribute(const char* name, int length, float* data);
207 int WriteVectorAttribute(const char* name, int length, double* data);
208#ifdef VTK_USE_64BIT_IDS
209 int WriteVectorAttribute(const char* name, int length, vtkIdType* data);
210#endif
211
212 int WriteDataModeAttribute(const char* name);
213 int WriteWordTypeAttribute(const char* name, int dataType);
214 int WriteStringAttribute(const char* name, const char* value);
215
216 // Returns true if any keys were written.
218
219 void WriteArrayHeader(vtkAbstractArray* a, vtkIndent indent, const char* alternateName,
220 int writeNumTuples, int timestep);
221 virtual void WriteArrayFooter(
222 ostream& os, vtkIndent indent, vtkAbstractArray* a, int shortFormat);
224 const char* alternateName = nullptr, int writeNumTuples = 0);
226
228 const char* alternateName = nullptr, int writeNumTuples = 0, int timestep = 0);
232 void WriteArrayAppendedData(vtkAbstractArray* a, vtkTypeInt64 pos, vtkTypeInt64& lastoffset);
233
234 // Methods for writing points, point data, and cell data.
244 void WriteCellDataAppendedData(vtkCellData* cd, int timestep, OffsetsManagerGroup* cdManager);
246 void WritePointsAppended(vtkPoints* points, vtkIndent indent, OffsetsManager* manager);
247 void WritePointsAppendedData(vtkPoints* points, int timestep, OffsetsManager* pdManager);
248 void WritePointsInline(vtkPoints* points, vtkIndent indent);
250 vtkDataArray* xc, vtkDataArray* yc, vtkDataArray* zc, vtkIndent indent);
252 vtkIndent indent, OffsetsManagerGroup* coordManager);
254 int timestep, OffsetsManagerGroup* coordManager);
257 void WritePPoints(vtkPoints* points, vtkIndent indent);
258 void WritePArray(vtkAbstractArray* a, vtkIndent indent, const char* alternateName = nullptr);
260
261 // Internal utility methods.
262 int WriteBinaryDataBlock(unsigned char* in_data, size_t numWords, int wordType);
263 void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
264 int CreateCompressionHeader(size_t size);
265 int WriteCompressionBlock(unsigned char* data, size_t size);
267 size_t GetWordTypeSize(int dataType);
268 const char* GetWordTypeName(int dataType);
269 size_t GetOutputWordTypeSize(int dataType);
270
271 char** CreateStringArray(int numStrings);
272 void DestroyStringArray(int numStrings, char** strings);
273
274 // The current range over which progress is moving. This allows for
275 // incrementally fine-tuned progress updates.
276 virtual void GetProgressRange(float range[2]);
277 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
278 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
279 virtual void SetProgressPartial(float fraction);
280 virtual void UpdateProgressDiscrete(float progress);
282
283 // This shallows copy input field data to the passed field data and
284 // then adds any additional field arrays. For example, TimeValue.
286
287 ostream* OutFile;
288 std::ostringstream* OutStringStream;
289
291 int OpenFile();
294 void CloseFile();
296
297 // The timestep currently being written
300
301 // Dummy boolean var to start/stop the continue executing:
302 // when using the Start/Stop/WriteNextTime API
303 int UserContinueExecuting; // can only be -1 = invalid, 0 = stop, 1 = start
304
305 vtkTypeInt64* NumberOfTimeValues; // one per piece / per timestep
307
308 friend class vtkXMLWriterHelper;
309
310private:
311 vtkXMLWriter(const vtkXMLWriter&) = delete;
312 void operator=(const vtkXMLWriter&) = delete;
313};
314
315VTK_ABI_NAMESPACE_END
316#endif
Helper class due to PIMPL excess.
Abstract superclass for all arrays.
Implementation template for a array iterator.
Abstract superclass to iterate over elements in an vtkAbstractArray.
represent and manipulate cell attribute data
Definition vtkCellData.h:32
Abstract interface for data compression classes.
general representation of visualization data
represent and manipulate attribute data in a dataset
abstract class to specify dataset behavior
Definition vtkDataSet.h:57
Represents and manipulates a collection of data arrays.
a simple class to control print indentation
Definition vtkIndent.h:29
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Wraps a binary output stream with a VTK interface.
represent and manipulate point attribute data
represent and manipulate 3D points
Definition vtkPoints.h:30
Wrapper around std::string to keep symbols short.
void EndAppendedData()
int WriteBinaryDataInternal(vtkAbstractArray *a)
int WriteBinaryDataBlock(unsigned char *in_data, size_t numWords, int wordType)
void WriteFieldData(vtkIndent indent)
void SetInputData(vtkDataObject *)
Assign a data object as input.
virtual const char * GetDataSetName()=0
friend class vtkXMLWriterHelper
void Stop()
API to interface an outside the VTK pipeline control.
ostream * OutFile
int WriteBinaryData(vtkAbstractArray *a)
unsigned char * ByteSwapBuffer
void WritePCellData(vtkCellData *cd, vtkIndent indent)
int UserContinueExecuting
void WriteArrayAppendedData(vtkAbstractArray *a, vtkTypeInt64 pos, vtkTypeInt64 &lastoffset)
int WriteCompressionHeader()
void WriteFieldDataAppendedData(vtkFieldData *fd, int timestep, OffsetsManagerGroup *fdManager)
int WriteScalarAttribute(const char *name, int data)
void DestroyStringArray(int numStrings, char **strings)
vtkXMLDataHeader * CompressionHeader
void ForwardAppendedDataDouble(vtkTypeInt64 streamPos, double value, const char *attr)
void WritePointDataAppended(vtkPointData *pd, vtkIndent indent, OffsetsManagerGroup *pdManager)
void DeleteAFile()
void WritePPointData(vtkPointData *pd, vtkIndent indent)
vtkDataSet * GetInputAsDataSet()
void WritePPoints(vtkPoints *points, vtkIndent indent)
vtkDataObject * GetInput()
Assign a data object as input.
vtkTypeInt64 AppendedDataPosition
void WriteFieldDataAppended(vtkFieldData *fd, vtkIndent indent, OffsetsManagerGroup *fdManager)
int WriteStringAttribute(const char *name, const char *value)
bool WriteInformation(vtkInformation *info, vtkIndent indent)
~vtkXMLWriter() override
char ** CreateStringArray(int numStrings)
virtual int WriteData()
int WriteCompressionBlock(unsigned char *data, size_t size)
size_t GetOutputWordTypeSize(int dataType)
void UpdateFieldData(vtkFieldData *)
std::ostringstream * OutStringStream
int WriteVectorAttribute(const char *name, int length, int *data)
void SetInputData(int, vtkDataObject *)
Assign a data object as input.
virtual void UpdateProgressDiscrete(float progress)
virtual int EndFile()
void ForwardAppendedDataOffset(vtkTypeInt64 streamPos, vtkTypeInt64 offset, const char *attr=nullptr)
void WritePointsAppended(vtkPoints *points, vtkIndent indent, OffsetsManager *manager)
int WriteVectorAttribute(const char *name, int length, float *data)
int WriteDataModeAttribute(const char *name)
void WritePArray(vtkAbstractArray *a, vtkIndent indent, const char *alternateName=nullptr)
void Start()
API to interface an outside the VTK pipeline control.
void WritePointsAppendedData(vtkPoints *points, int timestep, OffsetsManager *pdManager)
void WriteCoordinatesAppendedData(vtkDataArray *xc, vtkDataArray *yc, vtkDataArray *zc, int timestep, OffsetsManagerGroup *coordManager)
Int32IdType * Int32IdTypeBuffer
void WriteArrayHeader(vtkAbstractArray *a, vtkIndent indent, const char *alternateName, int writeNumTuples, int timestep)
virtual void WriteArrayInline(vtkAbstractArray *a, vtkIndent indent, const char *alternateName=nullptr, int writeNumTuples=0)
void WritePointsInline(vtkPoints *points, vtkIndent indent)
virtual void SetProgressRange(const float range[2], int curStep, const float *fractions)
vtkTypeInt64 GetAppendedDataOffset()
void WriteCellDataAppendedData(vtkCellData *cd, int timestep, OffsetsManagerGroup *cdManager)
virtual void SetDataStream(vtkOutputStream *)
int WriteVectorAttribute(const char *name, int length, double *data)
vtkTypeBool ProcessRequest(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Upstream/Downstream requests form the generalized interface through which executives invoke a algorit...
int WriteScalarAttribute(const char *name, double data)
void WriteCellDataAppended(vtkCellData *cd, vtkIndent indent, OffsetsManagerGroup *cdManager)
virtual void WriteFileAttributes()
void CloseStream()
void WritePCoordinates(vtkDataArray *xc, vtkDataArray *yc, vtkDataArray *zc, vtkIndent indent)
void WriteCoordinatesInline(vtkDataArray *xc, vtkDataArray *yc, vtkDataArray *zc, vtkIndent indent)
vtkTypeInt64 * NumberOfTimeValues
void WriteCoordinatesAppended(vtkDataArray *xc, vtkDataArray *yc, vtkDataArray *zc, vtkIndent indent, OffsetsManagerGroup *coordManager)
size_t CompressionBlockNumber
vtkOutputStream * DataStream
void WriteFieldDataInline(vtkFieldData *fd, vtkIndent indent)
void CloseFile()
void WritePointDataInline(vtkPointData *pd, vtkIndent indent)
int OpenStream()
vtkDataSet * GetDataSetInput()
void WriteArrayAppended(vtkAbstractArray *a, vtkIndent indent, OffsetsManager &offs, const char *alternateName=nullptr, int writeNumTuples=0, int timestep=0)
ostream * Stream
OffsetsManagerGroup * FieldDataOM
int OpenString()
virtual void GetProgressRange(float range[2])
vtkTypeInt64 ReserveAttributeSpace(const char *attr, size_t length=20)
virtual void SetProgressRange(const float range[2], int curStep, int numSteps)
virtual void WriteInlineData(vtkAbstractArray *a, vtkIndent indent)
int CreateCompressionHeader(size_t size)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual int WritePrimaryElement(ostream &os, vtkIndent indent)
virtual void SetProgressPartial(float fraction)
virtual int StartFile()
float ProgressRange[2]
int WriteScalarAttribute(const char *name, float data)
void WriteNextTime(double time)
API to interface an outside the VTK pipeline control.
void DeleteAFile(const char *name)
const char * GetWordTypeName(int dataType)
void WritePointDataAppendedData(vtkPointData *pd, int timestep, OffsetsManagerGroup *pdManager)
void StartAppendedData()
void CloseString()
vtkTypeInt64 CompressionHeaderPosition
void WriteAppendedDataOffset(vtkTypeInt64 streamPos, vtkTypeInt64 &lastoffset, const char *attr=nullptr)
vtkDataObject * GetInput(int port)
Assign a data object as input.
void WriteAttributeIndices(vtkDataSetAttributes *dsa, char **names)
int WriteAsciiData(vtkAbstractArray *a, vtkIndent indent)
virtual void WriteArrayFooter(ostream &os, vtkIndent indent, vtkAbstractArray *a, int shortFormat)
size_t GetWordTypeSize(int dataType)
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
virtual void WritePrimaryElementAttributes(ostream &os, vtkIndent indent)
virtual int WriteInternal()
void WriteCellDataInline(vtkCellData *cd, vtkIndent indent)
int WriteWordTypeAttribute(const char *name, int dataType)
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
void PerformByteSwap(void *data, size_t numWords, size_t wordSize)
int vtkTypeBool
Definition vtkABI.h:64
#define vtkDataArray
#define VTK_DEPRECATED_IN_9_5_0(reason)
int vtkIdType
Definition vtkType.h:368