ITK  4.8.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 #include "ITKIOMeshExport.h"
21 
22 #include "itkProcessObject.h"
23 #include "itkMeshIOBase.h"
24 #include "itkExceptionObject.h"
25 
26 namespace itk
27 {
33 class ITKIOMesh_HIDDEN MeshFileWriterException:public ExceptionObject
34 {
35 public:
38 
40  MeshFileWriterException(const char *file, unsigned int line,
41  const char *message = "Error in IO",
42  const char *loc = "Unknown"):
43  ExceptionObject(file, line, message, loc)
44  {}
45 
47  MeshFileWriterException(const std::string & file, unsigned int line,
48  const char *message = "Error in IO",
49  const char *loc = "Unknown"):
50  ExceptionObject(file, line, message, loc)
51  {}
52 };
54 
77 template< typename TInputMesh >
78 class ITKIOMesh_HIDDEN MeshFileWriter:public ProcessObject
79 {
80 public:
86 
88  itkNewMacro(Self);
89 
91  itkTypeMacro(MeshFileWriter, ProcessObject);
92 
94  typedef TInputMesh InputMeshType;
95  typedef typename InputMeshType::Pointer InputMeshPointer;
96  typedef typename InputMeshType::RegionType InputMeshRegionType;
97  typedef typename InputMeshType::PixelType InputMeshPixelType;
98  typedef typename InputMeshType::CellType InputMeshCellType;
100 
102  using Superclass::SetInput;
103  void SetInput(const InputMeshType *input);
104 
105  const InputMeshType * GetInput();
106 
107  const InputMeshType * GetInput(unsigned int idx);
108 
110  itkSetStringMacro(FileName);
111  itkGetStringMacro(FileName);
113 
124  {
125  if ( this->m_MeshIO != io )
126  {
127  this->Modified();
128  this->m_MeshIO = io;
129  }
130  m_FactorySpecifiedMeshIO = false;
131  m_UserSpecifiedMeshIO = true;
132  }
133  itkGetModifiableObjectMacro(MeshIO, MeshIOBase);
135 
136  void SetFileTypeAsASCII(){m_FileTypeIsBINARY = false; }
137  void SetFileTypeAsBINARY(){m_FileTypeIsBINARY = true; }
138 
142  virtual void Write();
143 
146  virtual void Update() ITK_OVERRIDE
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  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
161 
162  template< typename Output >
163  void CopyPointsToBuffer(Output *data);
164 
165  template< typename Output >
166  void CopyCellsToBuffer(Output *data);
167 
168  template< typename Output >
169  void CopyPointDataToBuffer(Output *data);
170 
171  template< typename 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
virtual void Update() override
Light weight base class for most itk classes.
MeshIOBase::Pointer m_MeshIO
MeshIOBase::SizeValueType SizeValueType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
MeshFileWriterException(const char *file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
MeshFileWriterException(const std::string &file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:84
InputMeshType::CellType InputMeshCellType
InputMeshType::PixelType InputMeshPixelType
ProcessObject Superclass
void SetMeshIO(MeshIOBase *io)
InputMeshType::Pointer InputMeshPointer
SmartPointer< const Self > ConstPointer
Standard exception handling object.
InputMeshType::RegionType InputMeshRegionType
SmartPointer< Self > Pointer
Writes mesh data to a single file.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:69
Base exception class for IO problems during writing.