diff Framework/Radiography/RadiographyWidget.cpp @ 1196:a5f2a6b04a31

RadiographyScene: windowing is now only applied to the Dicom layer
author Alain Mazy <alain@mazy.be>
date Wed, 27 Nov 2019 17:51:33 +0100
parents 4663f158c748
children 922d2e61aa5d
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyWidget.cpp	Tue Nov 26 16:32:29 2019 +0100
+++ b/Framework/Radiography/RadiographyWidget.cpp	Wed Nov 27 17:51:33 2019 +0100
@@ -70,83 +70,66 @@
                                          unsigned int height,
                                          ImageInterpolation interpolation)
   {
-    float windowCenter, windowWidth;
-    scene_->GetWindowingWithDefault(windowCenter, windowWidth);
-
-    float x0 = windowCenter - windowWidth / 2.0f;
-    float x1 = windowCenter + windowWidth / 2.0f;
+    if (floatBuffer_.get() == NULL ||
+        floatBuffer_->GetWidth() != width ||
+        floatBuffer_->GetHeight() != height)
+    {
+      floatBuffer_.reset(new Orthanc::Image(
+        Orthanc::PixelFormat_Float32, width, height, false));
+    }
 
-    if (windowWidth <= 0.001f)  // Avoid division by zero at (*)
-    {
-      return false;
-    }
-    else
+    if (cairoBuffer_.get() == NULL ||
+        cairoBuffer_->GetWidth() != width ||
+        cairoBuffer_->GetHeight() != height)
     {
-      if (floatBuffer_.get() == NULL ||
-          floatBuffer_->GetWidth() != width ||
-          floatBuffer_->GetHeight() != height)
-      {
-        floatBuffer_.reset(new Orthanc::Image(
-          Orthanc::PixelFormat_Float32, width, height, false));
-      }
+      cairoBuffer_.reset(new CairoSurface(width, height, false /* no alpha */));
+    }
+
+    RenderBackground(*floatBuffer_, 0.0, 65535.0);
+
+    scene_->Render(*floatBuffer_, GetView().GetMatrix(), interpolation, true);
 
-      if (cairoBuffer_.get() == NULL ||
-          cairoBuffer_->GetWidth() != width ||
-          cairoBuffer_->GetHeight() != height)
-      {
-        cairoBuffer_.reset(new CairoSurface(width, height, false /* no alpha */));
-      }
-
-      RenderBackground(*floatBuffer_, x0, x1);
+    // Conversion from Float32 to BGRA32 (cairo). Very similar to
+    // GrayscaleFrameRenderer => TODO MERGE?
+    Orthanc::ImageAccessor target;
+    cairoBuffer_->GetWriteableAccessor(target);
 
-      scene_->Render(*floatBuffer_, GetView().GetMatrix(), interpolation);
-
-      // Conversion from Float32 to BGRA32 (cairo). Very similar to
-      // GrayscaleFrameRenderer => TODO MERGE?
-
-      Orthanc::ImageAccessor target;
-      cairoBuffer_->GetWriteableAccessor(target);
-
-      float scaling = 255.0f / (x1 - x0);
+    bool invert = IsInvertedInternal();
 
-      bool invert = IsInvertedInternal();
+    for (unsigned int y = 0; y < height; y++)
+    {
+      const float* p = reinterpret_cast<const float*>(floatBuffer_->GetConstRow(y));
+      uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
 
-      for (unsigned int y = 0; y < height; y++)
+      for (unsigned int x = 0; x < width; x++, p++, q += 4)
       {
-        const float* p = reinterpret_cast<const float*>(floatBuffer_->GetConstRow(y));
-        uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
-
-        for (unsigned int x = 0; x < width; x++, p++, q += 4)
+        uint8_t v = 0;
+        if (*p >= 65535.0)
+        {
+          v = 255;
+        }
+        else if (*p <= 0.0)
         {
-          uint8_t v = 0;
-          if (*p >= x1)
-          {
-            v = 255;
-          }
-          else if (*p <= x0)
-          {
-            v = 0;
-          }
-          else
-          {
-            // https://en.wikipedia.org/wiki/Linear_interpolation
-            v = static_cast<uint8_t>(scaling * (*p - x0));  // (*)
-          }
+          v = 0;
+        }
+        else
+        {
+          v = static_cast<uint8_t>(*p / 256.0);
+        }
 
-          if (invert)
-          {
-            v = 255 - v;
-          }
+        if (invert)
+        {
+          v = 255 - v;
+        }
 
-          q[0] = v;
-          q[1] = v;
-          q[2] = v;
-          q[3] = 255;
-        }
+        q[0] = v;
+        q[1] = v;
+        q[2] = v;
+        q[3] = 255;
       }
+    }
 
-      return true;
-    }
+    return true;
   }