changeset 330:7a364e44fbb4 am-2

renamed SetDefaultView in FitContent
author am@osimis.io
date Wed, 17 Oct 2018 12:45:52 +0200
parents b10dfdb96866
children 7ccf919faff0
files Applications/Samples/LayoutPetCtFusionApplication.h Applications/Samples/SimpleViewer/MainWidgetInteractor.cpp Applications/Samples/SimpleViewer/SimpleViewerApplication.cpp Applications/Samples/SimpleViewerApplicationSingleFile.h Applications/Samples/SingleFrameApplication.h Applications/Samples/SingleFrameEditorApplication.h Applications/Sdl/SdlEngine.cpp Framework/SmartLoader.cpp Framework/SmartLoader.h Framework/Toolbox/ViewportGeometry.cpp Framework/Toolbox/ViewportGeometry.h Framework/Viewport/IViewport.h Framework/Viewport/WidgetViewport.cpp Framework/Viewport/WidgetViewport.h Framework/Widgets/EmptyWidget.h Framework/Widgets/IWidget.h Framework/Widgets/LayoutWidget.cpp Framework/Widgets/LayoutWidget.h Framework/Widgets/WidgetBase.h Framework/Widgets/WorldSceneWidget.cpp Framework/Widgets/WorldSceneWidget.h Framework/dev.h Resources/CMake/OrthancStoneConfiguration.cmake
diffstat 23 files changed, 65 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/LayoutPetCtFusionApplication.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Applications/Samples/LayoutPetCtFusionApplication.h	Wed Oct 17 12:45:52 2018 +0200
@@ -89,7 +89,7 @@
         {
           if (key == 's')
           {
-            that_.SetDefaultView();
+            that_.FitContent();
           }
         }
       };
@@ -109,11 +109,11 @@
       LayeredSceneWidget*  fusionSagittal_;
 
 
-      void SetDefaultView()
+      void FitContent()
       {
-        petAxial_->SetDefaultView();
-        petCoronal_->SetDefaultView();
-        petSagittal_->SetDefaultView();
+        petAxial_->FitContent();
+        petCoronal_->FitContent();
+        petSagittal_->FitContent();
       }
 
 
