# HG changeset patch # User Sebastien Jodogne # Date 1729519348 -7200 # Node ID 7e8b918b0482e990dc5b7e6bda2cc0114fc1a609 # Parent fe5406abd43f90077b7700aa193a848213f3f39b refactoring diff -r fe5406abd43f -r 7e8b918b0482 Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp --- 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 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(windowing_.GetCenter()); + const float width = static_cast(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_; std::unique_ptr frames_; std::unique_ptr cursor_; - float windowingCenter_; - float windowingWidth_; + OrthancStone::Windowing currentWindowing_; std::vector windowingPresets_; OrthancStone::Windowing fallbackWindowing_; unsigned int cineRate_; @@ -2236,7 +2233,7 @@ { std::unique_ptr 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 headers, arguments; // arguments["quality"] = "10"; // Low-level quality for test purpose arguments["window"] = ( - boost::lexical_cast(windowingCenter_) + "," + - boost::lexical_cast(windowingWidth_) + ",linear"); + boost::lexical_cast(currentWindowing_.GetCenter()) + "," + + boost::lexical_cast(currentWindowing_.GetWidth()) + ",linear"); std::unique_ptr command( source_.CreateDicomWebCommand( uri, arguments, headers, new SetLowQualityFrame( GetSharedObserver(), instance.GetSopInstanceUid(), frameNumber, - windowingCenter_, windowingWidth_, isMonochrome1, isPrefetch))); + currentWindowing_, isMonochrome1, isPrefetch))); { std::unique_ptr lock(context_.Lock()); @@ -2589,7 +2586,7 @@ { dynamic_cast( 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(boost::math::iround(windowingCenter)), - static_cast(boost::math::iround(windowingWidth))); + static_cast(boost::math::iround(windowing.GetCenter())), + static_cast(boost::math::iround(windowing.GetWidth()))); UpdateReferenceLines(); } diff -r fe5406abd43f -r 7e8b918b0482 OrthancStone/Sources/Scene2D/GrayscaleWindowingSceneTracker.cpp --- 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)); } } }; diff -r fe5406abd43f -r 7e8b918b0482 OrthancStone/Sources/Scene2DViewport/ViewportController.cpp --- 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, diff -r fe5406abd43f -r 7e8b918b0482 OrthancStone/Sources/Scene2DViewport/ViewportController.h --- 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 @@ -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,