diff Applications/Samples/SingleFrameEditorApplication.h @ 518:40bb5eb247a5 bgo-commands-codegen

Reverted a couple of files to AM version (wrong changes on my end)
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 12 Mar 2019 09:19:06 +0100
parents 11fa6f00e33c
children 79bb0a02d1cc
line wrap: on
line diff
--- a/Applications/Samples/SingleFrameEditorApplication.h	Tue Mar 12 08:51:35 2019 +0100
+++ b/Applications/Samples/SingleFrameEditorApplication.h	Tue Mar 12 09:19:06 2019 +0100
@@ -24,6 +24,7 @@
 #include "SampleApplicationBase.h"
 
 #include "../../Framework/Radiography/RadiographyLayerCropTracker.h"
+#include "../../Framework/Radiography/RadiographyLayerMaskTracker.h"
 #include "../../Framework/Radiography/RadiographyLayerMoveTracker.h"
 #include "../../Framework/Radiography/RadiographyLayerResizeTracker.h"
 #include "../../Framework/Radiography/RadiographyLayerRotateTracker.h"
@@ -33,6 +34,7 @@
 #include "../../Framework/Radiography/RadiographyWindowingTracker.h"
 #include "../../Framework/Radiography/RadiographySceneWriter.h"
 #include "../../Framework/Radiography/RadiographySceneReader.h"
+#include "../../Framework/Radiography/RadiographyMaskLayer.h"
 
 #include <Core/HttpClient.h>
 #include <Core/Images/FontRegistry.h>
@@ -60,6 +62,7 @@
         Tool_Rotate,
         Tool_Crop,
         Tool_Resize,
+        Tool_Mask,
         Tool_Windowing
       };
 
@@ -67,6 +70,7 @@
       StoneApplicationContext*  context_;
       UndoRedoStack             undoRedoStack_;
       Tool                      tool_;
+      RadiographyMaskLayer*     maskLayer_;
 
 
       static double GetHandleSize()
@@ -79,7 +83,8 @@
       RadiographyEditorInteractor(MessageBroker& broker) :
         IObserver(broker),
         context_(NULL),
-        tool_(Tool_Move)
+        tool_(Tool_Move),
+        maskLayer_(NULL)
       {
       }
 
@@ -88,6 +93,10 @@
         context_ = &context;
       }
 
+      void SetMaskLayer(RadiographyMaskLayer* maskLayer)
+      {
+        maskLayer_ = maskLayer;
+      }
       virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& worldWidget,
                                                           const ViewportGeometry& view,
                                                           MouseButton button,
@@ -96,7 +105,8 @@
                                                           int viewportY,
                                                           double x,
                                                           double y,
-                                                          IStatusBar* statusBar)
+                                                          IStatusBar* statusBar,
+                                                          const std::vector<Touch>& displayTouches)
       {
         RadiographyWidget& widget = dynamic_cast<RadiographyWidget&>(worldWidget);
 
@@ -126,22 +136,27 @@
             return NULL;
           }
           else if (tool_ == Tool_Crop ||
-                   tool_ == Tool_Resize)
+                   tool_ == Tool_Resize ||
+                   tool_ == Tool_Mask)
           {
             RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected);
             
-            ControlPoint corner;
-            if (accessor.GetLayer().LookupControlPoint(corner, x, y, view.GetZoom(), GetHandleSize()))
+            ControlPoint controlPoint;
+            if (accessor.GetLayer().LookupControlPoint(controlPoint, x, y, view.GetZoom(), GetHandleSize()))
             {
               switch (tool_)
               {
               case Tool_Crop:
                 return new RadiographyLayerCropTracker
-                    (undoRedoStack_, widget.GetScene(), view, selected, x, y, corner);
+                    (undoRedoStack_, widget.GetScene(), view, selected, controlPoint);
+
+              case Tool_Mask:
+                return new RadiographyLayerMaskTracker
+                    (undoRedoStack_, widget.GetScene(), view, selected, controlPoint);
 
               case Tool_Resize:
                 return new RadiographyLayerResizeTracker
-                    (undoRedoStack_, widget.GetScene(), selected, x, y, corner,
+                    (undoRedoStack_, widget.GetScene(), selected, controlPoint,
                      (modifiers & KeyboardModifiers_Shift));
 
               default:
@@ -207,6 +222,7 @@
         {
           return NULL;
         }
+        return NULL;
       }
 
       virtual void MouseOver(CairoContext& context,
@@ -231,25 +247,24 @@
 
         if (widget.LookupSelectedLayer(selected) &&
             (tool_ == Tool_Crop ||
-             tool_ == Tool_Resize))
+             tool_ == Tool_Resize ||
+             tool_ == Tool_Mask))
         {
           RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected);
 
-          Corner corner;
-          if (accessor.GetLayer().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize()))
+          ControlPoint controlPoint;
+          if (accessor.GetLayer().LookupControlPoint(controlPoint, x, y, view.GetZoom(), GetHandleSize()))
           {
-            accessor.GetLayer().GetCorner(x, y, corner);
-
             double z = 1.0 / view.GetZoom();
 
             context.SetSourceColor(255, 0, 0);
             cairo_t* cr = context.GetObject();
             cairo_set_line_width(cr, 2.0 * z);
-            cairo_move_to(cr, x - GetHandleSize() * z, y - GetHandleSize() * z);
-            cairo_line_to(cr, x + GetHandleSize() * z, y - GetHandleSize() * z);
-            cairo_line_to(cr, x + GetHandleSize() * z, y + GetHandleSize() * z);
-            cairo_line_to(cr, x - GetHandleSize() * z, y + GetHandleSize() * z);
-            cairo_line_to(cr, x - GetHandleSize() * z, y - GetHandleSize() * z);
+            cairo_move_to(cr, controlPoint.x - GetHandleSize() * z, controlPoint.y - GetHandleSize() * z);
+            cairo_line_to(cr, controlPoint.x + GetHandleSize() * z, controlPoint.y - GetHandleSize() * z);
+            cairo_line_to(cr, controlPoint.x + GetHandleSize() * z, controlPoint.y + GetHandleSize() * z);
+            cairo_line_to(cr, controlPoint.x - GetHandleSize() * z, controlPoint.y + GetHandleSize() * z);
+            cairo_line_to(cr, controlPoint.x - GetHandleSize() * z, controlPoint.y - GetHandleSize() * z);
             cairo_stroke(cr);
           }
         }
