Skip to content

COMP: Switch IOTransformDCMTK test from GDCMImageIO to DCMTKImageIO - #6456

Merged
hjmjohnson merged 2 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix-iodcmtk-use-dcmtkimageio
Jun 18, 2026
Merged

hjmjohnson merged 2 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix-iodcmtk-use-dcmtkimageio

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Switch itkDCMTKTransformIOResampleTest from GDCMImageIO/GDCMSeriesFileNames
to DCMTKImageIO/DCMTKSeriesFileNames now that ITKIODCMTK is in ITK proper
(PR #6310). Removes the unused ITKIOGDCM test dependency.

Resolves #6309

Baseline regeneration

DCMTKSeriesFileNames sorts slices by InstanceNumber (0020,0013) rather than
ImagePositionPatient, so the resampled output has different geometry from the
old GDCM-generated baseline (origin_z −12.5 vs −49.5, spacing_z 0.626 vs 1.0).
Baseline regenerated from DCMTKImageIO output; comparison reports 0 image error.
New CID uploaded to ITKTestingData (commit cb41220 on gh-pages).

@github-actions github-actions Bot added type:Compiler Compiler support or related warnings type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:IO Issues affecting the IO module labels Jun 16, 2026
@hjmjohnson
hjmjohnson marked this pull request as ready for review June 16, 2026 22:56
@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Switches itkDCMTKTransformIOResampleTest from GDCMImageIO/GDCMSeriesFileNames to DCMTKImageIO/DCMTKSeriesFileNames, removing the now-unnecessary ITKIOGDCM test dependency. The baseline image is regenerated because DCMTKSeriesFileNames orders slices by InstanceNumber rather than ImagePositionPatient, producing different output geometry.

  • itk-module.cmake: ITKIOGDCM dropped from TEST_DEPENDS; ITKIODCMTK (already listed) provides the new dependency.
  • itkDCMTKTransformIOResampleTest.cxx: All substituted API calls (SetInputDirectory, GetInputFileNames, GetSeriesUIDs) exist on DCMTKSeriesFileNames, and the DCMTK metadata-dictionary key format ("GGGG|EEEE") is confirmed to match GDCM's, so the 0020|0052 lookup is safe.
  • content-links.manifest: New baseline CID registered; the entry has an extra space that should be one (see inline comment).

Confidence Score: 4/5

Safe to merge; only finding is a cosmetic double-space in one manifest line.

The substitution is straightforward: every GDCM API call has a direct DCMTK equivalent with matching signatures, the metadata key format is confirmed identical between both IO backends, and the itk-module.cmake dependency list is correct. The only issue is the extra space in the manifest entry, which is harmless to the build and test infrastructure but inconsistent with the rest of the file.

Testing/Data/content-links.manifest — double-space in the new entry.

Important Files Changed

Filename Overview
Modules/IO/IOTransformDCMTK/itk-module.cmake Removes ITKIOGDCM from TEST_DEPENDS; ITKIODCMTK (already present) covers the new DCMTKImageIO/DCMTKSeriesFileNames requirement.
Modules/IO/IOTransformDCMTK/test/itkDCMTKTransformIOResampleTest.cxx GDCMImageIO/GDCMSeriesFileNames replaced with DCMTKImageIO/DCMTKSeriesFileNames; all three used methods (SetInputDirectory, GetInputFileNames, GetSeriesUIDs) are present in the DCMTK API, and the metadata key format is identical between both IO implementations.
Modules/IO/IOTransformDCMTK/test/Baseline/DicomTransformResampledMovingOutputBaseline.mha.cid CID updated to match the DCMTK-resampled baseline; expected given DCMTKSeriesFileNames sorts by InstanceNumber rather than ImagePositionPatient, yielding different geometry.
Testing/Data/content-links.manifest New CID registered for the regenerated baseline; entry has two spaces instead of one between the CID and the path, inconsistent with every other line in the file and with what upload.py writes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[itkDCMTKTransformIOResampleTest] --> B[DCMTKSeriesFileNames\nGetInputFileNames / GetSeriesUIDs]
    B --> C[ImageSeriesReader\nSetImageIO DCMTKImageIO]
    C --> D[fixedReader / movingReader Update]
    D --> E[DCMTKImageIO MetaDataDictionary\nFrameOfReferenceUID lookup]
    E --> F[DCMTKTransformIO\nSetFrameOfReferenceUID]
    F --> G[TransformFileReader Update x2]
    G --> H[ResampleImageFilter\nfixed to moving]
    H --> I[ImageFileWriter\nresampledMovingOutput]
    I --> J[Baseline comparison\nDicomTransformResampledMovingOutputBaseline.mha]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[itkDCMTKTransformIOResampleTest] --> B[DCMTKSeriesFileNames\nGetInputFileNames / GetSeriesUIDs]
    B --> C[ImageSeriesReader\nSetImageIO DCMTKImageIO]
    C --> D[fixedReader / movingReader Update]
    D --> E[DCMTKImageIO MetaDataDictionary\nFrameOfReferenceUID lookup]
    E --> F[DCMTKTransformIO\nSetFrameOfReferenceUID]
    F --> G[TransformFileReader Update x2]
    G --> H[ResampleImageFilter\nfixed to moving]
    H --> I[ImageFileWriter\nresampledMovingOutput]
    I --> J[Baseline comparison\nDicomTransformResampledMovingOutputBaseline.mha]
Loading

Reviews (1): Last reviewed commit: "COMP: Switch IOTransformDCMTK test from ..." | Re-trigger Greptile

Comment thread Testing/Data/content-links.manifest Resolved
@hjmjohnson
hjmjohnson force-pushed the fix-iodcmtk-use-dcmtkimageio branch from b364926 to 5508aab Compare June 17, 2026 00:09
itk::DCMTKSeriesFileNames ordered slices solely by InstanceNumber
(0020,0013) via an unstable std::sort. When InstanceNumber is absent or
constant across a series, every sort key is equal, so the resulting order
is implementation-defined and seeded by the directory-glob order. This
scrambles the reconstructed volume and yields a meaningless,
machine-dependent z-spacing -- in contrast to itk::GDCMSeriesFileNames,
which orders by ImagePositionPatient projected on the slice normal via
gdcm::SerieHelper.

Order by the same geometric criterion (ImagePositionPatient dotted with
the slice normal derived from ImageOrientationPatient), falling back to
InstanceNumber and then file name when orientation/position is
unavailable, using a stable sort so ties never scramble.

Add a GoogleTest (built only when both ITKIOGDCM and ITKIODCMTK are
present) asserting that GDCMSeriesFileNames and DCMTKSeriesFileNames
produce identical slice ordering on the rect-centered / rect-offset
fixtures, which all carry InstanceNumber 0 and previously triggered the
scramble.

DCMTK provides no directory-scanning series sorter analogous to
gdcm::SerieHelper::OrderFileList, so the geometric ordering is
implemented in ITK using the existing DCMTKFileReader accessors.
itkDCMTKTransformIOResampleTest used GDCMImageIO/GDCMSeriesFileNames to
read DICOM series because DCMTKImageIO was not in ITK proper at the time
the test was written.  PR InsightSoftwareConsortium#6310 ingested ITKIODCMTK; switch the test to
use the same reader as the rest of the module.

This depends on the preceding geometric-ordering fix to
itk::DCMTKSeriesFileNames: with correct ImagePositionPatient ordering,
DCMTKImageIO reproduces the existing GDCM baseline byte-for-byte (0
error), so the baseline is unchanged. ITKIOGDCM remains a test
dependency because the companion ordering GoogleTest compares the two
readers.

Resolves InsightSoftwareConsortium#6309
@hjmjohnson

Copy link
Copy Markdown
Member Author

Force-pushed (5508aab → 335877b) to rebase onto the slice-ordering fix and correct the approach.

Now depends on #6464 (fixes #6463). This PR is stacked on that branch.

What changed and why

The original approach (regenerate the baseline from DCMTKImageIO output) could never pass CI: itk::DCMTKSeriesFileNames ordered slices by InstanceNumber (0020,0013), which is 0 for all 100 rect-centered/rect-offset fixture slices. That left ordering to an unstable std::sort, producing a scrambled volume with a machine-dependent z-spacing — so each regenerated baseline only matched the machine that produced it (CI failed deterministically on all three platforms; see #6463 for the full root cause).

#6464 fixes DCMTKSeriesFileNames to order geometrically (ImagePositionPatient on the slice normal), matching GDCMSeriesFileNames. With correct ordering, DCMTKImageIO reproduces the existing GDCM baseline byte-for-byte (ImageError 0).

This PR is therefore reduced to just the GDCM→DCMTK source swap:

Verified locally: full IOTransformDCMTK suite passes, itkDCMTKTransformIOResampleTest ImageError 0 with no nonuniformity warning, pre-commit run --all-files clean.

Merge order

Merge #6464 first, then this PR rebases cleanly onto main (the ordering-fix commit drops out as already-merged, leaving the 4-line source swap).

@github-actions github-actions Bot added the type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots label Jun 17, 2026
@hjmjohnson
hjmjohnson merged commit 5862f6a into InsightSoftwareConsortium:main Jun 18, 2026
21 checks passed
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Jun 18, 2026
The geometric slice ordering (added via PR InsightSoftwareConsortium#6456 for issue InsightSoftwareConsortium#6463) derived
the slice normal from headers.front() alone. If the first file returned by
the directory glob lacks ImageOrientationPatient (e.g. a localizer or a
corrupt slice that sorted first), geometric ordering was silently suppressed
for the entire series. Scan for the first slice carrying a valid orientation
instead.

Also correct the regression-test comment to cite issue InsightSoftwareConsortium#6463 rather than the
downstream PR InsightSoftwareConsortium#6456.

Addresses the greptile review on PR InsightSoftwareConsortium#6464.
@hjmjohnson
hjmjohnson deleted the fix-iodcmtk-use-dcmtkimageio branch August 22, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:IO Issues affecting the IO module type:Compiler Compiler support or related warnings 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.

IOTransformDCMTK example uses GDCM fallback; verify DCMTKImageIO MetaDataDictionary path works end-to-end

2 participants