changeset 88:90bf4116a23c wasm

ISlicedVolume
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 May 2017 16:11:52 +0200
parents 4a541cd4fa83
children f244018a4e4b
files CMakeLists.txt Framework/Layers/MissingLayerRenderer.h Framework/Volumes/ISlicedVolume.h Framework/Volumes/SlicedVolumeBase.cpp Framework/Volumes/SlicedVolumeBase.h Resources/CMake/OrthancStone.cmake UnitTestsSources/UnitTestsMain.cpp
diffstat 7 files changed, 330 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Fri May 26 15:31:58 2017 +0200
+++ b/CMakeLists.txt	Fri May 26 16:11:52 2017 +0200
@@ -35,9 +35,9 @@
 BuildSample(OrthancStoneTestPattern 2)
 BuildSample(OrthancStoneSingleFrame 3)
 #BuildSample(OrthancStoneSingleVolume 4)
-BuildSample(OrthancStoneBasicPetCtFusion 5)
+#BuildSample(OrthancStoneBasicPetCtFusion 5)
 #BuildSample(OrthancStoneSynchronizedSeries 6)
-BuildSample(OrthancStoneLayoutPetCtFusion 7)
+#BuildSample(OrthancStoneLayoutPetCtFusion 7)
 
 
 #####################################################################
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Layers/MissingLayerRenderer.h	Fri May 26 16:11:52 2017 +0200
@@ -0,0 +1,91 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, 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 "ILayerRenderer.h"
+
+namespace OrthancStone
+{
+  class MissingLayerRenderer : public ILayerRenderer
+  {
+  private:
+    double       x1_;
+    double       y1_;
+    double       x2_;
+    double       y2_;
+    RenderStyle  style_;
+
+  public:
+    MissingLayerRenderer(double x1,
+                         double y1,
+                         double x2,
+                         double y2) : 
+      x1_(x1),
+      y1_(y1),
+      x2_(x2),
+      y2_(y2)
+    {
+      if (x1_ > x2_)
+      {
+        std::swap(x1_, x2_);
+      }
+
+      if (y1_ > y2_)
+      {
+        std::swap(y1_, y2_);
+      }
+    }
+
+    virtual bool RenderLayer(CairoContext& context,
+                             const ViewportGeometry& view,
+                             const SliceGeometry& viewportSlice)
+    {
+      if (style_.visible_)
+      {
+        view.ApplyTransform(context);
+        context.SetSourceColor(style_.drawColor_);
+
+        cairo_t *cr = context.GetObject();
+        cairo_set_line_width(cr, 1.0 / view.GetZoom());
+        cairo_rectangle(cr, x1_, y1_, x2_ - x1_, y2_ - y1_);
+
+        double handleSize = 10.0f / view.GetZoom();
+        cairo_move_to(cr, x1_ + handleSize, y1_);
+        cairo_line_to(cr, x1_, y1_ + handleSize);
+
+        cairo_stroke(cr);
+      }
+
+      return true;
+    }
+
+    virtual void SetLayerStyle(const RenderStyle& style)
+    {
+      style_ = style;
+    }
+
+    virtual bool IsFullQuality()
+    {
+      return true;
+    }
+  };
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Volumes/ISlicedVolume.h	Fri May 26 16:11:52 2017 +0200
@@ -0,0 +1,63 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, 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 "../Toolbox/Slice.h"
+
+namespace OrthancStone
+{
+  class ISlicedVolume : public boost::noncopyable
+  {
+  public:
+    class IObserver : public boost::noncopyable
+    {
+    public:
+      virtual ~IObserver()
+      {
+      }
+
+      virtual void NotifyGeometryReady(const ISlicedVolume& volume) = 0;
+      
+      virtual void NotifyGeometryError(const ISlicedVolume& volume) = 0;
+      
+      // Triggered if the content of several slices in the volume has
+      // changed
+      virtual void NotifyContentChange(const ISlicedVolume& volume) = 0;
+
+      // Triggered if the content of some individual slice in the
+      // source volume has changed
+      virtual void NotifySliceChange(const ISlicedVolume& volume,
+                                     size_t sliceIndex,
+                                     const Slice& slice) = 0;
+    };
+    
+    virtual ~ISlicedVolume()
+    {
+    }
+
+    virtual void Register(IObserver& observer) = 0;
+
+    virtual size_t GetSliceCount() const = 0;
+
+    virtual const Slice& GetSlice(size_t slice) const = 0;
+  };
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Volumes/SlicedVolumeBase.cpp	Fri May 26 16:11:52 2017 +0200
@@ -0,0 +1,99 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, 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 "SlicedVolumeBase.h"
+
+namespace OrthancStone
+{
+  namespace
+  {
+    struct GeometryReadyFunctor
+    {
+      void operator() (ISlicedVolume::IObserver& observer,
+                       const ISlicedVolume& source)
+      {
+        observer.NotifyGeometryReady(source);
+      }
+    };
+
+    struct GeometryErrorFunctor
+    {
+      void operator() (ISlicedVolume::IObserver& observer,
+                       const ISlicedVolume& source)
+      {
+        observer.NotifyGeometryError(source);
+      }
+    };
+
+    struct ContentChangeFunctor
+    {
+      void operator() (ISlicedVolume::IObserver& observer,
+                       const ISlicedVolume& source)
+      {
+        observer.NotifyContentChange(source);
+      }
+    };
+
+    struct SliceChangeFunctor
+    {
+      size_t sliceIndex_;
+      const Slice& slice_;
+
+      SliceChangeFunctor(size_t sliceIndex,
+                         const Slice& slice) :
+        sliceIndex_(sliceIndex),
+        slice_(slice)
+      {
+      }
+
+      void operator() (ISlicedVolume::IObserver& observer,
+                       const ISlicedVolume& source)
+      {
+        observer.NotifySliceChange(source, sliceIndex_, slice_);
+      }
+    };
+  }
+
+  void SlicedVolumeBase::NotifyGeometryReady()
+  {
+    GeometryReadyFunctor functor;
+    observers_.Notify(this, functor);
+  }
+      
+  void SlicedVolumeBase::NotifyGeometryError()
+  {
+    GeometryErrorFunctor functor;
+    observers_.Notify(this, functor);
+  }
+    
+  void SlicedVolumeBase::NotifyContentChange()
+  {
+    ContentChangeFunctor functor;
+    observers_.Notify(this, functor);
+  }
+
+  void SlicedVolumeBase::NotifySliceChange(size_t sliceIndex,
+                                           const Slice& slice)
+  {
+    SliceChangeFunctor functor(sliceIndex, slice);
+    observers_.Notify(this, functor);
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Volumes/SlicedVolumeBase.h	Fri May 26 16:11:52 2017 +0200
@@ -0,0 +1,52 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, 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 "ISlicedVolume.h"
+#include "../Toolbox/ObserversRegistry.h"
+
+namespace OrthancStone
+{
+  class SlicedVolumeBase : public ISlicedVolume
+  {
+  private:
+    typedef ObserversRegistry<SlicedVolumeBase, IObserver>  Observers;
+
+    Observers  observers_;
+
+  protected:
+    virtual void NotifyGeometryReady();
+      
+    virtual void NotifyGeometryError();
+    
+    virtual void NotifyContentChange();
+
+    virtual void NotifySliceChange(size_t sliceIndex,
+                                   const Slice& slice);
+
+  public:
+    virtual void Register(IObserver& observer)
+    {
+      observers_.Register(observer);
+    }
+  };
+}
--- a/Resources/CMake/OrthancStone.cmake	Fri May 26 15:31:58 2017 +0200
+++ b/Resources/CMake/OrthancStone.cmake	Fri May 26 16:11:52 2017 +0200
@@ -219,6 +219,7 @@
   ${ORTHANC_STONE_DIR}/Framework/Viewport/CairoSurface.cpp
   ${ORTHANC_STONE_DIR}/Framework/Viewport/WidgetViewport.cpp
   ${ORTHANC_STONE_DIR}/Framework/Volumes/ImageBuffer3D.cpp
+  ${ORTHANC_STONE_DIR}/Framework/Volumes/SlicedVolumeBase.cpp
   #${ORTHANC_STONE_DIR}/Framework/Volumes/VolumeImage.cpp
   #${ORTHANC_STONE_DIR}/Framework/Volumes/VolumeImagePolicyBase.cpp
   #${ORTHANC_STONE_DIR}/Framework/Volumes/VolumeImageProgressivePolicy.cpp
--- a/UnitTestsSources/UnitTestsMain.cpp	Fri May 26 15:31:58 2017 +0200
+++ b/UnitTestsSources/UnitTestsMain.cpp	Fri May 26 16:11:52 2017 +0200
@@ -30,6 +30,7 @@
 
 #include "../Framework/Toolbox/IVolumeSlicesObserver.h"
 #include "../Framework/Volumes/ImageBuffer3D.h"
+#include "../Framework/Volumes/SlicedVolumeBase.h"
 #include "../Framework/Toolbox/DownloadStack.h"
 #include "../Resources/Orthanc/Core/Images/ImageProcessing.h"
 
@@ -75,7 +76,9 @@
   };
 
 
-  class OrthancVolumeImageLoader : private OrthancSlicesLoader::ICallback
+  class OrthancVolumeImageLoader : 
+    public SlicedVolumeBase,
+    private OrthancSlicesLoader::ICallback
   { 
   private:
     OrthancSlicesLoader           loader_;
@@ -143,6 +146,7 @@
       if (loader.GetSliceCount() == 0)
       {
         LOG(ERROR) << "Empty volume image";
+        SlicedVolumeBase::NotifyGeometryError();
         return;
       }
 
@@ -150,6 +154,7 @@
       {
         if (!IsCompatible(loader.GetSlice(0), loader.GetSlice(i)))
         {
+          SlicedVolumeBase::NotifyGeometryError();
           return;
         }
       }
@@ -172,6 +177,7 @@
         if (!GeometryToolbox::IsNear(spacingZ, GetDistance(loader.GetSlice(i - 1), loader.GetSlice(i))))
         {
           LOG(ERROR) << "The distance between successive slices is not constant in a volume image";
+          SlicedVolumeBase::NotifyGeometryError();
           return;
         }
       }
@@ -190,6 +196,8 @@
 
       downloadStack_.reset(new DownloadStack(loader.GetSliceCount()));
 
+      SlicedVolumeBase::NotifyGeometryReady();
+
       for (unsigned int i = 0; i < 4; i++)  // Limit to 4 simultaneous downloads
       {
         ScheduleSliceDownload();
@@ -209,10 +217,12 @@
       std::auto_ptr<Orthanc::ImageAccessor> protection(image);
 
       {
-        ImageBuffer3D::SliceWriter writer(*image_, VolumeProjection_Axial, 0);
+        ImageBuffer3D::SliceWriter writer(*image_, VolumeProjection_Axial, sliceIndex);
         Orthanc::ImageProcessing::Copy(writer.GetAccessor(), *protection);
       }
 
+      SlicedVolumeBase::NotifySliceChange(sliceIndex, slice);
+
       ScheduleSliceDownload();
     }
 
@@ -242,6 +252,16 @@
       loader_.ScheduleLoadInstance(instanceId, frame);
     }
 
+    virtual size_t GetSliceCount() const
+    {
+      return loader_.GetSliceCount();
+    }
+
+    virtual const Slice& GetSlice(size_t index) const
+    {
+      return loader_.GetSlice(index);
+    }
+
     void SetObserver(IVolumeSlicesObserver& observer)
     {
       if (observer_ == NULL)