Mercurial > hg > orthanc-stone
changeset 2381:d27f022ac3ec refactoring
removed dependency of VolumeSceneLayerSource on IViewport
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Fri, 09 Oct 2026 16:50:12 +0200 |
| parents | 6a631b1d18ae |
| children | 362a33965e11 a77e2bb865c1 |
| files | Applications/Samples/Common/RtViewerView.cpp OrthancStone/Sources/Scene2DViewport/ViewportController.cpp OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp OrthancStone/Sources/Volumes/VolumeSceneLayerSource.h |
| diffstat | 4 files changed, 66 insertions(+), 118 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/Common/RtViewerView.cpp Fri Oct 09 16:33:43 2026 +0200 +++ b/Applications/Samples/Common/RtViewerView.cpp Fri Oct 09 16:50:12 2026 +0200 @@ -234,15 +234,15 @@ { if (ctVolumeLayerSource_.get() != NULL) { - ctVolumeLayerSource_->Update(planes_[currentPlane_]); + ctVolumeLayerSource_->Update(lock->GetController().GetScene(), planes_[currentPlane_]); } if (doseVolumeLayerSource_.get() != NULL) { - doseVolumeLayerSource_->Update(planes_[currentPlane_]); + doseVolumeLayerSource_->Update(lock->GetController().GetScene(), planes_[currentPlane_]); } if (structLayerSource_.get() != NULL) { - structLayerSource_->Update(planes_[currentPlane_]); + structLayerSource_->Update(lock->GetController().GetScene(), planes_[currentPlane_]); } } lock->Invalidate(); @@ -322,10 +322,10 @@ { std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); ViewportController& controller = lock->GetController(); - const Scene2D& scene = controller.GetScene(); + Scene2D& scene = controller.GetScene(); int depth = scene.GetMaxDepth() + 1; - ctVolumeLayerSource_.reset(new VolumeSceneLayerSource(viewport_, depth, volume)); + ctVolumeLayerSource_.reset(new VolumeSceneLayerSource(scene, depth, volume)); if (style != NULL) { @@ -340,10 +340,10 @@ { std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); ViewportController& controller = lock->GetController(); - const Scene2D& scene = controller.GetScene(); + Scene2D& scene = controller.GetScene(); int depth = scene.GetMaxDepth() + 1; - doseVolumeLayerSource_.reset(new VolumeSceneLayerSource(viewport_, depth, volume)); + doseVolumeLayerSource_.reset(new VolumeSceneLayerSource(scene, depth, volume)); if (style != NULL) { @@ -355,9 +355,9 @@ { std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); ViewportController& controller = lock->GetController(); - const Scene2D& scene = controller.GetScene(); + Scene2D& scene = controller.GetScene(); int depth = scene.GetMaxDepth() + 1; - structLayerSource_.reset(new VolumeSceneLayerSource(viewport_, depth, volume)); + structLayerSource_.reset(new VolumeSceneLayerSource(scene, depth, volume)); } }
--- a/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp Fri Oct 09 16:33:43 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp Fri Oct 09 16:50:12 2026 +0200 @@ -236,8 +236,7 @@ boost::shared_ptr<IViewport> sharedViewport(viewport_); if (sharedViewport) { - std::unique_ptr<IViewport::ILock> lock(sharedViewport->Lock()); - activeTracker_.reset(interactor.CreateTracker(lock->GetController().GetScene(), event, viewportWidth, viewportHeight)); + activeTracker_.reset(interactor.CreateTracker(GetScene(), event, viewportWidth, viewportHeight)); } else {
--- a/OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp Fri Oct 09 16:33:43 2026 +0200 +++ b/OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp Fri Oct 09 16:50:12 2026 +0200 @@ -24,12 +24,12 @@ #include "VolumeSceneLayerSource.h" #include "../Scene2D/NullLayer.h" -#include "../Viewport/IViewport.h" #include "../StoneException.h" -#include "../Scene2DViewport/ViewportController.h" +#include <Logging.h> #include <OrthancException.h> + namespace OrthancStone { static bool IsSameCuttingPlane(const CoordinateSystem3D& a, @@ -41,43 +41,15 @@ LinearAlgebra::IsCloseToZero(distance)); } - void VolumeSceneLayerSource::ClearLayer() + void VolumeSceneLayerSource::ClearLayer(Scene2D& scene) { - { - std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); - if (lock.get()) - { - ViewportController& controller = lock->GetController(); - Scene2D& scene = controller.GetScene(); - scene.DeleteLayer(layerDepth_); - } - } + scene.DeleteLayer(layerDepth_); lastPlane_.reset(NULL); } - IViewport::ILock* VolumeSceneLayerSource::GetViewportLock() - { - boost::shared_ptr<IViewport> viewport = viewport_.lock(); - if (viewport) - return viewport->Lock(); - else - return NULL; - } - - IViewport::ILock* VolumeSceneLayerSource::GetViewportLock() const - { - boost::shared_ptr<IViewport> viewport = viewport_.lock(); - if (viewport) - return viewport->Lock(); - else - return NULL; - } - - - VolumeSceneLayerSource::VolumeSceneLayerSource(boost::weak_ptr<IViewport> viewport, + VolumeSceneLayerSource::VolumeSceneLayerSource(Scene2D& scene, int layerDepth, const boost::shared_ptr<IVolumeSlicer>& slicer) : - viewport_(viewport), layerDepth_(layerDepth), slicer_(slicer), lastRevision_(0), @@ -88,22 +60,15 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); } + if (scene.HasLayer(layerDepth_)) { - std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); - ViewportController& controller = lock->GetController(); - Scene2D& scene = controller.GetScene(); - ORTHANC_ASSERT(!scene.HasLayer(layerDepth_)); + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } - // we need to book the scene layer depth by adding a dummy layer - std::unique_ptr<NullLayer> nullLayer(new NullLayer); - scene.SetLayer(layerDepth_,nullLayer.release()); - } + // we need to book the scene layer depth by adding a dummy layer + scene.SetLayer(layerDepth_, new NullLayer); } - VolumeSceneLayerSource::~VolumeSceneLayerSource() - { - ClearLayer(); - } void VolumeSceneLayerSource::RemoveConfigurator() { @@ -138,65 +103,59 @@ } - void VolumeSceneLayerSource::Update(const CoordinateSystem3D& plane) + void VolumeSceneLayerSource::Update(Scene2D& scene, + const CoordinateSystem3D& plane) { - std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); - if(lock) - { - ViewportController& controller = lock->GetController(); - Scene2D& scene = controller.GetScene(); + assert(slicer_.get() != NULL); + std::unique_ptr<IVolumeSlicer::IExtractedSlice> slice(slicer_->ExtractSlice(plane)); - assert(slicer_.get() != NULL); - std::unique_ptr<IVolumeSlicer::IExtractedSlice> slice(slicer_->ExtractSlice(plane)); - - if (slice.get() == NULL) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); - } + if (slice.get() == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } - if (!slice->IsValid()) - { - // The slicer cannot handle this cutting plane: Clear the layer - ClearLayer(); - } - else if (lastPlane_.get() != NULL && - IsSameCuttingPlane(*lastPlane_, plane) && - lastRevision_ == slice->GetRevision()) + if (!slice->IsValid()) + { + // The slicer cannot handle this cutting plane: Clear the layer + ClearLayer(scene); + } + else if (lastPlane_.get() != NULL && + IsSameCuttingPlane(*lastPlane_, plane) && + lastRevision_ == slice->GetRevision()) + { + // The content of the slice has not changed: Don't update the + // layer content, but possibly update its style + + if (configurator_.get() != NULL && + configurator_->GetRevision() != lastConfiguratorRevision_ && + scene.HasLayer(layerDepth_)) { - // The content of the slice has not changed: Don't update the - // layer content, but possibly update its style + configurator_->ApplyStyle(scene.GetLayer(layerDepth_)); + } + } + else + { + LOG(TRACE) << "VolumeSceneLayerSource::Update -- Content has changed: An update is needed"; + // Content has changed: An update is needed + lastPlane_.reset(new CoordinateSystem3D(plane)); + lastRevision_ = slice->GetRevision(); - if (configurator_.get() != NULL && - configurator_->GetRevision() != lastConfiguratorRevision_ && - scene.HasLayer(layerDepth_)) - { - configurator_->ApplyStyle(scene.GetLayer(layerDepth_)); - } + std::unique_ptr<ISceneLayer> layer(slice->CreateSceneLayer(configurator_.get(), plane)); + if (layer.get() == NULL) + { + LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() == NULL)"; + ClearLayer(scene); } else { - LOG(TRACE) << "VolumeSceneLayerSource::Update -- Content has changed: An update is needed"; - // Content has changed: An update is needed - lastPlane_.reset(new CoordinateSystem3D(plane)); - lastRevision_ = slice->GetRevision(); - - std::unique_ptr<ISceneLayer> layer(slice->CreateSceneLayer(configurator_.get(), plane)); - if (layer.get() == NULL) + LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() != NULL)"; + if (configurator_.get() != NULL) { - LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() == NULL)"; - ClearLayer(); + lastConfiguratorRevision_ = configurator_->GetRevision(); + configurator_->ApplyStyle(*layer); } - else - { - LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() != NULL)"; - if (configurator_.get() != NULL) - { - lastConfiguratorRevision_ = configurator_->GetRevision(); - configurator_->ApplyStyle(*layer); - } - scene.SetLayer(layerDepth_, layer.release()); - } + scene.SetLayer(layerDepth_, layer.release()); } } }
--- a/OrthancStone/Sources/Volumes/VolumeSceneLayerSource.h Fri Oct 09 16:33:43 2026 +0200 +++ b/OrthancStone/Sources/Volumes/VolumeSceneLayerSource.h Fri Oct 09 16:50:12 2026 +0200 @@ -24,7 +24,6 @@ #pragma once #include "../Scene2D/Scene2D.h" -#include "../Viewport/IViewport.h" #include "IVolumeSlicer.h" #include <boost/weak_ptr.hpp> @@ -42,7 +41,6 @@ class VolumeSceneLayerSource : public boost::noncopyable { private: - boost::weak_ptr<IViewport> viewport_; int layerDepth_; boost::shared_ptr<IVolumeSlicer> slicer_; std::unique_ptr<ILayerStyleConfigurator> configurator_; @@ -50,22 +48,13 @@ uint64_t lastRevision_; uint64_t lastConfiguratorRevision_; - void ClearLayer(); - - /** - This will return a scoped lock to the viewport. - If the viewport does not exist anymore, then nullptr is returned. - */ - IViewport::ILock* GetViewportLock(); - IViewport::ILock* GetViewportLock() const; + void ClearLayer(Scene2D& scene); public: - VolumeSceneLayerSource(boost::weak_ptr<IViewport> viewport, + VolumeSceneLayerSource(Scene2D& scene, int layerDepth, const boost::shared_ptr<IVolumeSlicer>& slicer); - ~VolumeSceneLayerSource(); - const IVolumeSlicer& GetSlicer() const { return *slicer_; @@ -90,6 +79,7 @@ you can lock the whole viewport data (including scene) by means of the IViewport::Lock method. */ - void Update(const CoordinateSystem3D& plane); + void Update(Scene2D& scene, + const CoordinateSystem3D& plane); }; }
