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 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
136  SetMeshIO(MeshIOBase * meshIO);
137  itkGetModifiableObjectMacro(MeshIO, MeshIOBase);
142  void
143  GenerateOutputInformation() override;
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
154  ReadPointData();
155 
156  void
157  ReadCellData();
158 
159 protected:
160  MeshFileReader();
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
180  TestFileExistanceAndReadability();
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 
191 private:
192  template <typename T>
193  void
194  ReadPointsUsingMeshIO();
195 
196  template <typename T>
197  void
198  ReadCellsUsingMeshIO();
199 
200  std::string m_ExceptionMessage{};
201 };
202 
203 
213 template <typename TOutputMesh,
214  typename ConvertPointPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::PixelType>,
215  typename ConvertCellPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::CellPixelType>>
216 typename TOutputMesh::Pointer
217 ReadMesh(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
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::MeshFileReader::OutputCellIdentifier
typename OutputMeshType::CellIdentifier OutputCellIdentifier
Definition: itkMeshFileReader.h:105
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::OutputCoordRepType
typename OutputMeshType::CoordRepType OutputCoordRepType
Definition: itkMeshFileReader.h:100
itk::MeshFileReader::SizeValueType
typename MeshIOBase::SizeValueType SizeValueType
Definition: itkMeshFileReader.h:108
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:104
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:101
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:217
itk::MeshFileReader::OutputPointType
typename OutputMeshType::PointType OutputPointType
Definition: itkMeshFileReader.h:103
itk::MeshFileReader::OutputCellPixelType
typename OutputMeshType::CellPixelType OutputCellPixelType
Definition: itkMeshFileReader.h:102
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:107
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:106
itkTetrahedronCell.h