ITK  5.3.0
Insight Toolkit
itkMeshFileWriter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 
22 #include "itkProcessObject.h"
23 #include "itkMeshIOBase.h"
24 
25 namespace itk
26 {
27 
51 template <typename TInputMesh>
52 class ITK_TEMPLATE_EXPORT MeshFileWriter : public ProcessObject
53 {
54 public:
55  ITK_DISALLOW_COPY_AND_MOVE(MeshFileWriter);
56 
62 
64  itkNewMacro(Self);
65 
67  itkTypeMacro(MeshFileWriter, ProcessObject);
68 
70  using InputMeshType = TInputMesh;
71  using InputMeshPointer = typename InputMeshType::Pointer;
73  using InputMeshPixelType = typename InputMeshType::PixelType;
74  using InputMeshCellType = typename InputMeshType::CellType;
76 
78  using Superclass::SetInput;
79  void
80  SetInput(const InputMeshType * input);
81 
82  const InputMeshType *
83  GetInput();
84 
85  const InputMeshType *
86  GetInput(unsigned int idx);
87 
89  itkSetStringMacro(FileName);
90  itkGetStringMacro(FileName);
92 
102  void
104  {
105  if (this->m_MeshIO != io)
106  {
107  this->Modified();
108  this->m_MeshIO = io;
109  }
110  m_FactorySpecifiedMeshIO = false;
111  m_UserSpecifiedMeshIO = true;
112  }
113  itkGetModifiableObjectMacro(MeshIO, MeshIOBase);
115 
116  void
118  {
119  m_FileTypeIsBINARY = false;
120  }
121  void
123  {
124  m_FileTypeIsBINARY = true;
125  }
126 
130  virtual void
131  Write();
132 
135  void
136  Update() override
137  {
138  this->Write();
139  }
140 
142  itkSetMacro(UseCompression, bool);
143  itkGetConstReferenceMacro(UseCompression, bool);
144  itkBooleanMacro(UseCompression);
146 
147 protected:
148  MeshFileWriter();
149  ~MeshFileWriter() override = default;
150  void
151  PrintSelf(std::ostream & os, Indent indent) const override;
152 
153  template <typename Output>
154  void
155  CopyPointsToBuffer(Output * data);
156 
157  template <typename Output>
158  void
159  CopyCellsToBuffer(Output * data);
160 
161  template <typename Output>
162  void
163  CopyPointDataToBuffer(Output * data);
164 
165  template <typename Output>
166  void
167  CopyCellDataToBuffer(Output * data);
168 
169  void
170  WritePoints();
171 
172  void
173  WriteCells();
174 
175  void
176  WritePointData();
177 
178  void
179  WriteCellData();
180 
181 private:
182  std::string m_FileName;
184  bool m_UserSpecifiedMeshIO; // track whether the MeshIO is
185  // user specified
186  bool m_FactorySpecifiedMeshIO; // track whether the factory
187  // mechanism set the MeshIO
190 };
191 } // end namespace itk
192 
193 #ifndef ITK_MANUAL_INSTANTIATION
194 # include "itkMeshFileWriter.hxx"
195 #endif
196 
197 #ifdef ITK_IO_FACTORY_REGISTER_MANAGER
198 # include "itkMeshIOFactoryRegisterManager.h"
199 #endif
200 
201 #endif // itkMeshFileWriter_h
itk::MeshFileWriter::InputMeshPixelType
typename InputMeshType::PixelType InputMeshPixelType
Definition: itkMeshFileWriter.h:73
itk::MeshFileWriter::m_FileTypeIsBINARY
bool m_FileTypeIsBINARY
Definition: itkMeshFileWriter.h:189
itk::MeshFileWriter
Writes mesh data to a single file.
Definition: itkMeshFileWriter.h:52
itk::MeshIOBase::SizeValueType
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:88
itk::MeshFileWriter::m_FactorySpecifiedMeshIO
bool m_FactorySpecifiedMeshIO
Definition: itkMeshFileWriter.h:186
itk::MeshIOBase
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:71
itk::MeshFileWriter::InputMeshRegionType
typename InputMeshType::RegionType InputMeshRegionType
Definition: itkMeshFileWriter.h:72
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::MeshFileWriter::InputMeshCellType
typename InputMeshType::CellType InputMeshCellType
Definition: itkMeshFileWriter.h:74
itk::MeshFileWriter::m_MeshIO
MeshIOBase::Pointer m_MeshIO
Definition: itkMeshFileWriter.h:183
itk::MeshFileWriter::m_UseCompression
bool m_UseCompression
Definition: itkMeshFileWriter.h:188
itkMeshFileWriterException.h
itk::MeshFileWriter::Update
void Update() override
Definition: itkMeshFileWriter.h:136
itk::MeshFileWriter::SetMeshIO
void SetMeshIO(MeshIOBase *io)
Definition: itkMeshFileWriter.h:103
itk::MeshFileWriter::m_UserSpecifiedMeshIO
bool m_UserSpecifiedMeshIO
Definition: itkMeshFileWriter.h:184
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itkProcessObject.h
itk::MeshFileWriter::SizeValueType
typename MeshIOBase::SizeValueType SizeValueType
Definition: itkMeshFileWriter.h:75
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::MeshFileWriter::InputMeshType
TInputMesh InputMeshType
Definition: itkMeshFileWriter.h:70
itk::MeshFileWriter::SetFileTypeAsBINARY
void SetFileTypeAsBINARY()
Definition: itkMeshFileWriter.h:122
itkMeshIOBase.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::ProcessObject
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
itk::MeshFileWriter::SetFileTypeAsASCII
void SetFileTypeAsASCII()
Definition: itkMeshFileWriter.h:117
itk::MeshFileWriter::InputMeshPointer
typename InputMeshType::Pointer InputMeshPointer
Definition: itkMeshFileWriter.h:71
itk::MeshFileWriter::m_FileName
std::string m_FileName
Definition: itkMeshFileWriter.h:182