@@ -361,7 +361,7 @@
       virtual void NotifySizeChange(const WorldSceneWidget& source,
                                     ViewportGeometry& view)
       {
-        view.SetDefaultView();
+        view.FitContent();
       }
 
       virtual void NotifyViewChange(const WorldSceneWidget& source,
--- a/Applications/Samples/SimpleViewer/MainWidgetInteractor.cpp	Wed Oct 17 12:30:32 2018 +0200
+++ b/Applications/Samples/SimpleViewer/MainWidgetInteractor.cpp	Wed Oct 17 12:45:52 2018 +0200
@@ -97,7 +97,7 @@
     switch (keyChar)
     {
     case 's':
-      widget.SetDefaultView();
+      widget.FitContent();
       break;
 
     default:
--- a/Applications/Samples/SimpleViewer/SimpleViewerApplication.cpp	Wed Oct 17 12:30:32 2018 +0200
+++ b/Applications/Samples/SimpleViewer/SimpleViewerApplication.cpp	Wed Oct 17 12:45:52 2018 +0200
@@ -166,7 +166,7 @@
 
   void SimpleViewerApplication::OnWidgetGeometryChanged(const LayerWidget::GeometryChangedMessage& message)
   {
-    message.origin_.SetDefaultView();
+    message.origin_.FitContent();
   }
 
   void SimpleViewerApplication::SelectSeriesInMainViewport(const std::string& seriesId)
--- a/Applications/Samples/SimpleViewerApplicationSingleFile.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Applications/Samples/SimpleViewerApplicationSingleFile.h	Wed Oct 17 12:45:52 2018 +0200
@@ -163,7 +163,7 @@
           switch (keyChar)
           {
           case 's':
-            widget.SetDefaultView();
+            widget.FitContent();
             break;
 
           default:
@@ -375,7 +375,7 @@
 
       void OnWidgetGeometryChanged(const LayerWidget::GeometryChangedMessage& message)
       {
-        message.origin_.SetDefaultView();
+        message.origin_.FitContent();
       }
 
       void SelectSeriesInMainViewport(const std::string& seriesId)
--- a/Applications/Samples/SingleFrameApplication.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Applications/Samples/SingleFrameApplication.h	Wed Oct 17 12:45:52 2018 +0200
@@ -108,7 +108,7 @@
           switch (keyChar)
           {
             case 's':
-              widget.SetDefaultView();
+              widget.FitContent();
               break;
 
             default:
@@ -181,7 +181,7 @@
           SetSlice(source_->GetSliceCount() / 2);
         }
 
-        mainWidget_->SetDefaultView();
+        mainWidget_->FitContent();
       }
       
       std::unique_ptr<Interactor>           mainWidgetInteractor_;
--- a/Applications/Samples/SingleFrameEditorApplication.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Applications/Samples/SingleFrameEditorApplication.h	Wed Oct 17 12:45:52 2018 +0200
@@ -119,7 +119,7 @@
           switch (keyChar)
           {
           case 's':
-            widget.SetDefaultView();
+            widget.FitContent();
             break;
           case 'p':
             application_.currentTool_ = Tools_Pan;
@@ -154,7 +154,7 @@
       void OnGeometryChanged(const LayerWidget::GeometryChangedMessage& message)
       {
         mainWidget_->SetSlice(source_->GetSlice(slice_).GetGeometry());
-        mainWidget_->SetDefaultView();
+        mainWidget_->FitContent();
       }
       
       std::unique_ptr<Interactor>           mainWidgetInteractor_;
--- a/Applications/Sdl/SdlEngine.cpp	Wed Oct 17 12:30:32 2018 +0200
+++ b/Applications/Sdl/SdlEngine.cpp	Wed Oct 17 12:45:52 2018 +0200
@@ -120,7 +120,7 @@
     {
       NativeStoneApplicationContext::GlobalMutexLocker locker(context_);
       SetSize(window_.GetWidth(), window_.GetHeight());
-      context_.GetCentralViewport().SetDefaultView();
+      context_.GetCentralViewport().FitContent();
     }
     
     bool stop = false;
--- a/Framework/SmartLoader.cpp	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/SmartLoader.cpp	Wed Oct 17 12:45:52 2018 +0200
@@ -26,6 +26,7 @@
 #include "Framework/Widgets/LayerWidget.h"
 #include "Framework/StoneException.h"
 #include "Framework/Layers/FrameRenderer.h"
+#include "Core/Logging.h"
 
 namespace OrthancStone
 {
@@ -50,6 +51,7 @@
     CachedSlice(MessageBroker& broker)
       : LayerSourceBase(broker)
     {}
+    virtual ~CachedSlice() {}
 
     virtual bool GetExtent(std::vector<Vector>& points,
                            const CoordinateSystem3D& viewportSlice)
@@ -63,12 +65,21 @@
     {
       // TODO: viewportSlice is not used !!!!
 
-      // it has already been loaded -> trigger the "layer ready" message immediately
-      bool isFull = (effectiveQuality_ == SliceImageQuality_FullPng || effectiveQuality_ == SliceImageQuality_FullPam);
-      std::auto_ptr<Orthanc::ImageAccessor> accessor(new Orthanc::ImageAccessor());
-      image_->GetReadOnlyAccessor(*accessor);
-      LayerSourceBase::NotifyLayerReady(FrameRenderer::CreateRenderer(accessor.release(), *slice_, isFull),
-                                        slice_->GetGeometry(), false);
+      // it has already been loaded -> trigger the "layer ready" message immediately otherwise, do nothing now.  The LayerReady will be triggered
+      // once the LayerSource is ready
+      if (status_ == CachedSliceStatus_ImageLoaded)
+      {
+        LOG(WARNING) << "ScheduleLayerCreation for CachedSlice (image is loaded): " << slice_->GetOrthancInstanceId();
+        bool isFull = (effectiveQuality_ == SliceImageQuality_FullPng || effectiveQuality_ == SliceImageQuality_FullPam);
+        std::auto_ptr<Orthanc::ImageAccessor> accessor(new Orthanc::ImageAccessor());
+        image_->GetReadOnlyAccessor(*accessor);
+        LayerSourceBase::NotifyLayerReady(FrameRenderer::CreateRenderer(accessor.release(), *slice_, isFull),
+                                          slice_->GetGeometry(), false);
+      }
+      else
+      {
+        LOG(WARNING) << "ScheduleLayerCreation for CachedSlice (image is not loaded yet): " << slice_->GetOrthancInstanceId();
+      }
     }
 
     CachedSlice* Clone() const
@@ -105,10 +116,12 @@
 
     std::auto_ptr<ILayerSource> layerSource;
     std::string sliceKeyId = instanceId + ":" + std::to_string(frame);
+    SmartLoader::CachedSlice* cachedSlice = NULL;
 
     if (cachedSlices_.find(sliceKeyId) != cachedSlices_.end()) // && cachedSlices_[sliceKeyId]->status_ == CachedSliceStatus_Loaded)
     {
       layerSource.reset(cachedSlices_[sliceKeyId]->Clone());
+      cachedSlice = dynamic_cast<SmartLoader::CachedSlice*>(layerSource.get());
     }
     else
     {
@@ -134,7 +147,6 @@
       throw StoneException(ErrorCode_CanOnlyAddOneLayerAtATime);
     }
 
-    SmartLoader::CachedSlice* cachedSlice = dynamic_cast<SmartLoader::CachedSlice*>(layerSource.get());
     if (cachedSlice != NULL)
     {
       cachedSlice->NotifyGeometryReady();
@@ -144,14 +156,20 @@
 
   void SmartLoader::PreloadSlice(const std::string instanceId, unsigned int frame)
   {
+    // TODO: reactivate -> need to be able to ScheduleLayerLoading in ILayerSource without calling ScheduleLayerCreation
+    return;
     // TODO: check if it is already in the cache
 
+
+
     // create the slice in the cache with "empty" data
     boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_));
     cachedSlice->slice_.reset(new Slice(instanceId, frame));
     cachedSlice->status_ = CachedSliceStatus_ScheduledToLoad;
     std::string sliceKeyId = instanceId + ":" + std::to_string(frame);
 
+    LOG(WARNING) << "Will preload: " << sliceKeyId;
+
     cachedSlices_[sliceKeyId] = boost::shared_ptr<CachedSlice>(cachedSlice);
 
     std::auto_ptr<ILayerSource> layerSource(new OrthancFrameLayerSource(IObserver::broker_, orthancApiClient_));
@@ -186,6 +204,8 @@
     const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount()
     std::string sliceKeyId = slice.GetOrthancInstanceId() + ":" + std::to_string(slice.GetFrame());
 
+    LOG(WARNING) << "Geometry ready: " << sliceKeyId;
+
     boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_));
     cachedSlice->slice_.reset(slice.Clone());
     cachedSlice->effectiveQuality_ = source.GetImageQuality();
@@ -205,6 +225,8 @@
     const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount() ?
     std::string sliceKeyId = slice.GetOrthancInstanceId() + ":" + std::to_string(slice.GetFrame());
 
+    LOG(WARNING) << "Image ready: " << sliceKeyId;
+
     boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_));
     cachedSlice->image_ = message.image_;
     cachedSlice->effectiveQuality_ = message.imageQuality_;
