comparison 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
comparison
equal deleted inserted replaced
517:64ee3033e1ca 518:40bb5eb247a5
22 #pragma once 22 #pragma once
23 23
24 #include "SampleApplicationBase.h" 24 #include "SampleApplicationBase.h"
25 25
26 #include "../../Framework/Radiography/RadiographyLayerCropTracker.h" 26 #include "../../Framework/Radiography/RadiographyLayerCropTracker.h"
27 #include "../../Framework/Radiography/RadiographyLayerMaskTracker.h"
27 #include "../../Framework/Radiography/RadiographyLayerMoveTracker.h" 28 #include "../../Framework/Radiography/RadiographyLayerMoveTracker.h"
28 #include "../../Framework/Radiography/RadiographyLayerResizeTracker.h" 29 #include "../../Framework/Radiography/RadiographyLayerResizeTracker.h"
29 #include "../../Framework/Radiography/RadiographyLayerRotateTracker.h" 30 #include "../../Framework/Radiography/RadiographyLayerRotateTracker.h"
30 #include "../../Framework/Radiography/RadiographyScene.h" 31 #include "../../Framework/Radiography/RadiographyScene.h"
31 #include "../../Framework/Radiography/RadiographySceneCommand.h" 32 #include "../../Framework/Radiography/RadiographySceneCommand.h"
32 #include "../../Framework/Radiography/RadiographyWidget.h" 33 #include "../../Framework/Radiography/RadiographyWidget.h"
33 #include "../../Framework/Radiography/RadiographyWindowingTracker.h" 34 #include "../../Framework/Radiography/RadiographyWindowingTracker.h"
34 #include "../../Framework/Radiography/RadiographySceneWriter.h" 35 #include "../../Framework/Radiography/RadiographySceneWriter.h"
35 #include "../../Framework/Radiography/RadiographySceneReader.h" 36 #include "../../Framework/Radiography/RadiographySceneReader.h"
37 #include "../../Framework/Radiography/RadiographyMaskLayer.h"
36 38
37 #include <Core/HttpClient.h> 39 #include <Core/HttpClient.h>
38 #include <Core/Images/FontRegistry.h> 40 #include <Core/Images/FontRegistry.h>
39 #include <Core/Logging.h> 41 #include <Core/Logging.h>
40 #include <Core/OrthancException.h> 42 #include <Core/OrthancException.h>
58 { 60 {
59 Tool_Move, 61 Tool_Move,
60 Tool_Rotate, 62 Tool_Rotate,
61 Tool_Crop, 63 Tool_Crop,
62 Tool_Resize, 64 Tool_Resize,
65 Tool_Mask,
63 Tool_Windowing 66 Tool_Windowing
64 }; 67 };
65 68
66 69
67 StoneApplicationContext* context_; 70 StoneApplicationContext* context_;
68 UndoRedoStack undoRedoStack_; 71 UndoRedoStack undoRedoStack_;
69 Tool tool_; 72 Tool tool_;
73 RadiographyMaskLayer* maskLayer_;
70 74
71 75
72 static double GetHandleSize() 76 static double GetHandleSize()
73 { 77 {
74 return 10.0; 78 return 10.0;
77 81
78 public: 82 public:
79 RadiographyEditorInteractor(MessageBroker& broker) : 83 RadiographyEditorInteractor(MessageBroker& broker) :
80 IObserver(broker), 84 IObserver(broker),
81 context_(NULL), 85 context_(NULL),
82 tool_(Tool_Move) 86 tool_(Tool_Move),
87 maskLayer_(NULL)
83 { 88 {
84 } 89 }
85 90
86 void SetContext(StoneApplicationContext& context) 91 void SetContext(StoneApplicationContext& context)
87 { 92 {
88 context_ = &context; 93 context_ = &context;
89 } 94 }
90 95
96 void SetMaskLayer(RadiographyMaskLayer* maskLayer)
97 {
98 maskLayer_ = maskLayer;
99 }
91 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& worldWidget, 100 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& worldWidget,
92 const ViewportGeometry& view, 101 const ViewportGeometry& view,
93 MouseButton button, 102 MouseButton button,
94 KeyboardModifiers modifiers, 103 KeyboardModifiers modifiers,
95 int viewportX, 104 int viewportX,
96 int viewportY, 105 int viewportY,
97 double x, 106 double x,
98 double y, 107 double y,
99 IStatusBar* statusBar) 108 IStatusBar* statusBar,
109 const std::vector<Touch>& displayTouches)
100 { 110 {
101 RadiographyWidget& widget = dynamic_cast<RadiographyWidget&>(worldWidget); 111 RadiographyWidget& widget = dynamic_cast<RadiographyWidget&>(worldWidget);
102 112
103 if (button == MouseButton_Left) 113 if (button == MouseButton_Left)
104 { 114 {
124 } 134 }
125 135
126 return NULL; 136 return NULL;
127 } 137 }
128 else if (tool_ == Tool_Crop || 138 else if (tool_ == Tool_Crop ||
129 tool_ == Tool_Resize) 139 tool_ == Tool_Resize ||
140 tool_ == Tool_Mask)
130 { 141 {
131 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected); 142 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected);
132 143
133 ControlPoint corner; 144 ControlPoint controlPoint;
134 if (accessor.GetLayer().LookupControlPoint(corner, x, y, view.GetZoom(), GetHandleSize())) 145 if (accessor.GetLayer().LookupControlPoint(controlPoint, x, y, view.GetZoom(), GetHandleSize()))
135 { 146 {
136 switch (tool_) 147 switch (tool_)
137 { 148 {
138 case Tool_Crop: 149 case Tool_Crop:
139 return new RadiographyLayerCropTracker 150 return new RadiographyLayerCropTracker
140 (undoRedoStack_, widget.GetScene(), view, selected, x, y, corner); 151 (undoRedoStack_, widget.GetScene(), view, selected, controlPoint);
152
153 case Tool_Mask:
154 return new RadiographyLayerMaskTracker
155 (undoRedoStack_, widget.GetScene(), view, selected, controlPoint);
141 156
142 case Tool_Resize: 157 case Tool_Resize:
143 return new RadiographyLayerResizeTracker 158 return new RadiographyLayerResizeTracker
144 (undoRedoStack_, widget.GetScene(), selected, x, y, corner, 159 (undoRedoStack_, widget.GetScene(), selected, controlPoint,
145 (modifiers & KeyboardModifiers_Shift)); 160 (modifiers & KeyboardModifiers_Shift));
146 161
147 default: 162 default:
148 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 163 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
149 } 164 }
205 } 220 }
206 else 221 else
207 { 222 {
208 return NULL; 223 return NULL;
209 } 224 }
225 return NULL;
210 } 226 }
211 227
212 virtual void MouseOver(CairoContext& context, 228 virtual void MouseOver(CairoContext& context,
213 WorldSceneWidget& worldWidget, 229 WorldSceneWidget& worldWidget,
214 const ViewportGeometry& view, 230 const ViewportGeometry& view,
229 245
230 size_t selected; 246 size_t selected;
231 247
232 if (widget.LookupSelectedLayer(selected) && 248 if (widget.LookupSelectedLayer(selected) &&
233 (tool_ == Tool_Crop || 249 (tool_ == Tool_Crop ||
234 tool_ == Tool_Resize)) 250 tool_ == Tool_Resize ||
251 tool_ == Tool_Mask))
235 { 252 {
236 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected); 253 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected);
237 254
238 Corner corner; 255 ControlPoint controlPoint;
239 if (accessor.GetLayer().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize())) 256 if (accessor.GetLayer().LookupControlPoint(controlPoint, x, y, view.GetZoom(), GetHandleSize()))
240 { 257 {
241 accessor.GetLayer().GetCorner(x, y, corner);
242
243 double z = 1.0 / view.GetZoom(); 258 double z = 1.0 / view.GetZoom();
244 259
245 context.SetSourceColor(255, 0, 0); 260 context.SetSourceColor(255, 0, 0);
246 cairo_t* cr = context.GetObject(); 261 cairo_t* cr = context.GetObject();
247 cairo_set_line_width(cr, 2.0 * z); 262 cairo_set_line_width(cr, 2.0 * z);
248 cairo_move_to(cr, x - GetHandleSize() * z, y - GetHandleSize() * z); 263 cairo_move_to(cr, controlPoint.x - GetHandleSize() * z, controlPoint.y - GetHandleSize() * z);
249 cairo_line_to(cr, x + GetHandleSize() * z, y - GetHandleSize() * z); 264 cairo_line_to(cr, controlPoint.x + GetHandleSize() * z, controlPoint.y - GetHandleSize() * z);
250 cairo_line_to(cr, x + GetHandleSize() * z, y + GetHandleSize() * z); 265 cairo_line_to(cr, controlPoint.x + GetHandleSize() * z, controlPoint.y + GetHandleSize() * z);
251 cairo_line_to(cr, x - GetHandleSize() * z, y + GetHandleSize() * z); 266 cairo_line_to(cr, controlPoint.x - GetHandleSize() * z, controlPoint.y + GetHandleSize() * z);
252 cairo_line_to(cr, x - GetHandleSize() * z, y - GetHandleSize() * z); 267 cairo_line_to(cr, controlPoint.x - GetHandleSize() * z, controlPoint.y - GetHandleSize() * z);
253 cairo_stroke(cr); 268 cairo_stroke(cr);
254 } 269 }
255 } 270 }
256 } 271 }
257 272
276 widget.FitContent(); 291 widget.FitContent();
277 break; 292 break;
278 293
279 case 'c': 294 case 'c':
280 tool_ = Tool_Crop; 295 tool_ = Tool_Crop;
296 break;
297
298 case 'm':
299 tool_ = Tool_Mask;
300 widget.Select(1);
281 break; 301 break;
282 302
283 case 'd': 303 case 'd':
284 { 304 {
285 // dump to json and reload 305 // dump to json and reload
336 356
337 case 'i': 357 case 'i':
338 widget.SwitchInvert(); 358 widget.SwitchInvert();
339 break; 359 break;
340 360
341 case 'm': 361 case 't':
342 tool_ = Tool_Move; 362 tool_ = Tool_Move;
343 break; 363 break;
344 364
345 case 'n': 365 case 'n':
346 { 366 {
405 { 425 {
406 private: 426 private:
407 boost::shared_ptr<RadiographyScene> scene_; 427 boost::shared_ptr<RadiographyScene> scene_;
408 RadiographyEditorInteractor interactor_; 428 RadiographyEditorInteractor interactor_;
409 Orthanc::FontRegistry fontRegistry_; 429 Orthanc::FontRegistry fontRegistry_;
430 RadiographyMaskLayer* maskLayer_;
410 431
411 public: 432 public:
412 SingleFrameEditorApplication(MessageBroker& broker) : 433 SingleFrameEditorApplication(MessageBroker& broker) :
413 IObserver(broker), 434 IObserver(broker),
414 interactor_(broker) 435 interactor_(broker)
445 statusBar.SetMessage("Use the key \"a\" to reinitialize the layout"); 466 statusBar.SetMessage("Use the key \"a\" to reinitialize the layout");
446 statusBar.SetMessage("Use the key \"c\" to crop"); 467 statusBar.SetMessage("Use the key \"c\" to crop");
447 statusBar.SetMessage("Use the key \"e\" to export DICOM to the Orthanc server"); 468 statusBar.SetMessage("Use the key \"e\" to export DICOM to the Orthanc server");
448 statusBar.SetMessage("Use the key \"f\" to switch full screen"); 469 statusBar.SetMessage("Use the key \"f\" to switch full screen");
449 statusBar.SetMessage("Use the key \"i\" to invert contrast"); 470 statusBar.SetMessage("Use the key \"i\" to invert contrast");
450 statusBar.SetMessage("Use the key \"m\" to move objects"); 471 statusBar.SetMessage("Use the key \"m\" to modify the mask");
451 statusBar.SetMessage("Use the key \"n\" to switch between nearest neighbor and bilinear interpolation"); 472 statusBar.SetMessage("Use the key \"n\" to switch between nearest neighbor and bilinear interpolation");
452 statusBar.SetMessage("Use the key \"r\" to rotate objects"); 473 statusBar.SetMessage("Use the key \"r\" to rotate objects");
453 statusBar.SetMessage("Use the key \"s\" to resize objects (not applicable to DICOM layers)"); 474 statusBar.SetMessage("Use the key \"s\" to resize objects (not applicable to DICOM layers)");
475 statusBar.SetMessage("Use the key \"t\" to move (translate) objects");
454 statusBar.SetMessage("Use the key \"w\" to change windowing"); 476 statusBar.SetMessage("Use the key \"w\" to change windowing");
455 477
456 statusBar.SetMessage("Use the key \"ctrl-z\" to undo action"); 478 statusBar.SetMessage("Use the key \"ctrl-z\" to undo action");
457 statusBar.SetMessage("Use the key \"ctrl-y\" to redo action"); 479 statusBar.SetMessage("Use the key \"ctrl-y\" to redo action");
458 480
466 int frame = parameters["frame"].as<unsigned int>(); 488 int frame = parameters["frame"].as<unsigned int>();
467 489
468 fontRegistry_.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16); 490 fontRegistry_.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16);
469 491
470 scene_.reset(new RadiographyScene(GetBroker())); 492 scene_.reset(new RadiographyScene(GetBroker()));
471 scene_->LoadDicomFrame(context->GetOrthancApiClient(), instance, 0, false, NULL); 493 //scene_->LoadDicomFrame(instance, frame, false); //.SetPan(200, 0);
494 RadiographyLayer& dicomLayer = scene_->LoadDicomFrame(context->GetOrthancApiClient(), "61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", 0, false, NULL);
472 495
473 #if !defined(ORTHANC_ENABLE_WASM) || ORTHANC_ENABLE_WASM != 1 496 #if !defined(ORTHANC_ENABLE_WASM) || ORTHANC_ENABLE_WASM != 1
474 Orthanc::HttpClient::ConfigureSsl(true, "/etc/ssl/certs/ca-certificates.crt"); 497 Orthanc::HttpClient::ConfigureSsl(true, "/etc/ssl/certs/ca-certificates.crt");
475 #endif 498 #endif
476 499
477 //scene_->LoadDicomWebFrame(context->GetWebService()); 500 //scene_->LoadDicomWebFrame(context->GetWebService());
478 501
502 std::vector<Orthanc::ImageProcessing::ImagePoint> mask;
503 mask.push_back(Orthanc::ImageProcessing::ImagePoint(1100, 100));
504 mask.push_back(Orthanc::ImageProcessing::ImagePoint(1100, 1000));
505 mask.push_back(Orthanc::ImageProcessing::ImagePoint(2000, 1000));
506 mask.push_back(Orthanc::ImageProcessing::ImagePoint(2200, 150));
507 mask.push_back(Orthanc::ImageProcessing::ImagePoint(1500, 550));
508 maskLayer_ = dynamic_cast<RadiographyMaskLayer*>(&(scene_->LoadMask(mask, dynamic_cast<RadiographyDicomLayer&>(dicomLayer), 128.0f, NULL)));
509 interactor_.SetMaskLayer(maskLayer_);
510
479 { 511 {
480 RadiographyLayer& layer = scene_->LoadText(fontRegistry_.GetFont(0), "Hello\nworld", NULL); 512 RadiographyLayer& layer = scene_->LoadText(fontRegistry_.GetFont(0), "Hello\nworld", NULL);
481 layer.SetResizeable(true); 513 layer.SetResizeable(true);
482 } 514 }
483 515