ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkMeshFileWriter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkMeshFileWriter_h
19 #define __itkMeshFileWriter_h
20 
21 #include "itkProcessObject.h"
22 #include "itkMeshIOBase.h"
23 #include "itkExceptionObject.h"
24 
25 namespace itk
26 {
32 class ITK_ABI_EXPORT MeshFileWriterException:public ExceptionObject
33 {
34 public:
37 
39  MeshFileWriterException(const char *file, unsigned int line,
40  const char *message = "Error in IO",
41  const char *loc = "Unknown"):
42  ExceptionObject(file, line, message, loc)
43  {}
44 
46  MeshFileWriterException(const std::string & file, unsigned int line,
47  const char *message = "Error in IO",
48  const char *loc = "Unknown"):
49  ExceptionObject(file, line, message, loc)
50  {}
51 };
53 
76 template< class TInputMesh >
77 class ITK_EXPORT MeshFileWriter:public ProcessObject
78 {
79 public:
85 
87  itkNewMacro(Self);
88 
90  itkTypeMacro(MeshFileWriter, ProcessObject);
91 
93  typedef TInputMesh InputMeshType;
94  typedef typename InputMeshType::Pointer InputMeshPointer;
95  typedef typename InputMeshType::RegionType InputMeshRegionType;
96  typedef typename InputMeshType::PixelType InputMeshPixelType;
97  typedef typename InputMeshType::CellType InputMeshCellType;
99 
101  using Superclass::SetInput;
102  void SetInput(const InputMeshType *input);
103 
104  const InputMeshType * GetInput(void);
105 
106  const InputMeshType * GetInput(unsigned int idx);
107 
109  itkSetStringMacro(FileName);
110  itkGetStringMacro(FileName);
112 
122  void SetMeshIO(MeshIOBase *io)
123  {
124  if ( this->m_MeshIO != io )
125  {
126  this->Modified();
127  this->m_MeshIO = io;
128  }
129  m_FactorySpecifiedMeshIO = false;
130  m_UserSpecifiedMeshIO = true;
131  }
132  itkGetModifiableObjectMacro(MeshIO, MeshIOBase);
134 
135  void SetFileTypeAsASCII(){m_FileTypeIsBINARY = false; }
136  void SetFileTypeAsBINARY(){m_FileTypeIsBINARY = true; }
137 
141  virtual void Write(void);
142 
145  virtual void Update()
146  {
147  this->Write();
148  }
149 
151  itkSetMacro(UseCompression, bool);
152  itkGetConstReferenceMacro(UseCompression, bool);
153  itkBooleanMacro(UseCompression);
155 
156 protected:
157  MeshFileWriter();
158  ~MeshFileWriter();
159  void PrintSelf(std::ostream & os, Indent indent) const;
160 
161  template< class Output >
162  void CopyPointsToBuffer(Output *data);
163 
164  template< class Output >
165  void CopyCellsToBuffer(Output *data);
166 
167  template< class Output >
168  void CopyPointDataToBuffer(Output *data);
169 
170  template< class Output >
171  void CopyCellDataToBuffer(Output *data);
172 
173  void WritePoints();
174 
175  void WriteCells();
176 
177  void WritePointData();
178 
179  void WriteCellData();
180 
181 private:
182  MeshFileWriter(const Self &); // purposely not implemented
183  void operator=(const Self &); // purposely not implemented
184 
185  std::string m_FileName;
187  bool m_UserSpecifiedMeshIO; // track whether the MeshIO is
188  // user specified
189  bool m_FactorySpecifiedMeshIO; // track whether the factory
190  // mechanism set the MeshIO
193 };
194 } // end namespace itk
195 
196 #ifndef ITK_MANUAL_INSTANTIATION
197 #include "itkMeshFileWriter.hxx"
198 #endif
199 
200 #endif // __itkMeshFileWriter_h
201