Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python wrapping for PhasedArray3DSpecialCoordinatesImage #4101

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Modules/Core/Common/wrapping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ set(WRAPPER_SUBMODULE_ORDER
itkSymmetricSecondRankTensor
itkImage
itkVectorImage
itkSpecialCoordinatesImage
itkPhasedArray3DSpecialCoordinatesImage
itkNeighborhood
# SwigExtras
itkImageSourceCommon
Expand Down
9 changes: 9 additions & 0 deletions Modules/Core/Common/wrapping/itkImageSource.wrap
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::ImageSource" POINTER)
# Force uchar and ulong image sources for saving in 8 bits and watershed filter
UNIQUE(image_types "UC;RGBUC;RGBAUC;SI;UI;UL;ULL;${ITKM_IT};${WRAP_ITK_ALL_TYPES}")
Expand All @@ -24,4 +25,12 @@ itk_wrap_class("itk::ImageSource" POINTER)
endforeach()
endif()

# PhasedArray3DSpecialCoordinatesImage
foreach(real_type ${WRAP_ITK_SCALAR})
itk_wrap_template("PA3DSCI${ITKM_${real_type}}" "itk::PhasedArray3DSpecialCoordinatesImage<${ITKT_${real_type}}>")
endforeach()
foreach(complex_type ${WRAP_ITK_COMPLEX_REAL})
itk_wrap_template("PA3DSCI${ITKM_${complex_type}}" "itk::PhasedArray3DSpecialCoordinatesImage<${ITKT_${complex_type}}>")
endforeach()

itk_end_wrap_class()
28 changes: 28 additions & 0 deletions Modules/Core/Common/wrapping/itkImageToImageFilterB.wrap
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::ImageToImageFilter" POINTER)

# scalar <-> RGB
Expand Down Expand Up @@ -71,4 +72,31 @@ itk_wrap_class("itk::ImageToImageFilter" POINTER)
endforeach()
endif()

# PhasedArray3DSpecialCoordinatesImage
foreach(t ${WRAP_ITK_SCALAR})
foreach(ut ${WRAP_ITK_INT})
itk_wrap_template("I${ITKM_${t}}3PA3DSCI${ITKM_${ut}}"
"itk::Image< ${ITKT_${t}}, 3 >, itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${ut}} >")
endforeach()
foreach(t2 ${WRAP_ITK_SCALAR})
itk_wrap_template("PA3DSCI${ITKM_${t}}PA3DSCI${ITKM_${t2}}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t2}} >")
itk_wrap_template("PA3DSCI${ITKM_${t}}I${ITKM_${t2}}3"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, itk::Image< ${ITKT_${t2}}, 3 >")
endforeach()
endforeach()

foreach(rt ${WRAP_ITK_REAL})
foreach(ct ${WRAP_ITK_COMPLEX_REAL})
itk_wrap_template("PA3DSCI${ITKM_${rt}}PA3DSCI${ITKM_${ct}}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${rt}} >, itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${ct}} >")
itk_wrap_template("PA3DSCI${ITKM_${ct}}PA3DSCI${ITKM_${rt}}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${ct}} >, itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${rt}} >")
endforeach()
endforeach()

foreach(t3 ${WRAP_ITK_COMPLEX_REAL})
itk_wrap_template("PA3DSCI${ITKM_${t3}}PA3DSCI${ITKM_${t3}}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t3}} >, itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t3}} >")
endforeach()
itk_end_wrap_class()
9 changes: 9 additions & 0 deletions Modules/Core/Common/wrapping/itkInPlaceImageFilterB.wrap
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::InPlaceImageFilter" POINTER)
# VectorImage <-> scalar
UNIQUE(to_types "UC;${WRAP_ITK_SCALAR}")
Expand Down Expand Up @@ -38,4 +39,12 @@ itk_wrap_class("itk::InPlaceImageFilter" POINTER)
endforeach()
endforeach()

# PhasedArray3DSpecialCoordinatesImage
foreach(t ${WRAP_ITK_SCALAR})
foreach(ut ${WRAP_ITK_INT})
itk_wrap_template("I${ITKM_${t}}3PA3DSCI${ITKM_${ut}}"
"itk::Image< ${ITKT_${t}}, 3 >, itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${ut}} >")
endforeach()
endforeach()

itk_end_wrap_class()
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
itk_wrap_include("complex")

# Explicitly override template method wrappings so that implicit
# scalar type is always `double` for greatest precision.
# Adds wrapping overrides to `itkPhasedArray3DSpecialCoordinatesImage_ext.i` configured with
# CMake for input to SWIG wrapping generation.
# See `DECL_PYTHON_IMAGEBASE_CLASS` definition in `ITK/Wrapping/Generators/Python/PyBase/pyBase.i`
# for precedent.
string(APPEND ITK_WRAP_PYTHON_SWIG_EXT "
%inline %{
#include \"itkContinuousIndexSwigInterface.h\"
%}

%define DECL_PYTHON_PHASEDARRAY3DSPECIALCOORDINATESIMAGE_CLASS(swig_name, template_params)

%extend swig_name {
itkIndex##template_params TransformPhysicalPointToIndex(const itkPointD##template_params & point ) {
return self->TransformPhysicalPointToIndex<double>( point );
}

itkContinuousIndexD##template_params TransformPhysicalPointToContinuousIndex(const itkPointD##template_params & point ) {
return self->TransformPhysicalPointToContinuousIndex<double>( point );
}

itkPointD##template_params TransformContinuousIndexToPhysicalPoint(const itkContinuousIndexD##template_params & idx ) {
return self->TransformContinuousIndexToPhysicalPoint<double>( idx );
}

itkPointD##template_params TransformIndexToPhysicalPoint(const itkIndex##template_params & idx ) {
return self->TransformIndexToPhysicalPoint<double>( idx );
}
}

