diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 24ad1c5..3276b16 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -6,13 +6,21 @@ set(ExampleSpecificComponents ) if(NOT ITK_SOURCE_DIR) - find_package(ITK REQUIRED COMPONENTS ITKImageIO ITKTransformIO ${ExampleSpecificComponents}) + find_package(ITK REQUIRED COMPONENTS ITKMeshIO ${ExampleSpecificComponents}) else() - # When being built as part of ITK, ITKImageIO and ITKTransformIO + # When being built as part of ITK, ITKMeshIO # lists of modules are not yet ready, causing a configure error find_package(ITK REQUIRED COMPONENTS ${ExampleSpecificComponents}) endif() include(${ITK_USE_FILE}) -add_executable(WriteMZ3Mesh WriteMZ3Mesh.cxx ) -target_link_libraries(WriteMZ3Mesh ${ITK_LIBRARIES}) +add_executable(ReadWriteMZ3Mesh ReadWriteMZ3Mesh.cxx) +target_link_libraries(ReadWriteMZ3Mesh ${ITK_LIBRARIES}) + +enable_testing() +add_test(NAME ReadWriteMZ3MeshTest + COMMAND ReadWriteMZ3Mesh + ${CMAKE_CURRENT_SOURCE_DIR}/cortex_5124.mz3 + ${CMAKE_CURRENT_BINARY_DIR}/cortex_5124_itk.mz3 + 1 + ) \ No newline at end of file diff --git a/examples/WriteMZ3Mesh.cxx b/examples/ReadWriteMZ3Mesh.cxx similarity index 54% rename from examples/WriteMZ3Mesh.cxx rename to examples/ReadWriteMZ3Mesh.cxx index 1f4af26..0fac7f9 100644 --- a/examples/WriteMZ3Mesh.cxx +++ b/examples/ReadWriteMZ3Mesh.cxx @@ -16,11 +16,10 @@ * *=========================================================================*/ -#include "itkMZ3MeshIO.h" - #include "itkCommand.h" -#include "itkImageFileReader.h" -#include "itkImageFileWriter.h" +#include "itkMeshFileReader.h" +#include "itkMeshFileWriter.h" +#include "itkMesh.h" int main( int argc, char * argv[] ) @@ -29,17 +28,30 @@ int main( int argc, char * argv[] ) { std::cerr << "Missing parameters." << std::endl; std::cerr << "Usage: " << argv[0] - << " inputImage" - << " outputImage" - << " parameters" << std::endl; + << " inputMesh" + << " outputMesh" + << " useCompression" << std::endl; return EXIT_FAILURE; } + char * inputMeshFileName = argv[1]; + char * outputMeshFileName = argv[2]; + bool useCompression = std::stoi( argv[3] ); + + constexpr unsigned int Dimension = 3; + using PixelType = float; + using MeshType = itk::Mesh< PixelType, Dimension >; + + // Read the mesh + // Any mesh format supported by ITK can be used here, including MZ3. + const auto mesh = itk::ReadMesh< MeshType >( inputMeshFileName ); - // Please, write a complete, self-containted and useful example that - // demonstrate a class when being used along with other ITK classes or in - // the context of a wider or specific application. + mesh->Print( std::cout ); + // Write the mesh + // Any mesh format supported by ITK can be used here, including MZ3. + // If useCompression is true, an MZ3 file includes GZip compression. + itk::WriteMesh( mesh, outputMeshFileName, useCompression ); return EXIT_SUCCESS; } diff --git a/examples/cortex_5124.mz3 b/examples/cortex_5124.mz3 new file mode 100644 index 0000000..92a88ad Binary files /dev/null and b/examples/cortex_5124.mz3 differ