changeset 404:ba4ace20454e

use of MessageBroker in DicomStructureSetSlicer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 11 Nov 2018 13:02:38 +0100
parents 99e31898910e
children 3942123602ba
files Framework/Layers/DicomStructureSetSlicer.cpp Framework/Layers/DicomStructureSetSlicer.h Framework/StoneEnumerations.h Framework/Viewport/IViewport.h Framework/Volumes/IVolumeLoader.h Framework/Volumes/StructureSetLoader.cpp Framework/Volumes/StructureSetLoader.h Framework/Volumes/VolumeLoaderBase.cpp Framework/Volumes/VolumeLoaderBase.h Resources/CMake/OrthancStoneConfiguration.cmake Resources/OrthancStone.doxygen
diffstat 11 files changed, 57 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Layers/DicomStructureSetSlicer.cpp	Sun Nov 11 12:13:31 2018 +0100
+++ b/Framework/Layers/DicomStructureSetSlicer.cpp	Sun Nov 11 13:02:38 2018 +0100
@@ -147,6 +147,18 @@
   };
   
 
+  DicomStructureSetSlicer::DicomStructureSetSlicer(MessageBroker& broker,
+                                                   StructureSetLoader& loader) :
+    IVolumeSlicer(broker),
+    IObserver(broker),
+    loader_(loader)
+  {
+    loader_.RegisterObserverCallback(
+      new Callable<DicomStructureSetSlicer, StructureSetLoader::ContentChangedMessage>
+      (*this, &DicomStructureSetSlicer::OnStructureSetLoaded));
+  }
+
+
   void DicomStructureSetSlicer::ScheduleLayerCreation(const CoordinateSystem3D& viewportPlane)
   {
     if (loader_.HasStructureSet())
--- a/Framework/Layers/DicomStructureSetSlicer.h	Sun Nov 11 12:13:31 2018 +0100
+++ b/Framework/Layers/DicomStructureSetSlicer.h	Sun Nov 11 13:02:38 2018 +0100
@@ -28,7 +28,7 @@
 {
   class DicomStructureSetSlicer :
     public IVolumeSlicer,
-    private IVolumeLoader::IObserver
+    public IObserver
   {
   private:
     class Renderer;
@@ -36,13 +36,14 @@
 
     StructureSetLoader& loader_;
 
+    void OnStructureSetLoaded(const IVolumeLoader::ContentChangedMessage& message)
+    {
+      EmitMessage(IVolumeSlicer::ContentChangedMessage(*this));
+    }
+
   public:
-    DicomStructureSetSlicer(MessageBroker& broker, StructureSetLoader& loader) :
-      IVolumeSlicer(broker),
-      loader_(loader)
-    {
-      loader_.Register(*this);
-    }
+    DicomStructureSetSlicer(MessageBroker& broker,
+                            StructureSetLoader& loader);
 
     virtual bool GetExtent(std::vector<Vector>& points,
                            const CoordinateSystem3D& viewportPlane)
--- a/Framework/StoneEnumerations.h	Sun Nov 11 12:13:31 2018 +0100
+++ b/Framework/StoneEnumerations.h	Sun Nov 11 13:02:38 2018 +0100
@@ -136,6 +136,10 @@
     MessageType_SliceLoader_ImageReady,
     MessageType_SliceLoader_ImageError,
 
+    MessageType_VolumeLoader_GeometryReady,
+    MessageType_VolumeLoader_GeometryError,
+    MessageType_VolumeLoader_ContentChanged,  // Content of several slices in the loader has changed
+
     MessageType_HttpRequestSuccess,
     MessageType_HttpRequestError,
 
--- a/Framework/Viewport/IViewport.h	Sun Nov 11 12:13:31 2018 +0100
+++ b/Framework/Viewport/IViewport.h	Sun Nov 11 13:02:38 2018 +0100
@@ -83,10 +83,10 @@
     virtual void DoAnimation() = 0;
 
     // Should only be called from IWidget
+    // TODO Why should this be virtual?
     virtual void NotifyContentChanged()
     {
-      ViewportChangedMessage message(*this);
-      EmitMessage(message);
+      EmitMessage(ViewportChangedMessage(*this));
     }
   };
 }
--- a/Framework/Volumes/IVolumeLoader.h	Sun Nov 11 12:13:31 2018 +0100
+++ b/Framework/Volumes/IVolumeLoader.h	Sun Nov 11 13:02:38 2018 +0100
@@ -21,33 +21,20 @@
 
 #pragma once
 
-#include <boost/noncopyable.hpp>
+#include "../Messages/IObservable.h"
 
 namespace OrthancStone
 {
-  class IVolumeLoader : public boost::noncopyable
+  class IVolumeLoader : public IObservable
   {
   public:
-    class IObserver : public boost::noncopyable
-    {
-    public:
-      virtual ~IObserver()
-      {
-      }
-      
-      virtual void NotifyGeometryReady(const IVolumeLoader& loader) = 0;
-      
-      virtual void NotifyGeometryError(const IVolumeLoader& loader) = 0;
-      
-      // Triggered if the content of several slices in the loader has
-      // changed
-      virtual void NotifyContentChange(const IVolumeLoader& loader) = 0;
-    };
-    
-    virtual ~IVolumeLoader()
+    typedef OriginMessage<MessageType_VolumeLoader_GeometryReady, IVolumeLoader> GeometryReadyMessage;
+    typedef OriginMessage<MessageType_VolumeLoader_GeometryError, IVolumeLoader> GeometryErrorMessage;
+    typedef OriginMessage<MessageType_VolumeLoader_ContentChanged, IVolumeLoader> ContentChangedMessage;
+
+    IVolumeLoader(MessageBroker& broker) :
+      IObservable(broker)
     {
     }
-
-    virtual void Register(IObserver& observer) = 0;
   };
 }
--- a/Framework/Volumes/StructureSetLoader.cpp	Sun Nov 11 12:13:31 2018 +0100
+++ b/Framework/Volumes/StructureSetLoader.cpp	Sun Nov 11 13:02:38 2018 +0100
@@ -27,9 +27,10 @@
 
 namespace OrthancStone
 {
-  
-  StructureSetLoader::StructureSetLoader(MessageBroker& broker, OrthancApiClient& orthanc) :
-    OrthancStone::IObserver(broker),
+  StructureSetLoader::StructureSetLoader(MessageBroker& broker,
+                                         OrthancApiClient& orthanc) :
+    IVolumeLoader(broker),
+    IObserver(broker),
     orthanc_(orthanc)
   {
   }
@@ -43,8 +44,9 @@
     MessagingToolbox::ConvertDataset(slice, dataset);
     structureSet_->AddReferencedSlice(slice);
 
-    VolumeLoaderBase::NotifyContentChange();
+    EmitMessage(ContentChangedMessage(*this));
   }
+  
 
   void StructureSetLoader::OnStructureSetLoaded(const OrthancApiClient::JsonResponseReadyMessage& message)
   {
@@ -61,9 +63,10 @@
                             new Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnLookupCompleted));
     }
 
