Skip to content

Commit

Permalink
DOC: Add C++ example
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Dec 3, 2024
1 parent 7a26bfc commit 3ec2fa5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
16 changes: 12 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
32 changes: 22 additions & 10 deletions examples/WriteMZ3Mesh.cxx → examples/ReadWriteMZ3Mesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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[] )
Expand All @@ -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;
}
Binary file added examples/cortex_5124.mz3
Binary file not shown.

0 comments on commit 3ec2fa5

Please sign in to comment.