diff --git a/Modules/IO/GDCM/include/itkGDCMSeriesFileNames.h b/Modules/IO/GDCM/include/itkGDCMSeriesFileNames.h index b1c0659d6f4..4015f2b38f6 100644 --- a/Modules/IO/GDCM/include/itkGDCMSeriesFileNames.h +++ b/Modules/IO/GDCM/include/itkGDCMSeriesFileNames.h @@ -42,7 +42,8 @@ namespace itk * orientation), an exception is thrown by default; see * FailOnAmbiguousOrdering. When FailOnAmbiguousOrdering is false, the * ordering falls back to 'Instance Number' when unique, else to - * lexicographic filename order. + * lexicographic filename order (and in either case, DidUseAmbiguousOrdering + * is set to true). * * If multiple volumes are being grouped as a single series for your * DICOM objects, you may want to try calling SetUseSeriesDetails(true) @@ -172,7 +173,7 @@ class ITKIOGDCM_EXPORT GDCMSeriesFileNames : public ProcessObject void AddSeriesRestriction(const std::string & tag); - /** Throw an exception when a series cannot be ordered geometrically by + /** When true, throw an exception when a series cannot be ordered geometrically by * gdcm::IPPSorter (duplicate ImagePositionPatient, inconsistent * orientation). When false, fall back to the legacy SerieHelper * heuristics: Instance Number when unique, else lexicographic filename @@ -184,6 +185,11 @@ class ITKIOGDCM_EXPORT GDCMSeriesFileNames : public ProcessObject itkBooleanMacro(FailOnAmbiguousOrdering); /** @ITKEndGrouping */ + /** If ambiguous ordering is encountered, this is set to true. */ + /** @ITKStartGrouping */ + itkGetConstMacro(DidUseAmbiguousOrdering, bool); + /** @ITKEndGrouping */ + /** No effect with the gdcm::Scanner backend (retained for source * compatibility). Series enumeration reads only the grouping and * ordering tags, so sequences are never parsed during the scan. @@ -256,6 +262,7 @@ class ITKIOGDCM_EXPORT GDCMSeriesFileNames : public ProcessObject bool m_UseSeriesDetails = false; bool m_FailOnAmbiguousOrdering = true; + bool m_DidUseAmbiguousOrdering = false; bool m_Recursive = false; bool m_LoadSequences = false; bool m_LoadPrivateTags = false; diff --git a/Modules/IO/GDCM/src/itkGDCMSeriesFileNames.cxx b/Modules/IO/GDCM/src/itkGDCMSeriesFileNames.cxx index 1aff70081ca..a1356007ebb 100644 --- a/Modules/IO/GDCM/src/itkGDCMSeriesFileNames.cxx +++ b/Modules/IO/GDCM/src/itkGDCMSeriesFileNames.cxx @@ -218,7 +218,12 @@ GDCMSeriesFileNames::OrderSeries(SeriesEntry & entry) // acquisitions (see issue #6468). gdcm::IPPSorter sorter; sorter.SetComputeZSpacing(false); - if (sorter.Sort(entry.Files)) + bool wasSortingAchieved = sorter.Sort(entry.Files); + + // Set a public flag so that callers know this fallback occurred, and can show a warning. + m_DidUseAmbiguousOrdering = !wasSortingAchieved; + + if (wasSortingAchieved) { entry.Files = sorter.GetFilenames(); entry.Ordered = true; @@ -230,6 +235,7 @@ GDCMSeriesFileNames::OrderSeries(SeriesEntry & entry) "orientation, see issue #6468). Set FailOnAmbiguousOrdering to false to accept the legacy " "non-standard ordering heuristics."); } + // Legacy SerieHelper heuristics (Instance Number, then lexicographic), // kept only for determinism and backward compatibility: an untrustworthy, // non-standard hack whose output should not be trusted. @@ -412,6 +418,7 @@ GDCMSeriesFileNames::PrintSelf(std::ostream & os, Indent indent) const itkPrintSelfBooleanMacro(UseSeriesDetails); itkPrintSelfBooleanMacro(FailOnAmbiguousOrdering); + itkPrintSelfBooleanMacro(DidUseAmbiguousOrdering); itkPrintSelfBooleanMacro(Recursive); itkPrintSelfBooleanMacro(LoadSequences); itkPrintSelfBooleanMacro(LoadPrivateTags);