Skip to content

Commit

Permalink
ENH: Add Python tests for existing input images
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Nov 29, 2024
1 parent 8409a4a commit 4e18770
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions itk-module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ itk_module(Cuberille
ITKQuadEdgeMeshFiltering
ITKThresholding
ITKIOImageBase
ITKIOMeta
ITKIONRRD
ITKIOMeshBase
ITKIOVTK
DESCRIPTION
"${DOCUMENTATION}"
EXCLUDE_FROM_DEFAULT
Expand Down
41 changes: 41 additions & 0 deletions wrapping/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
itk_python_expression_add_test(
NAME itkCuberilleImageToMeshFilterPythonTest
EXPRESSION "filter = itk.CuberilleImageToMeshFilter.New()"
)

set(test_input_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../test/Input)
# cmake_path(CONVERT ${test_input_dir} TO_CMAKE_PATH_LIST test_input_dir NORMALIZE) # CMake 3.20+

list(FIND ITK_WRAP_IMAGE_DIMS 3 wrap_3_index)
if(wrap_3_index GREATER -1)
itk_python_add_test(NAME Cuberille_blob0_python
TEST_DRIVER_ARGS
COMMAND cuberille_test.py
DATA{${test_input_dir}/blob0.mha}
${ITK_TEST_OUTPUT_DIR}/blob0.vtk
)

itk_python_add_test(NAME Cuberille_blob0_100_python
TEST_DRIVER_ARGS
COMMAND cuberille_test.py
DATA{${test_input_dir}/blob0.mha}
${ITK_TEST_OUTPUT_DIR}/blob0_100.vtk
100 # iso-surface value
)

itk_python_add_test(NAME Cuberille_hydrogenAtom_35_python
TEST_DRIVER_ARGS
COMMAND cuberille_test.py
DATA{${test_input_dir}/hydrogenAtom.mha}
${ITK_TEST_OUTPUT_DIR}/hydrogenAtom35.vtk
35 # iso-surface value
)

itk_python_add_test(NAME Cuberille_hydrogenAtom_50_python
TEST_DRIVER_ARGS
COMMAND cuberille_test.py
DATA{${test_input_dir}/hydrogenAtom.mha}
${ITK_TEST_OUTPUT_DIR}/hydrogenAtom50.vtk
50 # iso-surface value
)
endif()
30 changes: 30 additions & 0 deletions wrapping/test/cuberille_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys

import itk

image = itk.imread(sys.argv[1])

if len(sys.argv) > 3:
isosurface = sys.argv[3]
else:
calculator = itk.MinimumMaximumImageCalculator[type(image)].New()
calculator.SetImage(image)
calculator.Compute()
isosurface = (calculator.GetMaximum() + calculator.GetMinimum()) / 2

# convert number type
(input_image_template, (input_pixel_type, input_image_dimension)) = itk.template(image)
if input_pixel_type == itk.F or input_pixel_type == itk.D:
isosurface = float(isosurface)
else:
isosurface = int(isosurface)

mesh = itk.cuberille_image_to_mesh_filter(
image,
generate_triangle_faces=True,
iso_surface_value=isosurface,
project_vertices_to_iso_surface=True,
project_vertex_surface_distance_threshold=0.05,
)

itk.meshwrite(mesh, sys.argv[2])

0 comments on commit 4e18770

Please sign in to comment.