vtkMNIObjectWriter.h 5.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkMNIObjectWriter.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/*=========================================================================

Copyright (c) 2006 Atamai, Inc.

Use, modification and redistribution of the software, in source or
binary forms, are permitted provided that the following terms and
conditions are met:

1) Redistribution of the source code, in verbatim or modified
   form, must retain the above copyright notice, this license,
   the following disclaimer, and any notices that refer to this
   license and/or the following disclaimer.

2) Redistribution in binary form must include the above copyright
   notice, a copy of this license and the following disclaimer
   in the documentation or with other materials provided with the
   distribution.

3) Modified copies of the source code must be clearly marked as such,
   and must not be misrepresented as verbatim copies of the source code.

THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS"
WITHOUT EXPRESSED OR IMPLIED WARRANTY INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR OTHER PARTY WHO MAY
MODIFY AND/OR REDISTRIBUTE THE SOFTWARE UNDER THE TERMS OF THIS LICENSE
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, LOSS OF DATA OR DATA BECOMING INACCURATE
OR LOSS OF PROFIT OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF
THE USE OR INABILITY TO USE THE SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

=========================================================================*/
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
/**
 * @class   vtkMNIObjectWriter
 * @brief   A writer for MNI surface mesh files.
 *
 * The MNI .obj file format is used to store geometrical data.  This
 * file format was developed at the McConnell Brain Imaging Centre at
 * the Montreal Neurological Institute and is used by their software.
 * Only polygon and line files are supported by this writer.  For these
 * formats, all data elements are written including normals, colors,
 * and surface properties.  ASCII and binary file types are supported.
 * @sa
 * vtkMINCImageReader vtkMNIObjectReader vtkMNITransformReader
 * @par Thanks:
 * Thanks to David Gobbi for writing this class and Atamai Inc. for
 * contributing it to VTK.
*/
64

65 66
#ifndef vtkMNIObjectWriter_h
#define vtkMNIObjectWriter_h
67

68
#include "vtkIOMINCModule.h" // For export macro
69
#include "vtkWriter.h"
70

71
class vtkMapper;
72 73 74 75 76 77 78
class vtkProperty;
class vtkLookupTable;
class vtkPolyData;
class vtkFloatArray;
class vtkIntArray;
class vtkPoints;

79
class VTKIOMINC_EXPORT vtkMNIObjectWriter : public vtkWriter
80 81
{
public:
82
  vtkTypeMacro(vtkMNIObjectWriter,vtkWriter);
83 84

  static vtkMNIObjectWriter *New();
85
  void PrintSelf(ostream& os, vtkIndent indent) override;
86

87 88 89
  /**
   * Get the entension for this file format.
   */
90 91 92
  virtual const char* GetFileExtensions() {
    return ".obj"; }

93 94 95
  /**
   * Get the name of this file format.
   */
96 97 98
  virtual const char* GetDescriptiveName() {
    return "MNI object"; }

99 100 101 102 103
  //@{
  /**
   * Set the property associated with the object.  Optional.
   * This is useful for exporting an actor.
   */
104 105
  virtual void SetProperty(vtkProperty *property);
  virtual vtkProperty *GetProperty() { return this->Property; };
106 107 108 109 110 111 112 113
  //@}

  //@{
  /**
   * Set the mapper associated with the object.  Optional.
   * This is useful for exporting an actor with the same colors
   * that are used to display the actor within VTK.
   */
114 115
  virtual void SetMapper(vtkMapper *mapper);
  virtual vtkMapper *GetMapper() { return this->Mapper; };
116
  //@}
117

118 119 120 121 122
  //@{
  /**
   * Set the lookup table associated with the object.  This will be
   * used to convert scalar values to colors, if a mapper is not set.
   */
123 124
  virtual void SetLookupTable(vtkLookupTable *table);
  virtual vtkLookupTable *GetLookupTable() { return this->LookupTable; };
125
  //@}
126

127 128 129 130
  //@{
  /**
   * Get the input to this writer.
   */
131 132
  vtkPolyData* GetInput();
  vtkPolyData* GetInput(int port);
133
  //@}
134

135 136 137 138
  //@{
  /**
   * Specify file name of vtk polygon data file to write.
   */
139 140
  vtkSetStringMacro(FileName);
  vtkGetStringMacro(FileName);
141
  //@}
142

143 144 145 146
  //@{
  /**
   * Specify file type (ASCII or BINARY) for vtk data file.
   */
147 148 149 150
  vtkSetClampMacro(FileType,int,VTK_ASCII,VTK_BINARY);
  vtkGetMacro(FileType,int);
  void SetFileTypeToASCII() {this->SetFileType(VTK_ASCII);};
  void SetFileTypeToBinary() {this->SetFileType(VTK_BINARY);};
151
  //@}
152

153 154
protected:
  vtkMNIObjectWriter();
155
  ~vtkMNIObjectWriter() override;
156 157

  vtkProperty *Property;
158
  vtkMapper *Mapper;
159 160 161 162 163 164 165 166 167 168 169 170 171
  vtkLookupTable *LookupTable;

  ostream *OutputStream;

  int WriteObjectType(int objType);
  int WriteValues(vtkDataArray *array);
  int WriteIdValue(vtkIdType value);
  int WriteNewline();

  int WriteProperty(vtkProperty *property);
  int WriteLineThickness(vtkProperty *property);
  int WritePoints(vtkPolyData *polyData);
  int WriteNormals(vtkPolyData *polyData);
172
  int WriteColors(vtkProperty *property, vtkMapper *mapper, vtkPolyData *data);
173 174 175 176 177
  int WriteCells(vtkPolyData *data, int cellType);

  int WritePolygonObject(vtkPolyData *output);
  int WriteLineObject(vtkPolyData *output);

178
  void WriteData() override;
179

180 181 182 183
  char* FileName;

  int FileType;

184
  int FillInputPortInformation(int port, vtkInformation *info) override;
185 186 187 188

  ostream *OpenFile();
  void CloseFile(ostream *fp);

189
private:
190 191
  vtkMNIObjectWriter(const vtkMNIObjectWriter&) = delete;
  void operator=(const vtkMNIObjectWriter&) = delete;
192 193 194 195

};

#endif