comparison Framework/Toolbox/SlicesSorter.cpp @ 1156:34ee7204fde3 broker

removing IGeometryProvider
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 16 Nov 2019 14:37:33 +0100
parents 24fecc02bfb1
children 0ca50d275b9a
comparison
equal deleted inserted replaced
1155:e265ed3f7843 1156:34ee7204fde3
287 287
288 return found; 288 return found;
289 } 289 }
290 290
291 291
292 double SlicesSorter::ComputeSpacingBetweenSlices() const 292 bool SlicesSorter::ComputeSpacingBetweenSlices(double& spacing /* out */) const
293 { 293 {
294 if (GetSlicesCount() <= 1) 294 if (GetSlicesCount() <= 1)
295 { 295 {
296 // This is a volume that is empty or that contains one single 296 // This is a volume that is empty or that contains one single
297 // slice: Choose a dummy z-dimension for voxels 297 // slice: Choose a dummy z-dimension for voxels
298 return 1.0; 298 spacing = 1.0;
299 return true;
299 } 300 }
300 301
301 const OrthancStone::CoordinateSystem3D& reference = GetSliceGeometry(0); 302 const OrthancStone::CoordinateSystem3D& reference = GetSliceGeometry(0);
302 303
303 double referencePosition = reference.ProjectAlongNormal(reference.GetOrigin()); 304 double referencePosition = reference.ProjectAlongNormal(reference.GetOrigin());
304 305
305 double p = reference.ProjectAlongNormal(GetSliceGeometry(1).GetOrigin()); 306 double p = reference.ProjectAlongNormal(GetSliceGeometry(1).GetOrigin());
306 double spacingZ = p - referencePosition; 307 spacing = p - referencePosition;
307 308
308 if (spacingZ <= 0) 309 if (spacing <= 0)
309 { 310 {
310 LOG(ERROR) << "SlicesSorter::ComputeSpacingBetweenSlices(): (spacingZ <= 0)"; 311 LOG(ERROR) << "SlicesSorter::ComputeSpacingBetweenSlices(): (spacing <= 0)";
311 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, 312 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
312 "Please call the Sort() method before"); 313 "Please call the Sort() method before");
313 } 314 }
314 315
315 for (size_t i = 1; i < GetSlicesCount(); i++) 316 for (size_t i = 1; i < GetSlicesCount(); i++)
316 { 317 {
317 OrthancStone::Vector p = reference.GetOrigin() + spacingZ * static_cast<double>(i) * reference.GetNormal(); 318 OrthancStone::Vector p = reference.GetOrigin() + spacing * static_cast<double>(i) * reference.GetNormal();
318 double d = boost::numeric::ublas::norm_2(p - GetSliceGeometry(i).GetOrigin()); 319 double d = boost::numeric::ublas::norm_2(p - GetSliceGeometry(i).GetOrigin());
319 320
320 if (!OrthancStone::LinearAlgebra::IsNear(d, 0, 0.001 /* tolerance expressed in mm */)) 321 if (!OrthancStone::LinearAlgebra::IsNear(d, 0, 0.001 /* tolerance expressed in mm */))
321 { 322 {
322 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadGeometry, 323 return false;
323 "The origins of the slices of a volume image are not regularly spaced"); 324 }
324 } 325 }
325 } 326
326 327 return true;
327 return spacingZ;
328 } 328 }
329 329
330 330
331 bool SlicesSorter::AreAllSlicesDistinct() const 331 bool SlicesSorter::AreAllSlicesDistinct() const
332 { 332 {