Skip to content

Commit

Permalink
ENH: Add wrapping for PhasedArray3DSpecialCoordinatesImage and filters
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Jul 4, 2023
1 parent f5cc8f8 commit 8808f7a
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 0 deletions.
1 change: 1 addition & 0 deletions wrapping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(WRAPPER_SUBMODULE_ORDER
itkCurvilinearArraySpecialCoordinatesImage
itkImageUltrasound # Extra itk::Image wrappings for SupportWindow filters
itkCurvilinearArraySpecialCoordinatesImageFilters
itkPhasedArray3DSpecialCoordinatesImage # CASCI needs to come before
itkAttenuationImageFilter
itkBlockMatchingMetricImageFilter
itkBlockMatchingNormalizedCrossCorrelationMetricImageFilter
Expand Down
58 changes: 58 additions & 0 deletions wrapping/itkPhasedArray3DSpecialCoordinatesImage.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
itk_wrap_include("list")
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 ) {
itkIndex##template_params idx;
self->TransformPhysicalPointToIndex<double>( point, idx );
return idx;
}

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

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

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

%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
150 changes: 150 additions & 0 deletions wrapping/itkPhasedArray3DSpecialCoordinatesImageFilters.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# ITK image filters wrapped for ITKUltrasound `itk::PhasedArray3DSpecialCoordinatesImage` inputs.
# Must be wrapped in a separate file after `itkPhasedArray3DSpecialCoordinatesImage.wrap` so that
# SWIG does not implicitly define erroneous overrides for template methods such as
# `TransformPhysicalPointToContinuousIndex`, etc.

# See `WRAPPER_SUBMODULE_ORDER` in CMakeLists.txt for where
# `itkPhasedArray3DSpecialCoordinatesImageFilters.wrap` is set to
# be wrapped after `itkPhasedArray3DSpecialCoordinatesImage.wrap`.

itk_wrap_include("itkPhasedArray3DSpecialCoordinatesImage.h")
itk_wrap_class("itk::ImageSource" POINTER)
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()

itk_wrap_include("itkImage.h")
itk_wrap_class("itk::ImageToImageFilter" POINTER)
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}} >")
endforeach()
itk_wrap_template("PA3DSCI${ITKM_${t}}I${ITKM_${t}}3"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, itk::Image< ${ITKT_${t}}, 3>")
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()

itk_wrap_class("itk::ImageFileReader" POINTER_WITH_SUPERCLASS)
foreach(t ${WRAP_ITK_SCALAR})
itk_wrap_template("PA3DSCI${ITKM_${t}}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >")
endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::ImageFileWriter" POINTER)
foreach(t ${WRAP_ITK_SCALAR})
itk_wrap_template("PA3DSCI${ITKM_${t}}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >")
endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::CastImageFilter" POINTER_WITH_2_SUPERCLASSES)
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()

itk_wrap_class("itk::RescaleIntensityImageFilter" POINTER_WITH_2_SUPERCLASSES)
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()

itk_wrap_include("itkSpectra1DSupportWindowToMaskImageFilter.h")
itk_wrap_class("itk::Spectra1DSupportWindowToMaskImageFilter" POINTER_WITH_2_SUPERCLASSES)
foreach(t ${WRAP_ITK_INT})
itk_wrap_template("IlistitkIndex33PA3DSCI${ITKM_${t}}"
"itk::Image< std::list< itk::Index< 3 > >, 3 >, itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >")
endforeach()
itk_end_wrap_class()

# The rest is needed for ResampleImageFilter and interpolator functions
set(resample_filter_pixel_types "F")
if(ITK_WRAP_unsigned_char)
list(APPEND resample_filter_pixel_types "UC")
endif()
itk_wrap_include("itkResampleImageFilter.h")
itk_wrap_class("itk::ResampleImageFilter" POINTER)
foreach(t ${resample_filter_pixel_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()

itk_wrap_class("itk::ImageFunction" POINTER)
foreach(t ${resample_filter_pixel_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}${ITKM_D}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${ITKT_D}, ${ITKT_D}")
endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::InterpolateImageFunction" POINTER)
foreach(t ${resample_filter_pixel_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}${ITKM_D}" "itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${ITKT_D}")
endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::NearestNeighborInterpolateImageFunction" POINTER)
foreach(t ${resample_filter_pixel_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}${ITKM_D}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${ITKT_D}")
endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::LinearInterpolateImageFunction" POINTER)
foreach(t ${resample_filter_pixel_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}${ITKM_D}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${ITKT_D}")
endforeach()
itk_end_wrap_class()

itk_wrap_class("itk::GaussianInterpolateImageFunction" POINTER)
foreach(t ${resample_filter_pixel_types})
itk_wrap_template("PA3DSCI${ITKM_${t}}${ITKM_D}"
"itk::PhasedArray3DSpecialCoordinatesImage< ${ITKT_${t}} >, ${ITKT_D}")
endforeach()
itk_end_wrap_class()

itk_wrap_include("itkWindowedSincInterpolateImageFunction.h")
set(window_functions "Hamming" "Cosine" "Welch" "Lanczos")
set(radii 2 3)
itk_wrap_class("itk::WindowedSincInterpolateImageFunction" POINTER)
foreach(t ${resample_filter_pixel_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()

0 comments on commit 8808f7a

Please sign in to comment.