%enddef
")

# Wrap class for real and complex pixel types. Dimension is always 3.
itk_wrap_class("itk::PhasedArray3DSpecialCoordinatesImage" POINTER_WITH_SUPERCLASS)
foreach(t ${WRAP_ITK_SCALAR})
itk_wrap_template("${ITKM_${t}}" "${ITKT_${t}}")
string(APPEND ITK_WRAP_PYTHON_SWIG_EXT "DECL_PYTHON_PHASEDARRAY3DSPECIALCOORDINATESIMAGE_CLASS(${WRAPPER_SWIG_NAME}${ITKM_${t}}, 3)\n")
endforeach()
foreach(t3 ${WRAP_ITK_COMPLEX_REAL})
itk_wrap_template("${ITKM_${t3}}" "${ITKT_${t3}}")
string(APPEND ITK_WRAP_PYTHON_SWIG_EXT "DECL_PYTHON_PHASEDARRAY3DSPECIALCOORDINATESIMAGE_CLASS(${WRAPPER_SWIG_NAME}${ITKM_${t3}}, 3)\n")
endforeach()
itk_end_wrap_class()

# Then wrap consuming filters in itkPhasedArray3DSpecialCoordinatesImageFilters.wrap
13 changes: 13 additions & 0 deletions Modules/Core/Common/wrapping/itkSpecialCoordinatesImage.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
itk_wrap_include("complex")

# Wrap underlying class hierarchy
itk_wrap_class("itk::SpecialCoordinatesImage" POINTER)
foreach(d ${ITK_WRAP_IMAGE_DIMS})
foreach(t ${WRAP_ITK_SCALAR})
itk_wrap_template("${ITKM_${t}}${d}" "${ITKT_${t}}, ${d}")
endforeach()
foreach(t3 ${WRAP_ITK_COMPLEX_REAL})
itk_wrap_template("${ITKM_${t3}}${d}" "${ITKT_${t3}}, ${d}")
endforeach()
endforeach()
itk_end_wrap_class()
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::GaussianInterpolateImageFunction" POINTER)
foreach(d ${ITK_WRAP_IMAGE_DIMS})
foreach(t ${WRAP_ITK_SCALAR})
itk_wrap_template("${ITKM_I${t}${d}}${ITKM_D}" "${ITKT_I${t}${d}},${ITKT_D}")
endforeach()
endforeach()

