00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00035 #ifndef __vtkXMLWriter_h
00036 #define __vtkXMLWriter_h
00037
00038 #include "vtkProcessObject.h"
00039
00040 class vtkCellData;
00041 class vtkDataArray;
00042 class vtkDataCompressor;
00043 class vtkDataSet;
00044 class vtkDataSetAttributes;
00045 class vtkOutputStream;
00046 class vtkPointData;
00047 class vtkPoints;
00048
00049 class VTK_IO_EXPORT vtkXMLWriter : public vtkProcessObject
00050 {
00051 public:
00052 vtkTypeRevisionMacro(vtkXMLWriter,vtkProcessObject);
00053 void PrintSelf(ostream& os, vtkIndent indent);
00054
00055
00057
00058 enum { BigEndian, LittleEndian };
00059
00061
00062
00064
00067 enum { Ascii, Binary, Appended };
00068
00070
00071
00073
00076 enum { Int32=32, Int64=64 };
00077
00079
00081
00083 vtkSetMacro(ByteOrder, int);
00084 vtkGetMacro(ByteOrder, int);
00085 void SetByteOrderToBigEndian();
00086 void SetByteOrderToLittleEndian();
00088
00090
00092 virtual void SetIdType(int);
00093 vtkGetMacro(IdType, int);
00094 void SetIdTypeToInt32();
00095 void SetIdTypeToInt64();
00097
00099
00100 vtkSetStringMacro(FileName);
00101 vtkGetStringMacro(FileName);
00103
00105
00107 virtual void SetCompressor(vtkDataCompressor*);
00108 vtkGetObjectMacro(Compressor, vtkDataCompressor);
00110
00112
00116 virtual void SetBlockSize(unsigned int blockSize);
00117 vtkGetMacro(BlockSize, unsigned int);
00119
00121
00124 vtkSetMacro(DataMode, int);
00125 vtkGetMacro(DataMode, int);
00126 void SetDataModeToAscii();
00127 void SetDataModeToBinary();
00128 void SetDataModeToAppended();
00130
00132
00137 vtkSetMacro(EncodeAppendedData, int);
00138 vtkGetMacro(EncodeAppendedData, int);
00139 vtkBooleanMacro(EncodeAppendedData, int);
00141
00143 virtual const char* GetDefaultFileExtension()=0;
00144
00146 int Write();
00147
00148 protected:
00149 vtkXMLWriter();
00150 ~vtkXMLWriter();
00151
00152
00153 char* FileName;
00154
00155
00156 ostream* Stream;
00157
00158
00159 int ByteOrder;
00160
00161
00162 int IdType;
00163
00164
00165
00166 int DataMode;
00167
00168
00169 int EncodeAppendedData;
00170
00171
00172 unsigned long AppendedDataPosition;
00173
00174
00175
00176
00177
00178 #if VTK_SIZEOF_SHORT == 4
00179 typedef unsigned short HeaderType;
00180 #elif VTK_SIZEOF_INT == 4
00181 typedef unsigned int HeaderType;
00182 #elif VTK_SIZEOF_LONG == 4
00183 typedef unsigned long HeaderType;
00184 #else
00185 # error "No native data type can represent an unsigned 32-bit integer."
00186 #endif
00187
00188
00189
00190
00191
00192
00193 # if VTK_SIZEOF_SHORT == 4
00194 typedef short Int32IdType;
00195 # elif VTK_SIZEOF_INT == 4
00196 typedef int Int32IdType;
00197 # elif VTK_SIZEOF_LONG == 4
00198 typedef long Int32IdType;
00199 # else
00200 # error "No native data type can represent a signed 32-bit integer."
00201 # endif
00202
00203
00204
00205 Int32IdType* Int32IdTypeBuffer;
00206
00207
00208 unsigned char* ByteSwapBuffer;
00209
00210
00211 vtkDataCompressor* Compressor;
00212 unsigned int BlockSize;
00213 unsigned long CompressionBlockNumber;
00214 HeaderType* CompressionHeader;
00215 unsigned int CompressionHeaderLength;
00216 unsigned long CompressionHeaderPosition;
00217
00218
00219
00220 vtkOutputStream* DataStream;
00221
00222
00223 virtual void SetDataStream(vtkOutputStream*);
00224 vtkGetObjectMacro(DataStream, vtkOutputStream);
00225
00226
00227 virtual int WriteInternal();
00228
00229
00230
00231 virtual int WriteData()=0;
00232
00233
00234 virtual const char* GetDataSetName()=0;
00235
00236
00237 virtual int GetDataSetMajorVersion();
00238 virtual int GetDataSetMinorVersion();
00239
00240
00241 vtkDataSet* GetInputAsDataSet();
00242 int StartFile();
00243 virtual void WriteFileAttributes();
00244 int EndFile();
00245 void DeleteFile();
00246 void DeleteFile(const char* name);
00247
00248 void StartAppendedData();
00249 void EndAppendedData();
00250 unsigned long ReserveAttributeSpace(const char* attr=0);
00251 unsigned long GetAppendedDataOffset();
00252 unsigned long WriteAppendedDataOffset(unsigned long streamPos,
00253 const char* attr=0);
00254 int WriteBinaryData(void* data, int numWords, int wordType);
00255
00256 int WriteBinaryData(char* data)
00257 { return this->WriteBinaryData(data, static_cast<int>(strlen(data)),
00258 VTK_CHAR); }
00259 int WriteBinaryData(char* data, int numWords)
00260 { return this->WriteBinaryData(data, numWords, VTK_CHAR); }
00261 int WriteBinaryData(unsigned char* data, int numWords)
00262 { return this->WriteBinaryData(data, numWords, VTK_UNSIGNED_CHAR); }
00263 int WriteBinaryData(short* data, int numWords)
00264 { return this->WriteBinaryData(data, numWords, VTK_SHORT); }
00265 int WriteBinaryData(unsigned short* data, int numWords)
00266 { return this->WriteBinaryData(data, numWords, VTK_UNSIGNED_SHORT); }
00267 int WriteBinaryData(int* data, int numWords)
00268 { return this->WriteBinaryData(data, numWords, VTK_INT); }
00269 int WriteBinaryData(unsigned int* data, int numWords)
00270 { return this->WriteBinaryData(data, numWords, VTK_UNSIGNED_INT); }
00271
00272 int WriteAsciiData(void* data, int numWords, int wordType, vtkIndent indent);
00273
00274 int WriteAsciiData(char* data, vtkIndent indent)
00275 { return this->WriteAsciiData(data, static_cast<int>(strlen(data)),
00276 VTK_CHAR, indent); }
00277 int WriteAsciiData(char* data, int numWords, vtkIndent indent)
00278 { return this->WriteAsciiData(data, numWords, VTK_CHAR, indent); }
00279 int WriteAsciiData(unsigned char* data, int numWords, vtkIndent indent)
00280 { return this->WriteAsciiData(data, numWords, VTK_UNSIGNED_CHAR, indent); }
00281 int WriteAsciiData(short* data, int numWords, vtkIndent indent)
00282 { return this->WriteAsciiData(data, numWords, VTK_SHORT, indent); }
00283 int WriteAsciiData(unsigned short* data, int numWords, vtkIndent indent)
00284 { return this->WriteAsciiData(data, numWords, VTK_UNSIGNED_SHORT, indent); }
00285 int WriteAsciiData(int* data, int numWords, vtkIndent indent)
00286 { return this->WriteAsciiData(data, numWords, VTK_INT, indent); }
00287 int WriteAsciiData(unsigned int* data, int numWords, vtkIndent indent)
00288 { return this->WriteAsciiData(data, numWords, VTK_UNSIGNED_INT, indent); }
00289
00290 int WriteScalarAttribute(const char* name, int data);
00291 int WriteScalarAttribute(const char* name, float data);
00292 #ifdef VTK_ID_TYPE_IS_NOT_BASIC_TYPE
00293 int WriteScalarAttribute(const char* name, vtkIdType data);
00294 #endif
00295
00296 int WriteVectorAttribute(const char* name, int length, int* data);
00297 int WriteVectorAttribute(const char* name, int length, float* data);
00298 int WriteVectorAttribute(const char* name, int length, double* data);
00299 #ifdef VTK_ID_TYPE_IS_NOT_BASIC_TYPE
00300 int WriteVectorAttribute(const char* name, int length, vtkIdType* data);
00301 #endif
00302
00303 int WriteDataModeAttribute(const char* name);
00304 int WriteWordTypeAttribute(const char* name, int dataType);
00305 int WriteStringAttribute(const char* name, const char* value);
00306
00307 unsigned long WriteDataArrayAppended(vtkDataArray* a, vtkIndent indent,
00308 const char* alternateName=0);
00309 void WriteDataArrayAppendedData(vtkDataArray* a, unsigned long pos);
00310 void WriteDataArrayInline(vtkDataArray* a, vtkIndent indent,
00311 const char* alternateName=0);
00312 void WriteInlineData(void* data, int numWords, int wordType,
00313 vtkIndent indent);
00314
00315
00316 void WritePointDataInline(vtkPointData* pd, vtkIndent indent);
00317 void WriteCellDataInline(vtkCellData* cd, vtkIndent indent);
00318 unsigned long* WritePointDataAppended(vtkPointData* pd, vtkIndent indent);
00319 void WritePointDataAppendedData(vtkPointData* pd, unsigned long* pdPositions);
00320 unsigned long* WriteCellDataAppended(vtkCellData* cd, vtkIndent indent);
00321 void WriteCellDataAppendedData(vtkCellData* cd, unsigned long* cdPositions);
00322 void WriteAttributeIndices(vtkDataSetAttributes* dsa, char** names);
00323 unsigned long WritePointsAppended(vtkPoints* points, vtkIndent indent);
00324 void WritePointsAppendedData(vtkPoints* points, unsigned long pointsPosition);
00325 void WritePointsInline(vtkPoints* points, vtkIndent indent);
00326 void WriteCoordinatesInline(vtkDataArray* xc, vtkDataArray* yc,
00327 vtkDataArray* zc, vtkIndent indent);
00328 unsigned long* WriteCoordinatesAppended(vtkDataArray* xc, vtkDataArray* yc,
00329 vtkDataArray* zc, vtkIndent indent);
00330 void WriteCoordinatesAppendedData(vtkDataArray* xc, vtkDataArray* yc,
00331 vtkDataArray* zc,
00332 unsigned long* cPositions);
00333 virtual vtkDataArray* CreateArrayForPoints(vtkDataArray* inArray);
00334 virtual vtkDataArray* CreateArrayForCells(vtkDataArray* inArray);
00335 virtual vtkDataArray* CreateExactCoordinates(vtkDataArray* inArray, int xyz);
00336 void WritePPointData(vtkPointData* pd, vtkIndent indent);
00337 void WritePCellData(vtkCellData* cd, vtkIndent indent);
00338 void WritePPoints(vtkPoints* points, vtkIndent indent);
00339 void WritePDataArray(vtkDataArray* a, vtkIndent indent,
00340 const char* alternateName=0);
00341 void WritePCoordinates(vtkDataArray* xc, vtkDataArray* yc,
00342 vtkDataArray* zc, vtkIndent indent);
00343
00344
00345 int WriteBinaryDataInternal(void* data, int numWords, int wordType);
00346 int WriteBinaryDataBlock(unsigned char* in_data, int numWords, int wordType);
00347 void PerformByteSwap(void* data, int numWords, int wordSize);
00348 int CreateCompressionHeader(unsigned long size);
00349 int WriteCompressionBlock(unsigned char* data, unsigned long size);
00350 int WriteCompressionHeader();
00351 unsigned long GetWordTypeSize(int dataType);
00352 const char* GetWordTypeName(int dataType);
00353 unsigned long GetOutputWordTypeSize(int dataType);
00354
00355 char** CreateStringArray(int numStrings);
00356 void DestroyStringArray(int numStrings, char** strings);
00357
00358
00359
00360 virtual void GetProgressRange(float* range);
00361 virtual void SetProgressRange(float* range, int curStep, int numSteps);
00362 virtual void SetProgressRange(float* range, int curStep, float* fractions);
00363 virtual void SetProgressPartial(float fraction);
00364 virtual void UpdateProgressDiscrete(float progress);
00365 float ProgressRange[2];
00366
00367 private:
00368 vtkXMLWriter(const vtkXMLWriter&);
00369 void operator=(const vtkXMLWriter&);
00370 };
00371
00372 #endif