changeset 1204:b519c1c878f1 broker

integration mainline->broker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 29 Nov 2019 21:24:29 +0100
parents f3bb9a6dd949 (current diff) 9added0d371e (diff)
children 6009c59d8676
files Framework/Radiography/RadiographyDicomLayer.cpp Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h Framework/Radiography/RadiographyTextLayer.h
diffstat 7 files changed, 81 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyAlphaLayer.cpp	Fri Nov 29 21:22:21 2019 +0100
+++ b/Framework/Radiography/RadiographyAlphaLayer.cpp	Fri Nov 29 21:24:29 2019 +0100
@@ -79,15 +79,19 @@
 
     Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false);
 
-    t.Apply(tmp, cropped, interpolation, true /* clear */);
+    unsigned int x1, y1, x2, y2;
 
-    unsigned int x1, y1, x2, y2;
-    OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2,
-                                               t.GetHomogeneousMatrix(),
-                                               cropped.GetWidth(),
-                                               cropped.GetHeight(),
-                                               buffer.GetWidth(),
-                                               buffer.GetHeight());
+    if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2,
+                                                    t.GetHomogeneousMatrix(),
+                                                    cropped.GetWidth(),
+                                                    cropped.GetHeight(),
+                                                    buffer.GetWidth(),
+                                                    buffer.GetHeight()))
+    {
+      return;  // layer is outside the buffer
+    }
+
+    t.Apply(tmp, cropped, interpolation, true /* clear */);
 
     float value = foreground_;
 
--- a/Framework/Radiography/RadiographyDicomLayer.cpp	Fri Nov 29 21:22:21 2019 +0100
+++ b/Framework/Radiography/RadiographyDicomLayer.cpp	Fri Nov 29 21:24:29 2019 +0100
@@ -162,14 +162,18 @@
       Orthanc::ImageAccessor cropped;
       converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight);
 
+      unsigned int x1, y1, x2, y2;
+      if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2,
+                                                      t.GetHomogeneousMatrix(),
+                                                      cropped.GetWidth(),
+                                                      cropped.GetHeight(),
+                                                      buffer.GetWidth(),
+                                                      buffer.GetHeight()))
+      {
+        return;  // layer is outside the buffer
+      }
+
       t.Apply(buffer, cropped, interpolation, false);
-      unsigned int x1, y1, x2, y2;
-      OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2,
-                                                 t.GetHomogeneousMatrix(),
-                                                 cropped.GetWidth(),
-                                                 cropped.GetHeight(),
-                                                 buffer.GetWidth(),
-                                                 buffer.GetHeight());
 
       if (applyWindowing)
       {
--- a/Framework/Radiography/RadiographyMaskLayer.cpp	Fri Nov 29 21:22:21 2019 +0100
+++ b/Framework/Radiography/RadiographyMaskLayer.cpp	Fri Nov 29 21:24:29 2019 +0100
@@ -112,15 +112,19 @@
 
       Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false);
 
-      t.Apply(tmp, cropped, ImageInterpolation_Nearest, true /* clear */);
 
       unsigned int x1, y1, x2, y2;
-      OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2,
-                                                 t.GetHomogeneousMatrix(),
-                                                 cropped.GetWidth(),
-                                                 cropped.GetHeight(),
-                                                 buffer.GetWidth(),
-                                                 buffer.GetHeight());
+      if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2,
+                                                      t.GetHomogeneousMatrix(),
+                                                      cropped.GetWidth(),
+                                                      cropped.GetHeight(),
+                                                      buffer.GetWidth(),
+                                                      buffer.GetHeight()))
+      {
+        return;  // layer is outside the buffer
+      }
+
+      t.Apply(tmp, cropped, ImageInterpolation_Nearest, true /* clear */);
 
       // we have observed vertical lines at the image border (probably due to bilinear filtering of the DICOM image when it is not aligned with the buffer pixels)
       // -> draw the mask one line further on each side
--- a/Framework/Radiography/RadiographyScene.cpp	Fri Nov 29 21:22:21 2019 +0100
+++ b/Framework/Radiography/RadiographyScene.cpp	Fri Nov 29 21:24:29 2019 +0100
@@ -240,6 +240,21 @@
     }
   }
 
+  RadiographyLayer& RadiographyScene::GetLayer(size_t layerIndex)
+  {
+    Layers::const_iterator found = layers_.find(layerIndex);
+
+    if (found == layers_.end())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+    }
+    else
+    {
+      assert(found->second != NULL);
+      return *found->second;
+    }
+  }
+
   bool RadiographyScene::GetWindowing(float& center,
                                       float& width) const
   {
@@ -278,13 +293,27 @@
   }
 
 
