Mercurial > hg > orthanc-stone
diff Framework/Toolbox/SlicesSorter.cpp @ 667:e9339f2b5de7
refactoring of VolumeImage
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 15 May 2019 17:30:58 +0200 |
parents | 1088d4c4d78c |
children | f7c236894c1a |
line wrap: on
line diff
--- a/Framework/Toolbox/SlicesSorter.cpp Wed May 15 12:28:58 2019 +0200 +++ b/Framework/Toolbox/SlicesSorter.cpp Wed May 15 17:30:58 2019 +0200 @@ -285,4 +285,42 @@ return found; } + + + double SlicesSorter::ComputeSpacingBetweenSlices() const + { + if (GetSlicesCount() <= 1) + { + // This is a volume that is empty or that contains one single + // slice: Choose a dummy z-dimension for voxels + return 1.0; + } + + const OrthancStone::CoordinateSystem3D& reference = GetSliceGeometry(0); + + double referencePosition = reference.ProjectAlongNormal(reference.GetOrigin()); + + double p = reference.ProjectAlongNormal(GetSliceGeometry(1).GetOrigin()); + double spacingZ = p - referencePosition; + + if (spacingZ <= 0) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, + "Please call the Sort() method before"); + } + + for (size_t i = 1; i < GetSlicesCount(); i++) + { + OrthancStone::Vector p = reference.GetOrigin() + spacingZ * static_cast<double>(i) * reference.GetNormal(); + double d = boost::numeric::ublas::norm_2(p - GetSliceGeometry(i).GetOrigin()); + + if (!OrthancStone::LinearAlgebra::IsNear(d, 0, 0.001 /* tolerance expressed in mm */)) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadGeometry, + "The origins of the slices of a volume image are not regularly spaced"); + } + } + + return spacingZ; + } }