From 6784ad458a39a3a52e82f0de1af177281219b3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Thu, 4 Jun 2026 16:21:52 -0400 Subject: [PATCH] ENH: Wrap BSplineTransform for 2D-2D and 4D-4D case Currently available combinations are as follows: Options: [, 2, 3] [, 3, 3] [, 4, 3] --- .../wrapping/itkBSplineBaseTransform.wrap | 3 +++ .../Transform/wrapping/itkBSplineTransform.wrap | 3 +++ .../Core/Transform/wrapping/test/CMakeLists.txt | 13 +++++++++++++ Wrapping/WrapITKTypes.cmake | 17 +++++++++++++---- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Modules/Core/Transform/wrapping/itkBSplineBaseTransform.wrap b/Modules/Core/Transform/wrapping/itkBSplineBaseTransform.wrap index 512527a66cc..616f363d34a 100644 --- a/Modules/Core/Transform/wrapping/itkBSplineBaseTransform.wrap +++ b/Modules/Core/Transform/wrapping/itkBSplineBaseTransform.wrap @@ -1,5 +1,8 @@ itk_wrap_class("itk::BSplineBaseTransform" POINTER) foreach(d ${ITK_WRAP_IMAGE_DIMS}) itk_wrap_template("${ITKM_D}${d}3" "${ITKT_D},${d},3") + if (NOT ${d} EQUAL 3) + itk_wrap_template("${ITKM_D}${d}${d}" "${ITKT_D},${d},${d}") + endif() endforeach() itk_end_wrap_class() diff --git a/Modules/Core/Transform/wrapping/itkBSplineTransform.wrap b/Modules/Core/Transform/wrapping/itkBSplineTransform.wrap index a170e3efffd..91ed45a9d6b 100644 --- a/Modules/Core/Transform/wrapping/itkBSplineTransform.wrap +++ b/Modules/Core/Transform/wrapping/itkBSplineTransform.wrap @@ -1,5 +1,8 @@ itk_wrap_class("itk::BSplineTransform" POINTER) foreach(d ${ITK_WRAP_IMAGE_DIMS}) itk_wrap_template("${ITKM_D}${d}3" "${ITKT_D},${d},3") + if (NOT ${d} EQUAL 3) + itk_wrap_template("${ITKM_D}${d}${d}" "${ITKT_D},${d},${d}") + endif() endforeach() itk_end_wrap_class() diff --git a/Modules/Core/Transform/wrapping/test/CMakeLists.txt b/Modules/Core/Transform/wrapping/test/CMakeLists.txt index 51fbaec3979..7e2a6f6d86b 100644 --- a/Modules/Core/Transform/wrapping/test/CMakeLists.txt +++ b/Modules/Core/Transform/wrapping/test/CMakeLists.txt @@ -6,4 +6,17 @@ if(ITK_WRAP_PYTHON) ${CMAKE_CURRENT_SOURCE_DIR}/itkTransformSerializationTest.py DATA{Baseline/BSplineDeformationTransformDisplacements5.txt} ${ITK_EXAMPLE_DATA_ROOT}/DiagonalLines.png) + + itk_python_expression_add_test( + NAME PythonInstantiateBSplineTransform2D2D + EXPRESSION "t = itk.BSplineTransform[itk.D, 2, 2].New()" + ) + + list(FIND ITK_WRAP_IMAGE_DIMS 4 wrap_4_index) + if(wrap_4_index GREATER -1) + itk_python_expression_add_test( + NAME PythonInstantiateBSplineTransform4D4D + EXPRESSION "t = itk.BSplineTransform[itk.D, 4, 4].New()" + ) + endif() endif() diff --git a/Wrapping/WrapITKTypes.cmake b/Wrapping/WrapITKTypes.cmake index ac2347a9e65..738052883b4 100644 --- a/Wrapping/WrapITKTypes.cmake +++ b/Wrapping/WrapITKTypes.cmake @@ -135,8 +135,10 @@ wrap_type("itk::FixedArray" "FA" "itkFixedArray.h") set(dims ${ITK_WRAP_IMAGE_DIMS_INCREMENTED}) foreach(d ${ITK_WRAP_IMAGE_DIMS}) math(EXPR d2 "${d} * 2") + # for itk::SymmetricSecondRankTensor math(EXPR d3 "${d} * (${d} + 1) / 2") + list( APPEND dims @@ -149,9 +151,9 @@ endforeach() # needs to have defined sizes for: # - ITK_WRAP_IMAGE_DIMS_INCREMENTED # - ITK_WRAP_VECTOR_COMPONENTS_INCREMENTED -# Dimensions 1;2;3;4;6 should always be wrapped. +# Dimensions 1;2;3;4;6;9 should always be wrapped. -unique(array_sizes "${dims};1;2;3;4;6;${ITK_WRAP_VECTOR_COMPONENTS_INCREMENTED}") +unique(array_sizes "${dims};1;2;3;4;6;9;${ITK_WRAP_VECTOR_COMPONENTS_INCREMENTED}") # 3-D FixedArrays are required as superclass of rgb pixels # TODO: Do we need fixed arrays for all of these types? For just the selected @@ -178,8 +180,15 @@ foreach(d ${ITK_WRAP_IMAGE_DIMS}) foreach(i RANGE 1 ${d}) math(EXPR comp "${comp}*4") endforeach() - add_template("${ITKM_D}${comp}" "${ITKT_D},${comp}") - add_template("${ITKM_UL}${comp}" "${ITKT_UL},${comp}") + + # Check if computed comp dimension has already wrapped above + list(FIND array_sizes ${comp} array_sizes_index) + + if(array_sizes_index LESS 0) + # Not already in array_sizes + add_template("${ITKM_D}${comp}" "${ITKT_D},${comp}") + add_template("${ITKM_UL}${comp}" "${ITKT_UL},${comp}") + endif() endforeach() end_wrap_type() set(itk_Wrap_FixedArray ${WRAPPER_TEMPLATES})