+  RadiographyLayer& RadiographyScene::UpdateText(size_t layerIndex,
+                                                 const std::string& utf8,
+                                                 unsigned int fontSize,
+                                                 uint8_t foreground)
+  {
+    RadiographyTextLayer& textLayer = dynamic_cast<RadiographyTextLayer&>(GetLayer(layerIndex));
+    textLayer.SetText(utf8, fontSize, foreground);
+
+    BroadcastMessage(RadiographyScene::ContentChangedMessage(*this, textLayer));
+    BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, textLayer));
+    return textLayer;
+  }
+
+
   RadiographyLayer& RadiographyScene::LoadText(const std::string& utf8,
                                                unsigned int fontSize,
                                                uint8_t foreground,
                                                RadiographyLayer::Geometry* geometry)
   {
     std::auto_ptr<RadiographyTextLayer>  alpha(new RadiographyTextLayer(*this));
-    alpha->LoadText(utf8, fontSize, foreground);
+    alpha->SetText(utf8, fontSize, foreground);
     if (geometry != NULL)
     {
       alpha->SetGeometry(*geometry);
--- a/Framework/Radiography/RadiographyScene.h	Fri Nov 29 21:22:21 2019 +0100
+++ b/Framework/Radiography/RadiographyScene.h	Fri Nov 29 21:24:29 2019 +0100
@@ -180,6 +180,7 @@
     void OnDicomWebReceived(const Deprecated::IWebService::HttpRequestSuccessMessage& message);
 
     virtual void OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message);
+
   public:
     RadiographyScene();
     
@@ -202,7 +203,12 @@
                                unsigned int fontSize,
                                uint8_t foreground,
                                RadiographyLayer::Geometry* geometry);
-    
+
+    RadiographyLayer& UpdateText(size_t layerIndex,
+                                 const std::string& utf8,
+                                 unsigned int fontSize,
+                                 uint8_t foreground);
+
     RadiographyLayer& LoadTestBlock(unsigned int width,
                                     unsigned int height,
                                     RadiographyLayer::Geometry* geometry);
@@ -232,10 +238,12 @@
 
     void RemoveLayer(size_t layerIndex);
 
+    RadiographyLayer& GetLayer(size_t layerIndex);
+
     const RadiographyLayer& GetLayer(size_t layerIndex) const;
 
     template <typename TypeLayer>
-    TypeLayer* GetLayer(size_t index = 0)
+    TypeLayer* GetTypedLayer(size_t indexOfType = 0)
     {
       std::vector<size_t> layerIndexes;
       GetLayersIndexes(layerIndexes);
@@ -247,31 +255,7 @@
         TypeLayer* typedLayer = dynamic_cast<TypeLayer*>(layers_[layerIndexes[i]]);
         if (typedLayer != NULL)
         {
-          if (count == index)
-          {
-            return typedLayer;
-          }
-          count++;
-        }
-      }
-
-      return NULL;
-    }
-
-    template <typename TypeLayer>
-    const TypeLayer* GetLayer(size_t index = 0) const
-    {
-      std::vector<size_t> layerIndexes;
-      GetLayersIndexes(layerIndexes);
-
-      size_t count = 0;
-
-      for (size_t i = 0; i < layerIndexes.size(); ++i)
-      {
-        const TypeLayer* typedLayer = dynamic_cast<const TypeLayer*>(layers_.at(layerIndexes[i]));
-        if (typedLayer != NULL)
-        {
-          if (count == index)
+          if (count == indexOfType)
           {
             return typedLayer;
           }
@@ -352,6 +336,7 @@
                                   ImageInterpolation interpolation,
                                   bool invert,
                                   int64_t maxValue /* for inversion */,
-                                  bool applyWindowing);  // i.e.: when
+                                  bool applyWindowing);
+
   };
 }
--- a/Framework/Radiography/RadiographyTextLayer.cpp	Fri Nov 29 21:22:21 2019 +0100
+++ b/Framework/Radiography/RadiographyTextLayer.cpp	Fri Nov 29 21:24:29 2019 +0100
@@ -29,7 +29,7 @@
   bool RadiographyTextLayer::fontHasBeenConfigured_ = false;
   Orthanc::EmbeddedResources::FileResourceId RadiographyTextLayer::fontResourceId_;
 
-  void RadiographyTextLayer::LoadText(const std::string& utf8,
+  void RadiographyTextLayer::SetText(const std::string& utf8,
                                       unsigned int fontSize,
                                       uint8_t foreground)
   {
@@ -45,6 +45,8 @@
     SetAlpha(TextRenderer::Render(fontResourceId_,
                                   fontSize_,
                                   text_));
+
     SetForegroundValue(foreground * 256.0f);
   }
+
 }
--- a/Framework/Radiography/RadiographyTextLayer.h	Fri Nov 29 21:22:21 2019 +0100
+++ b/Framework/Radiography/RadiographyTextLayer.h	Fri Nov 29 21:24:29 2019 +0100
@@ -42,7 +42,7 @@
     {
     }
 
-    void LoadText(const std::string& utf8, unsigned int fontSize, uint8_t foreground);
+    void SetText(const std::string& utf8, unsigned int fontSize, uint8_t foreground);
 
     const std::string& GetText() const
     {