changeset 1015:24fecc02bfb1

SlicesSorter::AreAllSlicesDistinct()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Sep 2019 11:16:25 +0200
parents 86a18d201e27
children 78a516d5ead5 1e80a925323a
files Framework/Toolbox/SlicesSorter.cpp Framework/Toolbox/SlicesSorter.h
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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;
+    }
+  }
 }
--- 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;
   };
 }