comparison 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
comparison
equal deleted inserted replaced
665:419e5662d7a5 667:e9339f2b5de7
283 } 283 }
284 } 284 }
285 285
286 return found; 286 return found;
287 } 287 }
288
289
290 double SlicesSorter::ComputeSpacingBetweenSlices() const
291 {
292 if (GetSlicesCount() <= 1)
293 {
294 // This is a volume that is empty or that contains one single
295 // slice: Choose a dummy z-dimension for voxels
296 return 1.0;
297 }
298
299 const OrthancStone::CoordinateSystem3D& reference = GetSliceGeometry(0);
300
301 double referencePosition = reference.ProjectAlongNormal(reference.GetOrigin());
302
303 double p = reference.ProjectAlongNormal(GetSliceGeometry(1).GetOrigin());
304 double spacingZ = p - referencePosition;
305
306 if (spacingZ <= 0)
307 {
308 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
309 "Please call the Sort() method before");
310 }
311
312 for (size_t i = 1; i < GetSlicesCount(); i++)
313 {
314 OrthancStone::Vector p = reference.GetOrigin() + spacingZ * static_cast<double>(i) * reference.GetNormal();
315 double d = boost::numeric::ublas::norm_2(p - GetSliceGeometry(i).GetOrigin());
316
317 if (!OrthancStone::LinearAlgebra::IsNear(d, 0, 0.001 /* tolerance expressed in mm */))
318 {
319 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadGeometry,
320 "The origins of the slices of a volume image are not regularly spaced");
321 }
322 }
323
324 return spacingZ;
325 }
288 } 326 }