Skip to content

ENH: Simpler TransformPhysicalPointToContinuousIndex(point) overloads (rebase of #4002)#6186

Closed
hjmjohnson wants to merge 3 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson:Add-TransformPhysicalPointToContinuousIndex-overload-rebased
Closed

ENH: Simpler TransformPhysicalPointToContinuousIndex(point) overloads (rebase of #4002)#6186
hjmjohnson wants to merge 3 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson:Add-TransformPhysicalPointToContinuousIndex-overload-rebased

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

Rebased and finished version of #4002 (originally by @N-Dekker, April 2023). Adds non-template TransformPhysicalPointToContinuousIndex(point) overloads on ImageBase, PhasedArray3DSpecialCoordinatesImage, and ImageAdaptor, then converts internal call sites to the simpler form.

Why this supersedes #4002

#4002's branch was 4838 commits behind upstream/main. A direct cherry-pick reverted two years of style modernization (itkExceptionStringMacro, trailing-return auto, added consts, header reorganization) on the same files the STYLE commit touched. Rather than fight that, this PR is a clean re-implementation of N-Dekker's design on top of current main:

  • The original COMP: commit (adding template keyword in tests) was already merged upstream — dropped.
  • The ENH: overload additions were re-applied to the three header files at their current upstream locations.
  • The STYLE: call-site replacements were re-applied via regex; CoordRepType references on the touched lines were updated to CoordinateType (ITK 6 deprecated the old name).
Open design question from #4002 — do we also want a non-template float overload?

@N-Dekker raised this in an inline comment on #4002: should we also offer

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

@dzenanz's reply: the float overload is rarely used; users who need it can spell out the explicit template parameter. This PR follows that guidance — only the SpacePrecisionType-based overload is added. Users needing float precision can still call the templated form explicitly.

ITK_USE_FLOAT_SPACE_PRECISION compatibility

When ITK_USE_FLOAT_SPACE_PRECISION=ON, SpacePrecisionType=float, so the new overload returns ContinuousIndex<float, N>. At call sites that assign to ContinuousIndex<double, N> (e.g. WarpImageFilter, ImageToImageMetric), the ContinuousIndex converting constructor handles the widening. At sites that assign to ContinuousIndex<CoordinateType, N> where CoordinateType==SpacePrecisionType==float, the assignment is exact. Confirmed by @hjmjohnson in a 2025-09-16 comment on #4002 that ITK_USE_FLOAT_SPACE_PRECISION still compiles cleanly.

Closes #4002.

@github-actions github-actions Bot added type:Enhancement Improvement of existing methods or implementation 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 area:Documentation Issues affecting the Documentation module labels May 1, 2026
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request May 2, 2026
`Documentation/docs/releases/5.4.6.md` carries a trailing empty line
that the `end-of-file-fixer` pre-commit hook flags every time a PR
rebases onto current `main`.  Affected at least PRs InsightSoftwareConsortium#6032, InsightSoftwareConsortium#4221, and
InsightSoftwareConsortium#6186, where each had to carry an identical one-character fix.  Apply
once on `main` to stop the spurious `pre-commit` failures.
@hjmjohnson hjmjohnson force-pushed the Add-TransformPhysicalPointToContinuousIndex-overload-rebased branch from 8da1845 to 6128fea Compare May 2, 2026 00:21
@github-actions github-actions Bot removed the area:Documentation Issues affecting the Documentation module label May 2, 2026
@hjmjohnson hjmjohnson force-pushed the Add-TransformPhysicalPointToContinuousIndex-overload-rebased branch from 6128fea to de8c7ed Compare May 2, 2026 12:43
@hjmjohnson
Copy link
Copy Markdown
Member Author

@greptileai review this draft before I make it official

@greptile-apps

This comment was marked as resolved.

Comment thread Modules/Core/Mesh/include/itkTriangleMeshToBinaryImageFilter.hxx Outdated
Comment thread Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx Outdated
@hjmjohnson hjmjohnson force-pushed the Add-TransformPhysicalPointToContinuousIndex-overload-rebased branch from de8c7ed to 9cdd48f Compare May 2, 2026 16:42
@hjmjohnson hjmjohnson marked this pull request as ready for review May 2, 2026 18:05
Comment thread Modules/Core/Transform/include/itkBSplineBaseTransform.hxx Outdated
@hjmjohnson hjmjohnson force-pushed the Add-TransformPhysicalPointToContinuousIndex-overload-rebased branch 2 times, most recently from 0bc3437 to a140cff Compare May 2, 2026 20:20
@hjmjohnson
Copy link
Copy Markdown
Member Author

/azp run

@hjmjohnson
Copy link
Copy Markdown
Member Author

Retriggering ITK.Linux.Python — the previous run failed in Post-job: Restore ccache with Process returned non-zero exit code: 2 after 10 Free disk space on / is lower than 5% warnings (Azure runner disk-full at the cleanup step). Build/test ran, the failure is in CI infrastructure, not this PR's diff.

/azp run ITK.Linux.Python

@hjmjohnson
Copy link
Copy Markdown
Member Author

/azp run ITK.Linux.Python

hjmjohnson and others added 3 commits May 3, 2026 07:51
ITK.Linux.Python builds 14748 and 14751 (and presumably any
subsequent run) fail at the implicit `Cache@2` post-job step that
tars `CCACHE_DIR` for upload, with

    tar: <archive>: Wrote only 4096 of 10240 bytes
    tar: Error is not recoverable: exiting now
    ##[error]Process returned non-zero exit code: 2

after 10+ `Free disk space on / is lower than 5%` warnings.  The
build/test phase itself is green; only the cache upload fails.

The local ccache fills its 5G default ceiling during the build:

    Cache size (GB): 4.94 / 5.00 (98.87 %)
    Cleanups:          15

and the runner's writable disk is already 96% full when `tar` starts,
leaving no room for the staging archive.  Worse, because the upload
fails every run, the pipeline cache key reports a miss every time, so
the next run is also cold and refills the local store from scratch.

Insert a between-step that runs after `Build and test` and before the
implicit post-job `Restore ccache` upload:

  - `df -h /` for visibility on both sides of the cleanup;
  - `ccache --evict-older-than 5d` to drop stale entries;
  - `ccache --max-size 6.5G` to lower the soft ceiling;
  - `ccache -c` to force the store under that ceiling;
  - `ninja -C <build> clean` to free the .o files that are no longer
    needed once the build/test phase has reported (`|| true` so a
    missing/already-clean tree does not fail the step).

Setting max-size to 6.5G (above the in-build CCACHE_MAXSIZE=8G env
but below the runner's free-disk headroom) gives ccache room to
operate during the build while keeping the post-job tar inside the
runner's disk budget.
Added non-template overloads to `ImageBase`, `PhasedArray3DSpecialCoordinatesImage`,
and `ImageAdaptor`, which allow the user to write:

    index = image->TransformPhysicalPointToContinuousIndex(point);

Instead of having to spell out the explicit template argument:

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

The new overloads take the image's `PointType` (= `Point<SpacePrecisionType, N>`)
and return `ContinuousIndex<SpacePrecisionType, N>` — the dominant use case.
Users who need a different precision can still call the templated overload
explicitly.

Co-Authored-By: Hans Johnson <hans-johnson@uiowa.edu>
Replace `->template TransformPhysicalPointToContinuousIndex<X>(point)`
with the new non-template overload `->TransformPhysicalPointToContinuousIndex(point)`
at internal call sites where the explicit template parameter resolved to
`itk::SpacePrecisionType` (i.e. the dominant case).

Files updated cover ImageAlgorithm, TriangleMeshToBinaryImageFilter,
BSplineBaseTransform, WarpImageFilter, the Registration Common metrics,
and SLICImageFilter.

Excludes unit tests in itkImageBaseGTest.cxx and itkImageAdaptorGTest.cxx
which intentionally exercise the templated form.

Co-Authored-By: Hans Johnson <hans-johnson@uiowa.edu>
@hjmjohnson hjmjohnson force-pushed the Add-TransformPhysicalPointToContinuousIndex-overload-rebased branch from a140cff to 20865f1 Compare May 3, 2026 12:54
@github-actions github-actions Bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct labels May 3, 2026
@hjmjohnson
Copy link
Copy Markdown
Member Author

Rebased onto #6199 (COMP: Free disk on Linux.Python CI before post-job ccache tar) so this PR's CI run picks up the cleanup step. The previous two ITK.Linux.Python failures on this PR (builds 14748 and 14751) were not real test failures — both build/test phases were green; the post-job Cache@2 task tried to tar a 4.94 GB ccache on a runner with <5% free disk and hit ENOSPC. See #6199 for the diagnosis and fix.

Once #6199 merges, I'll rebase this PR back onto plain upstream/main to drop the stacked YAML commit.

@N-Dekker
Copy link
Copy Markdown
Contributor

N-Dekker commented May 4, 2026

I'm sorry but I think the extra overloads may introduce more confusion. It seemed like a good idea in the beginning, but it is of very limited use. It just isn't obvious what is the preferred scalar type of the return type of TransformPhysicalPointToContinuousIndex(point), "by default".

@hjmjohnson
Copy link
Copy Markdown
Member Author

@N-Dekker Thank you for the feedback. I'll close these to clean up the PR list.

@hjmjohnson hjmjohnson closed this May 4, 2026
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:Enhancement Improvement of existing methods or implementation type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots 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.

2 participants