-    VolumeLoaderBase::NotifyGeometryReady();
+    EmitMessage(GeometryReadyMessage(*this));
   }
 
+  
   void StructureSetLoader::OnLookupCompleted(const OrthancApiClient::JsonResponseReadyMessage& message)
   {
     const Json::Value& lookup = message.GetJson();
@@ -84,6 +87,7 @@
                           new Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnReferencedSliceLoaded));
   }
 
+  
   void StructureSetLoader::ScheduleLoadInstance(const std::string& instance)
   {
     if (structureSet_.get() != NULL)
--- a/Framework/Volumes/StructureSetLoader.h	Sun Nov 11 12:13:31 2018 +0100
+++ b/Framework/Volumes/StructureSetLoader.h	Sun Nov 11 13:02:38 2018 +0100
@@ -23,21 +23,27 @@
 
 #include "../Toolbox/DicomStructureSet.h"
 #include "../Toolbox/OrthancApiClient.h"
-#include "VolumeLoaderBase.h"
+#include "IVolumeLoader.h"
 
 namespace OrthancStone
 {
   class StructureSetLoader :
-    public VolumeLoaderBase,
-    public OrthancStone::IObserver
+    public IVolumeLoader,
+    public IObserver
   {
   private:
-
-    OrthancApiClient&                      orthanc_;
+    OrthancApiClient&                 orthanc_;
     std::auto_ptr<DicomStructureSet>  structureSet_;
 
+    void OnReferencedSliceLoaded(const OrthancApiClient::JsonResponseReadyMessage& message);
+
+    void OnStructureSetLoaded(const OrthancApiClient::JsonResponseReadyMessage& message);
+
+    void OnLookupCompleted(const OrthancApiClient::JsonResponseReadyMessage& message);
+
   public:
-    StructureSetLoader(MessageBroker& broker, OrthancApiClient& orthanc);
+    StructureSetLoader(MessageBroker& broker,
+                       OrthancApiClient& orthanc);
 
     void ScheduleLoadInstance(const std::string& instance);
 
@@ -47,12 +53,5 @@
     }
 
     DicomStructureSet& GetStructureSet();
-
-  protected:
-    void OnReferencedSliceLoaded(const OrthancApiClient::JsonResponseReadyMessage& message);
-
-    void OnStructureSetLoaded(const OrthancApiClient::JsonResponseReadyMessage& message);
-
-    void OnLookupCompleted(const OrthancApiClient::JsonResponseReadyMessage& message);
   };
 }
