ITK  5.4.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 OutputCoordRepType = typename OutputMeshType::CoordRepType;
101 using OutputPointPixelType = typename OutputMeshType::PixelType;
102 using OutputCellPixelType = typename OutputMeshType::CellPixelType;
104 using OutputPointIdentifier = typename OutputMeshType::PointIdentifier;
105 using OutputCellIdentifier = typename OutputMeshType::CellIdentifier;
106 using OutputCellAutoPointer = typename OutputMeshType::CellAutoPointer;
107 using OutputCellType = typename OutputMeshType::CellType;
109
120
122 static constexpr unsigned int OutputPointDimension = OutputMeshType::PointDimension;
123
125 itkSetStringMacro(FileName);
126 itkGetStringMacro(FileName);
135 void
137 itkGetModifiableObjectMacro(MeshIO, MeshIOBase);
142 void
144
145 template <typename T>
146 void
147 ReadPoints(T * buffer);
148
149 template <typename T>
150 void
151 ReadCells(T * buffer);
152
153 void
155
156 void
158
159protected:
161 ~MeshFileReader() override = default;
162 void
163 PrintSelf(std::ostream & os, Indent indent) const override;
164
166 template <typename T>
167 void
168 ConvertPointPixelBuffer(void * inputData, T * outputData, size_t numberOfPixels);
169
170 template <typename T>
171 void
172 ConvertCellPixelBuffer(void * inputData, T * outputData, size_t numberOfPixels);
173
179 void
181
183 void
184 GenerateData() override;
185
187 bool m_UserSpecifiedMeshIO{}; // keep track whether the MeshIO is
188 // user specified
189 std::string m_FileName{}; // The file to be read
190
191private:
192 template <typename T>
193 void
195
196 template <typename T>
197 void
199
200 std::string m_ExceptionMessage{};
201};
202
203
213template <typename TOutputMesh,
214 typename ConvertPointPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::PixelType>,
215 typename ConvertCellPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::CellPixelType>>
217ReadMesh(const std::string & filename)
218{
220 reader->SetFileName(filename);
221 reader->Update();
222 return reader->GetOutput();
223}
226} // end namespace itk
227
228#ifndef ITK_MANUAL_INSTANTIATION
229# include "itkMeshFileReader.hxx"
230#endif
231
232#if defined ITK_MESHIO_FACTORY_REGISTER_MANAGER || defined ITK_IO_FACTORY_REGISTER_MANAGER
233# include "itkMeshIOFactoryRegisterManager.h"
234#endif
235
236#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:46
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
void ConvertPointPixelBuffer(void *inputData, T *outputData, vcl_size_t numberOfPixels)
void ReadPoints(T *buffer)
typename OutputMeshType::CoordRepType OutputCoordRepType
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:43
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
TOutputMesh::Pointer ReadMesh(const std::string &filename)