• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

dox/IO/vtkXMLWriter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkXMLWriter.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00024 #ifndef __vtkXMLWriter_h
00025 #define __vtkXMLWriter_h
00026 
00027 #include "vtkAlgorithm.h"
00028 
00029 class vtkAbstractArray;
00030 class vtkArrayIterator;
00031 //BTX
00032 template <class T> class vtkArrayIteratorTemplate;
00033 //ETX
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 //BTX
00044 class vtkStdString;
00045 class OffsetsManager;      // one per piece/per time
00046 class OffsetsManagerGroup; // array of OffsetsManager
00047 class OffsetsManagerArray; // array of OffsetsManagerGroup
00048 //ETX
00049 
00050 class VTK_IO_EXPORT vtkXMLWriter : public vtkAlgorithm
00051 {
00052 public:
00053   vtkTypeRevisionMacro(vtkXMLWriter,vtkAlgorithm);
00054   void PrintSelf(ostream& os, vtkIndent indent);
00055  
00056   //BTX
00058 
00059   enum { BigEndian, LittleEndian };
00060   //ETX
00062 
00063   //BTX
00065 
00069   typedef vtkIdType OffsetType;
00070   //ETX
00072 
00073   //BTX
00075 
00078   enum { Ascii, Binary, Appended };
00079   //ETX
00081   
00082   //BTX
00084 
00087   enum { Int32=32, Int64=64 };
00088   //ETX
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   
00123 
00127   virtual void SetBlockSize(unsigned int blockSize);
00128   vtkGetMacro(BlockSize, unsigned int);
00130   
00132 
00135   vtkSetMacro(DataMode, int);
00136   vtkGetMacro(DataMode, int);
00137   void SetDataModeToAscii();
00138   void SetDataModeToBinary();
00139   void SetDataModeToAppended();
00141   
00143 
00148   vtkSetMacro(EncodeAppendedData, int);
00149   vtkGetMacro(EncodeAppendedData, int);
00150   vtkBooleanMacro(EncodeAppendedData, int);
00152   
00154 
00156   void SetInput(vtkDataObject *);
00157   void SetInput(int, vtkDataObject*);
00158   vtkDataObject *GetInput(int port);
00159   vtkDataObject *GetInput() { return this->GetInput(0); };
00161 
00163   virtual const char* GetDefaultFileExtension()=0;
00164   
00166   int Write();
00167 
00168   // See the vtkAlgorithm for a description of what these do
00169   virtual int ProcessRequest(vtkInformation* request,
00170                              vtkInformationVector** inputVector,
00171                              vtkInformationVector* outputVector);
00172 
00174 
00175   vtkSetMacro(TimeStep, int);
00176   vtkGetMacro(TimeStep, int);
00178 
00180 
00181   vtkGetVector2Macro(TimeStepRange, int);
00182   vtkSetVector2Macro(TimeStepRange, int);
00184 
00186 
00187   vtkGetMacro(NumberOfTimeSteps,int);
00188   vtkSetMacro(NumberOfTimeSteps,int);
00190 
00192 
00193   void Start();
00194   void Stop();
00195   void WriteNextTime(double time);
00197 
00198 protected:
00199   vtkXMLWriter();
00200   ~vtkXMLWriter();
00201 
00202   virtual int RequestInformation(
00203                           vtkInformation* request,
00204                           vtkInformationVector** inputVector,
00205                           vtkInformationVector* outputVector);
00206   virtual int RequestData(vtkInformation* request,
00207                           vtkInformationVector** inputVector,
00208                           vtkInformationVector* outputVector);
00209 
00210   // The name of the output file.
00211   char* FileName;
00212   
00213   // The output stream to which the XML is written.
00214   ostream* Stream;  
00215   
00216   // The output byte order.
00217   int ByteOrder;
00218   
00219   // The output vtkIdType.
00220   int IdType;
00221   
00222   // The form of binary data to write.  Used by subclasses to choose
00223   // how to write data.
00224   int DataMode;
00225   
00226   // Whether to base64-encode the appended data section.
00227   int EncodeAppendedData;
00228   
00229   // The stream position at which appended data starts.
00230   OffsetType AppendedDataPosition;
00231 
00232   // appended data offsets for field data
00233   OffsetsManagerGroup *FieldDataOM;  //one per array
00234 
00235   //BTX
00236   // We need a 32 bit unsigned integer type for platform-independent
00237   // binary headers.  Note that this is duplicated in
00238   // vtkXMLDataParser.h.
00239 #if VTK_SIZEOF_SHORT == 4
00240   typedef unsigned short HeaderType;
00241 #elif VTK_SIZEOF_INT == 4
00242   typedef unsigned int HeaderType;
00243 #elif VTK_SIZEOF_LONG == 4
00244   typedef unsigned long HeaderType;
00245 #else
00246 # error "No native data type can represent an unsigned 32-bit integer."
00247 #endif
00248   //ETX
00249 
00250   //BTX
00251   // We need a 32 bit signed integer type to which vtkIdType will be
00252   // converted if Int32 is specified for the IdType parameter to this
00253   // writer.
00254 # if VTK_SIZEOF_SHORT == 4
00255   typedef short Int32IdType;
00256 # elif VTK_SIZEOF_INT == 4
00257   typedef int Int32IdType;
00258 # elif VTK_SIZEOF_LONG == 4
00259   typedef long Int32IdType;
00260 # else
00261 #  error "No native data type can represent a signed 32-bit integer."
00262 # endif  
00263   //ETX
00264   
00265   // Buffer for vtkIdType conversion.
00266   Int32IdType* Int32IdTypeBuffer;
00267   
00268   // The byte swapping buffer.
00269   unsigned char* ByteSwapBuffer;
00270   
00271   // Compression information.
00272   vtkDataCompressor* Compressor;
00273   unsigned int   BlockSize;  
00274   OffsetType  CompressionBlockNumber;
00275   HeaderType*    CompressionHeader;
00276   unsigned int   CompressionHeaderLength;
00277   OffsetType  CompressionHeaderPosition;
00278   
00279   // The output stream used to write binary and appended data.  May
00280   // transparently encode the data.
00281   vtkOutputStream* DataStream;
00282   
00283   // Allow subclasses to set the data stream.
00284   virtual void SetDataStream(vtkOutputStream*);
00285   vtkGetObjectMacro(DataStream, vtkOutputStream);  
00286   
00287   // Method to drive most of actual writing.
00288   virtual int WriteInternal();
00289   
00290   // Method defined by subclasses to write data.  Return 1 for
00291   // success, 0 for failure.
00292   virtual int WriteData() {return 1;};
00293   
00294   // Method defined by subclasses to specify the data set's type name.
00295   virtual const char* GetDataSetName()=0;
00296   
00297   // Methods to define the file's major and minor version numbers.
00298   virtual int GetDataSetMajorVersion();
00299   virtual int GetDataSetMinorVersion();
00300   
00301   // Utility methods for subclasses.
00302   vtkDataSet* GetInputAsDataSet();  
00303   int StartFile();
00304   virtual void WriteFileAttributes();
00305   int EndFile();
00306   void DeleteAFile();
00307   void DeleteAFile(const char* name);
00308 
00309   virtual int WritePrimaryElement(ostream &os, vtkIndent indent);
00310   virtual void WritePrimaryElementAttributes(ostream &os, vtkIndent indent);
00311   void StartAppendedData();
00312   void EndAppendedData();
00313 
00314   // Write enough space to go back and write the given attribute with
00315   // at most "length" characters in the value.  Returns the stream
00316   // position at which attribute should be later written.  The default
00317   // length of 20 is enough for a 64-bit integer written in decimal or
00318   // a double-precision floating point value written to 13 digits of
00319   // precision (the other 7 come from a minus sign, decimal place, and
00320   // a big exponent like "e+300").
00321   OffsetType ReserveAttributeSpace(const char* attr, int length=20);
00322 
00323   OffsetType GetAppendedDataOffset();
00324   OffsetType WriteAppendedDataOffset(OffsetType streamPos,
00325                                         OffsetType &lastoffset,
00326                                         const char* attr=0);
00327   OffsetType ForwardAppendedDataOffset(OffsetType streamPos,
00328                                          OffsetType offset,
00329                                          const char* attr=0);
00330   OffsetType ForwardAppendedDataDouble(OffsetType streamPos,
00331                                           double value,
00332                                           const char* attr);
00333 
00334   int WriteScalarAttribute(const char* name, int data);
00335   int WriteScalarAttribute(const char* name, float data);
00336   int WriteScalarAttribute(const char* name, double data);
00337 #ifdef VTK_USE_64BIT_IDS
00338   int WriteScalarAttribute(const char* name, vtkIdType data);
00339 #endif
00340   
00341   int WriteVectorAttribute(const char* name, int length, int* data);
00342   int WriteVectorAttribute(const char* name, int length, float* data);
00343   int WriteVectorAttribute(const char* name, int length, double* data);
00344 #ifdef VTK_USE_64BIT_IDS
00345   int WriteVectorAttribute(const char* name, int length, vtkIdType* data);
00346 #endif
00347   
00348   int WriteDataModeAttribute(const char* name);
00349   int WriteWordTypeAttribute(const char* name, int dataType);
00350   int WriteStringAttribute(const char* name, const char* value);
00351   
00352   void WriteArrayHeader(vtkAbstractArray* a, vtkIndent indent,
00353     const char* alternateName, int writeNumTuples, int timestep);
00354   void WriteArrayFooter(ostream &os, vtkIndent indent, vtkAbstractArray *a, int shortFormat);
00355   void WriteArrayInline(vtkAbstractArray* a, vtkIndent indent,
00356     const char* alternateName=0, int writeNumTuples=0);
00357   void WriteInlineData(vtkAbstractArray* a, vtkIndent indent);
00358   
00359   void WriteArrayAppended(vtkAbstractArray* a, vtkIndent indent,
00360     OffsetsManager &offs, const char* alternateName=0,  int writeNumTuples=0, 
00361     int timestep=0);
00362   int WriteAsciiData(vtkAbstractArray* a, vtkIndent indent);
00363   int WriteBinaryData(vtkAbstractArray* a);
00364   int WriteBinaryDataInternal(vtkAbstractArray* a, OffsetType data_size);
00365   void WriteArrayAppendedData(vtkAbstractArray* a, OffsetType pos, 
00366     OffsetType &lastoffset);
00367   
00368   // Methods for writing points, point data, and cell data.
00369   void WriteFieldData(vtkIndent indent);
00370   void WriteFieldDataInline(vtkFieldData* fd, vtkIndent indent);
00371   void WritePointDataInline(vtkPointData* pd, vtkIndent indent);
00372   void WriteCellDataInline(vtkCellData* cd, vtkIndent indent);
00373   void WriteFieldDataAppended(vtkFieldData* fd, vtkIndent indent,
00374                               OffsetsManagerGroup *fdManager);
00375   void WriteFieldDataAppendedData(vtkFieldData* fd, int timestep,
00376                                   OffsetsManagerGroup *fdManager);
00377   void  WritePointDataAppended(vtkPointData* pd, vtkIndent indent, 
00378                                OffsetsManagerGroup *pdManager);
00379   void WritePointDataAppendedData(vtkPointData* pd, int timestep,
00380                                   OffsetsManagerGroup *pdManager);
00381   void WriteCellDataAppended(vtkCellData* cd, vtkIndent indent, 
00382                              OffsetsManagerGroup *cdManager);
00383   void WriteCellDataAppendedData(vtkCellData* cd, int timestep,
00384                                  OffsetsManagerGroup *cdManager);
00385   void WriteAttributeIndices(vtkDataSetAttributes* dsa, char** names);
00386   void WritePointsAppended(vtkPoints* points, vtkIndent indent, OffsetsManager *manager);
00387   void WritePointsAppendedData(vtkPoints* points, int timestep, OffsetsManager *pdManager);
00388   void WritePointsInline(vtkPoints* points, vtkIndent indent);
00389   void WriteCoordinatesInline(vtkDataArray* xc, vtkDataArray* yc,
00390                               vtkDataArray* zc, vtkIndent indent);
00391   void WriteCoordinatesAppended(vtkDataArray* xc, vtkDataArray* yc,
00392                                 vtkDataArray* zc, vtkIndent indent, 
00393                                 OffsetsManagerGroup *coordManager);
00394   void WriteCoordinatesAppendedData(vtkDataArray* xc, vtkDataArray* yc,
00395                                     vtkDataArray* zc, int timestep,
00396                                     OffsetsManagerGroup *coordManager);
00397   virtual vtkAbstractArray* CreateArrayForPoints(vtkAbstractArray* inArray);
00398   virtual vtkAbstractArray* CreateArrayForCells(vtkAbstractArray* inArray);
00399   virtual vtkDataArray* CreateExactCoordinates(vtkDataArray* inArray, int xyz);
00400   void WritePPointData(vtkPointData* pd, vtkIndent indent);
00401   void WritePCellData(vtkCellData* cd, vtkIndent indent);
00402   void WritePPoints(vtkPoints* points, vtkIndent indent);
00403   void WritePArray(vtkAbstractArray* a, vtkIndent indent, 
00404     const char* alternateName=0);
00405   void WritePCoordinates(vtkDataArray* xc, vtkDataArray* yc,
00406                          vtkDataArray* zc, vtkIndent indent);
00407   
00408   // Internal utility methods.
00409   int WriteBinaryDataInternal(void* data, OffsetType numWords, int wordType);
00410   int WriteBinaryDataBlock(unsigned char* in_data, OffsetType numWords, int wordType);
00411   void PerformByteSwap(void* data, OffsetType numWords, int wordSize);
00412   int CreateCompressionHeader(OffsetType size);
00413   int WriteCompressionBlock(unsigned char* data, OffsetType size);
00414   int WriteCompressionHeader();
00415   OffsetType GetWordTypeSize(int dataType);
00416   const char* GetWordTypeName(int dataType);
00417   OffsetType GetOutputWordTypeSize(int dataType);
00418   
00419   char** CreateStringArray(int numStrings);
00420   void DestroyStringArray(int numStrings, char** strings);
00421   
00422   // The current range over which progress is moving.  This allows for
00423   // incrementally fine-tuned progress updates.
00424   virtual void GetProgressRange(float* range);
00425   virtual void SetProgressRange(float* range, int curStep, int numSteps);
00426   virtual void SetProgressRange(float* range, int curStep, float* fractions);
00427   virtual void SetProgressPartial(float fraction);
00428   virtual void UpdateProgressDiscrete(float progress);
00429   float ProgressRange[2];
00430 
00431   ofstream* OutFile;
00432 
00433   int OpenFile();
00434   void CloseFile();
00435 
00436   // The timestep currently being written
00437   int TimeStep;
00438   int CurrentTimeIndex;
00439   int NumberOfTimeSteps;
00440   // Store the range of time steps
00441   int TimeStepRange[2];
00442 
00443   // Dummy boolean var to start/stop the continue executing:
00444   // when using the Start/Stop/WriteNextTime API
00445   int UserContinueExecuting; //can only be -1 = invalid, 0 = stop, 1 = start
00446 
00447   unsigned long *NumberOfTimeValues; //one per piece / per timestep
00448   //BTX
00449   friend class vtkXMLWriterHelper;
00450   //ETX
00451 
00452 private:
00453   vtkXMLWriter(const vtkXMLWriter&);  // Not implemented.
00454   void operator=(const vtkXMLWriter&);  // Not implemented.
00455 };
00456 
00457 #endif

Generated by  doxygen 1.7.1