Mercurial > hg > orthanc-stone
changeset 1433:8635b333fa5b
[BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 19 May 2020 13:22:48 +0200 |
parents | 1eaf19af15bf |
children | c6bfcc105414 |
files | Framework/Volumes/VolumeSceneLayerSource.cpp Framework/Volumes/VolumeSceneLayerSource.h Samples/Common/RtViewerView.cpp |
diffstat | 3 files changed, 32 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Volumes/VolumeSceneLayerSource.cpp Fri May 15 21:14:35 2020 +0200 +++ b/Framework/Volumes/VolumeSceneLayerSource.cpp Tue May 19 13:22:48 2020 +0200 @@ -22,6 +22,7 @@ #include "VolumeSceneLayerSource.h" #include "../Scene2D/NullLayer.h" +#include "../Viewport/IViewport.h" #include "../StoneException.h" #include <Core/OrthancException.h> @@ -40,16 +41,20 @@ void VolumeSceneLayerSource::ClearLayer() { - scene_.DeleteLayer(layerDepth_); + { + std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); + ViewportController& controller = lock->GetController(); + Scene2D& scene = controller.GetScene(); + scene.DeleteLayer(layerDepth_); + } lastPlane_.reset(NULL); } - VolumeSceneLayerSource::VolumeSceneLayerSource( - Scene2D& scene, + boost::shared_ptr<OrthancStone::IViewport> viewport, int layerDepth, const boost::shared_ptr<IVolumeSlicer>& slicer) - : scene_(scene) + : viewport_(viewport) , layerDepth_(layerDepth) , slicer_(slicer) { @@ -57,11 +62,17 @@ { throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); } - ORTHANC_ASSERT(!scene_.HasLayer(layerDepth_)); - // 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()); + { + std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); + ViewportController& controller = lock->GetController(); + Scene2D& scene = controller.GetScene(); + ORTHANC_ASSERT(!scene.HasLayer(layerDepth_)); + + // 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()); + } } VolumeSceneLayerSource::~VolumeSceneLayerSource() @@ -104,6 +115,10 @@ void VolumeSceneLayerSource::Update(const CoordinateSystem3D& plane) { + std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); + ViewportController& controller = lock->GetController(); + Scene2D& scene = controller.GetScene(); + assert(slicer_.get() != NULL); std::unique_ptr<IVolumeSlicer::IExtractedSlice> slice(slicer_->ExtractSlice(plane)); @@ -126,9 +141,9 @@ if (configurator_.get() != NULL && configurator_->GetRevision() != lastConfiguratorRevision_ && - scene_.HasLayer(layerDepth_)) + scene.HasLayer(layerDepth_)) { - configurator_->ApplyStyle(scene_.GetLayer(layerDepth_)); + configurator_->ApplyStyle(scene.GetLayer(layerDepth_)); } } else @@ -153,7 +168,7 @@ configurator_->ApplyStyle(*layer); } - scene_.SetLayer(layerDepth_, layer.release()); + scene.SetLayer(layerDepth_, layer.release()); } } }
--- a/Framework/Volumes/VolumeSceneLayerSource.h Fri May 15 21:14:35 2020 +0200 +++ b/Framework/Volumes/VolumeSceneLayerSource.h Tue May 19 13:22:48 2020 +0200 @@ -28,6 +28,7 @@ namespace OrthancStone { + class IViewport; /** This class applies one "volume slicer" to a "3D volume", in order to create one "2D scene layer" that will be set onto the "2D @@ -38,7 +39,7 @@ class VolumeSceneLayerSource : public boost::noncopyable { private: - Scene2D& scene_; + boost::shared_ptr<OrthancStone::IViewport> viewport_; int layerDepth_; boost::shared_ptr<IVolumeSlicer> slicer_; std::unique_ptr<ILayerStyleConfigurator> configurator_; @@ -50,7 +51,7 @@ void ClearLayer(); public: - VolumeSceneLayerSource(Scene2D& scene, + VolumeSceneLayerSource(boost::shared_ptr<OrthancStone::IViewport> viewport, int layerDepth, const boost::shared_ptr<IVolumeSlicer>& slicer);
--- a/Samples/Common/RtViewerView.cpp Fri May 15 21:14:35 2020 +0200 +++ b/Samples/Common/RtViewerView.cpp Tue May 19 13:22:48 2020 +0200 @@ -312,7 +312,7 @@ Scene2D& scene = controller.GetScene(); int depth = scene.GetMaxDepth() + 1; - ctVolumeLayerSource_.reset(new OrthancStone::VolumeSceneLayerSource(scene, depth, volume)); + ctVolumeLayerSource_.reset(new OrthancStone::VolumeSceneLayerSource(viewport_, depth, volume)); if (style != NULL) { @@ -328,7 +328,7 @@ Scene2D& scene = controller.GetScene(); int depth = scene.GetMaxDepth() + 1; - doseVolumeLayerSource_.reset(new OrthancStone::VolumeSceneLayerSource(scene, depth, volume)); + doseVolumeLayerSource_.reset(new OrthancStone::VolumeSceneLayerSource(viewport_, depth, volume)); if (style != NULL) { @@ -343,6 +343,6 @@ Scene2D& scene = controller.GetScene(); int depth = scene.GetMaxDepth() + 1; - structLayerSource_.reset(new OrthancStone::VolumeSceneLayerSource(scene, depth, volume)); + structLayerSource_.reset(new OrthancStone::VolumeSceneLayerSource(viewport_, depth, volume)); } } \ No newline at end of file