diff Framework/Inputs/OpenSlidePyramid.cpp @ 279:77afef2cf64b

automated extraction of the imaged volume if using OpenSlide
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2023 18:06:34 +0200
parents 20a730889ae2
children 7020852a8fa9
line wrap: on
line diff
--- a/Framework/Inputs/OpenSlidePyramid.cpp	Wed Jul 12 17:12:10 2023 +0200
+++ b/Framework/Inputs/OpenSlidePyramid.cpp	Wed Jul 12 18:06:34 2023 +0200
@@ -26,6 +26,7 @@
 #include <Compatibility.h>  // For std::unique_ptr
 #include <Images/ImageProcessing.h>
 #include <OrthancException.h>
+#include <SerializationToolbox.h>
 #include <Logging.h>
 
 #include <memory>
@@ -50,4 +51,28 @@
     tileHeight_(tileHeight)
   {
   }
+
+
+  bool OpenSlidePyramid::LookupImagedVolumeSize(float& width,
+                                                float& height) const
+  {
+    std::string s;
+    double mppx;
+    double mppy;
+
+    if (image_.LookupProperty(s, "openslide.mpp-x") &&
+        Orthanc::SerializationToolbox::ParseDouble(mppx, s) &&
+        image_.LookupProperty(s, "openslide.mpp-y") &&
+        Orthanc::SerializationToolbox::ParseDouble(mppy, s))
+    {
+      // In the 2 lines below, remember to switch X/Y when going from physical to pixel coordinates!
+      width = mppy / 1000.0 * static_cast<double>(image_.GetLevelHeight(0));
+      height = mppx / 1000.0 * static_cast<double>(image_.GetLevelWidth(0));
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
 }