--- a/Framework/Volumes/VolumeLoaderBase.cpp	Sun Nov 11 12:13:31 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/**
- * Stone of Orthanc
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2018 Osimis S.A., Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Affero General Public License for more details.
- * 
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-
-#include "VolumeLoaderBase.h"
-
-namespace OrthancStone
-{
-  void VolumeLoaderBase::NotifyGeometryReady()
-  {
-    observers_.Apply(*this, &IObserver::NotifyGeometryReady);
-  }
-      
-  void VolumeLoaderBase::NotifyGeometryError()
-  {
-    observers_.Apply(*this, &IObserver::NotifyGeometryError);
-  }
-    
-  void VolumeLoaderBase::NotifyContentChange()
-  {
-    observers_.Apply(*this, &IObserver::NotifyContentChange);
-  }
-}
--- a/Framework/Volumes/VolumeLoaderBase.h	Sun Nov 11 12:13:31 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/**
- * Stone of Orthanc
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2018 Osimis S.A., Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Affero General Public License for more details.
- * 
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-
-#pragma once
-
-#include "IVolumeLoader.h"
-#include "../Toolbox/ObserversRegistry.h"
-
-namespace OrthancStone
-{
-  class VolumeLoaderBase : public IVolumeLoader
-  {
-  private:
-    typedef ObserversRegistry<IVolumeLoader, IObserver>  Observers;
-
-    Observers  observers_;
-
-  protected:
-    virtual void NotifyGeometryReady();
-      
-    virtual void NotifyGeometryError();
-    
-    virtual void NotifyContentChange();
-
-  public:
-    virtual void Register(IObserver& observer)
-    {
-      observers_.Register(observer);
-    }
-  };
-}
--- a/Resources/CMake/OrthancStoneConfiguration.cmake	Sun Nov 11 12:13:31 2018 +0100
+++ b/Resources/CMake/OrthancStoneConfiguration.cmake	Sun Nov 11 13:02:38 2018 +0100
@@ -278,7 +278,6 @@
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/ImageBuffer3D.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/SlicedVolumeBase.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/StructureSetLoader.cpp
-  ${ORTHANC_STONE_ROOT}/Framework/Volumes/VolumeLoaderBase.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/VolumeReslicer.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Widgets/CairoWidget.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Widgets/EmptyWidget.cpp
--- a/Resources/OrthancStone.doxygen	Sun Nov 11 12:13:31 2018 +0100
+++ b/Resources/OrthancStone.doxygen	Sun Nov 11 13:02:38 2018 +0100
@@ -689,7 +689,8 @@
 # Note that relative paths are relative to the directory from which doxygen is
 # run.
 
-EXCLUDE                = @ORTHANC_STONE_ROOT@/Framework/Orthanc/Resources/
+EXCLUDE                = @ORTHANC_STONE_ROOT@/Framework/Orthanc/Resources/ \
+                         @ORTHANC_STONE_ROOT@/Applications/Samples/build-wasm/
 
 # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
 # directories that are symbolic links (a Unix file system feature) are excluded