Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Provide GetSpacing/GetOrigin calls that wrap for python #4775

Merged

Conversation

aylward
Copy link
Member

@aylward aylward commented Jul 12, 2024

itk::SpatialObjectToImageFilter provided GetSpacing() and GetOrigin() calls that returned double * objects. That return type is not well supported by SWIG for python wrapping.

Herein we provide GetSpacingVector() and GetOriginPoint() functions that return VectorType and PointType objects from the itk::Image class definition which are nicely wrapped by SWIG for python.

See: https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707

@github-actions github-actions bot added type:Enhancement Improvement of existing methods or implementation type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module labels Jul 12, 2024
{
for (unsigned int i = 0; i < OutputImageDimension; ++i)
{
m_SpacingVector[i] = m_Spacing[i];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this assignment is done in the getter, what is the point of also having it as an ivar? This could be a local variable in the getter instead. Same remark for the other one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to avoid returning a reference to a local var and to make the minimal changes to the code to preserve backward compatibility. What do you recommend?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, so we can't return spacing by value? If so, this is fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - this is still using a very old (the original) ITK API where spacing was double * - which doesn't wrap for python, hence this PR. For ITK v6.0, I'd like to do a major update to SpatialObjects to follow ITK's current API, but it will break backward compatibility.

Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add an extra ivar, we might want to print it in PrintSelf method.

@aylward
Copy link
Member Author

aylward commented Jul 15, 2024

If we add an extra ivar, we might want to print it in PrintSelf method.

Great point - will amend this commit!

Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

👍 for making breaking changes to improve the API with ITK 6

itk::SpatialObjectToImageFilter provided GetSpacing() and GetOrigin()
calls that returned double * objects.  That return type is not well
supported by SWIG for python wrapping.

Herein we provide GetSpacingVector() and GetOriginPoint() functions
that return VectorType and PointType objects from the itk::Image class
definition which are nicely wrapped by SWIG for python.
@dzenanz dzenanz merged commit b652989 into InsightSoftwareConsortium:master Jul 18, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Core Issues affecting the Core module type:Enhancement Improvement of existing methods or implementation type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants