diff OrthancStone/Sources/Loaders/SeriesFramesLoader.cpp @ 1677:51bab5188a13

start multiple preset windowings
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 23 Nov 2020 19:24:18 +0100
parents 8563ea5d8ae4
children 5b8b88e5bfd6
line wrap: on
line diff
--- a/OrthancStone/Sources/Loaders/SeriesFramesLoader.cpp	Mon Nov 23 18:49:42 2020 +0100
+++ b/OrthancStone/Sources/Loaders/SeriesFramesLoader.cpp	Mon Nov 23 19:24:18 2020 +0100
@@ -307,6 +307,16 @@
   }
 
 
+  static void GetBounds(float& low,
+                        float& high,
+                        double center,  // in
+                        double width)   // in
+  {
+    low = static_cast<float>(center - width / 2.0);
+    high = static_cast<float>(center + width / 2.0);
+  }
+  
+  
   void SeriesFramesLoader::GetPreviewWindowing(float& center,
                                                float& width,
                                                size_t index) const
@@ -314,11 +324,39 @@
     const Orthanc::DicomMap& instance = frames_.GetInstance(index);
     const DicomInstanceParameters& parameters = frames_.GetInstanceParameters(index);
 
-    if (parameters.HasDefaultWindowing())
+    size_t s = parameters.GetPresetWindowingsCount();
+
+    if (s > 0)
     {
-      // TODO - Handle multiple presets (take the largest width)
-      center = parameters.GetDefaultWindowingCenter();
-      width = parameters.GetDefaultWindowingWidth();
+      // Use the largest windowing given all the preset windowings
+      // that are available in the DICOM tags
+      float low, high;
+      GetBounds(low, high, parameters.GetPresetWindowingCenter(0),
+                parameters.GetPresetWindowingWidth(0));
+
+      for (size_t i = 1; i < s; i++)
+      {
+        float a, b;
+        GetBounds(a, b, parameters.GetPresetWindowingCenter(i),
+                  parameters.GetPresetWindowingWidth(i));
+        low = std::min(low, a);
+        high = std::max(high, b);
+      }
+
+      assert(low <= high);
+
+      if (LinearAlgebra::IsNear(low, high))
+      {
+        // Cannot infer a suitable windowing from the available tags
+        center = 128.0f;
+        width = 256.0f;
+      }
+      else
+      {
+        center = (low + high) / 2.0f;
+        width = (high - low);
+        printf(">> %f %f\n", center, width);
+      }
     }
     else
     {