00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00024 #ifndef __vtkXMLWriter_h
00025 #define __vtkXMLWriter_h
00026
00027 #include "vtkAlgorithm.h"
00028
00029 class vtkAbstractArray;
00030 class vtkArrayIterator;
00031
00032 template <class T> class vtkArrayIteratorTemplate;
00033
00034 class vtkCellData;
00035 class vtkDataArray;
00036 class vtkDataCompressor;
00037 class vtkDataSet;
00038 class vtkDataSetAttributes;
00039 class vtkOutputStream;
00040 class vtkPointData;
00041 class vtkPoints;
00042 class vtkFieldData;
00043
00044 class vtkStdString;
00045 class OffsetsManager;
00046 class OffsetsManagerGroup;
00047 class OffsetsManagerArray;
00048
00049
00050 class VTK_IO_EXPORT vtkXMLWriter : public vtkAlgorithm
00051 {
00052 public:
00053 vtkTypeMacro(vtkXMLWriter,vtkAlgorithm);
00054 void PrintSelf(ostream& os, vtkIndent indent);
00055
00056
00058
00059 enum { BigEndian, LittleEndian };
00060
00062
00063
00065
00069 typedef vtkIdType OffsetType;
00070
00072
00073
00075
00078 enum { Ascii, Binary, Appended };
00079
00081
00082
00084
00087 enum { Int32=32, Int64=64 };
00088
00090
00092
00094 vtkSetMacro(ByteOrder, int);
00095 vtkGetMacro(ByteOrder, int);
00096 void SetByteOrderToBigEndian();
00097 void SetByteOrderToLittleEndian();
00099
00101
00103 virtual void SetIdType(int);
00104 vtkGetMacro(IdType, int);
00105 void SetIdTypeToInt32();
00106 void SetIdTypeToInt64();
00108
00110
00111 vtkSetStringMacro(FileName);
00112 vtkGetStringMacro(FileName);
00114
00116
00118 virtual void SetCompressor(vtkDataCompressor*);
00119 vtkGetObjectMacro(Compressor, vtkDataCompressor);
00121
00122
00123 enum CompressorType
00124 {
00125 NONE,
00126 ZLIB
00127 };
00128
00129
00131
00132 void SetCompressorType(int compressorType);
00133 void SetCompressorTypeToNone()
00134 {
00135 this->SetCompressorType(NONE);
00136 }
00137 void SetCompressorTypeToZLib()
00138 {
00139 this->SetCompressorType(ZLIB);
00140 }
00142
00144
00148 virtual void SetBlockSize(unsigned int blockSize);
00149 vtkGetMacro(BlockSize, unsigned int);
00151
00153
00156 vtkSetMacro(DataMode, int);
00157 vtkGetMacro(DataMode, int);
00158 void SetDataModeToAscii();
00159 void SetDataModeToBinary();
00160 void SetDataModeToAppended();
00162
00164
00169 vtkSetMacro(EncodeAppendedData, int);
00170 vtkGetMacro(EncodeAppendedData, int);
00171 vtkBooleanMacro(EncodeAppendedData, int);
00173
00175
00177 void SetInput(vtkDataObject *);
00178 void SetInput(int, vtkDataObject*);
00179 vtkDataObject *GetInput(int port);
00180 vtkDataObject *GetInput() { return this->GetInput(0); };
00182
00184 virtual const char* GetDefaultFileExtension()=0;
00185
00187 int Write();
00188
00189
00190 virtual int ProcessRequest(vtkInformation* request,
00191 vtkInformationVector** inputVector,
00192 vtkInformationVector* outputVector);
00193
00195
00196 vtkSetMacro(TimeStep, int);
00197 vtkGetMacro(TimeStep, int);
00199
00201
00202 vtkGetVector2Macro(TimeStepRange, int);
00203 vtkSetVector2Macro(TimeStepRange, int);
00205
00207
00208 vtkGetMacro(NumberOfTimeSteps,int);
00209 vtkSetMacro(NumberOfTimeSteps,int);
00211
00213
00214 void Start();
00215 void Stop();
00216 void WriteNextTime(double time);
00218
00219 protected:
00220 vtkXMLWriter();
00221 ~vtkXMLWriter();
00222
00223 virtual int RequestInformation(
00224 vtkInformation* request,
00225 vtkInformationVector** inputVector,
00226 vtkInformationVector* outputVector);
00227 virtual int RequestData(vtkInformation* request,
00228 vtkInformationVector** inputVector,
00229 vtkInformationVector* outputVector);
00230
00231
00232 char* FileName;
00233
00234
00235 ostream* Stream;
00236
00237
00238 int ByteOrder;
00239
00240
00241 int IdType;
00242
00243
00244
00245 int DataMode;
00246
00247
00248 int EncodeAppendedData;
00249
00250
00251 OffsetType AppendedDataPosition;
00252
00253
00254 OffsetsManagerGroup *FieldDataOM;
00255
00256
00257
00258
00259
00260 #if VTK_SIZEOF_SHORT == 4
00261 typedef unsigned short HeaderType;
00262 #elif VTK_SIZEOF_INT == 4
00263 typedef unsigned int HeaderType;
00264 #elif VTK_SIZEOF_LONG == 4
00265 typedef unsigned long HeaderType;
00266 #else
00267 # error "No native data type can represent an unsigned 32-bit integer."
00268 #endif
00269
00270
00271
00272
00273
00274
00275 # if VTK_SIZEOF_SHORT == 4
00276 typedef short Int32IdType;
00277 # elif VTK_SIZEOF_INT == 4
00278 typedef int Int32IdType;
00279 # elif VTK_SIZEOF_LONG == 4
00280 typedef long Int32IdType;
00281 # else
00282 # error "No native data type can represent a signed 32-bit integer."
00283 # endif
00284
00285
00286
00287 Int32IdType* Int32IdTypeBuffer;
00288
00289
00290 unsigned char* ByteSwapBuffer;
00291
00292
00293 vtkDataCompressor* Compressor;
00294 unsigned int BlockSize;
00295 OffsetType CompressionBlockNumber;
00296 HeaderType* CompressionHeader;
00297 unsigned int CompressionHeaderLength;
00298 OffsetType CompressionHeaderPosition;
00299
00300
00301
00302 vtkOutputStream* DataStream;
00303
00304
00305 virtual void SetDataStream(vtkOutputStream*);
00306 vtkGetObjectMacro(DataStream, vtkOutputStream);
00307
00308
00309 virtual int WriteInternal();
00310
00311
00312
00313 virtual int WriteData() {return 1;};
00314
00315
00316 virtual const char* GetDataSetName()=0;
00317
00318
00319 virtual int GetDataSetMajorVersion();
00320 virtual int GetDataSetMinorVersion();
00321
00322
00323 vtkDataSet* GetInputAsDataSet();
00324 int StartFile();
00325 virtual void WriteFileAttributes();
00326 int EndFile();
00327 void DeleteAFile();
00328 void DeleteAFile(const char* name);
00329
00330 virtual int WritePrimaryElement(ostream &os, vtkIndent indent);
00331 virtual void WritePrimaryElementAttributes(ostream &os, vtkIndent indent);
00332 void StartAppendedData();
00333 void EndAppendedData();
00334
00335
00336
00337
00338
00339
00340
00341
00342 OffsetType ReserveAttributeSpace(const char* attr, int length=20);
00343
00344 OffsetType GetAppendedDataOffset();
00345 OffsetType WriteAppendedDataOffset(OffsetType streamPos,
00346 OffsetType &lastoffset,
00347 const char* attr=0);
00348 OffsetType ForwardAppendedDataOffset(OffsetType streamPos,
00349 OffsetType offset,
00350 const char* attr=0);
00351 OffsetType ForwardAppendedDataDouble(OffsetType streamPos,
00352 double value,
00353 const char* attr);
00354
00355 int WriteScalarAttribute(const char* name, int data);
00356 int WriteScalarAttribute(const char* name, float data);
00357 int WriteScalarAttribute(const char* name, double data);
00358 #ifdef VTK_USE_64BIT_IDS
00359 int WriteScalarAttribute(const char* name, vtkIdType data);
00360 #endif
00361
00362 int WriteVectorAttribute(const char* name, int length, int* data);
00363 int WriteVectorAttribute(const char* name, int length, float* data);
00364 int WriteVectorAttribute(const char* name, int length, double* data);
00365 #ifdef VTK_USE_64BIT_IDS
00366 int WriteVectorAttribute(const char* name, int length, vtkIdType* data);
00367 #endif
00368
00369 int WriteDataModeAttribute(const char* name);
00370 int WriteWordTypeAttribute(const char* name, int dataType);
00371 int WriteStringAttribute(const char* name, const char* value);
00372
00373 void WriteArrayHeader(vtkAbstractArray* a, vtkIndent indent,
00374 const char* alternateName, int writeNumTuples, int timestep);
00375 void WriteArrayFooter(ostream &os, vtkIndent indent, vtkAbstractArray *a, int shortFormat);
00376 void WriteArrayInline(vtkAbstractArray* a, vtkIndent indent,
00377 const char* alternateName=0, int writeNumTuples=0);
00378 void WriteInlineData(vtkAbstractArray* a, vtkIndent indent);
00379
00380 void WriteArrayAppended(vtkAbstractArray* a, vtkIndent indent,
00381 OffsetsManager &offs, const char* alternateName=0, int writeNumTuples=0,
00382 int timestep=0);
00383 int WriteAsciiData(vtkAbstractArray* a, vtkIndent indent);
00384 int WriteBinaryData(vtkAbstractArray* a);
00385 int WriteBinaryDataInternal(vtkAbstractArray* a, OffsetType data_size);
00386 void WriteArrayAppendedData(vtkAbstractArray* a, OffsetType pos,
00387 OffsetType &lastoffset);
00388
00389
00390 void WriteFieldData(vtkIndent indent);
00391 void WriteFieldDataInline(vtkFieldData* fd, vtkIndent indent);
00392 void WritePointDataInline(vtkPointData* pd, vtkIndent indent);
00393 void WriteCellDataInline(vtkCellData* cd, vtkIndent indent);
00394 void WriteFieldDataAppended(vtkFieldData* fd, vtkIndent indent,
00395 OffsetsManagerGroup *fdManager);
00396 void WriteFieldDataAppendedData(vtkFieldData* fd, int timestep,
00397 OffsetsManagerGroup *fdManager);
00398 void WritePointDataAppended(vtkPointData* pd, vtkIndent indent,
00399 OffsetsManagerGroup *pdManager);
00400 void WritePointDataAppendedData(vtkPointData* pd, int timestep,
00401 OffsetsManagerGroup *pdManager);
00402 void WriteCellDataAppended(vtkCellData* cd, vtkIndent indent,
00403 OffsetsManagerGroup *cdManager);
00404 void WriteCellDataAppendedData(vtkCellData* cd, int timestep,
00405 OffsetsManagerGroup *cdManager);
00406 void WriteAttributeIndices(vtkDataSetAttributes* dsa, char** names);
00407 void WritePointsAppended(vtkPoints* points, vtkIndent indent, OffsetsManager *manager);
00408 void WritePointsAppendedData(vtkPoints* points, int timestep, OffsetsManager *pdManager);
00409 void WritePointsInline(vtkPoints* points, vtkIndent indent);
00410 void WriteCoordinatesInline(vtkDataArray* xc, vtkDataArray* yc,
00411 vtkDataArray* zc, vtkIndent indent);
00412 void WriteCoordinatesAppended(vtkDataArray* xc, vtkDataArray* yc,
00413 vtkDataArray* zc, vtkIndent indent,
00414 OffsetsManagerGroup *coordManager);
00415 void WriteCoordinatesAppendedData(vtkDataArray* xc, vtkDataArray* yc,
00416 vtkDataArray* zc, int timestep,
00417 OffsetsManagerGroup *coordManager);
00418 virtual vtkAbstractArray* CreateArrayForPoints(vtkAbstractArray* inArray);
00419 virtual vtkAbstractArray* CreateArrayForCells(vtkAbstractArray* inArray);
00420 virtual vtkDataArray* CreateExactCoordinates(vtkDataArray* inArray, int xyz);
00421 void WritePPointData(vtkPointData* pd, vtkIndent indent);
00422 void WritePCellData(vtkCellData* cd, vtkIndent indent);
00423 void WritePPoints(vtkPoints* points, vtkIndent indent);
00424 void WritePArray(vtkAbstractArray* a, vtkIndent indent,
00425 const char* alternateName=0);
00426 void WritePCoordinates(vtkDataArray* xc, vtkDataArray* yc,
00427 vtkDataArray* zc, vtkIndent indent);
00428
00429
00430 int WriteBinaryDataInternal(void* data, OffsetType numWords, int wordType);
00431 int WriteBinaryDataBlock(unsigned char* in_data, OffsetType numWords, int wordType);
00432 void PerformByteSwap(void* data, OffsetType numWords, int wordSize);
00433 int CreateCompressionHeader(OffsetType size);
00434 int WriteCompressionBlock(unsigned char* data, OffsetType size);
00435 int WriteCompressionHeader();
00436 OffsetType GetWordTypeSize(int dataType);
00437 const char* GetWordTypeName(int dataType);
00438 OffsetType GetOutputWordTypeSize(int dataType);
00439
00440 char** CreateStringArray(int numStrings);
00441 void DestroyStringArray(int numStrings, char** strings);
00442
00443
00444
00445 virtual void GetProgressRange(float* range);
00446 virtual void SetProgressRange(float* range, int curStep, int numSteps);
00447 virtual void SetProgressRange(float* range, int curStep, float* fractions);
00448 virtual void SetProgressPartial(float fraction);
00449 virtual void UpdateProgressDiscrete(float progress);
00450 float ProgressRange[2];
00451
00452 ofstream* OutFile;
00453
00454 int OpenFile();
00455 void CloseFile();
00456
00457
00458 int TimeStep;
00459 int CurrentTimeIndex;
00460 int NumberOfTimeSteps;
00461
00462 int TimeStepRange[2];
00463
00464
00465
00466 int UserContinueExecuting;
00467
00468 unsigned long *NumberOfTimeValues;
00469
00470 friend class vtkXMLWriterHelper;
00471
00472
00473 private:
00474 vtkXMLWriter(const vtkXMLWriter&);
00475 void operator=(const vtkXMLWriter&);
00476 };
00477
00478 #endif