changeset 2170:7e8b918b0482

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Oct 2024 16:02:28 +0200
parents fe5406abd43f
children 8e3c403cc643
files Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp OrthancStone/Sources/Scene2D/GrayscaleWindowingSceneTracker.cpp OrthancStone/Sources/Scene2DViewport/ViewportController.cpp OrthancStone/Sources/Scene2DViewport/ViewportController.h
diffstat 4 files changed, 31 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Mon Oct 21 15:40:34 2024 +0200
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Mon Oct 21 16:02:28 2024 +0200
@@ -1665,8 +1665,7 @@
                                             const OrthancStone::Vector& normal) = 0;
 
     virtual void SignalWindowingUpdated(const ViewerViewport& viewport,
-                                        double windowingCenter,
-                                        double windowingWidth) = 0;
+                                        const OrthancStone::Windowing& windowing) = 0;
 
     virtual void SignalStoneAnnotationsChanged(const ViewerViewport& viewport,
                                                const std::string& sopInstanceUid,
@@ -1827,8 +1826,7 @@
   private:
     std::string   sopInstanceUid_;
     unsigned int  frameNumber_;
-    float         windowCenter_;
-    float         windowWidth_;
+    OrthancStone::Windowing  windowing_;
     bool          isMonochrome1_;
     bool          isPrefetch_;
     
@@ -1836,15 +1834,13 @@
     SetLowQualityFrame(boost::shared_ptr<ViewerViewport> viewport,
                        const std::string& sopInstanceUid,
                        unsigned int frameNumber,
-                       float windowCenter,
-                       float windowWidth,
+                       const OrthancStone::Windowing& windowing,
                        bool isMonochrome1,
                        bool isPrefetch) :
       ICommand(viewport),
       sopInstanceUid_(sopInstanceUid),
       frameNumber_(frameNumber),
-      windowCenter_(windowCenter),
-      windowWidth_(windowWidth),
+      windowing_(windowing),
       isMonochrome1_(isMonochrome1),
       isPrefetch_(isPrefetch)
     {
@@ -1890,9 +1886,11 @@
 
           **/
 
-          const float scaling = windowWidth_ / 255.0f;
+          const float center = static_cast<float>(windowing_.GetCenter());
+          const float width = static_cast<float>(windowing_.GetWidth());
+          const float scaling = width / 255.0f;
           const float offset = (OrthancStone::LinearAlgebra::IsCloseToZero(scaling) ? 0 :
-                                (windowCenter_ - windowWidth_ / 2.0f) / scaling);
+                                (center - width / 2.0f) / scaling);
 
           Orthanc::ImageProcessing::ShiftScale(*converted, offset, scaling, false);
           break;
@@ -2081,8 +2079,7 @@
   boost::shared_ptr<FramesCache>               framesCache_;  
   std::unique_ptr<IFramesCollection>           frames_;
   std::unique_ptr<SeriesCursor>                cursor_;
-  float                                        windowingCenter_;
-  float                                        windowingWidth_;
+  OrthancStone::Windowing                      currentWindowing_;
   std::vector<OrthancStone::Windowing>         windowingPresets_;
   OrthancStone::Windowing                      fallbackWindowing_;
   unsigned int                                 cineRate_;
@@ -2236,7 +2233,7 @@
       {
         std::unique_ptr<OrthancStone::FloatTextureSceneLayer> tmp(
           new OrthancStone::FloatTextureSceneLayer(frame));
-        tmp->SetCustomWindowing(windowingCenter_, windowingWidth_);
+        tmp->SetCustomWindowing(currentWindowing_.GetCenter(), currentWindowing_.GetWidth());
         tmp->SetInverted(inverted_ ^ isMonochrome1);
         layer.reset(tmp.release());
         break;
@@ -2562,14 +2559,14 @@
       std::map<std::string, std::string> headers, arguments;
       // arguments["quality"] = "10";   // Low-level quality for test purpose
       arguments["window"] = (
-        boost::lexical_cast<std::string>(windowingCenter_) + ","  +
-        boost::lexical_cast<std::string>(windowingWidth_) + ",linear");
+        boost::lexical_cast<std::string>(currentWindowing_.GetCenter()) + ","  +
+        boost::lexical_cast<std::string>(currentWindowing_.GetWidth()) + ",linear");
 
       std::unique_ptr<OrthancStone::IOracleCommand> command(
         source_.CreateDicomWebCommand(
           uri, arguments, headers, new SetLowQualityFrame(
             GetSharedObserver(), instance.GetSopInstanceUid(), frameNumber,
-            windowingCenter_, windowingWidth_, isMonochrome1, isPrefetch)));
+            currentWindowing_, isMonochrome1, isPrefetch)));
 
       {
         std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(context_.Lock());
@@ -2589,7 +2586,7 @@
       {
         dynamic_cast<OrthancStone::FloatTextureSceneLayer&>(
           lock->GetController().GetScene().GetLayer(LAYER_TEXTURE)).
-          SetCustomWindowing(windowingCenter_, windowingWidth_);
+          SetCustomWindowing(currentWindowing_.GetCenter(), currentWindowing_.GetWidth());
       }
         
       lock->Invalidate();
@@ -2651,12 +2648,11 @@
   void Handle(const OrthancStone::ViewportController::GrayscaleWindowingChanged& message)
   {
     // This event is triggered by the windowing mouse action, from class "GrayscaleWindowingSceneTracker"
-    windowingCenter_ = message.GetWindowingCenter();
-    windowingWidth_ = message.GetWindowingWidth();
+    currentWindowing_ = message.GetWindowing();
 
     if (observer_.get() != NULL)
     {
-      observer_->SignalWindowingUpdated(*this, message.GetWindowingCenter(), message.GetWindowingWidth());
+      observer_->SignalWindowingUpdated(*this, currentWindowing_);
     }
   }
 
@@ -3165,13 +3161,12 @@
 
   void SetWindowing(const OrthancStone::Windowing& windowing)
   {
-    windowingCenter_ = windowing.GetCenter();
-    windowingWidth_ = windowing.GetWidth();
+    currentWindowing_ = windowing;
     UpdateCurrentTextureParameters();
 
     if (observer_.get() != NULL)
     {
-      observer_->SignalWindowingUpdated(*this, windowingCenter_, windowingWidth_);
+      observer_->SignalWindowingUpdated(*this, currentWindowing_);
     }
   }
 
@@ -3494,8 +3489,6 @@
 
   void FormatWindowingPresets(Json::Value& target) const
   {
-    assert(windowingPresetCenters_.size() == windowingPresetWidths_.size());
-
     target = Json::arrayValue;
 
     for (size_t i = 0; i < windowingPresets_.size(); i++)
@@ -3791,8 +3784,7 @@
   }
 
   virtual void SignalWindowingUpdated(const ViewerViewport& viewport,
-                                      double windowingCenter,
-                                      double windowingWidth) ORTHANC_OVERRIDE
+                                      const OrthancStone::Windowing& windowing) ORTHANC_OVERRIDE
   {
     EM_ASM({
         const customEvent = document.createEvent("CustomEvent");
@@ -3803,8 +3795,8 @@
         window.dispatchEvent(customEvent);
       },
       viewport.GetCanvasId().c_str(),
-      static_cast<int>(boost::math::iround<double>(windowingCenter)),
-      static_cast<int>(boost::math::iround<double>(windowingWidth)));
+      static_cast<int>(boost::math::iround<double>(windowing.GetCenter())),
+      static_cast<int>(boost::math::iround<double>(windowing.GetWidth())));
 
     UpdateReferenceLines();
   }
