VTK  9.1.0
vtkXMLWriter.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkXMLWriter.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=========================================================================*/
30#ifndef vtkXMLWriter_h
31#define vtkXMLWriter_h
32
33#include "vtkIOXMLModule.h" // For export macro
34#include "vtkXMLWriterBase.h"
35
36#include <sstream> // For ostringstream ivar
37
40
41template <class T>
43
44class vtkCellData;
45class vtkDataArray;
47class vtkDataSet;
49class vtkFieldData;
50class vtkOutputStream;
51class vtkPointData;
52class vtkPoints;
53class vtkFieldData;
55
56class vtkStdString;
57class OffsetsManager; // one per piece/per time
58class OffsetsManagerGroup; // array of OffsetsManager
59class OffsetsManagerArray; // array of OffsetsManagerGroup
60
61class VTKIOXML_EXPORT vtkXMLWriter : public vtkXMLWriterBase
62{
63public:
65 void PrintSelf(ostream& os, vtkIndent indent) override;
66
68
76 vtkDataObject* GetInput() { return this->GetInput(0); }
78
79 // See the vtkAlgorithm for a description of what these do
81 vtkInformationVector* outputVector) override;
82
84
87 vtkGetMacro(NumberOfTimeSteps, int);
88 vtkSetMacro(NumberOfTimeSteps, int);
90
92
95 void Start();
96 void Stop();
97 void WriteNextTime(double time);
99
100protected:
102 ~vtkXMLWriter() override;
103
104 virtual int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
105 vtkInformationVector* outputVector);
106 virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
107 vtkInformationVector* outputVector);
108
109 // The output stream to which the XML is written.
110 ostream* Stream;
111
112 // The stream position at which appended data starts.
114
115 // appended data offsets for field data
117
118 // We need a 32 bit signed integer type to which vtkIdType will be
119 // converted if Int32 is specified for the IdType parameter to this
120 // writer.
121#if VTK_SIZEOF_SHORT == 4
122 typedef short Int32IdType;
123#elif VTK_SIZEOF_INT == 4
124 typedef int Int32IdType;
125#elif VTK_SIZEOF_LONG == 4
126 typedef long Int32IdType;
127#else
128#error "No native data type can represent a signed 32-bit integer."
129#endif
130
131 // Buffer for vtkIdType conversion.
132 Int32IdType* Int32IdTypeBuffer;
133
134 // The byte swapping buffer.
135 unsigned char* ByteSwapBuffer;
136
137 // Compression information.
141
142 // The output stream used to write binary and appended data. May
143 // transparently encode the data.
145
146 // Allow subclasses to set the data stream.
148 vtkGetObjectMacro(DataStream, vtkOutputStream);
149
150 // Method to drive most of actual writing.
151 virtual int WriteInternal();
152
153 // Method defined by subclasses to write data. Return 1 for
154 // success, 0 for failure.
155 virtual int WriteData() { return 1; }
156
157 // Method defined by subclasses to specify the data set's type name.
158 virtual const char* GetDataSetName() = 0;
159
160 // Utility methods for subclasses.
162 virtual int StartFile();
163 virtual void WriteFileAttributes();
164 virtual int EndFile();
166 void DeleteAFile(const char* name);
167
168 virtual int WritePrimaryElement(ostream& os, vtkIndent indent);
169 virtual void WritePrimaryElementAttributes(ostream& os, vtkIndent indent);
172
173 // Write enough space to go back and write the given attribute with
174 // at most "length" characters in the value. Returns the stream
175 // position at which attribute should be later written. The default
176 // length of 20 is enough for a 64-bit integer written in decimal or
177 // a double-precision floating point value written to 13 digits of
178 // precision (the other 7 come from a minus sign, decimal place, and
179 // a big exponent like "e+300").
180 vtkTypeInt64 ReserveAttributeSpace(const char* attr, size_t length = 20);
181
182 vtkTypeInt64 GetAppendedDataOffset();
184 vtkTypeInt64 streamPos, vtkTypeInt64& lastoffset, const char* attr = nullptr);
186 vtkTypeInt64 streamPos, vtkTypeInt64 offset, const char* attr = nullptr);
187 void ForwardAppendedDataDouble(vtkTypeInt64 streamPos, double value, const char* attr);
188
189 int WriteScalarAttribute(const char* name, int data);
190 int WriteScalarAttribute(const char* name, float data);
191 int WriteScalarAttribute(const char* name, double data);
192#ifdef VTK_USE_64BIT_IDS
193 int WriteScalarAttribute(const char* name, vtkIdType data);
194#endif
195
196 int WriteVectorAttribute(const char* name, int length, int* data);
197 int WriteVectorAttribute(const char* name, int length, float* data);
198 int WriteVectorAttribute(const char* name, int length, double* data);
199#ifdef VTK_USE_64BIT_IDS
200 int WriteVectorAttribute(const char* name, int length, vtkIdType* data);
201#endif
202
203 int WriteDataModeAttribute(const char* name);
204 int WriteWordTypeAttribute(const char* name, int dataType);
205 int WriteStringAttribute(const char* name, const char* value);
206
207 // Returns true if any keys were written.
209
210 void WriteArrayHeader(vtkAbstractArray* a, vtkIndent indent, const char* alternateName,
211 int writeNumTuples, int timestep);
212 virtual void WriteArrayFooter(
213 ostream& os, vtkIndent indent, vtkAbstractArray* a, int shortFormat);
215 const char* alternateName = nullptr, int writeNumTuples = 0);
217
219 const char* alternateName = nullptr, int writeNumTuples = 0, int timestep = 0);
223 void WriteArrayAppendedData(vtkAbstractArray* a, vtkTypeInt64 pos, vtkTypeInt64& lastoffset);
224
225 // Methods for writing points, point data, and cell data.
235 void WriteCellDataAppendedData(vtkCellData* cd, int timestep, OffsetsManagerGroup* cdManager);
238 void WritePointsAppendedData(vtkPoints* points, int timestep, OffsetsManager* pdManager);
241 vtkDataArray* xc, vtkDataArray* yc, vtkDataArray* zc, vtkIndent indent);
243 vtkIndent indent, OffsetsManagerGroup* coordManager);
245 int timestep, OffsetsManagerGroup* coordManager);
249 void WritePArray(vtkAbstractArray* a, vtkIndent indent, const char* alternateName = nullptr);
251
252 // Internal utility methods.
253 int WriteBinaryDataBlock(unsigned char* in_data, size_t numWords, int wordType);
254 void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
256 int WriteCompressionBlock(unsigned char* data, size_t size);
258 size_t GetWordTypeSize(int dataType);
259 const char* GetWordTypeName(int dataType);
260 size_t GetOutputWordTypeSize(int dataType);
261
262 char** CreateStringArray(int numStrings);
263 void DestroyStringArray(int numStrings, char** strings);
264
265 // The current range over which progress is moving. This allows for
266 // incrementally fine-tuned progress updates.
267 virtual void GetProgressRange(float range[2]);
268 virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
269 virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
270 virtual void SetProgressPartial(float fraction);
271 virtual void UpdateProgressDiscrete(float progress);
272 float ProgressRange[2];
273
274 // This shallows copy input field data to the passed field data and
275 // then adds any additional field arrays. For example, TimeValue.
277
278 ostream* OutFile;
279 std::ostringstream* OutStringStream;
280
282 int OpenFile();
285 void CloseFile();
287
288 // The timestep currently being written
291
292 // Dummy boolean var to start/stop the continue executing:
293 // when using the Start/Stop/WriteNextTime API
294 int UserContinueExecuting; // can only be -1 = invalid, 0 = stop, 1 = start
295
296 vtkTypeInt64* NumberOfTimeValues; // one per piece / per timestep
297
298 friend class vtkXMLWriterHelper;
299
300private:
301 vtkXMLWriter(const vtkXMLWriter&) = delete;
302 void operator=(const vtkXMLWriter&) = delete;
303};
304
305#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:142
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
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:166
represent and manipulate fields of data
Definition: vtkFieldData.h:164
a simple class to control print indentation
Definition: vtkIndent.h:113
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
Definition: vtkPointData.h:142
represent and manipulate 3D points
Definition: vtkPoints.h:143
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:105
Abstract base class for VTK-XML writers.
Superclass for VTK's XML file writers.
Definition: vtkXMLWriter.h:62
void EndAppendedData()
int WriteBinaryDataInternal(vtkAbstractArray *a)
int CurrentTimeIndex
Definition: vtkXMLWriter.h:289
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
void Stop()
API to interface an outside the VTK pipeline control.
ostream * OutFile
Definition: vtkXMLWriter.h:278
int WriteBinaryData(vtkAbstractArray *a)
unsigned char * ByteSwapBuffer
Definition: vtkXMLWriter.h:135
void WritePCellData(vtkCellData *cd, vtkIndent indent)
int UserContinueExecuting
Definition: vtkXMLWriter.h:294
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
Definition: vtkXMLWriter.h:139
void ForwardAppendedDataDouble(vtkTypeInt64 streamPos, double value, const char *attr)
void WritePointDataAppended(vtkPointData *pd, vtkIndent indent, OffsetsManagerGroup *pdManager)
int NumberOfTimeSteps
Definition: vtkXMLWriter.h:290
void DeleteAFile()
void WritePPointData(vtkPointData *pd, vtkIndent indent)
vtkDataSet * GetInputAsDataSet()
void WritePPoints(vtkPoints *points, vtkIndent indent)
vtkDataObject * GetInput()
Assign a data object as input.
Definition: vtkXMLWriter.h:76
vtkTypeInt64 AppendedDataPosition
Definition: vtkXMLWriter.h:113
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()
Definition: vtkXMLWriter.h:155
int WriteCompressionBlock(unsigned char *data, size_t size)
size_t GetOutputWordTypeSize(int dataType)
void UpdateFieldData(vtkFieldData *)
std::ostringstream * OutStringStream
Definition: vtkXMLWriter.h:279
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
Definition: vtkXMLWriter.h:132
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
Definition: vtkXMLWriter.h:296
void WriteCoordinatesAppended(vtkDataArray *xc, vtkDataArray *yc, vtkDataArray *zc, vtkIndent indent, OffsetsManagerGroup *coordManager)
size_t CompressionBlockNumber
Definition: vtkXMLWriter.h:138
vtkOutputStream * DataStream
Definition: vtkXMLWriter.h:144
void WriteFieldDataInline(vtkFieldData *fd, vtkIndent indent)
void CloseFile()
void WritePointDataInline(vtkPointData *pd, vtkIndent indent)
int OpenStream()
void WriteArrayAppended(vtkAbstractArray *a, vtkIndent indent, OffsetsManager &offs, const char *alternateName=nullptr, int writeNumTuples=0, int timestep=0)
ostream * Stream
Definition: vtkXMLWriter.h:110
OffsetsManagerGroup * FieldDataOM
Definition: vtkXMLWriter.h:116
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()
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
Definition: vtkXMLWriter.h:140
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)
@ points
Definition: vtkX3D.h:452
@ info
Definition: vtkX3D.h:382
@ length
Definition: vtkX3D.h:399
@ value
Definition: vtkX3D.h:226
@ port
Definition: vtkX3D.h:453
@ range
Definition: vtkX3D.h:244
@ time
Definition: vtkX3D.h:503
@ name
Definition: vtkX3D.h:225
@ size
Definition: vtkX3D.h:259
@ offset
Definition: vtkX3D.h:444
@ progress
Definition: vtkX3D.h:458
@ data
Definition: vtkX3D.h:321
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:332