Skip to content

BUG: Fix DicomSeriesReader test for ITK PR#5357 direction fix - #2591

Merged
blowekamp merged 1 commit into
SimpleITK:mainfrom
blowekamp:fix-dicom-reverse-order-direction-test
May 9, 2026
Merged

blowekamp merged 1 commit into
SimpleITK:mainfrom
blowekamp:fix-dicom-reverse-order-direction-test

Conversation

@blowekamp

Copy link
Copy Markdown
Member

Summary

The IO.DicomSeriesReader test was failing due to a behavioral change in ITK PR InsightSoftwareConsortium/ITK#5357, which fixed ForceOrthogonalDirection to correctly negate the z-column of the direction matrix when reading a DICOM series in reverse order.

The previous test used EXPECT_EQ on the full direction matrix, expecting it to be identical between forward and reversed reads. This was correct for old ITK (where the z-column sign was not updated — a bug), but fails with the fixed ITK.

Fix

Replace the single EXPECT_EQ(direction, direction_reverse) with element-wise checks that are valid for both old and new ITK:

  • x/y-columns (flat indices 0,1,3,4,6,7): must be identical regardless of ReverseOrder — these come from DICOM image orientation tags and are unaffected.
  • z-column (flat indices 2,5,8): must match in magnitude — old ITK keeps the sign (bug), new ITK negates it (correct), but the unit vector magnitude is preserved in both cases.

Copilot AI 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.

Pull request overview

Updates the IO.DicomSeriesReader unit test to accommodate the ITK behavior change from InsightSoftwareConsortium/ITK#5357, where ForceOrthogonalDirection now negates the z-column of the direction matrix when reading a DICOM series in reverse order.

Changes:

  • Replaces full-matrix EXPECT_EQ direction comparison with element-wise checks.
  • Validates x/y direction columns are unchanged and z-column matches in magnitude (allowing sign differences across ITK versions).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +558 to +561
{
const auto d = image2.GetDirection();
const auto dr = image2_reverse.GetDirection();
ASSERT_EQ(d.size(), 9u);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed: added ASSERT_EQ(d.size(), dr.size()) before ASSERT_EQ(d.size(), 9u) so a dimension mismatch between the two images is caught as a distinct pre-condition failure.

Comment on lines +569 to +570
EXPECT_NEAR(std::abs(d[i]), std::abs(dr[i]), 1e-10)
<< "Direction z-column element [" << i << "] magnitude should be unchanged by ReverseOrder";

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed: added #include <cmath> explicitly to make the std::abs dependency clear and avoid reliance on transitive includes.

Comment thread Testing/Unit/sitkImageIOTests.cxx Outdated
EXPECT_EQ(image2.GetDirection(), image2_reverse.GetDirection());
// ITK PR#5357 fixed ForceOrthogonalDirection to negate the z-column when
// reading in reverse order. X/y-columns are unaffected; z-column must match
// in magnitude (sign may differ between old and new ITK).

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.

Comment should refer to the ITK versions explicitly (<6.0.0 and >6.0.0), old and new will change over time.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed: updated the comment to reference explicit ITK versions — ITK < 6.0 (pre-fix, sign preserved) and ITK >= 6.0 (post ITK PR#5357, sign negated).

@blowekamp
blowekamp force-pushed the fix-dicom-reverse-order-direction-test branch from 52563b5 to 6900990 Compare May 8, 2026 20:57
@blowekamp
blowekamp merged commit 853c78a into SimpleITK:main May 9, 2026
16 of 17 checks passed
@blowekamp
blowekamp deleted the fix-dicom-reverse-order-direction-test branch September 9, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants