1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkMNIObjectWriter.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 /*========================================================================= 16 17 Copyright (c) 2006 Atamai, Inc. 18 19 Use, modification and redistribution of the software, in source or 20 binary forms, are permitted provided that the following terms and 21 conditions are met: 22 23 1) Redistribution of the source code, in verbatim or modified 24 form, must retain the above copyright notice, this license, 25 the following disclaimer, and any notices that refer to this 26 license and/or the following disclaimer. 27 28 2) Redistribution in binary form must include the above copyright 29 notice, a copy of this license and the following disclaimer 30 in the documentation or with other materials provided with the 31 distribution. 32 33 3) Modified copies of the source code must be clearly marked as such, 34 and must not be misrepresented as verbatim copies of the source code. 35 36 THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" 37 WITHOUT EXPRESSED OR IMPLIED WARRANTY INCLUDING, BUT NOT LIMITED TO, 38 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39 PURPOSE. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR OTHER PARTY WHO MAY 40 MODIFY AND/OR REDISTRIBUTE THE SOFTWARE UNDER THE TERMS OF THIS LICENSE 41 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES 42 (INCLUDING, BUT NOT LIMITED TO, LOSS OF DATA OR DATA BECOMING INACCURATE 43 OR LOSS OF PROFIT OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF 44 THE USE OR INABILITY TO USE THE SOFTWARE, EVEN IF ADVISED OF THE 45 POSSIBILITY OF SUCH DAMAGES. 46 47 =========================================================================*/ 48 /** 49 * @class vtkMNIObjectWriter 50 * @brief A writer for MNI surface mesh files. 51 * 52 * The MNI .obj file format is used to store geometrical data. This 53 * file format was developed at the McConnell Brain Imaging Centre at 54 * the Montreal Neurological Institute and is used by their software. 55 * Only polygon and line files are supported by this writer. For these 56 * formats, all data elements are written including normals, colors, 57 * and surface properties. ASCII and binary file types are supported. 58 * @sa 59 * vtkMINCImageReader vtkMNIObjectReader vtkMNITransformReader 60 * @par Thanks: 61 * Thanks to David Gobbi for writing this class and Atamai Inc. for 62 * contributing it to VTK. 63 */ 64 65 #ifndef vtkMNIObjectWriter_h 66 #define vtkMNIObjectWriter_h 67 68 #include "vtkIOMINCModule.h" // For export macro 69 #include "vtkWriter.h" 70 71 class vtkMapper; 72 class vtkProperty; 73 class vtkLookupTable; 74 class vtkPolyData; 75 class vtkFloatArray; 76 class vtkIntArray; 77 class vtkPoints; 78 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 * Get the extension for this file format. 89 */ GetFileExtensions()90 virtual const char* GetFileExtensions() { return ".obj"; } 91 92 /** 93 * Get the name of this file format. 94 */ GetDescriptiveName()95 virtual const char* GetDescriptiveName() { return "MNI object"; } 96 97 ///@{ 98 /** 99 * Set the property associated with the object. Optional. 100 * This is useful for exporting an actor. 101 */ 102 virtual void SetProperty(vtkProperty* property); GetProperty()103 virtual vtkProperty* GetProperty() { return this->Property; } 104 ///@} 105 106 ///@{ 107 /** 108 * Set the mapper associated with the object. Optional. 109 * This is useful for exporting an actor with the same colors 110 * that are used to display the actor within VTK. 111 */ 112 virtual void SetMapper(vtkMapper* mapper); GetMapper()113 virtual vtkMapper* GetMapper() { return this->Mapper; } 114 ///@} 115 116 ///@{ 117 /** 118 * Set the lookup table associated with the object. This will be 119 * used to convert scalar values to colors, if a mapper is not set. 120 */ 121 virtual void SetLookupTable(vtkLookupTable* table); GetLookupTable()122 virtual vtkLookupTable* GetLookupTable() { return this->LookupTable; } 123 ///@} 124 125 ///@{ 126 /** 127 * Get the input to this writer. 128 */ 129 vtkPolyData* GetInput(); 130 vtkPolyData* GetInput(int port); 131 ///@} 132 133 ///@{ 134 /** 135 * Specify file name of vtk polygon data file to write. 136 */ 137 vtkSetFilePathMacro(FileName); 138 vtkGetFilePathMacro(FileName); 139 ///@} 140 141 ///@{ 142 /** 143 * Specify file type (ASCII or BINARY) for vtk data file. 144 */ 145 vtkSetClampMacro(FileType, int, VTK_ASCII, VTK_BINARY); 146 vtkGetMacro(FileType, int); SetFileTypeToASCII()147 void SetFileTypeToASCII() { this->SetFileType(VTK_ASCII); } SetFileTypeToBinary()148 void SetFileTypeToBinary() { this->SetFileType(VTK_BINARY); } 149 ///@} 150 151 protected: 152 vtkMNIObjectWriter(); 153 ~vtkMNIObjectWriter() override; 154 155 vtkProperty* Property; 156 vtkMapper* Mapper; 157 vtkLookupTable* LookupTable; 158 159 ostream* OutputStream; 160 161 int WriteObjectType(int objType); 162 int WriteValues(vtkDataArray* array); 163 int WriteIdValue(vtkIdType value); 164 int WriteNewline(); 165 166 int WriteProperty(vtkProperty* property); 167 int WriteLineThickness(vtkProperty* property); 168 int WritePoints(vtkPolyData* polyData); 169 int WriteNormals(vtkPolyData* polyData); 170 int WriteColors(vtkProperty* property, vtkMapper* mapper, vtkPolyData* data); 171 int WriteCells(vtkPolyData* data, int cellType); 172 173 int WritePolygonObject(vtkPolyData* output); 174 int WriteLineObject(vtkPolyData* output); 175 176 void WriteData() override; 177 178 char* FileName; 179 180 int FileType; 181 182 int FillInputPortInformation(int port, vtkInformation* info) override; 183 184 ostream* OpenFile(); 185 void CloseFile(ostream* fp); 186 187 private: 188 vtkMNIObjectWriter(const vtkMNIObjectWriter&) = delete; 189 void operator=(const vtkMNIObjectWriter&) = delete; 190 }; 191 192 #endif 193