diff 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
line wrap: on
line diff
--- a/OrthancStone/Sources/Toolbox/SortedFrames.cpp	Thu Nov 12 16:57:15 2020 +0100
+++ b/OrthancStone/Sources/Toolbox/SortedFrames.cpp	Thu Nov 12 19:27:08 2020 +0100
@@ -42,6 +42,13 @@
   }
 
 
+  double SortedFrames::Frame::ComputeDistance(const Vector& p) const
+  {
+    const CoordinateSystem3D& plane = instance_->GetFrameGeometry(frameNumber_);
+    return plane.ComputeDistance(p);
+  }
+
+
   const DicomInstanceParameters& SortedFrames::GetInstance(size_t instanceIndex) const
   {
     if (instanceIndex >= instances_.size())
@@ -399,4 +406,42 @@
       sorted_ = true;
     }
   }
+
+
+  bool SortedFrames::FindClosestFrame(size_t& frameIndex,
+                                      const Vector& point,
+                                      double maximumDistance) const
+  {
+    if (sorted_)
+    {
+      if (frames_.empty())
+      {
+        return false;
+      }
+      else
+      {
+        frameIndex = 0;
+        double closestDistance = frames_[0].ComputeDistance(point);
+
+        for (size_t i = 1; i < frames_.size(); i++)
+        {
+          double d = frames_[i].ComputeDistance(point);
+          printf("%f ", d);
+          if (d < closestDistance)
+          {
+            frameIndex = i;
+            closestDistance = d;
+          }
+        }
+
+        printf("\n>> %f\n", closestDistance);
+        return (closestDistance <= maximumDistance);
+      }
+    }
+    else
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
+                                      "Sort() has not been called");
+    }
+  }
 }