--- a/OrthancStone/Sources/Scene2D/GrayscaleWindowingSceneTracker.cpp	Mon Oct 21 15:40:34 2024 +0200
+++ b/OrthancStone/Sources/Scene2D/GrayscaleWindowingSceneTracker.cpp	Mon Oct 21 16:02:28 2024 +0200
@@ -89,7 +89,7 @@
       {
         if (lock_.get() != NULL)
         {
-          lock_->GetController().BroadcastGrayscaleWindowingChanged(center, width);
+          lock_->GetController().BroadcastGrayscaleWindowingChanged(Windowing(center, width));
         }
       }        
     };
--- a/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp	Mon Oct 21 15:40:34 2024 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp	Mon Oct 21 16:02:28 2024 +0200
@@ -151,10 +151,9 @@
     BroadcastMessage(SceneTransformChanged(*this));
   }
 
-  void ViewportController::BroadcastGrayscaleWindowingChanged(double windowingCenter,
-                                                              double windowingWidth)
+  void ViewportController::BroadcastGrayscaleWindowingChanged(const Windowing& windowing)
   {
-    BroadcastMessage(GrayscaleWindowingChanged(*this, windowingCenter, windowingWidth));
+    BroadcastMessage(GrayscaleWindowingChanged(*this, windowing));
   }
 
   void ViewportController::FitContent(unsigned int viewportWidth,
--- a/OrthancStone/Sources/Scene2DViewport/ViewportController.h	Mon Oct 21 15:40:34 2024 +0200
+++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.h	Mon Oct 21 16:02:28 2024 +0200
@@ -27,6 +27,7 @@
 #include "../Messages/IObservable.h"
 #include "../Scene2D/Scene2D.h"
 #include "../Scene2DViewport/IFlexiblePointerTracker.h"
+#include "../Toolbox/Windowing.h"
 #include "../Viewport/IViewportInteractor.h"
 
 #include <Compatibility.h>
@@ -94,27 +95,19 @@
       ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
       
     private:
-      double  windowingCenter_;
-      double  windowingWidth_;
+      Windowing windowing_;
       
     public:
       GrayscaleWindowingChanged(const ViewportController& origin,
-                                double windowingCenter,
-                                double windowingWidth) :
+                                const Windowing& windowing) :
         OriginMessage(origin),
-        windowingCenter_(windowingCenter),
-        windowingWidth_(windowingWidth)        
+        windowing_(windowing)
       {
       }
 
-      double GetWindowingCenter() const
+      const Windowing& GetWindowing() const
       {
-        return windowingCenter_;
-      }
-
-      double GetWindowingWidth() const
-      {
-        return windowingWidth_;
+        return windowing_;
       }
     };
 
@@ -155,8 +148,7 @@
     void SetSceneToCanvasTransform(const AffineTransform2D& transform);
 
     /** Info broadcasted to the observers */
-    void BroadcastGrayscaleWindowingChanged(double windowingCenter,
-                                            double windowingWidth);
+    void BroadcastGrayscaleWindowingChanged(const Windowing& windowing);
 
     /** Forwarded to the underlying scene, and broadcasted to the observers */
     void FitContent(unsigned int viewportWidth,