Skip to content

Commit fc7fbd3

Browse files
Copilotthewtex
andcommitted
ENH: Add Python wrapping for ObjectToObjectMultiMetricv4
Co-authored-by: thewtex <[email protected]>
1 parent 70204be commit fc7fbd3

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
itk_wrap_class("itk::ObjectToObjectMultiMetricv4" POINTER)
2+
foreach(d ${ITK_WRAP_IMAGE_DIMS})
3+
foreach(t ${WRAP_ITK_REAL})
4+
itk_wrap_template("${d}${d}I${ITKM_${t}}${d}" "${d},${d},itk::Image< ${ITKT_${t}}, ${d} >")
5+
endforeach()
6+
endforeach()
7+
itk_end_wrap_class()

Modules/Registration/Metricsv4/wrapping/test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ if(ITK_WRAP_PYTHON)
5959
EXPRESSION "instance = itk.MeanSquaresImageToImageMetricv4.New()"
6060
)
6161

62+
itk_python_add_test(
63+
NAME itkObjectToObjectMultiMetricv4PythonTest
64+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/itkObjectToObjectMultiMetricv4Test.py
65+
)
66+
6267
itk_python_expression_add_test(
6368
NAME itkPointSetToPointSetMetricv4PythonTest
6469
EXPRESSION "instance = itk.PointSetToPointSetMetricv4.New()"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# ==========================================================================
2+
#
3+
# Copyright NumFOCUS
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0.txt
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# ==========================================================================
18+
19+
import itk
20+
21+
# Test with float images
22+
Dimension = 2
23+
ImageType = itk.Image[itk.F, Dimension]
24+
25+
# Test basic instantiation
26+
multi_metric = itk.ObjectToObjectMultiMetricv4[Dimension, Dimension, ImageType].New()
27+
assert multi_metric is not None
28+
29+
# Create a simple metric to add
30+
ms_metric = itk.MeanSquaresImageToImageMetricv4[ImageType, ImageType].New()
31+
assert ms_metric is not None
32+
33+
# Add metric to the multi-metric
34+
multi_metric.AddMetric(ms_metric)
35+
36+
# Test that we can get the number of metrics
37+
assert multi_metric.GetNumberOfMetrics() == 1
38+
39+
# Set metric weights
40+
weights = itk.Array[itk.D](1)
41+
weights[0] = 0.5
42+
multi_metric.SetMetricWeights(weights)
43+
44+
# Verify weights were set
45+
retrieved_weights = multi_metric.GetMetricWeights()
46+
assert retrieved_weights.GetSize() == 1
47+
48+
print("Test passed!")

0 commit comments

Comments
 (0)