00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00060
00061 enum { BigEndian, LittleEndian };
00062
00064
00065
00067
00068 = Inline binary data (base64 encoded, possibly compressed). Appended
00069 = Appended binary data (possibly compressed and/or base64). */
00070 enum { Ascii, Binary, Appended };
00071
00073
00074
00076
00077 32-bit values for vtkIdType. Int64 = File stores 64-bit values for
00078 vtkIdType. */
00079 enum { Int32=32, Int64=64 };
00080
00082
00084
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
00155 char* FileName;
00156
00157
00158 ostream* Stream;
00159
00160
00161 int ByteOrder;
00162
00163
00164 int IdType;
00165
00166
00167
00168 int DataMode;
00169
00170
00171 int EncodeAppendedData;
00172
00173
00174 unsigned long AppendedDataPosition;
00175
00176
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
00185
00186 vtkOutputStream* DataStream;
00187
00188
00189 virtual void SetDataStream(vtkOutputStream*);
00190 vtkGetObjectMacro(DataStream, vtkOutputStream);
00191
00192
00193
00194 virtual int WriteData()=0;
00195
00196
00197 virtual const char* GetDataSetName()=0;
00198
00199
00200 virtual int GetDataSetMajorVersion();
00201 virtual int GetDataSetMinorVersion();
00202
00203
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
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
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&);
00318 void operator=(const vtkXMLWriter&);
00319 };
00320
00321 #endif