# HG changeset patch # User Sebastien Jodogne # Date 1606823517 -3600 # Node ID d4a8e2b19a65370073e87e19b5522dbd8a8c8d8f # Parent b8d19f53aaca5b96c7b65e391d14b29244f68883 new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker diff -r b8d19f53aaca -r d4a8e2b19a65 Applications/StoneWebViewer/WebApplication/app.js --- 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); } }); }, diff -r b8d19f53aaca -r d4a8e2b19a65 Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp --- 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 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(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 lock(viewport->viewport_->Lock()); + viewport->Register(lock->GetController(), &ViewerViewport::Handle); + } + return viewport; } @@ -2445,14 +2441,12 @@ void FlipX() { flipX_ = !flipX_; - SaveCurrentWindowing(); UpdateCurrentTextureParameters(); } void FlipY() { flipY_ = !flipY_; - SaveCurrentWindowing(); UpdateCurrentTextureParameters(); } diff -r b8d19f53aaca -r d4a8e2b19a65 OrthancStone/Sources/Scene2D/GrayscaleWindowingSceneTracker.cpp --- 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(); } } diff -r b8d19f53aaca -r d4a8e2b19a65 OrthancStone/Sources/Scene2DViewport/ViewportController.cpp --- 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) { diff -r b8d19f53aaca -r d4a8e2b19a65 OrthancStone/Sources/Scene2DViewport/ViewportController.h --- 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 + { + 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 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);