Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# IO/vtkXMLWriter.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program:   Visualization Toolkit
    00004   Module:    $RCSfile: vtkXMLWriter.h,v $
    00005   Language:  C++
    00006
    00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
    00008   All rights reserved.
    00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
    00010
    00011      This software is distributed WITHOUT ANY WARRANTY; without even
    00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00013      PURPOSE.  See the above copyright notice for more information.
    00014
    00015 =========================================================================*/
    00038 #ifndef __vtkXMLWriter_h
    00039 #define __vtkXMLWriter_h
    00040
    00041 #include "vtkProcessObject.h"
    00042
    00043 class vtkCellData;
    00044 class vtkDataArray;
    00045 class vtkDataCompressor;
    00046 class vtkDataSet;
    00047 class vtkDataSetAttributes;
    00048 class vtkOutputStream;
    00049 class vtkPointData;
    00050 class vtkPoints;
    00051
    00052 class VTK_IO_EXPORT vtkXMLWriter : public vtkProcessObject
    00053 {
    00054 public:
    00055   vtkTypeRevisionMacro(vtkXMLWriter,vtkProcessObject);
    00056   void PrintSelf(ostream& os, vtkIndent indent);
    00057
    00058   //BTX
    00060   /*! Enumerate big and little endian byte order settings. */
    00061   enum { BigEndian, LittleEndian };
    00062   //ETX
    00064
    00065   //BTX
    00067   /*! Enumerate the supported data modes. Ascii = Inline ascii data. Binary
    00068       = Inline binary data (base64 encoded, possibly compressed). Appended
    00069       = Appended binary data (possibly compressed and/or base64). */
    00070   enum { Ascii, Binary, Appended };
    00071   //ETX
    00073
    00074   //BTX
    00076   /*! Enumerate the supported vtkIdType bit lengths. Int32 = File stores
    00077       32-bit values for vtkIdType. Int64 = File stores 64-bit values for
    00078       vtkIdType. */
    00079   enum { Int32=32, Int64=64 };
    00080   //ETX
    00082
    00084   /*! Get/Set the byte order of data written to the file.  The default is
    00085       the machine's hardware byte order. */
    00086   vtkSetMacro(ByteOrder, int);
    00087   vtkGetMacro(ByteOrder, int);
    00088   void SetByteOrderToBigEndian();
    00089   void SetByteOrderToLittleEndian();
    00091
    00093
    00095   virtual void SetIdType(int);
    00096   vtkGetMacro(IdType, int);
    00097   void SetIdTypeToInt32();
    00098   void SetIdTypeToInt64();
    00100
    00102
    00103   vtkSetStringMacro(FileName);
    00104   vtkGetStringMacro(FileName);
    00106
    00108
    00110   virtual void SetCompressor(vtkDataCompressor*);
    00111   vtkGetObjectMacro(Compressor, vtkDataCompressor);
    00113
    00115
    00118   vtkSetMacro(BlockSize, unsigned int);
    00119   vtkGetMacro(BlockSize, unsigned int);
    00121
    00123
    00126   vtkSetMacro(DataMode, int);
    00127   vtkGetMacro(DataMode, int);
    00128   void SetDataModeToAscii();
    00129   void SetDataModeToBinary();
    00130   void SetDataModeToAppended();
    00132
    00134
    00139   vtkSetMacro(EncodeAppendedData, int);
    00140   vtkGetMacro(EncodeAppendedData, int);
    00141   vtkBooleanMacro(EncodeAppendedData, int);
    00143
    00145   virtual const char* GetDefaultFileExtension()=0;
    00146
    00148   virtual int Write();
    00149
    00150 protected:
    00151   vtkXMLWriter();
    00152   ~vtkXMLWriter();
    00153
    00154   // The name of the output file.
    00155   char* FileName;
    00156
    00157   // The output stream to which the XML is written.
    00158   ostream* Stream;
    00159
    00160   // The output byte order.
    00161   int ByteOrder;
    00162
    00163   // The output vtkIdType.
    00164   int IdType;
    00165
    00166   // The form of binary data to write.  Used by subclasses to choose
    00167   // how to write data.
    00168   int DataMode;
    00169
    00170   // Whether to base64-encode the appended data section.
    00171   int EncodeAppendedData;
    00172
    00173   // The stream position at which appended data starts.
    00174   unsigned long AppendedDataPosition;
    00175
    00176   // Compression information.
    00177   vtkDataCompressor* Compressor;
    00178   unsigned int   BlockSize;
    00179   unsigned long  CompressionBlockNumber;
    00180   unsigned int*  CompressionHeader;
    00181   unsigned int   CompressionHeaderLength;
    00182   unsigned long  CompressionHeaderPosition;
    00183
    00184   // The output stream used to write binary and appended data.  May
    00185   // transparently encode the data.
    00186   vtkOutputStream* DataStream;
    00187
    00188   // Allow subclasses to set the data stream.
    00189   virtual void SetDataStream(vtkOutputStream*);
    00190   vtkGetObjectMacro(DataStream, vtkOutputStream);
    00191
    00192   // Method defined by subclasses to write data.  Return 1 for
    00193   // success, 0 for failure.
    00194   virtual int WriteData()=0;
    00195
    00196   // Method defined by subclasses to specify the data set's type name.
    00197   virtual const char* GetDataSetName()=0;
    00198
    00199   // Methods to define the file's major and minor version numbers.
    00200   virtual int GetDataSetMajorVersion();
    00201   virtual int GetDataSetMinorVersion();
    00202
    00203   // Utility methods for subclasses.
    00204   vtkDataSet* GetInputAsDataSet();
    00205   void StartFile();
    00206   virtual void WriteFileAttributes();
    00207   void EndFile();
    00208   void StartAppendedData();
    00209   void EndAppendedData();
    00210   unsigned long ReserveAttributeSpace(const char* attr=0);
    00211   unsigned long GetAppendedDataOffset();
    00212   unsigned long WriteAppendedDataOffset(unsigned long streamPos,
    00213                                         const char* attr=0);
    00214   int WriteBinaryData(void* data, int numWords, int wordType);
    00215
    00216   int WriteBinaryData(char* data)
    00217     { return this->WriteBinaryData(data, static_cast<int>(strlen(data)),
    00218                                    VTK_CHAR); }
    00219   int WriteBinaryData(char* data, int numWords)
    00220     { return this->WriteBinaryData(data, numWords, VTK_CHAR); }
    00221   int WriteBinaryData(unsigned char* data, int numWords)
    00222     { return this->WriteBinaryData(data, numWords, VTK_UNSIGNED_CHAR); }
    00223   int WriteBinaryData(short* data, int numWords)
    00224     { return this->WriteBinaryData(data, numWords, VTK_SHORT); }
    00225   int WriteBinaryData(unsigned short* data, int numWords)
    00226     { return this->WriteBinaryData(data, numWords, VTK_UNSIGNED_SHORT); }
    00227   int WriteBinaryData(int* data, int numWords)
    00228     { return this->WriteBinaryData(data, numWords, VTK_INT); }
    00229   int WriteBinaryData(unsigned int* data, int numWords)
    00230     { return this->WriteBinaryData(data, numWords, VTK_UNSIGNED_INT); }
    00231
    00232   int WriteAsciiData(void* data, int numWords, int wordType, vtkIndent indent);
    00233
    00234   int WriteAsciiData(char* data, vtkIndent indent)
    00235     { return this->WriteAsciiData(data, static_cast<int>(strlen(data)),
    00236                                   VTK_CHAR, indent); }
    00237   int WriteAsciiData(char* data, int numWords, vtkIndent indent)
    00238     { return this->WriteAsciiData(data, numWords, VTK_CHAR, indent); }
    00239   int WriteAsciiData(unsigned char* data, int numWords, vtkIndent indent)
    00240     { return this->WriteAsciiData(data, numWords, VTK_UNSIGNED_CHAR, indent); }
    00241   int WriteAsciiData(short* data, int numWords, vtkIndent indent)
    00242     { return this->WriteAsciiData(data, numWords, VTK_SHORT, indent); }
    00243   int WriteAsciiData(unsigned short* data, int numWords, vtkIndent indent)
    00244     { return this->WriteAsciiData(data, numWords, VTK_UNSIGNED_SHORT, indent); }
    00245   int WriteAsciiData(int* data, int numWords, vtkIndent indent)
    00246     { return this->WriteAsciiData(data, numWords, VTK_INT, indent); }
    00247   int WriteAsciiData(unsigned int* data, int numWords, vtkIndent indent)
    00248     { return this->WriteAsciiData(data, numWords, VTK_UNSIGNED_INT, indent); }
    00249
    00250   int WriteScalarAttribute(const char* name, int data);
    00251   int WriteScalarAttribute(const char* name, float data);
    00252 #ifdef VTK_ID_TYPE_IS_NOT_BASIC_TYPE
    00253   int WriteScalarAttribute(const char* name, vtkIdType data);
    00254 #endif
    00255
    00256   int WriteVectorAttribute(const char* name, int length, int* data);
    00257   int WriteVectorAttribute(const char* name, int length, float* data);
    00258 #ifdef VTK_ID_TYPE_IS_NOT_BASIC_TYPE
    00259   int WriteVectorAttribute(const char* name, int length, vtkIdType* data);
    00260 #endif
    00261
    00262   int WriteDataModeAttribute(const char* name);
    00263   int WriteWordTypeAttribute(const char* name, int dataType);
    00264   int WriteStringAttribute(const char* name, const char* value);
    00265
    00266   unsigned long WriteDataArrayAppended(vtkDataArray* a, vtkIndent indent,
    00267                                        const char* alternateName=0);
    00268   void WriteDataArrayAppendedData(vtkDataArray* a, unsigned long pos);
    00269   void WriteDataArrayInline(vtkDataArray* a, vtkIndent indent,
    00270                             const char* alternateName=0);
    00271   void WriteInlineData(void* data, int numWords, int wordType,
    00272                        vtkIndent indent);
    00273
    00274   // Methods for writing points, point data, and cell data.
    00275   void WritePointDataInline(vtkPointData* pd, vtkIndent indent);
    00276   void WriteCellDataInline(vtkCellData* cd, vtkIndent indent);
    00277   unsigned long* WritePointDataAppended(vtkPointData* pd, vtkIndent indent);
    00278   void WritePointDataAppendedData(vtkPointData* pd, unsigned long* pdPositions);
    00279   unsigned long* WriteCellDataAppended(vtkCellData* cd, vtkIndent indent);
    00280   void WriteCellDataAppendedData(vtkCellData* cd, unsigned long* cdPositions);
    00281   void WriteAttributeIndices(vtkDataSetAttributes* dsa, char** names);
    00282   unsigned long WritePointsAppended(vtkPoints* points, vtkIndent indent);
    00283   void WritePointsAppendedData(vtkPoints* points, unsigned long pointsPosition);
    00284   void WritePointsInline(vtkPoints* points, vtkIndent indent);
    00285   void WriteCoordinatesInline(vtkDataArray* xc, vtkDataArray* yc,
    00286                               vtkDataArray* zc, vtkIndent indent);
    00287   unsigned long* WriteCoordinatesAppended(vtkDataArray* xc, vtkDataArray* yc,
    00288                                           vtkDataArray* zc, vtkIndent indent);
    00289   void WriteCoordinatesAppendedData(vtkDataArray* xc, vtkDataArray* yc,
    00290                                     vtkDataArray* zc,
    00291                                     unsigned long* cPositions);
    00292   virtual vtkDataArray* CreateArrayForPoints(vtkDataArray* inArray);
    00293   virtual vtkDataArray* CreateArrayForCells(vtkDataArray* inArray);
    00294   virtual vtkDataArray* CreateExactCoordinates(vtkDataArray* inArray, int xyz);
    00295   void WritePPointData(vtkPointData* pd, vtkIndent indent);
    00296   void WritePCellData(vtkCellData* cd, vtkIndent indent);
    00297   void WritePPoints(vtkPoints* points, vtkIndent indent);
    00298   void WritePDataArray(vtkDataArray* a, vtkIndent indent,
    00299                        const char* alternateName=0);
    00300   void WritePCoordinates(vtkDataArray* xc, vtkDataArray* yc,
    00301                          vtkDataArray* zc, vtkIndent indent);
    00302
    00303   // Internal utility methods.
    00304   int WriteBinaryDataInternal(void* data, unsigned long size);
    00305   void PerformByteSwap(void* data, int numWords, int wordSize);
    00306   int CreateCompressionHeader(unsigned long size);
    00307   int WriteCompressionBlock(unsigned char* data, unsigned long size);
    00308   int WriteCompressionHeader();
    00309   unsigned long GetWordTypeSize(int dataType);
    00310   const char* GetWordTypeName(int dataType);
    00311
    00312   char** CreateStringArray(int numStrings);
    00313   void DestroyStringArray(int numStrings, char** strings);
    00314   virtual int IsSafeToWrite();
    00315
    00316 private:
    00317   vtkXMLWriter(const vtkXMLWriter&);  // Not implemented.
    00318   void operator=(const vtkXMLWriter&);  // Not implemented.
    00319 };
    00320
    00321 #endif