ITK  6.0.0
Insight Toolkit
itkMeshFileReader.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 itkMeshFileReader_h
19#define itkMeshFileReader_h
20
22#include "itkMacro.h"
23#include "itkHexahedronCell.h"
24#include "itkLineCell.h"
25#include "itkPolyLineCell.h"
26#include "itkMeshIOBase.h"
27#include "itkMeshSource.h"
28#include "itkPolygonCell.h"
32#include "itkTetrahedronCell.h"
33#include "itkTriangleCell.h"
34#include "itkVertexCell.h"
35
38
39namespace itk
40{
41
78template <typename TOutputMesh,
79 typename ConvertPointPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::PixelType>,
80 typename ConvertCellPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::CellPixelType>>
81class ITK_TEMPLATE_EXPORT MeshFileReader : public MeshSource<TOutputMesh>
82{
83public:
84 ITK_DISALLOW_COPY_AND_MOVE(MeshFileReader);
85
91
93 itkNewMacro(Self);
94
96 itkOverrideGetNameOfClassMacro(MeshFileReader);
97
99 using OutputMeshType = TOutputMesh;
100 using OutputCoordinateType = typename OutputMeshType::CoordinateType;
101#ifndef ITK_FUTURE_LEGACY_REMOVE
102 using OutputCoordRepType ITK_FUTURE_DEPRECATED(
103 "ITK 6 discourages using `OutputCoordRepType`. Please use `OutputCoordinateType` instead!") = OutputCoordinateType;
104#endif
105 using OutputPointPixelType = typename OutputMeshType::PixelType;
106 using OutputCellPixelType = typename OutputMeshType::CellPixelType;
108 using OutputPointIdentifier = typename OutputMeshType::PointIdentifier;
109 using OutputCellIdentifier = typename OutputMeshType::CellIdentifier;
110 using OutputCellAutoPointer = typename OutputMeshType::CellAutoPointer;
111 using OutputCellType = typename OutputMeshType::CellType;
113
124
126 static constexpr unsigned int OutputPointDimension = OutputMeshType::PointDimension;
127
129 itkSetStringMacro(FileName);
130 itkGetStringMacro(FileName);
139 void
141 itkGetModifiableObjectMacro(MeshIO, MeshIOBase);
146 void
148
149 template <typename T>
150 void
151 ReadPoints(T * buffer);
152
153 template <typename T>
154 void
155 ReadCells(T * buffer);
156
157 void
159
160 void
162
163protected:
165 ~MeshFileReader() override = default;
166 void
167 PrintSelf(std::ostream & os, Indent indent) const override;
168
170 template <typename T>
171 void
172 ConvertPointPixelBuffer(void * inputData, T * outputData, size_t numberOfPixels);
173
174 template <typename T>
175 void
176 ConvertCellPixelBuffer(void * inputData, T * outputData, size_t numberOfPixels);
177
183 void
185
187 void
188 GenerateData() override;
189
191 bool m_UserSpecifiedMeshIO{}; // keep track whether the MeshIO is
192 // user specified
193 std::string m_FileName{}; // The file to be read
194
195private:
196 template <typename T>
197 void
199
200 template <typename T>
201 void
203
204 std::string m_ExceptionMessage{};
205};
206
207
217template <typename TOutputMesh,
218 typename ConvertPointPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::PixelType>,
219 typename ConvertCellPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::CellPixelType>>
221ReadMesh(const std::string & filename)
222{
224 reader->SetFileName(filename);
225 reader->Update();
226 return reader->GetOutput();
227}
230} // end namespace itk
231
232#ifndef ITK_MANUAL_INSTANTIATION
233# include "itkMeshFileReader.hxx"
234#endif
235
236#if defined ITK_MESHIO_FACTORY_REGISTER_MANAGER || defined ITK_IO_FACTORY_REGISTER_MANAGER
237# include "itkMeshIOFactoryRegisterManager.h"
238#endif
239
240#endif
Represents a hexahedron (cuboid) for a Mesh.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Represents a line segment for a Mesh.
Definition: itkLineCell.h:41
Mesh source that reads mesh data from a single file.
typename OutputMeshType::CellType OutputCellType
typename OutputMeshType::PointIdentifier OutputPointIdentifier
void TestFileExistanceAndReadability()
void ConvertCellPixelBuffer(void *inputData, T *outputData, vcl_size_t numberOfPixels)
typename OutputMeshType::CellIdentifier OutputCellIdentifier
void GenerateData() override
typename MeshIOBase::SizeValueType SizeValueType
typename OutputMeshType::CoordinateType OutputCoordinateType
void ConvertPointPixelBuffer(void *inputData, T *outputData, vcl_size_t numberOfPixels)
void ReadPoints(T *buffer)
typename OutputMeshType::PixelType OutputPointPixelType
void SetMeshIO(MeshIOBase *meshIO)
typename OutputMeshType::CellPixelType OutputCellPixelType
void GenerateOutputInformation() override
~MeshFileReader() override=default
typename OutputMeshType::CellAutoPointer OutputCellAutoPointer
static Pointer New()
void ReadPointsUsingMeshIO()
typename OutputMeshType::PointType OutputPointType
void PrintSelf(std::ostream &os, Indent indent) const override
void ReadCells(T *buffer)
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:73
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:89
Base class for all process objects that output mesh data.
Definition: itkMeshSource.h:50
TOutputMesh OutputMeshType
Definition: itkMeshSource.h:68
Represents a series of connected line segments for a Mesh.
Represents a polygon in a Mesh.
Represents a second order line segment for a Mesh.
Represents a second order triangular patch for a Mesh.
Represents a quadrilateral for a Mesh.
TetrahedronCell represents a tetrahedron for a Mesh.
Represents a single vertex for a Mesh.
Definition: itkVertexCell.h:38
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
TOutputMesh::Pointer ReadMesh(const std::string &filename)