changeset 99:efd9ef2b67f1 wasm

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 May 2017 21:08:31 +0200
parents a33abae66344
children 166a555becbf
files Framework/Layers/MissingLayerRenderer.h Framework/Layers/OrthancFrameLayerSource.cpp Framework/Layers/OrthancFrameLayerSource.h Framework/Layers/SliceOutlineRenderer.h Framework/Toolbox/Extent.cpp Framework/Toolbox/OrthancSlicesLoader.cpp Framework/Toolbox/OrthancSlicesLoader.h Framework/Toolbox/Slice.h Framework/Widgets/LayerWidget.cpp Resources/CMake/OrthancStone.cmake
diffstat 10 files changed, 100 insertions(+), 121 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Layers/MissingLayerRenderer.h	Tue May 30 15:02:24 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/**
- * 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;
-    }
-  };
-}
--- a/Framework/Layers/OrthancFrameLayerSource.cpp	Tue May 30 15:02:24 2017 +0200
+++ b/Framework/Layers/OrthancFrameLayerSource.cpp	Tue May 30 21:08:31 2017 +0200
@@ -22,7 +22,6 @@
 #include "OrthancFrameLayerSource.h"
 
 #include "FrameRenderer.h"
-#include "../../Resources/Orthanc/Core/Images/PngReader.h"
 #include "../../Resources/Orthanc/Core/Logging.h"
 #include "../../Resources/Orthanc/Core/OrthancException.h"
 #include "../Toolbox/DicomFrameConverter.h"
@@ -51,11 +50,12 @@
   void OrthancFrameLayerSource::NotifySliceImageReady(const OrthancSlicesLoader& loader,
                                                       unsigned int sliceIndex,
                                                       const Slice& slice,
-                                                      Orthanc::ImageAccessor* image,
+                                                      std::auto_ptr<Orthanc::ImageAccessor>& image,
                                                       SliceImageQuality quality)
   {
     bool isFull = (quality == SliceImageQuality_Full);
-    LayerSourceBase::NotifyLayerReady(FrameRenderer::CreateRenderer(image, slice, isFull), slice, false);
+    LayerSourceBase::NotifyLayerReady(FrameRenderer::CreateRenderer(image.release(), slice, isFull),
+                                      slice, false);
   }
 
   void OrthancFrameLayerSource::NotifySliceImageError(const OrthancSlicesLoader& loader,
--- a/Framework/Layers/OrthancFrameLayerSource.h	Tue May 30 15:02:24 2017 +0200
+++ b/Framework/Layers/OrthancFrameLayerSource.h	Tue May 30 21:08:31 2017 +0200
@@ -41,7 +41,7 @@
     virtual void NotifySliceImageReady(const OrthancSlicesLoader& loader,
                                        unsigned int sliceIndex,
                                        const Slice& slice,
-                                       Orthanc::ImageAccessor* image,
+                                       std::auto_ptr<Orthanc::ImageAccessor>& image,
                                        SliceImageQuality quality);
 
     virtual void NotifySliceImageError(const OrthancSlicesLoader& loader,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Layers/SliceOutlineRenderer.h	Tue May 30 21:08:31 2017 +0200
@@ -0,0 +1,59 @@
+/**
+ * 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"
+#include "../Toolbox/Slice.h"
+
+namespace OrthancStone
+{
+  class SliceOutlineRenderer : public ILayerRenderer
+  {
+  private:
+    Slice        slice_;
+    RenderStyle  style_;
+
+  public:
+    SliceOutlineRenderer(const Slice& slice) : 
+      slice_(slice)
+    {
+    }
+
+    virtual bool RenderLayer(CairoContext& context,
+                             const ViewportGeometry& view);
+
+    virtual void SetLayerStyle(const RenderStyle& style)
+    {
+      style_ = style;
+    }
+
+    virtual const SliceGeometry& GetLayerSlice()
+    {
+      return slice_.GetGeometry();
+    }
+
+    virtual bool IsFullQuality()
+    {
+      return true;
+    }
+  };
+}
--- a/Framework/Toolbox/Extent.cpp	Tue May 30 15:02:24 2017 +0200
+++ b/Framework/Toolbox/Extent.cpp	Tue May 30 21:08:31 2017 +0200
@@ -76,8 +76,8 @@
 
     x1_ = std::min(x1_, other.x1_);
     y1_ = std::min(y1_, other.y1_);
-    x2_ = std::min(x2_, other.x2_);
-    y2_ = std::min(y2_, other.y2_);
+    x2_ = std::max(x2_, other.x2_);
+    y2_ = std::max(y2_, other.y2_);
 
     assert(x1_ <= x2_ &&
            y1_ <= y2_);    // This is the invariant of the structure
--- a/Framework/Toolbox/OrthancSlicesLoader.cpp	Tue May 30 15:02:24 2017 +0200
+++ b/Framework/Toolbox/OrthancSlicesLoader.cpp	Tue May 30 21:08:31 2017 +0200
@@ -197,9 +197,9 @@
 
   
   void OrthancSlicesLoader::NotifySliceImageSuccess(const Operation& operation,
-                                                    Orthanc::ImageAccessor* image) const
+                                                    std::auto_ptr<Orthanc::ImageAccessor>& image) const
   {
-    if (image == NULL)
+    if (image.get() == NULL)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
     }
@@ -313,13 +313,12 @@
                                                const void* answer,
                                                size_t size)
   {
-    std::auto_ptr<Orthanc::PngReader>  image(new Orthanc::PngReader);
+    std::auto_ptr<Orthanc::ImageAccessor>  image;
 
-    bool ok = false;
-    
     try
     {
-      image->ReadFromMemory(answer, size);
+      image.reset(new Orthanc::PngReader);
+      dynamic_cast<Orthanc::PngReader&>(*image).ReadFromMemory(answer, size);
     }
     catch (Orthanc::OrthancException&)
     {
@@ -348,7 +347,7 @@
       }
     }
 
-    NotifySliceImageSuccess(operation, image.release());
+    NotifySliceImageSuccess(operation, image);
   }
     
     
@@ -398,11 +397,12 @@
     std::string jpeg;
     Orthanc::Toolbox::DecodeBase64(jpeg, info["PixelData"].asString());
 
-    std::auto_ptr<Orthanc::JpegReader> reader(new Orthanc::JpegReader);
+    std::auto_ptr<Orthanc::ImageAccessor> reader;
 
     try
     {
-      reader->ReadFromMemory(jpeg);
+      reader.reset(new Orthanc::JpegReader);
+      dynamic_cast<Orthanc::JpegReader&>(*reader).ReadFromMemory(jpeg);
     }
     catch (Orthanc::OrthancException&)
     {
@@ -428,7 +428,7 @@
       }
       else
       {
-        NotifySliceImageSuccess(operation, reader.release());
+        NotifySliceImageSuccess(operation, reader);
         return;
       }
     }
@@ -448,7 +448,7 @@
       }
       else
       {
-        NotifySliceImageSuccess(operation, reader.release());
+        NotifySliceImageSuccess(operation, reader);
         return;
       }
     }
@@ -489,7 +489,7 @@
     
     Orthanc::ImageProcessing::ShiftScale(*image, offset, scaling);
 
-    NotifySliceImageSuccess(operation, image.release());
+    NotifySliceImageSuccess(operation, image);
   }
     
     
--- a/Framework/Toolbox/OrthancSlicesLoader.h	Tue May 30 15:02:24 2017 +0200
+++ b/Framework/Toolbox/OrthancSlicesLoader.h	Tue May 30 21:08:31 2017 +0200
@@ -46,7 +46,7 @@
       virtual void NotifySliceImageReady(const OrthancSlicesLoader& loader,
                                          unsigned int sliceIndex,
                                          const Slice& slice,
-                                         Orthanc::ImageAccessor* image,
+                                         std::auto_ptr<Orthanc::ImageAccessor>& image,
                                          SliceImageQuality quality) = 0;
 
       virtual void NotifySliceImageError(const OrthancSlicesLoader& loader,
@@ -82,7 +82,7 @@
     SlicesSorter  slices_;
 
     void NotifySliceImageSuccess(const Operation& operation,
-                                 Orthanc::ImageAccessor* image) const;
+                                 std::auto_ptr<Orthanc::ImageAccessor>& image) const;
   
     void NotifySliceImageError(const Operation& operation) const;
     
--- a/Framework/Toolbox/Slice.h	Tue May 30 15:02:24 2017 +0200
+++ b/Framework/Toolbox/Slice.h	Tue May 30 21:08:31 2017 +0200
@@ -68,6 +68,11 @@
     {      
     }
 
+    bool IsValid() const
+    {
+      return type_ != Type_Invalid;
+    } 
+
     bool ParseOrthancFrame(const OrthancPlugins::IDicomDataset& dataset,
                            const std::string& instanceId,
                            unsigned int frame);
--- a/Framework/Widgets/LayerWidget.cpp	Tue May 30 15:02:24 2017 +0200
+++ b/Framework/Widgets/LayerWidget.cpp	Tue May 30 21:08:31 2017 +0200
@@ -22,7 +22,7 @@
 #include "LayerWidget.h"
 
 #include "../../Resources/Orthanc/Core/Logging.h"
-#include "../Layers/MissingLayerRenderer.h"
+#include "../Layers/SliceOutlineRenderer.h"
 
 static const double THIN_SLICE_THICKNESS = 100.0 * std::numeric_limits<double>::epsilon();
 
@@ -241,8 +241,6 @@
 
     for (size_t i = 0; i < layers_.size(); i++)
     {
-      double ax, ay, bx, by;
-
       assert(layers_[i] != NULL);
       Extent layerExtent;
       GetLayerExtent(layerExtent, *layers_[i]);
@@ -500,7 +498,7 @@
                                      bool isError)
   {
     size_t index;
-    if (renderer.get() != NULL &&
+    if (slice.IsValid() &&
         LookupLayer(index, source) &&
         slice.ContainsPlane(slice_))  // Whether the slice comes from an older request
     {
@@ -513,7 +511,14 @@
         LOG(INFO) << "Renderer ready for layer " << index;
       }
       
-      UpdateLayer(index, renderer.release(), slice);
+      if (renderer.get() != NULL)
+      {
+        UpdateLayer(index, renderer.release(), slice);
+      }
+      else if (isError)
+      {
+        UpdateLayer(index, new SliceOutlineRenderer(slice), slice);
+      }
     }
   }
 }
--- a/Resources/CMake/OrthancStone.cmake	Tue May 30 15:02:24 2017 +0200
+++ b/Resources/CMake/OrthancStone.cmake	Tue May 30 21:08:31 2017 +0200
@@ -188,13 +188,17 @@
   ${ORTHANC_STONE_DIR}/Applications/Sdl/SdlSurface.cpp
   ${ORTHANC_STONE_DIR}/Applications/Sdl/SdlWindow.cpp
 
+  #${ORTHANC_STONE_DIR}/Framework/Layers/DicomStructureSetRendererFactory.cpp
+  #${ORTHANC_STONE_DIR}/Framework/Layers/SeriesFrameRendererFactory.cpp
+  #${ORTHANC_STONE_DIR}/Framework/Layers/SiblingSliceLocationFactory.cpp
+  #${ORTHANC_STONE_DIR}/Framework/Layers/SingleFrameRendererFactory.cpp
   #${ORTHANC_STONE_DIR}/Framework/Volumes/VolumeImage.cpp
   #${ORTHANC_STONE_DIR}/Framework/Volumes/VolumeImagePolicyBase.cpp
   #${ORTHANC_STONE_DIR}/Framework/Volumes/VolumeImageProgressivePolicy.cpp
   #${ORTHANC_STONE_DIR}/Framework/Volumes/VolumeImageSimplePolicy.cpp
+  #${ORTHANC_STONE_DIR}/Framework/Widgets/LayeredSceneWidget.cpp
   ${ORTHANC_STONE_DIR}/Framework/Layers/CircleMeasureTracker.cpp
   ${ORTHANC_STONE_DIR}/Framework/Layers/ColorFrameRenderer.cpp
-  #${ORTHANC_STONE_DIR}/Framework/Layers/DicomStructureSetRendererFactory.cpp
   ${ORTHANC_STONE_DIR}/Framework/Layers/FrameRenderer.cpp
   ${ORTHANC_STONE_DIR}/Framework/Layers/GrayscaleFrameRenderer.cpp
   ${ORTHANC_STONE_DIR}/Framework/Layers/LayerSourceBase.cpp
@@ -202,9 +206,7 @@
   ${ORTHANC_STONE_DIR}/Framework/Layers/LineMeasureTracker.cpp
   ${ORTHANC_STONE_DIR}/Framework/Layers/OrthancFrameLayerSource.cpp
   ${ORTHANC_STONE_DIR}/Framework/Layers/RenderStyle.cpp
-  #${ORTHANC_STONE_DIR}/Framework/Layers/SeriesFrameRendererFactory.cpp
-  #${ORTHANC_STONE_DIR}/Framework/Layers/SiblingSliceLocationFactory.cpp
-  #${ORTHANC_STONE_DIR}/Framework/Layers/SingleFrameRendererFactory.cpp
+  ${ORTHANC_STONE_DIR}/Framework/Layers/SliceOutlineRenderer.cpp
   ${ORTHANC_STONE_DIR}/Framework/Toolbox/DicomFrameConverter.cpp
   ${ORTHANC_STONE_DIR}/Framework/Toolbox/DicomStructureSet.cpp
   ${ORTHANC_STONE_DIR}/Framework/Toolbox/DownloadStack.cpp
@@ -228,7 +230,6 @@
   ${ORTHANC_STONE_DIR}/Framework/Widgets/CairoWidget.cpp
   ${ORTHANC_STONE_DIR}/Framework/Widgets/EmptyWidget.cpp
   ${ORTHANC_STONE_DIR}/Framework/Widgets/LayerWidget.cpp
-  #${ORTHANC_STONE_DIR}/Framework/Widgets/LayeredSceneWidget.cpp
   ${ORTHANC_STONE_DIR}/Framework/Widgets/LayoutWidget.cpp
   ${ORTHANC_STONE_DIR}/Framework/Widgets/TestCairoWidget.cpp
   ${ORTHANC_STONE_DIR}/Framework/Widgets/TestWorldSceneWidget.cpp