comparison OrthancStone/Sources/Toolbox/SortedFrames.cpp @ 1648:4a43106bc122

cross-hair starts to work
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 12 Nov 2020 19:27:08 +0100
parents 882e2253a90e
children d77618883551
comparison
equal deleted inserted replaced
1647:adff3cd78775 1648:4a43106bc122
40 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 40 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
41 } 41 }
42 } 42 }
43 43
44 44
45 double SortedFrames::Frame::ComputeDistance(const Vector& p) const
46 {
47 const CoordinateSystem3D& plane = instance_->GetFrameGeometry(frameNumber_);
48 return plane.ComputeDistance(p);
49 }
50
51
45 const DicomInstanceParameters& SortedFrames::GetInstance(size_t instanceIndex) const 52 const DicomInstanceParameters& SortedFrames::GetInstance(size_t instanceIndex) const
46 { 53 {
47 if (instanceIndex >= instances_.size()) 54 if (instanceIndex >= instances_.size())
48 { 55 {
49 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 56 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
397 } 404 }
398 405
399 sorted_ = true; 406 sorted_ = true;
400 } 407 }
401 } 408 }
409
410
411 bool SortedFrames::FindClosestFrame(size_t& frameIndex,
412 const Vector& point,
413 double maximumDistance) const
414 {
415 if (sorted_)
416 {
417 if (frames_.empty())
418 {
419 return false;
420 }
421 else
422 {
423 frameIndex = 0;
424 double closestDistance = frames_[0].ComputeDistance(point);
425
426 for (size_t i = 1; i < frames_.size(); i++)
427 {
428 double d = frames_[i].ComputeDistance(point);
429 printf("%f ", d);
430 if (d < closestDistance)
431 {
432 frameIndex = i;
433 closestDistance = d;
434 }
435 }
436
437 printf("\n>> %f\n", closestDistance);
438 return (closestDistance <= maximumDistance);
439 }
440 }
441 else
442 {
443 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
444 "Sort() has not been called");
445 }
446 }
402 } 447 }