From f14f7d71f16f31b9f6f2af90f36a93715ac3475c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Wed, 16 Apr 2025 09:47:34 -0400 Subject: [PATCH] ENH: Add LinearImageFunction wrapping test Based on code provided on the forum: https://discourse.itk.org/t/improper-wrapping-of-imagefunction-isinsidebuffer/7495 --- .../wrapping/test/CMakeLists.txt | 5 ++ .../itkLinearImageFunctionWrappingTest.py | 46 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Modules/Core/ImageFunction/wrapping/test/itkLinearImageFunctionWrappingTest.py diff --git a/Modules/Core/ImageFunction/wrapping/test/CMakeLists.txt b/Modules/Core/ImageFunction/wrapping/test/CMakeLists.txt index 0e499c0eaf0..b3cf5f471c2 100644 --- a/Modules/Core/ImageFunction/wrapping/test/CMakeLists.txt +++ b/Modules/Core/ImageFunction/wrapping/test/CMakeLists.txt @@ -9,4 +9,9 @@ if(ITK_WRAP_PYTHON) itkWindowedSincInterpolateImageFunctionPythonTest EXPRESSION "windowed_sinc = itk.WindowedSincInterpolateImageFunction.New()") + itk_python_add_test( + NAME + itkLinearImageFunctionWrappingTest + COMMAND + ${CMAKE_CURRENT_SOURCE_DIR}/itkLinearImageFunctionWrappingTest.py) endif() diff --git a/Modules/Core/ImageFunction/wrapping/test/itkLinearImageFunctionWrappingTest.py b/Modules/Core/ImageFunction/wrapping/test/itkLinearImageFunctionWrappingTest.py new file mode 100644 index 00000000000..2d382b8c085 --- /dev/null +++ b/Modules/Core/ImageFunction/wrapping/test/itkLinearImageFunctionWrappingTest.py @@ -0,0 +1,46 @@ +# ========================================================================== +# +# Copyright NumFOCUS +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ==========================================================================*/ + +import itk +import numpy as np + +image = itk.GetImageFromArray(np.full((200, 200, 200), 1.0)) +interp = itk.LinearInterpolateImageFunction.New(image) + +# From the doc, the three versions of IsInsideBuffer appear +print(interp.IsInsideBuffer.__doc__) + +# The following line calls the "point version" +print(interp.IsInsideBuffer([1, 2, 3])) + +# Force the function to be called with a continuous index +cindex = itk.ContinuousIndex[itk.D, 3]() +cindex[0] = 1.5 +cindex[1] = 2.5 +cindex[2] = 3.5 +print(interp.IsInsideBuffer(cindex)) + +# Force the function to be called with a point +point = itk.Point[itk.D, 3]() +point[0] = 1.5 +point[1] = 2.5 +point[2] = 3.5 +print(interp.IsInsideBuffer(point)) + +# TODO: Which variant will this call? +print(interp.IsInsideBuffer([1.5, 2.5, 3.5]))