ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkMeshFileWriter_h 00019 #define __itkMeshFileWriter_h 00020 00021 #include "itkProcessObject.h" 00022 #include "itkMeshIOBase.h" 00023 #include "itkExceptionObject.h" 00024 00025 namespace itk 00026 { 00032 class ITK_ABI_EXPORT MeshFileWriterException:public ExceptionObject 00033 { 00034 public: 00036 itkTypeMacro(MeshFileWriterException, ExceptionObject); 00037 00039 MeshFileWriterException(const char *file, unsigned int line, 00040 const char *message = "Error in IO", 00041 const char *loc = "Unknown"): 00042 ExceptionObject(file, line, message, loc) 00043 {} 00044 00046 MeshFileWriterException(const std::string & file, unsigned int line, 00047 const char *message = "Error in IO", 00048 const char *loc = "Unknown"): 00049 ExceptionObject(file, line, message, loc) 00050 {} 00051 }; 00053 00076 template< class TInputMesh > 00077 class ITK_EXPORT MeshFileWriter:public ProcessObject 00078 { 00079 public: 00081 typedef MeshFileWriter Self; 00082 typedef ProcessObject Superclass; 00083 typedef SmartPointer< Self > Pointer; 00084 typedef SmartPointer< const Self > ConstPointer; 00085 00087 itkNewMacro(Self); 00088 00090 itkTypeMacro(MeshFileWriter, ProcessObject); 00091 00093 typedef TInputMesh InputMeshType; 00094 typedef typename InputMeshType::Pointer InputMeshPointer; 00095 typedef typename InputMeshType::RegionType InputMeshRegionType; 00096 typedef typename InputMeshType::PixelType InputMeshPixelType; 00097 typedef typename InputMeshType::CellType InputMeshCellType; 00098 typedef typename MeshIOBase::SizeValueType SizeValueType; 00099 00101 using Superclass::SetInput; 00102 void SetInput(const InputMeshType *input); 00103 00104 const InputMeshType * GetInput(void); 00105 00106 const InputMeshType * GetInput(unsigned int idx); 00107 00109 itkSetStringMacro(FileName); 00110 itkGetStringMacro(FileName); 00112 00122 void SetMeshIO(MeshIOBase *io) 00123 { 00124 if ( this->m_MeshIO != io ) 00125 { 00126 this->Modified(); 00127 this->m_MeshIO = io; 00128 } 00129 m_FactorySpecifiedMeshIO = false; 00130 m_UserSpecifiedMeshIO = true; 00131 } 00133 00134 itkGetObjectMacro(MeshIO, MeshIOBase); 00135 00136 void SetFileTypeAsASCII(){m_FileTypeIsBINARY = false; } 00137 void SetFileTypeAsBINARY(){m_FileTypeIsBINARY = true; } 00138 00142 virtual void Write(void); 00143 00146 virtual void Update() 00147 { 00148 this->Write(); 00149 } 00150 00152 itkSetMacro(UseCompression, bool); 00153 itkGetConstReferenceMacro(UseCompression, bool); 00154 itkBooleanMacro(UseCompression); 00156 00157 protected: 00158 MeshFileWriter(); 00159 ~MeshFileWriter(); 00160 void PrintSelf(std::ostream & os, Indent indent) const; 00161 00162 template< class Output > 00163 void CopyPointsToBuffer(Output *data); 00164 00165 template< class Output > 00166 void CopyCellsToBuffer(Output *data); 00167 00168 template< class Output > 00169 void CopyPointDataToBuffer(Output *data); 00170 00171 template< class Output > 00172 void CopyCellDataToBuffer(Output *data); 00173 00174 void WritePoints(); 00175 00176 void WriteCells(); 00177 00178 void WritePointData(); 00179 00180 void WriteCellData(); 00181 00182 private: 00183 MeshFileWriter(const Self &); // purposely not implemented 00184 void operator=(const Self &); // purposely not implemented 00185 00186 std::string m_FileName; 00187 MeshIOBase::Pointer m_MeshIO; 00188 bool m_UserSpecifiedMeshIO; // track whether the MeshIO is 00189 // user specified 00190 bool m_FactorySpecifiedMeshIO; // track whether the factory 00191 // mechanism set the MeshIO 00192 bool m_UseCompression; 00193 bool m_FileTypeIsBINARY; 00194 }; 00195 } // end namespace itk 00196 00197 #ifndef ITK_MANUAL_INSTANTIATION 00198 #include "itkMeshFileWriter.hxx" 00199 #endif 00200 00201 #endif // __itkMeshFileWriter_h 00202