ITK  4.3.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  }
133 
134  itkGetObjectMacro(MeshIO, MeshIOBase);
135 
136  void SetFileTypeAsASCII(){m_FileTypeIsBINARY = false; }
137  void SetFileTypeAsBINARY(){m_FileTypeIsBINARY = true; }
138 
142  virtual void Write(void);
143 
146  virtual void Update()
147  {
148  this->Write();
149  }
150 
152  itkSetMacro(UseCompression, bool);
153  itkGetConstReferenceMacro(UseCompression, bool);
154  itkBooleanMacro(UseCompression);
156 
157 protected:
158  MeshFileWriter();
159  ~MeshFileWriter();
160  void PrintSelf(std::ostream & os, Indent indent) const;
161 
162  template< class Output >
163  void CopyPointsToBuffer(Output *data);
164 
165  template< class Output >
166  void CopyCellsToBuffer(Output *data);
167 
168  template< class Output >
169  void CopyPointDataToBuffer(Output *data);
170 
171  template< class Output >
172  void CopyCellDataToBuffer(Output *data);
173 
174  void WritePoints();
175 
176  void WriteCells();
177 
178  void WritePointData();
179 
180  void WriteCellData();
181 
182 private:
183  MeshFileWriter(const Self &); // purposely not implemented
184  void operator=(const Self &); // purposely not implemented
185 
186  std::string m_FileName;
188  bool m_UserSpecifiedMeshIO; // track whether the MeshIO is
189  // user specified
190  bool m_FactorySpecifiedMeshIO; // track whether the factory
191  // mechanism set the MeshIO
194 };
195 } // end namespace itk
196 
197 #ifndef ITK_MANUAL_INSTANTIATION
198 #include "itkMeshFileWriter.hxx"
199 #endif
200 
201 #endif // __itkMeshFileWriter_h
202