changeset 1721:d4a8e2b19a65

new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 01 Dec 2020 12:51:57 +0100
parents b8d19f53aaca
children 802cb1272f3a
files Applications/StoneWebViewer/WebApplication/app.js Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp OrthancStone/Sources/Scene2D/GrayscaleWindowingSceneTracker.cpp OrthancStone/Sources/Scene2DViewport/ViewportController.cpp OrthancStone/Sources/Scene2DViewport/ViewportController.h
diffstat 5 files changed, 67 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebApplication/app.js	Tue Dec 01 12:13:43 2020 +0100
+++ b/Applications/StoneWebViewer/WebApplication/app.js	Tue Dec 01 12:51:57 2020 +0100
@@ -286,7 +286,6 @@
       if (args.detail.canvasId == that.canvasId) {
         that.windowingCenter = args.detail.windowingCenter;
         that.windowingWidth = args.detail.windowingWidth;
-        console.log(that.windowingCenter + ' ' + that.windowingWidth);
       }
     });
   },
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Tue Dec 01 12:13:43 2020 +0100
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Tue Dec 01 12:51:57 2020 +0100
@@ -1609,26 +1609,6 @@
   }
 
 
-  void SaveCurrentWindowing()
-  {
-    // Save the current windowing (that could have been altered by
-    // GrayscaleWindowingSceneTracker), so that it can be reused
-    // by the next frames
-
-    std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport_->Lock());
-
-    OrthancStone::Scene2D& scene = lock->GetController().GetScene();
-
-    if (scene.HasLayer(LAYER_TEXTURE) &&
-        scene.GetLayer(LAYER_TEXTURE).GetType() == OrthancStone::ISceneLayer::Type_FloatTexture)
-    {
-      OrthancStone::FloatTextureSceneLayer& layer =
-        dynamic_cast<OrthancStone::FloatTextureSceneLayer&>(scene.GetLayer(LAYER_TEXTURE));
-      layer.GetWindowing(windowingCenter_, windowingWidth_);
-    }
-  }
-
-
   /**
    * NB: "frame" is only used to estimate the memory size to store 1
    * frame, in order to avoid prefetching too much data.
@@ -1692,8 +1672,6 @@
      * (cf. LSD-479).
      **/
     
-    SaveCurrentWindowing();
-    
     bool isMonochrome1 = (instance.GetImageInformation().GetPhotometricInterpretation() ==
                           Orthanc::PhotometricInterpretation_Monochrome1);
       
@@ -2030,6 +2008,19 @@
     SetWindowingPreset();
   }
 
+
+  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();
+
+    if (observer_.get() != NULL)
+    {
+      observer_->SignalWindowingUpdated(*this, message.GetWindowingCenter(), message.GetWindowingWidth());
+    }
+  }
+
   
   static EM_BOOL OnWheel(int eventType,
                          const EmscriptenWheelEvent *wheelEvent,
@@ -2126,6 +2117,11 @@
         lock->GetOracleObservable(), &ViewerViewport::Handle);
     }
 
+    {
+      std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->viewport_->Lock());
+      viewport->Register<OrthancStone::ViewportController::GrayscaleWindowingChanged>(lock->GetController(), &ViewerViewport::Handle);
+    }
+
     return viewport;    
   }
 
@@ -2445,14 +2441,12 @@
   void FlipX()
   {
     flipX_ = !flipX_;
-    SaveCurrentWindowing();
     UpdateCurrentTextureParameters();
   }
 
   void FlipY()
   {
     flipY_ = !flipY_;
-    SaveCurrentWindowing();
     UpdateCurrentTextureParameters();
   }
 
--- a/OrthancStone/Sources/Scene2D/GrayscaleWindowingSceneTracker.cpp	Tue Dec 01 12:13:43 2020 +0100
+++ b/OrthancStone/Sources/Scene2D/GrayscaleWindowingSceneTracker.cpp	Tue Dec 01 12:51:57 2020 +0100
@@ -82,6 +82,15 @@
           lock_->Invalidate();
         }
       }
+
+      void BroadcastGrayscaleWindowingChanged(double center,
+                                              double width)
+      {
+        if (lock_.get() != NULL)
+        {
+          lock_->GetController().BroadcastGrayscaleWindowingChanged(center, width);
+        }
+      }        
     };
   }
   
@@ -96,6 +105,7 @@
       if (accessor.IsValid())
       {
         accessor.GetLayer().SetCustomWindowing(center, width);
+        accessor.BroadcastGrayscaleWindowingChanged(center, width);
         accessor.Invalidate();
       }
     }      
--- a/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp	Tue Dec 01 12:13:43 2020 +0100
+++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp	Tue Dec 01 12:51:57 2020 +0100
@@ -152,6 +152,12 @@
     BroadcastMessage(SceneTransformChanged(*this));
   }
 
+  void ViewportController::BroadcastGrayscaleWindowingChanged(double windowingCenter,
+                                                              double windowingWidth)
+  {
+    BroadcastMessage(GrayscaleWindowingChanged(*this, windowingCenter, windowingWidth));
+  }
+
   void ViewportController::FitContent(unsigned int viewportWidth,
                                       unsigned int viewportHeight)
   {
--- a/OrthancStone/Sources/Scene2DViewport/ViewportController.h	Tue Dec 01 12:13:43 2020 +0100
+++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.h	Tue Dec 01 12:51:57 2020 +0100
@@ -88,6 +88,35 @@
                                         SceneTransformChanged, \
                                         ViewportController);
 
+    class GrayscaleWindowingChanged : public OriginMessage<ViewportController>
+    {
+      ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
+      
+    private:
+      double  windowingCenter_;
+      double  windowingWidth_;
+      
+    public:
+      GrayscaleWindowingChanged(const ViewportController& origin,
+                                double windowingCenter,
+                                double windowingWidth) :
+        OriginMessage(origin),
+        windowingCenter_(windowingCenter),
+        windowingWidth_(windowingWidth)        
+      {
+      }
+
+      double GetWindowingCenter() const
+      {
+        return windowingCenter_;
+      }
+
+      double GetWindowingWidth() const
+      {
+        return windowingWidth_;
+      }
+    };
+
     explicit ViewportController(boost::weak_ptr<IViewport> viewport);
 
     ~ViewportController();
@@ -121,6 +150,10 @@
     /** Forwarded to the underlying scene, and broadcasted to the observers */
     void SetSceneToCanvasTransform(const AffineTransform2D& transform);
 
+    /** Info broadcasted to the observers */
+    void BroadcastGrayscaleWindowingChanged(double windowingCenter,
+                                            double windowingWidth);
+
     /** Forwarded to the underlying scene, and broadcasted to the observers */
     void FitContent(unsigned int viewportWidth,
                     unsigned int viewportHeight);