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"
29 #include "itkQuadrilateralCell.h"
30 #include "itkQuadraticEdgeCell.h"
32 #include "itkTetrahedronCell.h"
33 #include "itkTriangleCell.h"
34 #include "itkVertexCell.h"
35 
38 
39 namespace itk
40 {
41 
78 template <typename TOutputMesh,
79  typename ConvertPointPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::PixelType>,
80  typename ConvertCellPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::CellPixelType>>
81 class ITK_TEMPLATE_EXPORT MeshFileReader : public MeshSource<TOutputMesh>
82 {
83 public:
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
140  SetMeshIO(MeshIOBase * meshIO);
141  itkGetModifiableObjectMacro(MeshIO, MeshIOBase);
146  void
147  GenerateOutputInformation() override;
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
158  ReadPointData();
159 
160  void
161  ReadCellData();
162 
163 protected:
164  MeshFileReader();
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
184  TestFileExistanceAndReadability();
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 
195 private:
196  template <typename T>
197  void
198  ReadPointsUsingMeshIO();
199 
200  template <typename T>
201  void
202  ReadCellsUsingMeshIO();
203 
204  std::string m_ExceptionMessage{};
205 };
206 
207 
217 template <typename TOutputMesh,
218  typename ConvertPointPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::PixelType>,
219  typename ConvertCellPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::CellPixelType>>
220 typename TOutputMesh::Pointer
221 ReadMesh(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
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::MeshFileReader::OutputCellIdentifier
typename OutputMeshType::CellIdentifier OutputCellIdentifier
Definition: itkMeshFileReader.h:109
itkHexahedronCell.h
itk::VertexCell
Represents a single vertex for a Mesh.
Definition: itkVertexCell.h:37
itk::QuadrilateralCell
Represents a quadrilateral for a Mesh.
Definition: itkQuadrilateralCell.h:37
itk::PolyLineCell
Represents a series of connected line segments for a Mesh.
Definition: itkPolyLineCell.h:36
itkQuadrilateralCell.h
itk::MeshFileReader::New
static Pointer New()
itk::MeshIOBase::SizeValueType
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:89
itk::MeshFileReader::SizeValueType
typename MeshIOBase::SizeValueType SizeValueType
Definition: itkMeshFileReader.h:112
itk::MeshFileReader
Mesh source that reads mesh data from a single file.
Definition: itkMeshFileReader.h:81
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::MeshIOBase
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:72
itkLineCell.h
itk::PolygonCell
Represents a polygon in a Mesh.
Definition: itkPolygonCell.h:49
itk::SmartPointer< const Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::QuadraticEdgeCell
Represents a second order line segment for a Mesh.
Definition: itkQuadraticEdgeCell.h:35
itkDefaultConvertPixelTraits.h
itk::TetrahedronCell
TetrahedronCell represents a tetrahedron for a Mesh.
Definition: itkTetrahedronCell.h:36
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::MeshFileReader::OutputPointIdentifier
typename OutputMeshType::PointIdentifier OutputPointIdentifier
Definition: itkMeshFileReader.h:108
itk::MeshSource
Base class for all process objects that output mesh data.
Definition: itkMeshSource.h:49
itkMacro.h
itkMeshSource.h
itkPolyLineCell.h
itk::HexahedronCell
Represents a hexahedron (cuboid) for a Mesh.
Definition: itkHexahedronCell.h:45
itk::TriangleCell
Definition: itkTriangleCell.h:46
itkMeshFileReaderException.h
itk::MeshFileReader::OutputPointPixelType
typename OutputMeshType::PixelType OutputPointPixelType
Definition: itkMeshFileReader.h:105
itk::LineCell
Represents a line segment for a Mesh.
Definition: itkLineCell.h:40
itkVertexCell.h
itkMeshIOBase.h
itk::ReadMesh
TOutputMesh::Pointer ReadMesh(const std::string &filename)
Definition: itkMeshFileReader.h:221
itk::MeshFileReader::OutputCoordinateType
typename OutputMeshType::CoordinateType OutputCoordinateType
Definition: itkMeshFileReader.h:100
itk::MeshFileReader::OutputPointType
typename OutputMeshType::PointType OutputPointType
Definition: itkMeshFileReader.h:107
itk::MeshFileReader::OutputCellPixelType
typename OutputMeshType::CellPixelType OutputCellPixelType
Definition: itkMeshFileReader.h:106
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkPolygonCell.h
itkQuadraticEdgeCell.h
itk::MeshSource::OutputMeshType
TOutputMesh OutputMeshType
Definition: itkMeshSource.h:68
itk::MeshFileReader::OutputCellType
typename OutputMeshType::CellType OutputCellType
Definition: itkMeshFileReader.h:111
itkQuadraticTriangleCell.h
itk::QuadraticTriangleCell
Represents a second order triangular patch for a Mesh.
Definition: itkQuadraticTriangleCell.h:36
itkTriangleCell.h
itkMeshConvertPixelTraits.h
itk::MeshFileReader::OutputCellAutoPointer
typename OutputMeshType::CellAutoPointer OutputCellAutoPointer
Definition: itkMeshFileReader.h:110
itkTetrahedronCell.h