Skip to content

BUG: Mark BSplineInterpolateImageFunction modified on a spline order change - #7277

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bspline-spline-order-modified
Nov 30, 2026
Merged

hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bspline-spline-order-modified

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

BSplineInterpolateImageFunction::SetSplineOrder() now calls Modified(). Before this change, changing the spline order after an Update() left ResampleImageFilter up to date, so the next Update() returned the output of the old order. Found while reviewing #7223, whose fixed sample cache is keyed on the fixed interpolator's modified time; this should land first.

Merge danger: two-way door. Blast radius: anything that reads a B-spline interpolator's modified time, which now changes when the order changes.

Not fixed here: ComplexBSplineInterpolateImageFunction::SetSplineOrder() (Review module) has the same missing Modified(); it can follow separately.

Shape of the change
  BSplineInterpolateImageFunction::SetSplineOrder(order)
    if (order == m_SplineOrder) return;   // unchanged: MTime untouched
    ... update order, poles, points-to-index ...
+   this->Modified();

SetInputImage() is deliberately left alone. ResampleImageFilter calls it during every execution (itkResampleImageFilter.hxx:163, :195) and folds the interpolator's modified time into its own (:645). The v3 ImageRegistrationMethod, MultiResolutionImageRegistrationMethod, ImageToSpatialObjectRegistrationMethod, and PointSetToImageRegistrationMethod also fold it in, and their metrics call SetInputImage() in Initialize(). Marking it modified there would make all of these re-execute on every update.

Outside tests, the only ITK callers of this interpolator's SetSplineOrder() are ComplexBSplineInterpolateImageFunction, which holds its interpolators as private members, and DirectFourierReconstructionImageToImageFilter, which creates them inside GenerateData(). Neither folds their modified time into its own.

Evidence

Two GTests in itkResampleImageFilterGTest.cxx:

  • ReexecutesWhenBSplineOrderChanges: resample a random 8x8 image at spline order 1, call SetSplineOrder(3), update again, and compare with a fresh order 3 resample.
  • KeepsUpToDateWhenBSplineOrderIsUnchanged: setting the order the interpolator already has leaves both its modified time and the filter's output untouched.

Without the Modified() line:

Expected: (interpolator->GetMTime()) > (timeBefore), actual: 6 vs 6
Expected equality of these values:
  PixelsOf(resampler->GetOutput())   Which is: { 43.8774834, 39.8867874, ... }
  cubicPixels                        Which is: { 40.89328, 29.2692928, ... }
[  FAILED  ] ResampleImageFilter.ReexecutesWhenBSplineOrderChanges

With it, all 6 ResampleImageFilter GTests pass, and ctest -L "ITKImageFunction|ITKImageGrid" -R "BSpline|Resample" passes 40 of 40 (macOS arm64, conda clang, Release). pre-commit run --all-files passes.

#7223 rebased onto this branch: a metric that changes its fixed interpolator's order and calls SetInputImage(), without Initialize(), returned the order 1 value (2.5768 instead of 2.6680) without this fix and the order 3 value with it.

Not tested: Windows/MSVC, downstream consumers.

AI assistance

Claude Code (claude-opus-5-5) did the root-cause analysis, the caller audit, and the regression tests, under review by the author.

@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances 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 area:Filtering Issues affecting the Filtering module labels Nov 30, 2026
…change

SetSplineOrder() changed the interpolator without calling Modified().
ResampleImageFilter folds the interpolator's modified time into its own,
so after changing the spline order, the next Update() did nothing and
returned the output of the old order. Any cache keyed on the
interpolator's modified time had the same problem.

SetSplineOrder() now calls Modified() when the order changes; setting
the order it already has leaves the time alone. SetInputImage() still
does not call Modified(), because ResampleImageFilter calls it during
every execution.
@hjmjohnson
hjmjohnson force-pushed the bspline-spline-order-modified branch from 7030c3d to 73de3d0 Compare November 30, 2026 19:24
@hjmjohnson
hjmjohnson marked this pull request as ready for review November 30, 2026 19:35
@hjmjohnson hjmjohnson self-assigned this Nov 30, 2026
@greptile-apps

greptile-apps Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

BSplineInterpolateImageFunction::SetSplineOrder() now calls Modified() when the order changes.

  • Changing a B-spline order makes resampling use the new order.

Acknowledged scope: hjmjohnson explicitly deferred the existing missing Modified() call in ComplexBSplineInterpolateImageFunction::SetSplineOrder() to a separate change.

Reviews (1) · Last reviewed commit: "BUG: Mark BSplineInterpolateImageFunctio..." · Reviewed by Greptile

@dzenanz dzenanz left a comment

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.

Change itself looks good. I did not take a good look at the test.

@gdevenyi gdevenyi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change is right. Approving.

  • Early return: SetSplineOrder() returns before Modified() when the order is unchanged, so an unchanged order costs nothing. KeepsUpToDateWhenBSplineOrderIsUnchanged pins that.
  • SetInputImage(): leaving it alone is correct, for the ResampleImageFilter and v3 registration reasons in the PR body.
  • Stale coefficients (no change needed here): changing the order still leaves the coefficients of the old order until SetInputImage() runs. ResampleImageFilter and the metrics' Initialize() both call it, so the new Modified() is enough for them. A caller that changes the order and evaluates directly must still call SetInputImage() again, as before.
  • Local run at 73de3d0, GCC 15, Release, minimal ImageGrid + ImageFunction build: both new ResampleImageFilter GTests pass, and ctest passes 339/339.
  • #7223: now that it is stacked here, it has FollowsTheFixedInterpolatorSplineOrder, which fails without this Modified().

The ComplexBSplineInterpolateImageFunction follow-up sounds right.

Review assisted by Claude Code (claude-opus-5-5); the build and tests above were run locally.

@hjmjohnson
hjmjohnson merged commit 7830484 into InsightSoftwareConsortium:main Nov 30, 2026
19 of 20 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 area:Filtering Issues affecting the Filtering module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances 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