@@ -223,6 +245,8 @@
     const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount() ?
     std::string sliceKeyId = slice.GetOrthancInstanceId() + ":" + std::to_string(slice.GetFrame());
 
+    LOG(WARNING) << "Layer ready: " << sliceKeyId;
+
     // remove the slice from the preloading slices now that it has been fully loaded and it is referenced in the cache
     if (preloadingInstances_.find(sliceKeyId) != preloadingInstances_.end())
     {
--- a/Framework/SmartLoader.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/SmartLoader.h	Wed Oct 17 12:45:52 2018 +0200
@@ -32,7 +32,7 @@
 
   class SmartLoader : public IObservable, public IObserver
   {
-    struct CachedSlice;
+    class CachedSlice;
 
   protected:
     typedef std::map<std::string, boost::shared_ptr<SmartLoader::CachedSlice>> CachedSlices;
--- a/Framework/Toolbox/ViewportGeometry.cpp	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Toolbox/ViewportGeometry.cpp	Wed Oct 17 12:45:52 2018 +0200
@@ -121,7 +121,7 @@
   }
 
 
-  void ViewportGeometry::SetDefaultView()
+  void ViewportGeometry::FitContent()
   {
     if (width_ > 0 &&
         height_ > 0 &&
--- a/Framework/Toolbox/ViewportGeometry.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Toolbox/ViewportGeometry.h	Wed Oct 17 12:45:52 2018 +0200
@@ -83,7 +83,7 @@
       return zoom_;
     }
 
-    void SetDefaultView();
+    void FitContent();
 
     void ApplyTransform(CairoContext& context) const;
 
--- a/Framework/Viewport/IViewport.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Viewport/IViewport.h	Wed Oct 17 12:45:52 2018 +0200
@@ -47,7 +47,7 @@
     {
     }
 
-    virtual void SetDefaultView() = 0;
+    virtual void FitContent() = 0;
 
     virtual void Register(IObserver& observer) = 0;
 
--- a/Framework/Viewport/WidgetViewport.cpp	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Viewport/WidgetViewport.cpp	Wed Oct 17 12:45:52 2018 +0200
@@ -36,11 +36,11 @@
   }
 
 
-  void WidgetViewport::SetDefaultView()
+  void WidgetViewport::FitContent()
   {
     if (centralWidget_.get() != NULL)
     {
-      centralWidget_->SetDefaultView();
+      centralWidget_->FitContent();
     }
   }
 
--- a/Framework/Viewport/WidgetViewport.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Viewport/WidgetViewport.h	Wed Oct 17 12:45:52 2018 +0200
@@ -45,7 +45,7 @@
   public:
     WidgetViewport();
 
-    virtual void SetDefaultView();
+    virtual void FitContent();
 
     virtual void SetStatusBar(IStatusBar& statusBar);
 
--- a/Framework/Widgets/EmptyWidget.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Widgets/EmptyWidget.h	Wed Oct 17 12:45:52 2018 +0200
@@ -46,7 +46,7 @@
     {
     }
 
-    virtual void SetDefaultView()
+    virtual void FitContent()
     {
     }
 
--- a/Framework/Widgets/IWidget.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Widgets/IWidget.h	Wed Oct 17 12:45:52 2018 +0200
@@ -35,7 +35,7 @@
     {
     }
 
-    virtual void SetDefaultView() = 0;
+    virtual void FitContent() = 0;
 
     virtual void SetParent(IWidget& parent) = 0;
     
--- a/Framework/Widgets/LayoutWidget.cpp	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Widgets/LayoutWidget.cpp	Wed Oct 17 12:45:52 2018 +0200
@@ -291,11 +291,11 @@
   }
 
 
