ITK  5.4.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 * https://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
25namespace itk
26{
27
51template <typename TInputMesh>
52class ITK_TEMPLATE_EXPORT MeshFileWriter : public ProcessObject
53{
54public:
55 ITK_DISALLOW_COPY_AND_MOVE(MeshFileWriter);
56
62
64 itkNewMacro(Self);
65
67 itkOverrideGetNameOfClassMacro(MeshFileWriter);
68
70 using InputMeshType = TInputMesh;
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 *
84
85 const InputMeshType *
86 GetInput(unsigned int idx);
87
89 itkSetStringMacro(FileName);
90 itkGetStringMacro(FileName);
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);
116 void
118 {
119 m_FileTypeIsBINARY = false;
120 }
121 void
123 {
124 m_FileTypeIsBINARY = true;
125 }
126
130 virtual void
132
135 void
136 Update() override
137 {
138 this->Write();
139 }
140
142 itkSetMacro(UseCompression, bool);
143 itkGetConstReferenceMacro(UseCompression, bool);
144 itkBooleanMacro(UseCompression);
147protected:
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
171
172 void
174
175 void
177
178 void
180
181private:
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
188 bool m_UseCompression{};
189 bool m_FileTypeIsBINARY{};
190};
191
192
197template <typename TMeshPointer>
198ITK_TEMPLATE_EXPORT void
199WriteMesh(TMeshPointer && mesh, const std::string & filename, bool compress = false)
200{
201 using NonReferenceMeshPointer = std::remove_reference_t<TMeshPointer>;
202 static_assert(std::is_pointer_v<NonReferenceMeshPointer> || mpl::IsSmartPointer<NonReferenceMeshPointer>::Value,
203 "WriteMesh requires a raw pointer or SmartPointer.");
206 using MeshType = std::remove_const_t<std::remove_reference_t<decltype(*mesh)>>;
207 auto writer = MeshFileWriter<MeshType>::New();
208 writer->SetInput(mesh);
209 writer->SetFileName(filename);
210 writer->SetUseCompression(compress);
211 writer->Update();
212}
213
214} // end namespace itk
215
216#ifndef ITK_MANUAL_INSTANTIATION
217# include "itkMeshFileWriter.hxx"
218#endif
219
220#if defined ITK_MESHIO_FACTORY_REGISTER_MANAGER || defined ITK_IO_FACTORY_REGISTER_MANAGER
221# include "itkMeshIOFactoryRegisterManager.h"
222#endif
223
224#endif // itkMeshFileWriter_h
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Writes mesh data to a single file.
typename InputMeshType::Pointer InputMeshPointer
typename MeshIOBase::SizeValueType SizeValueType
void SetInput(const InputMeshType *input)
const InputMeshType * GetInput()
void CopyPointDataToBuffer(Output *data)
void CopyPointsToBuffer(Output *data)
~MeshFileWriter() override=default
const InputMeshType * GetInput(unsigned int idx)
void PrintSelf(std::ostream &os, Indent indent) const override
void CopyCellDataToBuffer(Output *data)
void SetMeshIO(MeshIOBase *io)
static Pointer New()
void Update() override
typename InputMeshType::RegionType InputMeshRegionType
typename InputMeshType::PixelType InputMeshPixelType
void CopyCellsToBuffer(Output *data)
typename InputMeshType::CellType InputMeshCellType
virtual void Write()
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:73
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:89
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITK_TEMPLATE_EXPORT void WriteMesh(TMeshPointer &&mesh, const std::string &filename, bool compress=false)
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41