InsightSoftwareConsortium / ITK

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.
https://itk.org
Apache License 2.0
1.37k stars 660 forks source link

BUG: Fix SpatialObjectProperties.GetTag*Value() to return values in python #4612

Closed aylward closed 2 months ago

aylward commented 2 months ago

The dictionary used by SpatialObjectProperties is queried using functions that return the dictionary value in a variable that is passed by reference: https://itk.org/Doxygen/html/classitk_1_1SpatialObjectProperty.html#aff2b1c659a8e77bdb6afeef0bab037fb

bool itk::SpatialObjectProperty::GetTagScalarValue ( const std::string & tag, double & value ) const

This function is not correctly wrapped by SWIG, and cannot be used from within python.

Here is a snippet of code that demonstrates the issue:

In [1]: import itk
In [2]: so = itk.TubeSpatialObject[3].New()
In [3]: so.GetProperty().SetTagScalarValue("foo",1) In [4]: ret = 0.0
In [5]: so.GetProperty().GetTagScalarValue("foo",ret)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[5], line 1
----> 1 so.GetProperty().GetTagScalarValue("foo",ret)
TypeError: in method 'itkSpatialObjectProperty_GetTagScalarValue', argument 3 of type 'double &'

This commit simply creates two new version of the problematic functions, that differ only by arguments passed and returned values. The new functions are also more consistent with ITK's standard Get function format:

double itk::SpatialObjectProperty::GetTagScalarValue(const std::string & tag) const

std::string itk::SpatialObjectProperty::GetTagStringValue(const std::string & tag) const