Skip to content

Commit eb98045

Browse files
committed
ENH: Add itk::ReadMesh
Similar to itk::ReadImage. Use typename over class in MeshFileReader
1 parent af32a77 commit eb98045

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Modules/IO/MeshBase/include/itkMeshFileReader.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace itk
7676

7777
template <typename TOutputMesh,
7878
typename ConvertPointPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::PixelType>,
79-
class ConvertCellPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::CellPixelType>>
79+
typename ConvertCellPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::CellPixelType>>
8080
class ITK_TEMPLATE_EXPORT MeshFileReader : public MeshSource<TOutputMesh>
8181
{
8282
public:
@@ -187,6 +187,29 @@ class ITK_TEMPLATE_EXPORT MeshFileReader : public MeshSource<TOutputMesh>
187187
private:
188188
std::string m_ExceptionMessage;
189189
};
190+
191+
192+
/** Convenience function for reading a mesh.
193+
*
194+
* `TOutputMesh` is the expected output mesh type, and the optional
195+
* `ConvertPointPixelTraits`, ``ConvertCellPixelTraits` template parameters are used to do the conversion,
196+
* as specified by MeshFileReader.
197+
*
198+
* The function reads the mesh from the specified file, and returns the
199+
* mesh that it has read.
200+
* */
201+
template <typename TOutputMesh,
202+
typename ConvertPointPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::PixelType>,
203+
typename ConvertCellPixelTraits = MeshConvertPixelTraits<typename TOutputMesh::CellPixelType>>
204+
typename TOutputMesh::Pointer
205+
ReadMesh(const std::string & filename)
206+
{
207+
const auto reader = MeshFileReader<TOutputMesh, ConvertPointPixelTraits, ConvertCellPixelTraits>::New();
208+
reader->SetFileName(filename);
209+
reader->Update();
210+
return reader->GetOutput();
211+
}
212+
190213
} // end namespace itk
191214

192215
#ifndef ITK_MANUAL_INSTANTIATION

Modules/IO/MeshBase/test/itkMeshFileReaderTest.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ itkMeshFileReaderTest(int argc, char * argv[])
5151

5252
ITK_TRY_EXPECT_NO_EXCEPTION(reader->Update());
5353

54+
MeshType::Pointer readMesh = nullptr;
55+
ITK_TRY_EXPECT_NO_EXCEPTION(readMesh = itk::ReadMesh<MeshType>(inputFileName));
5456

5557
std::cout << "Test finished" << std::endl;
5658
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)