Mercurial > hg > orthanc-stone
comparison Applications/Samples/SingleFrameEditorApplication.h @ 476:a95090305dd4 am-touch-events
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
author | am@osimis.io |
---|---|
date | Wed, 13 Feb 2019 12:04:02 +0100 |
parents | 3c28542229a3 |
children | 2f6ecb5037ea |
comparison
equal
deleted
inserted
replaced
475:3c28542229a3 | 476:a95090305dd4 |
---|---|
59 { | 59 { |
60 Tool_Move, | 60 Tool_Move, |
61 Tool_Rotate, | 61 Tool_Rotate, |
62 Tool_Crop, | 62 Tool_Crop, |
63 Tool_Resize, | 63 Tool_Resize, |
64 Tool_Mask, | |
64 Tool_Windowing | 65 Tool_Windowing |
65 }; | 66 }; |
66 | 67 |
67 | 68 |
68 StoneApplicationContext* context_; | 69 StoneApplicationContext* context_; |
69 UndoRedoStack undoRedoStack_; | 70 UndoRedoStack undoRedoStack_; |
70 Tool tool_; | 71 Tool tool_; |
72 RadiographyMaskLayer* maskLayer_; | |
71 | 73 |
72 | 74 |
73 static double GetHandleSize() | 75 static double GetHandleSize() |
74 { | 76 { |
75 return 10.0; | 77 return 10.0; |
78 | 80 |
79 public: | 81 public: |
80 RadiographyEditorInteractor(MessageBroker& broker) : | 82 RadiographyEditorInteractor(MessageBroker& broker) : |
81 IObserver(broker), | 83 IObserver(broker), |
82 context_(NULL), | 84 context_(NULL), |
83 tool_(Tool_Move) | 85 tool_(Tool_Move), |
86 maskLayer_(NULL) | |
84 { | 87 { |
85 } | 88 } |
86 | 89 |
87 void SetContext(StoneApplicationContext& context) | 90 void SetContext(StoneApplicationContext& context) |
88 { | 91 { |
89 context_ = &context; | 92 context_ = &context; |
90 } | 93 } |
91 | 94 |
95 void SetMaskLayer(RadiographyMaskLayer* maskLayer) | |
96 { | |
97 maskLayer_ = maskLayer; | |
98 } | |
92 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& worldWidget, | 99 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& worldWidget, |
93 const ViewportGeometry& view, | 100 const ViewportGeometry& view, |
94 MouseButton button, | 101 MouseButton button, |
95 KeyboardModifiers modifiers, | 102 KeyboardModifiers modifiers, |
96 int viewportX, | 103 int viewportX, |
125 widget.Select(layer); | 132 widget.Select(layer); |
126 } | 133 } |
127 | 134 |
128 return NULL; | 135 return NULL; |
129 } | 136 } |
137 else if (tool_ == Tool_Mask) | |
138 { | |
139 // maskLayer_ | |
140 // case Tool_Mask: | |
141 // return new RadiographyLayerMaskTracker | |
142 // (undoRedoStack_, widget.GetScene(), view, selected, x, y, corner); | |
143 return NULL; | |
144 } | |
130 else if (tool_ == Tool_Crop || | 145 else if (tool_ == Tool_Crop || |
131 tool_ == Tool_Resize) | 146 tool_ == Tool_Resize) |
132 { | 147 { |
133 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected); | 148 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected); |
134 | 149 |
135 Corner corner; | 150 ControlPoint controlPoint; |
136 if (accessor.GetLayer().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize())) | 151 if (accessor.GetLayer().LookupControlPoint(controlPoint, x, y, view.GetZoom(), GetHandleSize())) |
137 { | 152 { |
138 switch (tool_) | 153 switch (tool_) |
139 { | 154 { |
140 case Tool_Crop: | 155 case Tool_Crop: |
141 return new RadiographyLayerCropTracker | 156 return new RadiographyLayerCropTracker |
142 (undoRedoStack_, widget.GetScene(), view, selected, x, y, corner); | 157 (undoRedoStack_, widget.GetScene(), view, selected, controlPoint); |
158 | |
143 | 159 |
144 case Tool_Resize: | 160 case Tool_Resize: |
145 return new RadiographyLayerResizeTracker | 161 return new RadiographyLayerResizeTracker |
146 (undoRedoStack_, widget.GetScene(), selected, x, y, corner, | 162 (undoRedoStack_, widget.GetScene(), selected, controlPoint, |
147 (modifiers & KeyboardModifiers_Shift)); | 163 (modifiers & KeyboardModifiers_Shift)); |
148 | 164 |
149 default: | 165 default: |
150 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 166 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
151 } | 167 } |
207 } | 223 } |
208 else | 224 else |
209 { | 225 { |
210 return NULL; | 226 return NULL; |
211 } | 227 } |
228 return NULL; | |
212 } | 229 } |
213 | 230 |
214 virtual void MouseOver(CairoContext& context, | 231 virtual void MouseOver(CairoContext& context, |
215 WorldSceneWidget& worldWidget, | 232 WorldSceneWidget& worldWidget, |
216 const ViewportGeometry& view, | 233 const ViewportGeometry& view, |
231 | 248 |
232 size_t selected; | 249 size_t selected; |
233 | 250 |
234 if (widget.LookupSelectedLayer(selected) && | 251 if (widget.LookupSelectedLayer(selected) && |
235 (tool_ == Tool_Crop || | 252 (tool_ == Tool_Crop || |
236 tool_ == Tool_Resize)) | 253 tool_ == Tool_Resize) || |
254 tool_ == Tool_Mask) | |
237 { | 255 { |
238 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected); | 256 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected); |
239 | 257 |
240 Corner corner; | 258 ControlPoint controlPoint; |
241 if (accessor.GetLayer().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize())) | 259 if (accessor.GetLayer().LookupControlPoint(controlPoint, x, y, view.GetZoom(), GetHandleSize())) |
242 { | 260 { |
243 accessor.GetLayer().GetCorner(x, y, corner); | |
244 | |
245 double z = 1.0 / view.GetZoom(); | 261 double z = 1.0 / view.GetZoom(); |
246 | 262 |
247 context.SetSourceColor(255, 0, 0); | 263 context.SetSourceColor(255, 0, 0); |
248 cairo_t* cr = context.GetObject(); | 264 cairo_t* cr = context.GetObject(); |
249 cairo_set_line_width(cr, 2.0 * z); | 265 cairo_set_line_width(cr, 2.0 * z); |
250 cairo_move_to(cr, x - GetHandleSize() * z, y - GetHandleSize() * z); | 266 cairo_move_to(cr, controlPoint.x - GetHandleSize() * z, controlPoint.y - GetHandleSize() * z); |
251 cairo_line_to(cr, x + GetHandleSize() * z, y - GetHandleSize() * z); | 267 cairo_line_to(cr, controlPoint.x + GetHandleSize() * z, controlPoint.y - GetHandleSize() * z); |
252 cairo_line_to(cr, x + GetHandleSize() * z, y + GetHandleSize() * z); | 268 cairo_line_to(cr, controlPoint.x + GetHandleSize() * z, controlPoint.y + GetHandleSize() * z); |
253 cairo_line_to(cr, x - GetHandleSize() * z, y + GetHandleSize() * z); | 269 cairo_line_to(cr, controlPoint.x - GetHandleSize() * z, controlPoint.y + GetHandleSize() * z); |
254 cairo_line_to(cr, x - GetHandleSize() * z, y - GetHandleSize() * z); | 270 cairo_line_to(cr, controlPoint.x - GetHandleSize() * z, controlPoint.y - GetHandleSize() * z); |
255 cairo_stroke(cr); | 271 cairo_stroke(cr); |
256 } | 272 } |
257 } | 273 } |
258 } | 274 } |
259 | 275 |
278 widget.FitContent(); | 294 widget.FitContent(); |
279 break; | 295 break; |
280 | 296 |
281 case 'c': | 297 case 'c': |
282 tool_ = Tool_Crop; | 298 tool_ = Tool_Crop; |
299 break; | |
300 | |
301 case 'm': | |
302 tool_ = Tool_Mask; | |
303 widget.Select(1); | |
283 break; | 304 break; |
284 | 305 |
285 case 'd': | 306 case 'd': |
286 { | 307 { |
287 // dump to json and reload | 308 // dump to json and reload |
338 | 359 |
339 case 'i': | 360 case 'i': |
340 widget.SwitchInvert(); | 361 widget.SwitchInvert(); |
341 break; | 362 break; |
342 | 363 |
343 case 'm': | 364 case 't': |
344 tool_ = Tool_Move; | 365 tool_ = Tool_Move; |
345 break; | 366 break; |
346 | 367 |
347 case 'n': | 368 case 'n': |
348 { | 369 { |
407 { | 428 { |
408 private: | 429 private: |
409 boost::shared_ptr<RadiographyScene> scene_; | 430 boost::shared_ptr<RadiographyScene> scene_; |
410 RadiographyEditorInteractor interactor_; | 431 RadiographyEditorInteractor interactor_; |
411 Orthanc::FontRegistry fontRegistry_; | 432 Orthanc::FontRegistry fontRegistry_; |
433 RadiographyMaskLayer* maskLayer_; | |
412 | 434 |
413 public: | 435 public: |
414 SingleFrameEditorApplication(MessageBroker& broker) : | 436 SingleFrameEditorApplication(MessageBroker& broker) : |
415 IObserver(broker), | 437 IObserver(broker), |
416 interactor_(broker) | 438 interactor_(broker) |
447 statusBar.SetMessage("Use the key \"a\" to reinitialize the layout"); | 469 statusBar.SetMessage("Use the key \"a\" to reinitialize the layout"); |
448 statusBar.SetMessage("Use the key \"c\" to crop"); | 470 statusBar.SetMessage("Use the key \"c\" to crop"); |
449 statusBar.SetMessage("Use the key \"e\" to export DICOM to the Orthanc server"); | 471 statusBar.SetMessage("Use the key \"e\" to export DICOM to the Orthanc server"); |
450 statusBar.SetMessage("Use the key \"f\" to switch full screen"); | 472 statusBar.SetMessage("Use the key \"f\" to switch full screen"); |
451 statusBar.SetMessage("Use the key \"i\" to invert contrast"); | 473 statusBar.SetMessage("Use the key \"i\" to invert contrast"); |
452 statusBar.SetMessage("Use the key \"m\" to move objects"); | 474 statusBar.SetMessage("Use the key \"m\" to modify the mask"); |
453 statusBar.SetMessage("Use the key \"n\" to switch between nearest neighbor and bilinear interpolation"); | 475 statusBar.SetMessage("Use the key \"n\" to switch between nearest neighbor and bilinear interpolation"); |
454 statusBar.SetMessage("Use the key \"r\" to rotate objects"); | 476 statusBar.SetMessage("Use the key \"r\" to rotate objects"); |
455 statusBar.SetMessage("Use the key \"s\" to resize objects (not applicable to DICOM layers)"); | 477 statusBar.SetMessage("Use the key \"s\" to resize objects (not applicable to DICOM layers)"); |
478 statusBar.SetMessage("Use the key \"t\" to move (translate) objects"); | |
456 statusBar.SetMessage("Use the key \"w\" to change windowing"); | 479 statusBar.SetMessage("Use the key \"w\" to change windowing"); |
457 | 480 |
458 statusBar.SetMessage("Use the key \"ctrl-z\" to undo action"); | 481 statusBar.SetMessage("Use the key \"ctrl-z\" to undo action"); |
459 statusBar.SetMessage("Use the key \"ctrl-y\" to redo action"); | 482 statusBar.SetMessage("Use the key \"ctrl-y\" to redo action"); |
460 | 483 |
478 #endif | 501 #endif |
479 | 502 |
480 //scene_->LoadDicomWebFrame(context->GetWebService()); | 503 //scene_->LoadDicomWebFrame(context->GetWebService()); |
481 | 504 |
482 std::vector<MaskPoint> mask; | 505 std::vector<MaskPoint> mask; |
483 mask.push_back(MaskPoint(100, 100)); | 506 mask.push_back(MaskPoint(1100, 100)); |
484 mask.push_back(MaskPoint(100, 1000)); | 507 mask.push_back(MaskPoint(1100, 1000)); |
485 mask.push_back(MaskPoint(1000, 1000)); | 508 mask.push_back(MaskPoint(2000, 1000)); |
486 scene_->LoadMask(mask, dynamic_cast<RadiographyDicomLayer&>(dicomLayer), 128.0f, NULL); | 509 mask.push_back(MaskPoint(2200, 150)); |
510 mask.push_back(MaskPoint(1500, 550)); | |
511 maskLayer_ = dynamic_cast<RadiographyMaskLayer*>(&(scene_->LoadMask(mask, dynamic_cast<RadiographyDicomLayer&>(dicomLayer), 128.0f, NULL))); | |
512 interactor_.SetMaskLayer(maskLayer_); | |
487 | 513 |
488 { | 514 { |
489 RadiographyLayer& layer = scene_->LoadText(fontRegistry_.GetFont(0), "Hello\nworld", NULL); | 515 RadiographyLayer& layer = scene_->LoadText(fontRegistry_.GetFont(0), "Hello\nworld", NULL); |
490 layer.SetResizeable(true); | 516 layer.SetResizeable(true); |
491 } | 517 } |