Skip to content

Use the faster TransformPhysicalPointToIndex overload#2873

Merged
dzenanz merged 2 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:Use-faster-TransformPhysicalPointToIndex-overload
Nov 16, 2021
Merged

Use the faster TransformPhysicalPointToIndex overload#2873
dzenanz merged 2 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:Use-faster-TransformPhysicalPointToIndex-overload

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

Replaced image->TransformPhysicalPointToIndex(point, index) calls by
image->TransformPhysicalPointToIndex(point), which is slightly faster,
as it does not figure out whether or not the point is inside the image.

Follow-up to pull request #993
commit 0703516
"STYLE: Use image->TransformPhysicalPointToIndex(point), returning index"

@github-actions github-actions Bot added 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 labels Nov 15, 2021
Copy link
Copy Markdown
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.

The second is more of a style commit, than a performance one. Potentially split most of it into a separate style commit. Only calls inside large for loops (per pixel) count as real performance improvement!

IndexType centerIndex;

outputImage->TransformPhysicalPointToIndex(center, centerIndex);
IndexType centerIndex = outputImage->TransformPhysicalPointToIndex(center);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure how important performance is here, and other similar instances. But this improves style slightly, and saves a line of code.

@N-Dekker
Copy link
Copy Markdown
Contributor Author

The second is more of a style commit, than a performance one. Potentially split most of it into a separate style commit. Only calls inside large for loops (per pixel) count as real performance improvement!

@dzenanz I agree, it's mostly a style commit, it just might improve the performance. 😄 The first commit might improve the performance of user code, as it is part of a filter.

Actually I was trying out the C++17 [[nodiscard]] attribute on the older (potentially slower) overload, ImageBase::TransformPhysicalPointToIndex(point, index). I think [[nodiscard]] would make sense in this case.

Will adjust the commit message of the second commit, from PERF to STYLE.

Replaced `image->TransformPhysicalPointToIndex(point, index)` call by
`image->TransformPhysicalPointToIndex(point)`, which is slightly faster,
as it does not figure out whether or not the point is inside the image.

Follow-up to pull request InsightSoftwareConsortium#993
commit 0703516
"STYLE: Use image->TransformPhysicalPointToIndex(point), returning index"
Replaced `image->TransformPhysicalPointToIndex(point, index)` calls by
`image->TransformPhysicalPointToIndex(point)`, which is slightly faster,
as it does not figure out whether or not the point is inside the image.

This is mostly a style improvement. It is recommended to only use the
slightly slower overload, `TransformPhysicalPointToIndex(point, index)`
when its `bool` return value is to be used.

Follow-up to pull request InsightSoftwareConsortium#993
commit 0703516
"STYLE: Use image->TransformPhysicalPointToIndex(point), returning index"
@N-Dekker N-Dekker force-pushed the Use-faster-TransformPhysicalPointToIndex-overload branch from d8d8473 to 919a3a6 Compare November 15, 2021 22:53
@N-Dekker N-Dekker marked this pull request as ready for review November 15, 2021 22:56
@N-Dekker
Copy link
Copy Markdown
Contributor Author

I think this pull request is ready now, only CircleCi has failed, saying "Build timed out", and:

Upgrade your pricing plan to take advantage of longer build times
context deadline exceeded

https://app.circleci.com/pipelines/github/InsightSoftwareConsortium/ITK/3864/workflows/c431702d-7d38-400b-a113-07357a08f3b8/jobs/10620

@dzenanz dzenanz merged commit c1f266a into InsightSoftwareConsortium:master Nov 16, 2021
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Nov 25, 2021
Replaced image->TransformPhysicalPointToContinuousIndex(point, index)
calls by image->TransformPhysicalPointToContinuousIndex<T>(point), which
is slightly faster, as it does not figure out whether or not the point
is inside the image.

Follow-up to pull request InsightSoftwareConsortium#2873
commit eb6ac88
"PERF: Use the faster TransformPhysicalPointToIndex overload in filter"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Nov 25, 2021
Replaced `image->TransformPhysicalPointToContinuousIndex(point, index)`
calls by `image->TransformPhysicalPointToContinuousIndex<T>(point)`,
which is slightly faster, as it does not figure out whether or not the
point is inside the image.

Follow-up to pull request InsightSoftwareConsortium#2873
commit eb6ac88
"PERF: Use the faster TransformPhysicalPointToIndex overload in filter"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Nov 25, 2021
Replaced `image->TransformPhysicalPointToContinuousIndex(point, index)`
calls by `image->TransformPhysicalPointToContinuousIndex<T>(point)`,
which is slightly faster, as it does not figure out whether or not the
point is inside the image.

Declared variables that are initialized by
`image->TransformPhysicalPointToContinuousIndex<T>(point)` `const`, when
possible.

Follow-up to pull request InsightSoftwareConsortium#2873
commit eb6ac88
"PERF: Use the faster TransformPhysicalPointToIndex overload in filter"
dzenanz pushed a commit that referenced this pull request Nov 27, 2021
Replaced `image->TransformPhysicalPointToContinuousIndex(point, index)`
calls by `image->TransformPhysicalPointToContinuousIndex<T>(point)`,
which is slightly faster, as it does not figure out whether or not the
point is inside the image.

Declared variables that are initialized by
`image->TransformPhysicalPointToContinuousIndex<T>(point)` `const`, when
possible.

Follow-up to pull request #2873
commit eb6ac88
"PERF: Use the faster TransformPhysicalPointToIndex overload in filter"
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Aug 29, 2024
Adjusted its `GPUGenerateData()` member function to call the faster `TransformPhysicalPointToIndex` overload.

Addresses MSVC compiler warnings saying:

    itkGPUShrinkImageFilter.hxx(109,39): warning C4834: discarding return value of function with [[nodiscard]] attribute

Similar to pull request InsightSoftwareConsortium/ITK#2873 commit InsightSoftwareConsortium/ITK@eb6ac88 "Use the faster `TransformPhysicalPointToIndex` overload in filter", November 16, 2021.
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Aug 29, 2024
Adjusted its `GPUGenerateData()` member function to call the faster `TransformPhysicalPointToIndex` overload.

Addresses MSVC compiler warnings saying:

    itkGPUShrinkImageFilter.hxx(109,39): warning C4834: discarding return value of function with [[nodiscard]] attribute

Similar to pull request InsightSoftwareConsortium/ITK#2873 commit InsightSoftwareConsortium/ITK@eb6ac88 "Use the faster `TransformPhysicalPointToIndex` overload in filter", November 16, 2021.
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this pull request May 6, 2026
Replaced `image->TransformPhysicalPointToContinuousIndex(point, index)`
calls by `image->TransformPhysicalPointToContinuousIndex<T>(point)`,
which is slightly faster, as it does not figure out whether or not the
point is inside the image.

Declared variables that are initialized by
`image->TransformPhysicalPointToContinuousIndex<T>(point)` `const`, when
possible.

Follow-up to pull request InsightSoftwareConsortium#2873
commit 264b885
"PERF: Use the faster TransformPhysicalPointToIndex overload in filter"
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.

3 participants