set(PA3DSCI_types "F")
if(ITK_WRAP_unsigned_char)
list(APPEND PA3DSCI_types "UC")
endif()
foreach(t ${PA3DSCI_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}${ITKM_D}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${ITKT_D}")
endforeach()
itk_end_wrap_class()
10 changes: 10 additions & 0 deletions Modules/Core/ImageFunction/wrapping/itkImageFunctionBase.wrap
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::ImageFunction" POINTER)
foreach(d ${ITK_WRAP_IMAGE_DIMS})
# UC is required for InterpolateImageFunction
Expand Down Expand Up @@ -31,4 +32,13 @@ itk_wrap_class("itk::ImageFunction" POINTER)
endforeach()

endforeach()

set(PA3DSCI_types "F")
if(ITK_WRAP_unsigned_char)
list(APPEND PA3DSCI_types "UC")
endif()
foreach(t ${PA3DSCI_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}${ITKM_D}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${ITKT_D}, ${ITKT_D}")
endforeach()
itk_end_wrap_class()
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::InterpolateImageFunction" POINTER)
UNIQUE(types "${WRAP_ITK_SCALAR};UC")
foreach(d ${ITK_WRAP_IMAGE_DIMS})
Expand All @@ -15,4 +16,12 @@ itk_wrap_class("itk::InterpolateImageFunction" POINTER)
itk_wrap_template("${ITKM_I${v}${d}}${ITKM_D}" "${ITKT_I${v}${d}},${ITKT_D}")
endforeach()
endforeach()

set(PA3DSCI_types "F")
if(ITK_WRAP_unsigned_char)
list(APPEND PA3DSCI_types "UC")
endif()
foreach(t ${PA3DSCI_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}${ITKM_D}" "itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${ITKT_D}")
endforeach()
itk_end_wrap_class()
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::LinearInterpolateImageFunction" POINTER)
foreach(d ${ITK_WRAP_IMAGE_DIMS})
foreach(t ${WRAP_ITK_SCALAR})
Expand All @@ -13,4 +14,13 @@ itk_wrap_class("itk::LinearInterpolateImageFunction" POINTER)
itk_wrap_template("${ITKM_I${v}${d}}${ITKM_D}" "${ITKT_I${v}${d}},${ITKT_D}")
endforeach()
endforeach()

set(PA3DSCI_types "F")
if(ITK_WRAP_unsigned_char)
list(APPEND PA3DSCI_types "UC")
endif()
foreach(t ${PA3DSCI_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}${ITKM_D}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${ITKT_D}")
endforeach()
itk_end_wrap_class()
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::NearestNeighborInterpolateImageFunction" POINTER)
foreach(d ${ITK_WRAP_IMAGE_DIMS})
foreach(t ${WRAP_ITK_SCALAR})
itk_wrap_template("${ITKM_I${t}${d}}${ITKM_D}" "${ITKT_I${t}${d}},${ITKT_D}")
endforeach()
endforeach()

set(PA3DSCI_types "F")
if(ITK_WRAP_unsigned_char)
list(APPEND PA3DSCI_types "UC")
endif()
foreach(t ${PA3DSCI_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}${ITKM_D}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${ITKT_D}")
endforeach()
itk_end_wrap_class()
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF)
itk_wrap_include("itkWindowedSincInterpolateImageFunction.h")
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")

set(window_functions "Hamming" "Cosine" "Welch" "Lanczos")
set(radii 2 3)
Expand All @@ -21,4 +22,16 @@ itk_wrap_class("itk::WindowedSincInterpolateImageFunction" POINTER)
endforeach()
endforeach()
endforeach()

set(PA3DSCI_types "F")
if(ITK_WRAP_unsigned_char)
list(APPEND PA3DSCI_types "UC")
endif()
foreach(t ${PA3DSCI_types})
foreach(r ${radii}) # radius
foreach(function ${window_functions})
itk_wrap_template("PA3DSCI${ITKM_${t}}${r}${function}" "itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${r}, itk::Function::${function}WindowFunction< ${r} >")
endforeach()
endforeach()
endforeach()
itk_end_wrap_class()
11 changes: 11 additions & 0 deletions Modules/Filtering/ImageFilterBase/wrapping/itkCastImageFilter.wrap
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::CastImageFilter" POINTER_WITH_SUPERCLASS)
# Create cast filters between all scalar types. Also force that cast-to-uchar
# filters are created for all scalar types, and unsigned long for
Expand Down Expand Up @@ -80,4 +81,14 @@ itk_wrap_class("itk::CastImageFilter" POINTER_WITH_SUPERCLASS)
if(NOT ITK_WRAP_unsigned_long_long AND NOT ${ITKM_IT} STREQUAL "ULL")
itk_wrap_image_filter_combinations("ULL" "${WRAP_ITK_INT}")
endif()

# PhasedArray3DSpecialCoordinatesImage
foreach(t1 ${WRAP_ITK_SCALAR})
foreach(t2 ${WRAP_ITK_SCALAR})
itk_wrap_template("PA3DSCI${ITKM_${t1}}PA3DSCI${ITKM_${t2}}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t1}} >, itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t2}} >")
itk_wrap_template("PA3DSCI${ITKM_${t1}}I${ITKM_${t2}}3"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t1}} >, itk::Image< ${ITKT_${t2}}, 3 >")
endforeach()
endforeach()
itk_end_wrap_class()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7d5e6c2b070107a279277c48ead400bab15edd7aaa1b1b2238a8437da1435c41f75c3b2323fdba17f6415d10ea37992ff053f52a5f6d7a0937f78cfaf1f3687a
10 changes: 10 additions & 0 deletions Modules/Filtering/ImageGrid/wrapping/itkResampleImageFilter.wrap
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::ResampleImageFilter" POINTER)
itk_wrap_image_filter("${WRAP_ITK_SCALAR}" 2)
itk_wrap_image_filter("${WRAP_ITK_VECTOR_REAL}" 2)
Expand All @@ -11,4 +12,13 @@ itk_wrap_class("itk::ResampleImageFilter" POINTER)
endforeach()
endforeach()

set(PA3DSCI_types "F")
if(ITK_WRAP_unsigned_char)
list(APPEND PA3DSCI_types "UC")
endif()
foreach(t ${PA3DSCI_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}I${ITKM_${t}}3"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, itk::Image< ${ITKT_${t}}, 3 >")
endforeach()

itk_end_wrap_class()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8fc8129454b6ec93fb5c133d9835f8a49df0ab14584d44b3454e1b36dee60ef92e29bb9e8c3b9a1340129877fc0ec81d7beb5022eaf3bcbbed8fa3ebab8e6c74
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cf4bac01a2692100f1c2b2445f3468b26c754e380f4d0119b466c079639f309ad18f775106f341a72c6126a7a636d55c494ed40edf441de262418ff65b2a792e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6e589887b660f79513d1c09479cc70bd815e532e013fcb3bb185a21c641e417210d6a8286199a265b8e6b9159254e6237108539d0c5eb865a7bedb03d64cbf50
54 changes: 53 additions & 1 deletion Modules/Filtering/ImageGrid/wrapping/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ endif()

# let's make sure 3D uchar images are wrapped
list(FIND ITK_WRAP_IMAGE_DIMS 3 wrap_3_index)
if(ITK_WRAP_PYTHON AND ITK_WRAP_unsigned_char AND wrap_2_index GREATER -1)
if(ITK_WRAP_PYTHON AND ITK_WRAP_unsigned_char AND wrap_3_index GREATER -1)
itk_python_add_test(NAME OrientImageFilterTest
TEST_DRIVER_ARGS
--compare DATA{Baseline/OrientImageFilterTest.mha}
Expand All @@ -55,4 +55,56 @@ if(ITK_WRAP_PYTHON AND ITK_WRAP_unsigned_char AND wrap_2_index GREATER -1)
DATA{${ITK_DATA_ROOT}/Baseline/Filtering/SubsampleVolume.mha}
${ITK_TEST_OUTPUT_DIR}/OrientImageFilterTest.mha
)

itk_python_expression_add_test(NAME PythonInstantiateGaussianInterpolateImageFunctionPA3DSCI
EXPRESSION "iFunc = itk.GaussianInterpolateImageFunction[itk.PhasedArray3DSpecialCoordinatesImage[itk.F], itk.D].New()"
)

itk_python_add_test(NAME PythonPhasedArray3DResampleNearestTest
TEST_DRIVER_ARGS
--compareIntensityTolerance 1
--compare
DATA{Baseline/ScanConvertPhasedArray3DITKNearestNeighborTestOutput.mha}
${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DITKNearestNeighborTestOutput.mha
COMMAND PhasedArray3DResampleTest.py
-i DATA{${test_input_dir}/ScanConvertPhasedArray3DTestInput.mha}
-o ${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DITKNearestNeighborTestOutput.mha
--azimuth-angular-separation 0.0872665
--elevation-angular-separation 0.0174533
--radius-sample-size 0.2
--first-sample-distance 8.0
--interpolation-type nearest
)

itk_python_add_test(NAME PythonPhasedArray3DResampleLinearTest
TEST_DRIVER_ARGS
--compareIntensityTolerance 1
--compare
DATA{Baseline/ScanConvertPhasedArray3DTestOutput.mha}
${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DTestOutput.mha
COMMAND PhasedArray3DResampleTest.py
-i DATA{${test_input_dir}/ScanConvertPhasedArray3DTestInput.mha}
-o ${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DTestOutput.mha
--azimuth-angular-separation 0.0872665
--elevation-angular-separation 0.0174533
--radius-sample-size 0.2
--first-sample-distance 8.0
# --interpolation-type linear # linear is the default
)

itk_python_add_test(NAME PythonPhasedArray3DResampleSincTest
TEST_DRIVER_ARGS
--compareIntensityTolerance 1
--compare
DATA{Baseline/ScanConvertPhasedArray3DITKWindowedSincTestOutput.mha}
${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DITKWindowedSincTestOutput.mha
COMMAND PhasedArray3DResampleTest.py
-i DATA{${test_input_dir}/ScanConvertPhasedArray3DTestInput.mha}
-o ${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DITKWindowedSincTestOutput.mha
--azimuth-angular-separation 0.0872665
--elevation-angular-separation 0.0174533
--radius-sample-size 0.2
--first-sample-distance 8.0
--interpolation-type sinc
)
endif()
Loading