Mercurial > hg > orthanc-stone
changeset 258:e5a9b3d03478 am-2
first very basic version of SmartLoader
author | am@osimis.io |
---|---|
date | Tue, 10 Jul 2018 14:48:13 +0200 |
parents | 9afafb192180 |
children | c887eddd48f1 |
files | Applications/Samples/SimpleViewerApplication.h Framework/Layers/LayerSourceBase.cpp Framework/Messages/IObservable.h Framework/Messages/MessageBroker.cpp Framework/Messages/MessageBroker.h Platforms/Generic/WebServiceCommandBase.cpp Resources/CMake/OrthancStoneConfiguration.cmake UnitTestsSources/TestMessageBroker.cpp |
diffstat | 8 files changed, 30 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/SimpleViewerApplication.h Tue Jul 10 12:39:01 2018 +0200 +++ b/Applications/Samples/SimpleViewerApplication.h Tue Jul 10 14:48:13 2018 +0200 @@ -27,6 +27,7 @@ #include "../../Framework/Widgets/LayerWidget.h" #include "../../Framework/Widgets/LayoutWidget.h" #include "../../Framework/Messages/IObserver.h" +#include "../../Framework/SmartLoader.h" #include <Core/Logging.h> @@ -195,18 +196,17 @@ OrthancStone::WidgetViewport* wasmViewport2_; IStatusBar* statusBar_; - OrthancFrameLayerSource* source_; unsigned int slice_; + std::unique_ptr<SmartLoader> smartLoader_; public: SimpleViewerApplication(MessageBroker& broker) : + IObserver(broker), mainLayout_(NULL), currentInstanceIndex_(0), - source_(NULL), - slice_(0), wasmViewport1_(NULL), wasmViewport2_(NULL), - IObserver(broker) + slice_(0) { } @@ -275,24 +275,13 @@ thumbnailsLayout_->AddWidget(thumbnails_[1]); // sources - source_ = new OrthancFrameLayerSource(broker_, context_->GetWebService()); - source_->RegisterObserver(*this); - source_->SetImageQuality(SliceImageQuality_FullPam); - source_->LoadFrame(instances_[currentInstanceIndex_], 0); - - mainViewport_->AddLayer(source_); + smartLoader_.reset(new SmartLoader(broker_, context_->GetWebService())); + smartLoader_->SetImageQuality(SliceImageQuality_FullPam); + smartLoader_->RegisterObserver(*this); - OrthancFrameLayerSource* thumb0 = new OrthancFrameLayerSource(broker_, context_->GetWebService()); - thumb0->RegisterObserver(*this); - thumb0->SetImageQuality(SliceImageQuality_FullPam); - thumb0->LoadFrame(instances_[0], 0); - OrthancFrameLayerSource* thumb1 = new OrthancFrameLayerSource(broker_, context_->GetWebService()); - thumb1->RegisterObserver(*this); - thumb1->SetImageQuality(SliceImageQuality_FullPam); - thumb1->LoadFrame(instances_[1], 0); - - thumbnails_[0]->AddLayer(thumb0); - thumbnails_[1]->AddLayer(thumb1); + mainViewport_->AddLayer(smartLoader_->GetFrame(instances_[currentInstanceIndex_], 0)); + thumbnails_[0]->AddLayer(smartLoader_->GetFrame(instances_[0], 0)); + thumbnails_[1]->AddLayer(smartLoader_->GetFrame(instances_[1], 0)); mainLayout_->SetTransmitMouseOver(true); interactor_.reset(new Interactor(*this)); @@ -313,13 +302,8 @@ currentInstanceIndex_ = (currentInstanceIndex_ + 1) % instances_.size(); - std::auto_ptr<OrthancFrameLayerSource> layer - (new OrthancFrameLayerSource(broker_, context_->GetWebService())); - layer->SetImageQuality(SliceImageQuality_FullPam); - layer->RegisterObserver(*this); - layer->LoadFrame(instances_[currentInstanceIndex_], 0); + mainViewport_->ReplaceLayer(0, smartLoader_->GetFrame(instances_[currentInstanceIndex_], 0)); - mainViewport_->ReplaceLayer(0, layer.release()); } };
--- a/Framework/Layers/LayerSourceBase.cpp Tue Jul 10 12:39:01 2018 +0200 +++ b/Framework/Layers/LayerSourceBase.cpp Tue Jul 10 14:48:13 2018 +0200 @@ -54,22 +54,22 @@ void LayerSourceBase::NotifyGeometryReady() { - Emit(IMessage(MessageType_GeometryReady)); + EmitMessage(IMessage(MessageType_GeometryReady)); } void LayerSourceBase::NotifyGeometryError() { - Emit(IMessage(MessageType_GeometryError)); + EmitMessage(IMessage(MessageType_GeometryError)); } void LayerSourceBase::NotifyContentChange() { - Emit(IMessage(MessageType_ContentChanged)); + EmitMessage(IMessage(MessageType_ContentChanged)); } void LayerSourceBase::NotifySliceChange(const Slice& slice) { - Emit(ILayerSource::SliceChangedMessage(slice)); + EmitMessage(ILayerSource::SliceChangedMessage(slice)); } void LayerSourceBase::NotifyLayerReady(ILayerRenderer* layer, @@ -77,7 +77,7 @@ bool isError) { std::auto_ptr<ILayerRenderer> renderer(layer); - Emit(ILayerSource::LayerReadyMessage(renderer, slice, isError)); + EmitMessage(ILayerSource::LayerReadyMessage(renderer, slice, isError)); } }
--- a/Framework/Messages/IObservable.h Tue Jul 10 12:39:01 2018 +0200 +++ b/Framework/Messages/IObservable.h Tue Jul 10 14:48:13 2018 +0200 @@ -28,6 +28,7 @@ class IObservable : public boost::noncopyable { + protected: MessageBroker& broker_; std::set<IObserver*> observers_; @@ -42,9 +43,9 @@ { } - void Emit(const IMessage& message) + void EmitMessage(const IMessage& message) { - broker_.Emit(*this, observers_, message); + broker_.EmitMessage(*this, observers_, message); } void RegisterObserver(IObserver& observer)
--- a/Framework/Messages/MessageBroker.cpp Tue Jul 10 12:39:01 2018 +0200 +++ b/Framework/Messages/MessageBroker.cpp Tue Jul 10 14:48:13 2018 +0200 @@ -30,7 +30,7 @@ namespace OrthancStone { - void MessageBroker::Emit(IObservable& from, std::set<IObserver*> observers, const IMessage& message) + void MessageBroker::EmitMessage(IObservable& from, std::set<IObserver*> observers, const IMessage& message) { std::vector<IObserver*> activeObservers; std::set_intersection(observers.begin(),
--- a/Framework/Messages/MessageBroker.h Tue Jul 10 12:39:01 2018 +0200 +++ b/Framework/Messages/MessageBroker.h Tue Jul 10 14:48:13 2018 +0200 @@ -56,7 +56,7 @@ activeObservers_.erase(&observer); } - void Emit(IObservable& from, std::set<IObserver*> observers, const IMessage& message); + void EmitMessage(IObservable& from, std::set<IObserver*> observers, const IMessage& message); }; }
--- a/Platforms/Generic/WebServiceCommandBase.cpp Tue Jul 10 12:39:01 2018 +0200 +++ b/Platforms/Generic/WebServiceCommandBase.cpp Tue Jul 10 14:48:13 2018 +0200 @@ -47,12 +47,12 @@ if (success_) { IWebService::ICallback::HttpRequestSuccessMessage message(uri_, answer_.c_str(), answer_.size(), payload_.release()); - Emit(message); + EmitMessage(message); } else { IWebService::ICallback::HttpRequestErrorMessage message(uri_, payload_.release()); - Emit(message); + EmitMessage(message); } } }
--- a/Resources/CMake/OrthancStoneConfiguration.cmake Tue Jul 10 12:39:01 2018 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Tue Jul 10 14:48:13 2018 +0200 @@ -174,6 +174,7 @@ #${ORTHANC_STONE_ROOT}/Framework/Layers/SiblingSliceLocationFactory.cpp #${ORTHANC_STONE_ROOT}/Framework/Layers/SingleFrameRendererFactory.cpp ${ORTHANC_STONE_ROOT}/Framework/StoneEnumerations.cpp + ${ORTHANC_STONE_ROOT}/Framework/SmartLoader.cpp ${ORTHANC_STONE_ROOT}/Framework/Layers/CircleMeasureTracker.cpp ${ORTHANC_STONE_ROOT}/Framework/Layers/ColorFrameRenderer.cpp ${ORTHANC_STONE_ROOT}/Framework/Layers/DicomStructureSetRendererFactory.cpp
--- a/UnitTestsSources/TestMessageBroker.cpp Tue Jul 10 12:39:01 2018 +0200 +++ b/UnitTestsSources/TestMessageBroker.cpp Tue Jul 10 14:48:13 2018 +0200 @@ -58,7 +58,7 @@ OrthancStone::IMessage genericMessage(OrthancStone::MessageType_Generic); // no observers have been registered -> nothing shall happen - observable.Emit(genericMessage); + observable.EmitMessage(genericMessage); ASSERT_EQ(0, globalCounter); @@ -66,20 +66,20 @@ MyObserver observer(broker); observable.RegisterObserver(observer); - observable.Emit(genericMessage); + observable.EmitMessage(genericMessage); ASSERT_EQ(1, globalCounter); // check the observer is not called when another message is issued OrthancStone::IMessage wrongMessage(OrthancStone::MessageType_GeometryReady); // no observers have been registered - observable.Emit(wrongMessage); + observable.EmitMessage(wrongMessage); ASSERT_EQ(1, globalCounter); // unregister the observer, make sure nothing happens afterwards observable.UnregisterObserver(observer); - observable.Emit(genericMessage); + observable.EmitMessage(genericMessage); ASSERT_EQ(1, globalCounter); } @@ -97,13 +97,13 @@ MyObserver observer(broker); observable.RegisterObserver(observer); - observable.Emit(genericMessage); + observable.EmitMessage(genericMessage); ASSERT_EQ(1, globalCounter); } // at this point, the observer has been deleted, the handle shall not be called again (and it shall not crash !) - observable.Emit(genericMessage); + observable.EmitMessage(genericMessage); ASSERT_EQ(1, globalCounter); }