From 095abb292fe3aea5ccbd2c96022b096f242c3ac4 Mon Sep 17 00:00:00 2001 From: Alexy Pellegrini Date: Tue, 31 May 2022 17:45:34 +0200 Subject: [PATCH] ENH: Add python wrapping for CudaCommon This wrapping differs from the one that used to be in RTK by the fact that it only wraps the interface for floating type data and only for image dimensions included in ${ITK_WRAP_IMAGE_DIMS} and vector components included in ${ITK_WRAP_VECTOR_COMPONENTS}. RTK will have to wrap itself everything else it needs. --- wrapping/itkCudaDataManager.wrap | 6 +-- wrapping/itkCudaImage.wrap | 37 +++++--------- wrapping/itkCudaImageDataManager.wrap | 39 ++++---------- wrapping/itkCudaImageToImageFilter.wrap | 27 ++++------ wrapping/itkCudaInPlaceImageFilter.wrap | 51 ++++++++----------- wrapping/itkCudaSquareImageFilter.wrap | 7 ++- wrapping/itkImageSourceCudaCommon.wrap | 15 ++++++ wrapping/itkImageToImageFilterCudaCommon.wrap | 19 +++++++ wrapping/itkInPlaceImageFilterCudaCommon.wrap | 18 +++++++ 9 files changed, 112 insertions(+), 107 deletions(-) create mode 100644 wrapping/itkImageSourceCudaCommon.wrap create mode 100644 wrapping/itkImageToImageFilterCudaCommon.wrap create mode 100644 wrapping/itkInPlaceImageFilterCudaCommon.wrap diff --git a/wrapping/itkCudaDataManager.wrap b/wrapping/itkCudaDataManager.wrap index 46dce69..9be4ed2 100644 --- a/wrapping/itkCudaDataManager.wrap +++ b/wrapping/itkCudaDataManager.wrap @@ -1,5 +1 @@ -if(RTK_USE_CUDA) - - itk_wrap_simple_class("itk::CudaDataManager" POINTER) - -endif() +itk_wrap_simple_class("itk::CudaDataManager" POINTER) diff --git a/wrapping/itkCudaImage.wrap b/wrapping/itkCudaImage.wrap index ca4e51f..c37eda3 100644 --- a/wrapping/itkCudaImage.wrap +++ b/wrapping/itkCudaImage.wrap @@ -1,31 +1,18 @@ -if(RTK_USE_CUDA) +itk_wrap_class("itk::CudaImage" POINTER_WITH_CONST_POINTER) - itk_wrap_class("itk::CudaImage" POINTER_WITH_CONST_POINTER) + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("F${d}" "float, ${d}") + endforeach() + foreach(component ${ITK_WRAP_VECTOR_COMPONENTS}) foreach(d ${ITK_WRAP_IMAGE_DIMS}) - itk_wrap_template("F${d}" "float, ${d}") - endforeach() - - list(FIND ITK_WRAP_IMAGE_DIMS "4" _index) - if (${_index} EQUAL -1) - itk_wrap_template("F4" "${ITKT_F}, 4") - endif() - - # Force VECTOR_COMPONENTS to "2;3;4;5" - # Force ITK_WRAP_IMAGE_DIMS to "2;3;4" - UNIQUE(imageDimensions "${ITK_WRAP_IMAGE_DIMS};2;3;4") - UNIQUE(vectorComponents "${ITK_WRAP_VECTOR_COMPONENTS};2;3;4;5") - foreach(component ${vectorComponents}) - foreach(d ${imageDimensions}) - foreach(vt ${WRAP_ITK_VECTOR_REAL}) - itk_wrap_template("${ITKM_${vt}${component}}${d}" "${ITKT_${vt}${component}}, ${d}") - endforeach() - foreach(cvt ${WRAP_ITK_COV_VECTOR_REAL}) - itk_wrap_template("${ITKM_${cvt}${component}}${d}" "${ITKT_${cvt}${component}}, ${d}") - endforeach() + foreach(vt ${WRAP_ITK_VECTOR_REAL}) + itk_wrap_template("${ITKM_${vt}${component}}${d}" "${ITKT_${vt}${component}}, ${d}") + endforeach() + foreach(cvt ${WRAP_ITK_COV_VECTOR_REAL}) + itk_wrap_template("${ITKM_${cvt}${component}}${d}" "${ITKT_${cvt}${component}}, ${d}") endforeach() endforeach() + endforeach() - itk_end_wrap_class() - -endif() +itk_end_wrap_class() diff --git a/wrapping/itkCudaImageDataManager.wrap b/wrapping/itkCudaImageDataManager.wrap index 490349c..24dc072 100644 --- a/wrapping/itkCudaImageDataManager.wrap +++ b/wrapping/itkCudaImageDataManager.wrap @@ -1,35 +1,16 @@ -if(RTK_USE_CUDA) +itk_wrap_include(itkCudaImage.h) - itk_wrap_include(itkCudaImage.h) +itk_wrap_class("itk::CudaImageDataManager" POINTER) - itk_wrap_class("itk::CudaImageDataManager" POINTER) + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_F}${d}" "itk::CudaImage<${ITKT_F}, ${d}>") + endforeach() + foreach(component ${ITK_WRAP_VECTOR_COMPONENTS}) foreach(d ${ITK_WRAP_IMAGE_DIMS}) - itk_wrap_template("CI${ITKM_F}${d}" "itk::CudaImage<${ITKT_F}, ${d}>") + itk_wrap_template("CI${ITKM_VF${component}}${d}" "itk::CudaImage<${ITKT_VF${component}}, ${d}>") + itk_wrap_template("CI${ITKM_CVF${component}}${d}" "itk::CudaImage<${ITKT_CVF${component}}, ${d}>") endforeach() + endforeach() - list(FIND ITK_WRAP_IMAGE_DIMS "4" _index) - if(${_index} EQUAL -1) - itk_wrap_template("CI${ITKM_F}4" "itk::CudaImage<${ITKT_F}, 4>") - endif() - - # Force VECTOR_COMPONENTS to "2;3;4;5" - UNIQUE(vectorComponents "${ITK_WRAP_VECTOR_COMPONENTS};2;3;4;5") - foreach(component ${vectorComponents}) - - foreach(d ${ITK_WRAP_IMAGE_DIMS}) - itk_wrap_template("CI${ITKM_VF${component}}${d}" "itk::CudaImage<${ITKT_VF${component}}, ${d}>") - itk_wrap_template("CI${ITKM_CVF${component}}${d}" "itk::CudaImage<${ITKT_CVF${component}}, ${d}>") - endforeach() - - list(FIND ITK_WRAP_IMAGE_DIMS "4" _index) - if(${_index} EQUAL -1) - itk_wrap_template("CI${ITKM_VF${component}}4" "itk::CudaImage<${ITKT_VF${component}}, 4>") - itk_wrap_template("CI${ITKM_CVF${component}}4" "itk::CudaImage<${ITKT_CVF${component}}, 4>") - endif() - - endforeach() - - itk_end_wrap_class() - -endif() +itk_end_wrap_class() diff --git a/wrapping/itkCudaImageToImageFilter.wrap b/wrapping/itkCudaImageToImageFilter.wrap index ece678b..47be295 100644 --- a/wrapping/itkCudaImageToImageFilter.wrap +++ b/wrapping/itkCudaImageToImageFilter.wrap @@ -1,22 +1,15 @@ -if(RTK_USE_CUDA) +itk_wrap_class("itk::CudaImageToImageFilter" POINTER) - itk_wrap_class("itk::CudaImageToImageFilter" POINTER) + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_F}${d}CI${ITKM_F}${d}" + "itk::CudaImage<${ITKT_F}, ${d}>, itk::CudaImage<${ITKT_F}, ${d}>") + endforeach() + foreach(component ${ITK_WRAP_VECTOR_COMPONENTS}) foreach(d ${ITK_WRAP_IMAGE_DIMS}) - itk_wrap_template("CI${ITKM_F}${d}CI${ITKM_F}${d}" - "itk::CudaImage<${ITKT_F}, ${d}>, itk::CudaImage<${ITKT_F}, ${d}>") + itk_wrap_template("CI${ITKM_VF${component}}${d}CI${ITKM_VF${component}}${d}" + "itk::CudaImage<${ITKT_VF${component}}, ${d}>, itk::CudaImage<${ITKT_VF${component}}, ${d}>") endforeach() + endforeach() - # Force VECTOR_COMPONENTS to "2;3;4;5" - UNIQUE(imageDimensions "${ITK_WRAP_IMAGE_DIMS};2;3;4") - UNIQUE(vectorComponents "${ITK_WRAP_VECTOR_COMPONENTS};2;3;4;5") - foreach(component ${vectorComponents}) - foreach(d ${imageDimensions}) - itk_wrap_template("CI${ITKM_VF${component}}${d}CI${ITKM_VF${component}}${d}" - "itk::CudaImage<${ITKT_VF${component}}, ${d}>, itk::CudaImage<${ITKT_VF${component}}, ${d}>") - endforeach() - endforeach() - - itk_end_wrap_class() - -endif() +itk_end_wrap_class() diff --git a/wrapping/itkCudaInPlaceImageFilter.wrap b/wrapping/itkCudaInPlaceImageFilter.wrap index 783b257..9902caa 100644 --- a/wrapping/itkCudaInPlaceImageFilter.wrap +++ b/wrapping/itkCudaInPlaceImageFilter.wrap @@ -1,40 +1,31 @@ -if(RTK_USE_CUDA) +itk_wrap_class("itk::CudaInPlaceImageFilter" POINTER) - itk_wrap_class("itk::CudaInPlaceImageFilter" POINTER) + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_F}${d}CI${ITKM_F}${d}" + "itk::CudaImage<${ITKT_F}, ${d}>, itk::CudaImage<${ITKT_F}, ${d}>") + endforeach() - #itk_wrap_image_filter_combinations("${WRAP_ITK_REAL}" "${WRAP_ITK_REAL}") + foreach(component ${ITK_WRAP_VECTOR_COMPONENTS}) foreach(d ${ITK_WRAP_IMAGE_DIMS}) - itk_wrap_template("CI${ITKM_F}${d}CI${ITKM_F}${d}" - "itk::CudaImage<${ITKT_F}, ${d}>, itk::CudaImage<${ITKT_F}, ${d}>") + itk_wrap_template("CI${ITKM_V${ITKM_F}${component}}${d}CI${ITKM_V${ITKM_F}${component}}${d}" + "itk::CudaImage, ${d}>, itk::CudaImage, ${d}>") endforeach() + endforeach() - # Force VECTOR_COMPONENTS to "2;3;4;5" - UNIQUE(vectorComponents "${ITK_WRAP_VECTOR_COMPONENTS};2;3;4;5") - foreach(component ${vectorComponents}) - foreach(d ${ITK_WRAP_IMAGE_DIMS}) - itk_wrap_template("CI${ITKM_V${ITKM_F}${component}}${d}CI${ITKM_V${ITKM_F}${component}}${d}" - "itk::CudaImage, ${d}>, itk::CudaImage, ${d}>") - endforeach() - endforeach() +itk_end_wrap_class() - itk_end_wrap_class() +itk_wrap_class("itk::CudaImageToImageFilter" POINTER) - itk_wrap_class("itk::CudaImageToImageFilter" POINTER) - foreach(d ${ITK_WRAP_IMAGE_DIMS}) - itk_wrap_template("CI${ITKM_F}${d}CI${ITKM_F}${d}IPIFCI${ITKM_F}${d}" "itk::CudaImage<${ITKT_F}, ${d}>, itk::CudaImage<${ITKT_F}, ${d}>, itk::InPlaceImageFilter< itk::CudaImage<${ITKT_F}, ${d}> >") - endforeach() + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_F}${d}CI${ITKM_F}${d}IPIFCI${ITKM_F}${d}" + "itk::CudaImage<${ITKT_F}, ${d}>, itk::CudaImage<${ITKT_F}, ${d}>, itk::InPlaceImageFilter< itk::CudaImage<${ITKT_F}, ${d}> >") + endforeach() - # Force VECTOR_COMPONENTS to "2;3;4;5" - # Force ITK_WRAP_IMAGE_DIMS to "2;3;4" - UNIQUE(imageDimensions "${ITK_WRAP_IMAGE_DIMS};2;3;4") - UNIQUE(vectorComponents "${ITK_WRAP_VECTOR_COMPONENTS};2;3;4;5") - foreach(component ${vectorComponents}) - foreach(d ${imageDimensions}) - itk_wrap_template("CI${ITKM_VF${component}}${d}CI${ITKM_VF${component}}${d}IPIFCI${ITKM_VF${component}}${d}" - "itk::CudaImage<${ITKT_VF${component}}, ${d}>, itk::CudaImage<${ITKT_VF${component}}, ${d}>, itk::InPlaceImageFilter< itk::CudaImage<${ITKT_VF${component}}, ${d}> >") - endforeach() + foreach(component ${ITK_WRAP_VECTOR_COMPONENTS}) + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_VF${component}}${d}CI${ITKM_VF${component}}${d}IPIFCI${ITKM_VF${component}}${d}" + "itk::CudaImage<${ITKT_VF${component}}, ${d}>, itk::CudaImage<${ITKT_VF${component}}, ${d}>, itk::InPlaceImageFilter< itk::CudaImage<${ITKT_VF${component}}, ${d}> >") endforeach() + endforeach() - itk_end_wrap_class() - -endif() +itk_end_wrap_class() diff --git a/wrapping/itkCudaSquareImageFilter.wrap b/wrapping/itkCudaSquareImageFilter.wrap index 2470197..0b37e4c 100644 --- a/wrapping/itkCudaSquareImageFilter.wrap +++ b/wrapping/itkCudaSquareImageFilter.wrap @@ -1,4 +1,9 @@ itk_wrap_class("itk::CudaSquareImageFilter" POINTER) - itk_wrap_image_filter("${WRAP_ITK_SCALAR}" 2) + + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_F}${d}CI${ITKM_F}${d}" + "itk::CudaImage<${ITKT_F}, ${d}>") + endforeach() + itk_end_wrap_class() diff --git a/wrapping/itkImageSourceCudaCommon.wrap b/wrapping/itkImageSourceCudaCommon.wrap new file mode 100644 index 0000000..5a9032b --- /dev/null +++ b/wrapping/itkImageSourceCudaCommon.wrap @@ -0,0 +1,15 @@ +itk_wrap_include(itkCudaImage.h) + +itk_wrap_class("itk::ImageSource" POINTER) + + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_F}${d}" "itk::CudaImage<${ITKT_F}, ${d}>") + endforeach() + + foreach(component ${ITK_WRAP_VECTOR_COMPONENTS}) + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_VF${component}}${d}" "itk::CudaImage<${ITKT_VF${component}}, ${d}>") + endforeach() + endforeach() + +itk_end_wrap_class() diff --git a/wrapping/itkImageToImageFilterCudaCommon.wrap b/wrapping/itkImageToImageFilterCudaCommon.wrap new file mode 100644 index 0000000..0829458 --- /dev/null +++ b/wrapping/itkImageToImageFilterCudaCommon.wrap @@ -0,0 +1,19 @@ +itk_wrap_include(itkCudaImage.h) + +itk_wrap_class("itk::ImageToImageFilter" POINTER) + + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_F}${d}CI${ITKM_F}${d}" + "itk::CudaImage<${ITKT_F}, ${d}>, itk::CudaImage<${ITKT_F}, ${d}>") + endforeach() + + foreach(component ${ITK_WRAP_VECTOR_COMPONENTS}) + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_VF${component}}${d}CI${ITKM_VF${component}}${d}" + "itk::CudaImage<${ITKT_VF${component}}, ${d}>, itk::CudaImage<${ITKT_VF${component}}, ${d}>") + endforeach() + endforeach() + +itk_end_wrap_class() + + diff --git a/wrapping/itkInPlaceImageFilterCudaCommon.wrap b/wrapping/itkInPlaceImageFilterCudaCommon.wrap new file mode 100644 index 0000000..94c8980 --- /dev/null +++ b/wrapping/itkInPlaceImageFilterCudaCommon.wrap @@ -0,0 +1,18 @@ +itk_wrap_include(itkCudaImage.h) + +itk_wrap_class("itk::InPlaceImageFilter" POINTER) + + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_F}${d}" "itk::CudaImage<${ITKT_F}, ${d}>") + endforeach() + + foreach(component ${ITK_WRAP_VECTOR_COMPONENTS}) + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("CI${ITKM_VF${component}}${d}" "itk::CudaImage<${ITKT_VF${component}}, ${d}>") + itk_wrap_template("CI${ITKM_VF${component}}${d}CI${ITKM_VF${component}}${d}" + "itk::CudaImage<${ITKT_VF${component}}, ${d}>, itk::CudaImage<${ITKT_VF${component}}, ${d}>") + endforeach() + endforeach() + +itk_end_wrap_class() +