# HG changeset patch # User Sebastien Jodogne # Date 1569316585 -7200 # Node ID 24fecc02bfb15f8ea2277873140540117bbae091 # Parent 86a18d201e2741e3fef1e58db90516eee20d3049 SlicesSorter::AreAllSlicesDistinct() diff -r 86a18d201e27 -r 24fecc02bfb1 Framework/Toolbox/SlicesSorter.cpp --- a/Framework/Toolbox/SlicesSorter.cpp Mon Sep 23 15:19:04 2019 +0200 +++ b/Framework/Toolbox/SlicesSorter.cpp Tue Sep 24 11:16:25 2019 +0200 @@ -326,4 +326,32 @@ return spacingZ; } + + + bool SlicesSorter::AreAllSlicesDistinct() const + { + if (GetSlicesCount() <= 1) + { + return true; + } + else + { + const OrthancStone::CoordinateSystem3D& reference = GetSliceGeometry(0); + double previousPosition = reference.ProjectAlongNormal(GetSliceGeometry(0).GetOrigin()); + + for (size_t i = 1; i < GetSlicesCount(); i++) + { + double position = reference.ProjectAlongNormal(GetSliceGeometry(i).GetOrigin()); + + if (OrthancStone::LinearAlgebra::IsNear(position, previousPosition, 0.001 /* tolerance expressed in mm */)) + { + return false; + } + + previousPosition = position; + } + + return true; + } + } } diff -r 86a18d201e27 -r 24fecc02bfb1 Framework/Toolbox/SlicesSorter.h --- a/Framework/Toolbox/SlicesSorter.h Mon Sep 23 15:19:04 2019 +0200 +++ b/Framework/Toolbox/SlicesSorter.h Tue Sep 24 11:16:25 2019 +0200 @@ -92,5 +92,8 @@ // WARNING - The slices must have been sorted before calling this method double ComputeSpacingBetweenSlices() const; + + // WARNING - The slices must have been sorted before calling this method + bool AreAllSlicesDistinct() const; }; }