Home Docs Forums Bugzilla LXR Doxygen CVS Bonsai
Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

vtkDataWriter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkDataWriter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2001/11/13 14:30:27 $
00007   Version:   $Revision: 1.50 $
00008 
00009 
00010 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00011 All rights reserved.
00012 
00013 Redistribution and use in source and binary forms, with or without
00014 modification, are permitted provided that the following conditions are met:
00015 
00016  * Redistributions of source code must retain the above copyright notice,
00017    this list of conditions and the following disclaimer.
00018 
00019  * Redistributions in binary form must reproduce the above copyright notice,
00020    this list of conditions and the following disclaimer in the documentation
00021    and/or other materials provided with the distribution.
00022 
00023  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00024    of any contributors may be used to endorse or promote products derived
00025    from this software without specific prior written permission.
00026 
00027  * Modified source versions must be plainly marked as such, and must not be
00028    misrepresented as being the original software.
00029 
00030 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00031 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00032 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00033 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00034 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00035 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00036 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00037 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00038 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00039 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00040 
00041 =========================================================================*/
00042 // .NAME vtkDataWriter - helper class for objects that write vtk data files
00043 // .SECTION Description
00044 // vtkDataWriter is a helper class that opens and writes the vtk header and 
00045 // point data (e.g., scalars, vectors, normals, etc.) from a vtk data file. 
00046 // See text for various formats.
00047 
00048 // .SECTION See Also
00049 // vtkDataSetWriter vtkPolyDataWriter vtkStructuredGridWriter
00050 // vtkStructuredPointsWriter vtkUnstructuredGridWriter
00051 // vtkFieldDataWriter vtkRectilinearGridWriter
00052 
00053 #ifndef __vtkDataWriter_h
00054 #define __vtkDataWriter_h
00055 
00056 #include <stdio.h>
00057 #include "vtkWriter.h"
00058 
00059 class vtkDataSet;
00060 class vtkPoints;
00061 class vtkCellArray;
00062 class vtkDataArray;
00063 
00064 class VTK_IO_EXPORT vtkDataWriter : public vtkWriter
00065 {
00066 public:
00067   vtkTypeMacro(vtkDataWriter,vtkWriter);
00068   void PrintSelf(ostream& os, vtkIndent indent);
00069 
00070   // Description:
00071   // Created object with default header, ASCII format, and default names for 
00072   // scalars, vectors, tensors, normals, and texture coordinates.
00073   static vtkDataWriter *New();
00074 
00075   // Description:
00076   // Specify file name of vtk polygon data file to write.
00077   vtkSetStringMacro(FileName);
00078   vtkGetStringMacro(FileName);
00079 
00080   // Description:
00081   // Enable writing to an OutputString instead of the default, a file.
00082   vtkSetMacro(WriteToOutputString,int);
00083   vtkGetMacro(WriteToOutputString,int);
00084   vtkBooleanMacro(WriteToOutputString,int);
00085 
00086   // Description:
00087   // When WriteToOutputString in on, then a string is allocated, written to,
00088   // and can be retrieved with these methods.  The string is deleted during
00089   // the next call to write ...
00090   vtkGetMacro(OutputStringLength, int);  
00091   vtkGetStringMacro(OutputString);
00092   unsigned char *GetBinaryOutputString() {
00093       return (unsigned char *)this->OutputString;};
00094       
00095   // Description:
00096   // This convenience method returns the string, sets the IVAR to NULL,
00097   // so that the user is responsible for deleting the string.
00098   // I am not sure what the name should be, so it may change in the future.
00099   char *RegisterAndGetOutputString();
00100   
00101   // Description:
00102   // Specify the header for the vtk data file.
00103   vtkSetStringMacro(Header);
00104   vtkGetStringMacro(Header);
00105 
00106   // Description:
00107   // Specify file type (ASCII or BINARY) for vtk data file.
00108   vtkSetClampMacro(FileType,int,VTK_ASCII,VTK_BINARY);
00109   vtkGetMacro(FileType,int);
00110   void SetFileTypeToASCII() {this->SetFileType(VTK_ASCII);};
00111   void SetFileTypeToBinary() {this->SetFileType(VTK_BINARY);};
00112 
00113   // Description:
00114   // Give a name to the scalar data. If not specified, uses default
00115   // name "scalars".
00116   vtkSetStringMacro(ScalarsName);
00117   vtkGetStringMacro(ScalarsName);
00118 
00119   // Description:
00120   // Give a name to the vector data. If not specified, uses default
00121   // name "vectors".
00122   vtkSetStringMacro(VectorsName);
00123   vtkGetStringMacro(VectorsName);
00124 
00125   // Description:
00126   // Give a name to the tensors data. If not specified, uses default
00127   // name "tensors".
00128   vtkSetStringMacro(TensorsName);
00129   vtkGetStringMacro(TensorsName);
00130 
00131   // Description:
00132   // Give a name to the normals data. If not specified, uses default
00133   // name "normals".
00134   vtkSetStringMacro(NormalsName);
00135   vtkGetStringMacro(NormalsName);
00136 
00137   // Description:
00138   // Give a name to the texture coordinates data. If not specified, uses 
00139   // default name "textureCoords".
00140   vtkSetStringMacro(TCoordsName);
00141   vtkGetStringMacro(TCoordsName);
00142 
00143   // Description:
00144   // Give a name to the lookup table. If not specified, uses default
00145   // name "lookupTable".
00146   vtkSetStringMacro(LookupTableName);
00147   vtkGetStringMacro(LookupTableName);
00148 
00149   // Description:
00150   // Give a name to the field data. If not specified, uses default 
00151   // name "field".
00152   vtkSetStringMacro(FieldDataName);
00153   vtkGetStringMacro(FieldDataName);
00154 
00155   // Description:
00156   // Open a vtk data file. Returns NULL if error.
00157   virtual ostream *OpenVTKFile();
00158 
00159   // Description:
00160   // Write the header of a vtk data file. Returns 0 if error.
00161   int WriteHeader(ostream *fp);
00162 
00163   // Description:
00164   // Write out the points of the data set.
00165   int WritePoints(ostream *fp, vtkPoints *p);
00166 
00167   // Description:
00168   // Write out coordinates for rectilinear grids.
00169   int WriteCoordinates(ostream *fp, vtkDataArray *coords, int axes);
00170 
00171   // Description:
00172   // Write out the cells of the data set.
00173   int WriteCells(ostream *fp, vtkCellArray *cells, const char *label);
00174 
00175   // Description:
00176   // Write the cell data (e.g., scalars, vectors, ...) of a vtk dataset.
00177   // Returns 0 if error.
00178   int WriteCellData(ostream *fp, vtkDataSet *ds);
00179 
00180   // Description:
00181   // Write the point data (e.g., scalars, vectors, ...) of a vtk dataset.
00182   // Returns 0 if error.
00183   int WritePointData(ostream *fp, vtkDataSet *ds);
00184 
00185   // Description:
00186   // Write out the field data.
00187   int WriteFieldData(ostream *fp, vtkFieldData *f);
00188 
00189   // Description:
00190   // Write out the data associated with the dataset (i.e. field data owned by
00191   // the dataset itself - distinct from that owned by the cells or points).
00192   int WriteDataSetData(ostream *fp, vtkDataSet *ds);
00193 
00194   // Description:
00195   // Close a vtk file.
00196   void CloseVTKFile(ostream *fp);
00197 
00198 
00199 protected:
00200   vtkDataWriter();
00201   ~vtkDataWriter();
00202 
00203   int WriteToOutputString;
00204   char *OutputString;
00205   int OutputStringLength;
00206   int OutputStringAllocatedLength;
00207   
00208   void WriteData(); //dummy method to allow this class to be instantiated and delegated to
00209 
00210   char *FileName;
00211   char *Header;
00212   int FileType;
00213 
00214   char *ScalarsName;
00215   char *VectorsName;
00216   char *TensorsName;
00217   char *TCoordsName;
00218   char *NormalsName;
00219   char *LookupTableName;
00220   char *FieldDataName;
00221 
00222   int WriteArray(ostream *fp, int dataType, vtkDataArray *data, const char *format, 
00223                  int num, int numComp);
00224   int WriteScalarData(ostream *fp, vtkDataArray *s, int num);
00225   int WriteVectorData(ostream *fp, vtkDataArray *v, int num);
00226   int WriteNormalData(ostream *fp, vtkDataArray *n, int num);
00227   int WriteTCoordData(ostream *fp, vtkDataArray *tc, int num);
00228   int WriteTensorData(ostream *fp, vtkDataArray *t, int num);
00229 
00230 private:
00231   vtkDataWriter(const vtkDataWriter&);  // Not implemented.
00232   void operator=(const vtkDataWriter&);  // Not implemented.
00233 };
00234 
00235 #endif
00236 
00237