-  void LayoutWidget::SetDefaultView()
+  void LayoutWidget::FitContent()
   {
     for (size_t i = 0; i < children_.size(); i++)
     {
-      children_[i]->GetWidget().SetDefaultView();
+      children_[i]->GetWidget().FitContent();
     }
   }
   
--- a/Framework/Widgets/LayoutWidget.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Widgets/LayoutWidget.h	Wed Oct 17 12:45:52 2018 +0200
@@ -53,7 +53,7 @@
 
     virtual ~LayoutWidget();
 
-    virtual void SetDefaultView();
+    virtual void FitContent();
 
     virtual void NotifyContentChanged(const IWidget& widget);
 
--- a/Framework/Widgets/WidgetBase.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Widgets/WidgetBase.h	Wed Oct 17 12:45:52 2018 +0200
@@ -55,7 +55,7 @@
   public:
     WidgetBase(const std::string& name);
 
-    virtual void SetDefaultView()
+    virtual void FitContent()
     {
     }
   
--- a/Framework/Widgets/WorldSceneWidget.cpp	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Widgets/WorldSceneWidget.cpp	Wed Oct 17 12:45:52 2018 +0200
@@ -200,10 +200,10 @@
   }
 
 
-  void WorldSceneWidget::SetDefaultView()
+  void WorldSceneWidget::FitContent()
   {
     SetSceneExtent(view_);
-    view_.SetDefaultView();
+    view_.FitContent();
 
     NotifyContentChanged();
   }
--- a/Framework/Widgets/WorldSceneWidget.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/Widgets/WorldSceneWidget.h	Wed Oct 17 12:45:52 2018 +0200
@@ -106,7 +106,7 @@
 
     void SetInteractor(IWorldSceneInteractor& interactor);
 
-    virtual void SetDefaultView();
+    virtual void FitContent();
 
     void SetView(const ViewportGeometry& view);
 
--- a/Framework/dev.h	Wed Oct 17 12:30:32 2018 +0200
+++ b/Framework/dev.h	Wed Oct 17 12:45:52 2018 +0200
@@ -684,7 +684,7 @@
         slices_.reset(new VolumeImageGeometry(image, projection_));
         SetSlice(slices_->GetSliceCount() / 2);
 
-        widget_.SetDefaultView();
+        widget_.FitContent();
       }
     }
 
@@ -756,7 +756,7 @@
       switch (keyChar)
       {
       case 's':
-        widget.SetDefaultView();
+        widget.FitContent();
         break;
 
       default:
--- a/Resources/CMake/OrthancStoneConfiguration.cmake	Wed Oct 17 12:30:32 2018 +0200
+++ b/Resources/CMake/OrthancStoneConfiguration.cmake	Wed Oct 17 12:45:52 2018 +0200
@@ -264,6 +264,7 @@
   ${ORTHANC_STONE_ROOT}/Framework/Viewport/CairoContext.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Viewport/CairoFont.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Viewport/CairoSurface.cpp
+  ${ORTHANC_STONE_ROOT}/Framework/Viewport/IViewport.h
   ${ORTHANC_STONE_ROOT}/Framework/Viewport/IStatusBar.h
   ${ORTHANC_STONE_ROOT}/Framework/Viewport/WidgetViewport.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/ImageBuffer3D.cpp