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

(Not ready) Simpler TransformPhysicalPointToContinuousIndex(point) overloads #4002

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Apr 6, 2023

Added non-template overloads, which allow the user to write:

index = image->TransformPhysicalPointToContinuousIndex(point);

Instead of calling one of the overload that was added with ITK 5.0, for example:

index = image->template TransformPhysicalPointToContinuousIndex<typename ContinuousIndexType::ValueType>(point);

I assume that usually (or at least in most common use cases), the user just wants TransformPhysicalPointToContinuousIndex to just yield a ContinuousIndex<SpacePrecisionType, N> (with SpacePrecisionType = double, by default). So in most use cases, the ValueType of ContinuousIndex does not need to be a template argument of this function. Is that OK?

@github-actions github-actions bot added type:Enhancement Improvement of existing methods or implementation area:Core Issues affecting the Core module labels Apr 6, 2023
@N-Dekker N-Dekker force-pushed the Add-TransformPhysicalPointToContinuousIndex-overload branch from ba80ce2 to a58b507 Compare April 6, 2023 20:02
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.

I love it!

@N-Dekker N-Dekker force-pushed the Add-TransformPhysicalPointToContinuousIndex-overload branch from a58b507 to 2abdcb5 Compare April 6, 2023 20:22
Comment on lines +518 to +522
[[nodiscard]] ContinuousIndex<SpacePrecisionType, VImageDimension>
TransformPhysicalPointToContinuousIndex(const PointType & point) const
{
return TransformPhysicalPointToContinuousIndex<SpacePrecisionType>(point);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be useful to have two of such (simple, non-templated) overloads? One of float and one of double? Specifically:

ContinuousIndex<float, VImageDimension>
TransformPhysicalPointToContinuousIndex(const Point<float, VImageDimension> &) const;

ContinuousIndex<double, VImageDimension>
TransformPhysicalPointToContinuousIndex(const Point<double, VImageDimension> &) const;

So one from Point<float, N> to ContinuousIndex<float, N>, and one from Point<double, N> to ContinuousIndex<double, N>? Overload resolution would then automatically choose the right one, no need for the user to specify template arguments. Right?

Copy link
Member

Choose a reason for hiding this comment

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

The float one is rarely used, I believe. If someone wants an unusual thing, they can spell out the template parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm wondering, could all those image->template TransformPhysicalPointToContinuousIndex<ContinuousValueType>(point) calls inside ITK itself then replaced by simple non-templated image->TransformPhysicalPointToContinuousIndex(point) calls?

@N-Dekker N-Dekker changed the title ENH: A simpler TransformPhysicalPointToContinuousIndex(point) overload Simpler TransformPhysicalPointToContinuousIndex(point) overloads Apr 9, 2023
Added missing `template` keywords to TransformPhysicalPointToContinuousIndex
calls in Nonunit/Review tests.

Addressed compile errors from Ubuntu-22.04-gcc11.2-TBB-Debug saying:

> error: expected primary-expression before '>' token

These compile errors were introduced by pull request InsightSoftwareConsortium#4000
commit 7cda5ba
"COMP: Fix TransformPhysicalPointToContinuousIndex `nodiscard` warnings"
Added non-template overloads, which allow the user to write:

    index = image->TransformPhysicalPointToContinuousIndex(point);

Instead of calling one of the overload that was added with ITK 5.0, for example:

    index = image->template TransformPhysicalPointToContinuousIndex<typename ContinuousIndexType::ValueType>(point);
@N-Dekker N-Dekker force-pushed the Add-TransformPhysicalPointToContinuousIndex-overload branch from 2abdcb5 to f5950a8 Compare April 9, 2023 22:16
@github-actions github-actions bot added type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module area:Numerics Issues affecting the Numerics module and removed type:Enhancement Improvement of existing methods or implementation labels Apr 9, 2023
Did replace `template TransformPhysicalPointToContinuousIndex<.+>` calls
with `TransformPhysicalPointToContinuousIndex`, using regular expressions.

Only included `TransformPhysicalPointToContinuousIndex` calls for which both
template parameters (for `TIndexRep` and `TCoordRep`) were equal to
`itk::SpacePrecisionType`.

Excluded unit tests from tkImageBaseGTest.cxx and itkImageAdaptorGTest.cxx
as they intentionally called the member function _template_.
@N-Dekker N-Dekker force-pushed the Add-TransformPhysicalPointToContinuousIndex-overload branch from f5950a8 to 983bf81 Compare April 10, 2023 08:33
@github-actions github-actions bot removed the area:Numerics Issues affecting the Numerics module label Apr 10, 2023
@dzenanz
Copy link
Member

dzenanz commented Apr 10, 2023

Is this ready for merging? It would fix a lot of compile errors on the dashboard.

@N-Dekker
Copy link
Contributor Author

Is this ready for merging?

@dzenanz No it's still a draft, sorry! PR #4005 is ready, though!

@N-Dekker
Copy link
Contributor Author

Is ITK_USE_FLOAT_SPACE_PRECISION still supported? As in:

// Allow using single precision by default
#if defined(ITK_USE_FLOAT_SPACE_PRECISION)
using SpacePrecisionType = float;
#else
using SpacePrecisionType = double;
#endif

Maybe it's just me, but I got a lot of compile errors when I try to compile the current master with ITK_USE_FLOAT_SPACE_PRECISION = ON. Is it still tested elsewhere?

I'm asking here because ITK_USE_FLOAT_SPACE_PRECISION = ON would make it harder to use the simpler TransformPhysicalPointToContinuousIndex overload (proposed by this PR) inside ITK itself.

@dzenanz
Copy link
Member

dzenanz commented Apr 10, 2023

ITK_USE_FLOAT_SPACE_PRECISION is still exposed in CMake, but I don't think it has been tested for a very long time. I think some components assume it is double. Maybe it is time to remove that setting and deprecate that header? What do @blowekamp and @hjmjohnson think about this?

@N-Dekker
Copy link
Contributor Author

If we can't have a simple, easy to use alternative to the old "IsInside estimating" TransformPhysicalPointToContinuousIndex(point, index), maybe just remove the [[nodiscard]] from that particular member function. I'm sorry, I had not expected so much trouble from [[nodiscard]]. I still think users should be aware of the fact that TransformPhysicalPointToContinuousIndex(point, index) is estimating IsInside. And I still think they should only use it when they really want to know whether the point is inside. But I just don't know how to make it easier. 🤷

@N-Dekker
Copy link
Contributor Author

ITK_USE_FLOAT_SPACE_PRECISION is still exposed in CMake, but I don't think it has been tested for a very long time. I think some components assume it is double. Maybe it is time to remove that setting and deprecate that header? What do @blowekamp and @hjmjohnson think about this?

I think that as long as ITK supports ITK_USE_FLOAT_SPACE_PRECISION (allowing the user to choose between SpacePrecisionType = float and SpacePrecisionType = double) and as long as ContinuousIndex supports float, double, and SpacePrecisionType as value type, a simple TransformPhysicalPointToContinuousIndex(point) overload that just returns ContinuousIndex<SpacePrecisionType, N> (proposed by this PR) is of very limited use.

@hjmjohnson
Copy link
Member

I think that as long as ITK supports ITK_USE_FLOAT_SPACE_PRECISION (allowing the user to choose between SpacePrecisionType = float

I think we should test the ITK_USE_FLOAT_SPACE_PRECISION, I could think of a customer who may use FLOAT_SPACE_PRECISION for the purpose of improving computational speed for their algorithm. Removing this option MAY cause that customer great pain.

The above scenario is purely hypothetical .... just pointing out that removal may have unintended consequences for customers.

@N-Dekker N-Dekker changed the title Simpler TransformPhysicalPointToContinuousIndex(point) overloads (Not ready) Simpler TransformPhysicalPointToContinuousIndex(point) overloads Aug 31, 2023
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 area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module 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