VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 =========================================================================*/
24 #ifndef __vtkXMLWriter_h
25 #define __vtkXMLWriter_h
26 
27 #include "vtkIOXMLModule.h" // For export macro
28 #include "vtkAlgorithm.h"
29 
30 class vtkAbstractArray;
31 class vtkArrayIterator;
32 //BTX
33 template <class T> class vtkArrayIteratorTemplate;
34 //ETX
35 class vtkCellData;
36 class vtkDataArray;
37 class vtkDataCompressor;
38 class vtkDataSet;
40 class vtkOutputStream;
41 class vtkPointData;
42 class vtkPoints;
43 class vtkFieldData;
44 class vtkXMLDataHeader;
45 //BTX
46 class vtkStdString;
47 class OffsetsManager; // one per piece/per time
48 class OffsetsManagerGroup; // array of OffsetsManager
49 class OffsetsManagerArray; // array of OffsetsManagerGroup
50 //ETX
51 
53 {
54 public:
56  void PrintSelf(ostream& os, vtkIndent indent);
57 
58  //BTX
60 
61  enum { BigEndian, LittleEndian };
62  //ETX
64 
65  //BTX
67 
70  enum { Ascii, Binary, Appended };
71  //ETX
73 
74  //BTX
78  enum { Int32=32, Int64=64 };
79 
81 
84  enum { UInt32=32, UInt64=64 };
85  //ETX
87 
89 
91  vtkSetMacro(ByteOrder, int);
92  vtkGetMacro(ByteOrder, int);
93  void SetByteOrderToBigEndian();
94  void SetByteOrderToLittleEndian();
96 
98 
100  virtual void SetHeaderType(int);
101  vtkGetMacro(HeaderType, int);
102  void SetHeaderTypeToUInt32();
103  void SetHeaderTypeToUInt64();
105 
107 
109  virtual void SetIdType(int);
110  vtkGetMacro(IdType, int);
111  void SetIdTypeToInt32();
112  void SetIdTypeToInt64();
114 
116 
117  vtkSetStringMacro(FileName);
118  vtkGetStringMacro(FileName);
120 
122 
124  virtual void SetCompressor(vtkDataCompressor*);
127 
128 //BTX
130  {
132  ZLIB
133  };
134 //ETX
135 
137 
138  void SetCompressorType(int compressorType);
140  {
141  this->SetCompressorType(NONE);
142  }
144  {
145  this->SetCompressorType(ZLIB);
146  }
148 
150 
154  virtual void SetBlockSize(size_t blockSize);
155  vtkGetMacro(BlockSize, size_t);
157 
159 
162  vtkSetMacro(DataMode, int);
163  vtkGetMacro(DataMode, int);
164  void SetDataModeToAscii();
165  void SetDataModeToBinary();
166  void SetDataModeToAppended();
168 
170 
175  vtkSetMacro(EncodeAppendedData, int);
176  vtkGetMacro(EncodeAppendedData, int);
177  vtkBooleanMacro(EncodeAppendedData, int);
179 
181 
184  void SetInputData(vtkDataObject *);
185  void SetInputData(int, vtkDataObject*);
186  vtkDataObject *GetInput(int port);
187  vtkDataObject *GetInput() { return this->GetInput(0); };
189 
191  virtual const char* GetDefaultFileExtension()=0;
192 
194  int Write();
195 
196  // See the vtkAlgorithm for a description of what these do
197  virtual int ProcessRequest(vtkInformation* request,
198  vtkInformationVector** inputVector,
199  vtkInformationVector* outputVector);
200 
202 
203  vtkSetMacro(TimeStep, int);
204  vtkGetMacro(TimeStep, int);
206 
208 
209  vtkGetVector2Macro(TimeStepRange, int);
210  vtkSetVector2Macro(TimeStepRange, int);
212 
214 
215  vtkGetMacro(NumberOfTimeSteps,int);
216  vtkSetMacro(NumberOfTimeSteps,int);
218 
220 
221  void Start();
222  void Stop();
223  void WriteNextTime(double time);
225 
226 protected:
227  vtkXMLWriter();
228  ~vtkXMLWriter();
229 
230  virtual int RequestInformation(
231  vtkInformation* request,
232  vtkInformationVector** inputVector,
233  vtkInformationVector* outputVector);
234  virtual int RequestData(vtkInformation* request,
235  vtkInformationVector** inputVector,
236  vtkInformationVector* outputVector);
237 
238  // The name of the output file.
239  char* FileName;
240 
241  // The output stream to which the XML is written.
242  ostream* Stream;
243 
244  // The output byte order.
246 
247  // The output binary header word type.
249 
250  // The output vtkIdType.
251  int IdType;
252 
253  // The form of binary data to write. Used by subclasses to choose
254  // how to write data.
255  int DataMode;
256 
257  // Whether to base64-encode the appended data section.
259 
260  // The stream position at which appended data starts.
261  vtkTypeInt64 AppendedDataPosition;
262 
263  // appended data offsets for field data
265 
266  //BTX
267  // We need a 32 bit signed integer type to which vtkIdType will be
268  // converted if Int32 is specified for the IdType parameter to this
269  // writer.
270 # if VTK_SIZEOF_SHORT == 4
271  typedef short Int32IdType;
272 # elif VTK_SIZEOF_INT == 4
273  typedef int Int32IdType;
274 # elif VTK_SIZEOF_LONG == 4
275  typedef long Int32IdType;
276 # else
277 # error "No native data type can represent a signed 32-bit integer."
278 # endif
279  //ETX
280 
281  // Buffer for vtkIdType conversion.
282  Int32IdType* Int32IdTypeBuffer;
283 
284  // The byte swapping buffer.
285  unsigned char* ByteSwapBuffer;
286 
287  // Compression information.
289  size_t BlockSize;
293 
294  // The output stream used to write binary and appended data. May
295  // transparently encode the data.
297 
298  // Allow subclasses to set the data stream.
299  virtual void SetDataStream(vtkOutputStream*);
300  vtkGetObjectMacro(DataStream, vtkOutputStream);
301 
302  // Method to drive most of actual writing.
303  virtual int WriteInternal();
304 
305  // Method defined by subclasses to write data. Return 1 for
306  // success, 0 for failure.
307  virtual int WriteData() {return 1;};
308 
309  // Method defined by subclasses to specify the data set's type name.
310  virtual const char* GetDataSetName()=0;
311 
312  // Methods to define the file's major and minor version numbers.
313  virtual int GetDataSetMajorVersion();
314  virtual int GetDataSetMinorVersion();
315 
316  // Utility methods for subclasses.
317  vtkDataSet* GetInputAsDataSet();
318  int StartFile();
319  virtual void WriteFileAttributes();
320  int EndFile();
321  void DeleteAFile();
322  void DeleteAFile(const char* name);
323 
324  virtual int WritePrimaryElement(ostream &os, vtkIndent indent);
325  virtual void WritePrimaryElementAttributes(ostream &os, vtkIndent indent);
326  void StartAppendedData();
327  void EndAppendedData();
328 
329  // Write enough space to go back and write the given attribute with
330  // at most "length" characters in the value. Returns the stream
331  // position at which attribute should be later written. The default
332  // length of 20 is enough for a 64-bit integer written in decimal or
333  // a double-precision floating point value written to 13 digits of
334  // precision (the other 7 come from a minus sign, decimal place, and
335  // a big exponent like "e+300").
336  vtkTypeInt64 ReserveAttributeSpace(const char* attr, size_t length=20);
337 
338  vtkTypeInt64 GetAppendedDataOffset();
339  void WriteAppendedDataOffset(vtkTypeInt64 streamPos,
340  vtkTypeInt64 &lastoffset,
341  const char* attr=0);
342  void ForwardAppendedDataOffset(vtkTypeInt64 streamPos,
343  vtkTypeInt64 offset,
344  const char* attr=0);
345  void ForwardAppendedDataDouble(vtkTypeInt64 streamPos,
346  double value,
347  const char* attr);
348 
349  int WriteScalarAttribute(const char* name, int data);
350  int WriteScalarAttribute(const char* name, float data);
351  int WriteScalarAttribute(const char* name, double data);
352 #ifdef VTK_USE_64BIT_IDS
353  int WriteScalarAttribute(const char* name, vtkIdType data);
354 #endif
355 
356  int WriteVectorAttribute(const char* name, int length, int* data);
357  int WriteVectorAttribute(const char* name, int length, float* data);
358  int WriteVectorAttribute(const char* name, int length, double* data);
359 #ifdef VTK_USE_64BIT_IDS
360  int WriteVectorAttribute(const char* name, int length, vtkIdType* data);
361 #endif
362 
363  int WriteDataModeAttribute(const char* name);
364  int WriteWordTypeAttribute(const char* name, int dataType);
365  int WriteStringAttribute(const char* name, const char* value);
366 
367  void WriteArrayHeader(vtkAbstractArray* a, vtkIndent indent,
368  const char* alternateName, int writeNumTuples, int timestep);
369  void WriteArrayFooter(ostream &os, vtkIndent indent, vtkAbstractArray *a, int shortFormat);
370  void WriteArrayInline(vtkAbstractArray* a, vtkIndent indent,
371  const char* alternateName=0, int writeNumTuples=0);
372  void WriteInlineData(vtkAbstractArray* a, vtkIndent indent);
373 
374  void WriteArrayAppended(vtkAbstractArray* a, vtkIndent indent,
375  OffsetsManager &offs, const char* alternateName=0, int writeNumTuples=0,
376  int timestep=0);
377  int WriteAsciiData(vtkAbstractArray* a, vtkIndent indent);
378  int WriteBinaryData(vtkAbstractArray* a);
379  int WriteBinaryDataInternal(vtkAbstractArray* a);
380  void WriteArrayAppendedData(vtkAbstractArray* a, vtkTypeInt64 pos,
381  vtkTypeInt64 &lastoffset);
382 
383  // Methods for writing points, point data, and cell data.
384  void WriteFieldData(vtkIndent indent);
385  void WriteFieldDataInline(vtkFieldData* fd, vtkIndent indent);
386  void WritePointDataInline(vtkPointData* pd, vtkIndent indent);
387  void WriteCellDataInline(vtkCellData* cd, vtkIndent indent);
388  void WriteFieldDataAppended(vtkFieldData* fd, vtkIndent indent,
389  OffsetsManagerGroup *fdManager);
390  void WriteFieldDataAppendedData(vtkFieldData* fd, int timestep,
391  OffsetsManagerGroup *fdManager);
392  void WritePointDataAppended(vtkPointData* pd, vtkIndent indent,
393  OffsetsManagerGroup *pdManager);
394  void WritePointDataAppendedData(vtkPointData* pd, int timestep,
395  OffsetsManagerGroup *pdManager);
396  void WriteCellDataAppended(vtkCellData* cd, vtkIndent indent,
397  OffsetsManagerGroup *cdManager);
398  void WriteCellDataAppendedData(vtkCellData* cd, int timestep,
399  OffsetsManagerGroup *cdManager);
400  void WriteAttributeIndices(vtkDataSetAttributes* dsa, char** names);
401  void WritePointsAppended(vtkPoints* points, vtkIndent indent, OffsetsManager *manager);
402  void WritePointsAppendedData(vtkPoints* points, int timestep, OffsetsManager *pdManager);
403  void WritePointsInline(vtkPoints* points, vtkIndent indent);
404  void WriteCoordinatesInline(vtkDataArray* xc, vtkDataArray* yc,
405  vtkDataArray* zc, vtkIndent indent);
406  void WriteCoordinatesAppended(vtkDataArray* xc, vtkDataArray* yc,
407  vtkDataArray* zc, vtkIndent indent,
408  OffsetsManagerGroup *coordManager);
409  void WriteCoordinatesAppendedData(vtkDataArray* xc, vtkDataArray* yc,
410  vtkDataArray* zc, int timestep,
411  OffsetsManagerGroup *coordManager);
412  virtual vtkAbstractArray* CreateArrayForPoints(vtkAbstractArray* inArray);
413  virtual vtkAbstractArray* CreateArrayForCells(vtkAbstractArray* inArray);
414  virtual vtkDataArray* CreateExactCoordinates(vtkDataArray* inArray, int xyz);
415  void WritePPointData(vtkPointData* pd, vtkIndent indent);
416  void WritePCellData(vtkCellData* cd, vtkIndent indent);
417  void WritePPoints(vtkPoints* points, vtkIndent indent);
418  void WritePArray(vtkAbstractArray* a, vtkIndent indent,
419  const char* alternateName=0);
420  void WritePCoordinates(vtkDataArray* xc, vtkDataArray* yc,
421  vtkDataArray* zc, vtkIndent indent);
422 
423  // Internal utility methods.
424  int WriteBinaryDataBlock(unsigned char* in_data, size_t numWords, int wordType);
425  void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
426  int CreateCompressionHeader(size_t size);
427  int WriteCompressionBlock(unsigned char* data, size_t size);
428  int WriteCompressionHeader();
429  size_t GetWordTypeSize(int dataType);
430  const char* GetWordTypeName(int dataType);
431  size_t GetOutputWordTypeSize(int dataType);
432 
433  char** CreateStringArray(int numStrings);
434  void DestroyStringArray(int numStrings, char** strings);
435 
436  // The current range over which progress is moving. This allows for
437  // incrementally fine-tuned progress updates.
438  virtual void GetProgressRange(float range[2]);
439  virtual void SetProgressRange(const float range[2], int curStep, int numSteps);
440  virtual void SetProgressRange(const float range[2], int curStep, const float* fractions);
441  virtual void SetProgressPartial(float fraction);
442  virtual void UpdateProgressDiscrete(float progress);
443  float ProgressRange[2];
444 
445  ofstream* OutFile;
446 
447  int OpenFile();
448  void CloseFile();
449 
450  // The timestep currently being written
451  int TimeStep;
454  // Store the range of time steps
455  int TimeStepRange[2];
456 
457  // Dummy boolean var to start/stop the continue executing:
458  // when using the Start/Stop/WriteNextTime API
459  int UserContinueExecuting; //can only be -1 = invalid, 0 = stop, 1 = start
460 
461  vtkTypeInt64 *NumberOfTimeValues; //one per piece / per timestep
462  //BTX
463  friend class vtkXMLWriterHelper;
464  //ETX
465 
466 private:
467  vtkXMLWriter(const vtkXMLWriter&); // Not implemented.
468  void operator=(const vtkXMLWriter&); // Not implemented.
469 };
470 
471 #endif
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: vtkgl.h:11339
vtkTypeInt64 * NumberOfTimeValues
Definition: vtkXMLWriter.h:461
GLsizeiptr size
Definition: vtkgl.h:11843
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
int NumberOfTimeSteps
Definition: vtkXMLWriter.h:453
Abstract interface for data compression classes.
represent and manipulate point attribute data
Definition: vtkPointData.h:36
vtkDataObject * GetInput()
Definition: vtkXMLWriter.h:187
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:60
Abstract superclass for all arrays.
GLintptr offset
Definition: vtkgl.h:11844
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:83
represent and manipulate cell attribute data
Definition: vtkCellData.h:37
virtual int ProcessRequest(vtkInformation *request, vtkInformationVector **inInfo, vtkInformationVector *outInfo)
char * FileName
Definition: vtkXMLWriter.h:239
GLuint GLsizei GLsizei * length
Definition: vtkgl.h:11992
GLsizei const GLfloat * value
Definition: vtkgl.h:12021
Helper class due to PIMPL excess.
int vtkIdType
Definition: vtkType.h:268
#define vtkSetStringMacro(name)
Definition: vtkSetGet.h:94
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:619
Implementation template for a array iterator.
vtkOutputStream * DataStream
Definition: vtkXMLWriter.h:296
virtual int WriteData()
Definition: vtkXMLWriter.h:307
GLsizei const GLchar ** strings
Definition: vtkgl.h:14213
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:61
vtkTypeInt64 AppendedDataPosition
Definition: vtkXMLWriter.h:261
GLuint const GLchar * name
Definition: vtkgl.h:11983
Superclass for VTK's XML file writers.
Definition: vtkXMLWriter.h:52
a simple class to control print indentation
Definition: vtkIndent.h:38
#define VTKIOXML_EXPORT
int EncodeAppendedData
Definition: vtkXMLWriter.h:258
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:53
size_t CompressionBlockNumber
Definition: vtkXMLWriter.h:290
Abstract superclass to iterate over elements in an vtkAbstractArray.
represent and manipulate attribute data in a dataset
#define vtkGetStringMacro(name)
Definition: vtkSetGet.h:120
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:222
GLuint GLuint * names
Definition: vtkgl.h:19215
ofstream * OutFile
Definition: vtkXMLWriter.h:445
GLboolean GLboolean GLboolean GLboolean a
Definition: vtkgl.h:12312
GLsizei const GLfloat * points
Definition: vtkgl.h:14786
#define vtkGetVector2Macro(name, type)
Definition: vtkSetGet.h:260
void SetCompressorTypeToNone()
Definition: vtkXMLWriter.h:139
vtkTypeInt64 CompressionHeaderPosition
Definition: vtkXMLWriter.h:292
int CurrentTimeIndex
Definition: vtkXMLWriter.h:452
Wraps a binary output stream with a VTK interface.
Store zero or more vtkInformation instances.
#define vtkBooleanMacro(name, type)
Definition: vtkSetGet.h:234
ostream * Stream
Definition: vtkXMLWriter.h:242
vtkDataCompressor * Compressor
Definition: vtkXMLWriter.h:288
unsigned char * ByteSwapBuffer
Definition: vtkXMLWriter.h:285
general representation of visualization data
Definition: vtkDataObject.h:64
size_t BlockSize
Definition: vtkXMLWriter.h:289
GLenum GLint * range
Definition: vtkgl.h:14180
#define vtkSetVector2Macro(name, type)
Definition: vtkSetGet.h:244
void SetCompressorTypeToZLib()
Definition: vtkXMLWriter.h:143
const GLenum NONE
Definition: vtkgl.h:19335
represent and manipulate 3D points
Definition: vtkPoints.h:39
vtkXMLDataHeader * CompressionHeader
Definition: vtkXMLWriter.h:291
int UserContinueExecuting
Definition: vtkXMLWriter.h:459
OffsetsManagerGroup * FieldDataOM
Definition: vtkXMLWriter.h:264
represent and manipulate fields of data
Definition: vtkFieldData.h:55
Int32IdType * Int32IdTypeBuffer
Definition: vtkXMLWriter.h:282
void PrintSelf(ostream &os, vtkIndent indent)
#define vtkSetMacro(name, type)
Definition: vtkSetGet.h:69