@@ -280,6 +295,11 @@
           tool_ = Tool_Crop;
           break;
 
+        case 'm':
+          tool_ = Tool_Mask;
+          widget.Select(1);
+          break;
+
         case 'd':
         {
           // dump to json and reload
@@ -338,7 +358,7 @@
           widget.SwitchInvert();
           break;
 
-        case 'm':
+        case 't':
           tool_ = Tool_Move;
           break;
 
@@ -407,6 +427,7 @@
       boost::shared_ptr<RadiographyScene>   scene_;
       RadiographyEditorInteractor           interactor_;
       Orthanc::FontRegistry                 fontRegistry_;
+      RadiographyMaskLayer*                 maskLayer_;
 
     public:
       SingleFrameEditorApplication(MessageBroker& broker) :
@@ -447,10 +468,11 @@
         statusBar.SetMessage("Use the key \"e\" to export DICOM to the Orthanc server");
         statusBar.SetMessage("Use the key \"f\" to switch full screen");
         statusBar.SetMessage("Use the key \"i\" to invert contrast");
-        statusBar.SetMessage("Use the key \"m\" to move objects");
+        statusBar.SetMessage("Use the key \"m\" to modify the mask");
         statusBar.SetMessage("Use the key \"n\" to switch between nearest neighbor and bilinear interpolation");
         statusBar.SetMessage("Use the key \"r\" to rotate objects");
         statusBar.SetMessage("Use the key \"s\" to resize objects (not applicable to DICOM layers)");
+        statusBar.SetMessage("Use the key \"t\" to move (translate) objects");
         statusBar.SetMessage("Use the key \"w\" to change windowing");
         
         statusBar.SetMessage("Use the key \"ctrl-z\" to undo action");
@@ -468,7 +490,8 @@
         fontRegistry_.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16);
         
         scene_.reset(new RadiographyScene(GetBroker()));
-        scene_->LoadDicomFrame(context->GetOrthancApiClient(), instance, 0, false, NULL);
+        //scene_->LoadDicomFrame(instance, frame, false); //.SetPan(200, 0);
+        RadiographyLayer& dicomLayer = scene_->LoadDicomFrame(context->GetOrthancApiClient(), "61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", 0, false, NULL);
 
 #if !defined(ORTHANC_ENABLE_WASM) || ORTHANC_ENABLE_WASM != 1
         Orthanc::HttpClient::ConfigureSsl(true, "/etc/ssl/certs/ca-certificates.crt");
@@ -476,6 +499,15 @@
         
         //scene_->LoadDicomWebFrame(context->GetWebService());
         
+        std::vector<Orthanc::ImageProcessing::ImagePoint> mask;
+        mask.push_back(Orthanc::ImageProcessing::ImagePoint(1100, 100));
+        mask.push_back(Orthanc::ImageProcessing::ImagePoint(1100, 1000));
+        mask.push_back(Orthanc::ImageProcessing::ImagePoint(2000, 1000));
+        mask.push_back(Orthanc::ImageProcessing::ImagePoint(2200, 150));
+        mask.push_back(Orthanc::ImageProcessing::ImagePoint(1500, 550));
+        maskLayer_ = dynamic_cast<RadiographyMaskLayer*>(&(scene_->LoadMask(mask, dynamic_cast<RadiographyDicomLayer&>(dicomLayer), 128.0f, NULL)));
+        interactor_.SetMaskLayer(maskLayer_);
+
         {
           RadiographyLayer& layer = scene_->LoadText(fontRegistry_.GetFont(0), "Hello\nworld", NULL);
           layer.SetResizeable(true);