comparison Applications/Samples/SingleFrameEditorApplication.h @ 410:6decc0ba9da5

rename RadiographyScene::Layer as RadiographyLayer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Nov 2018 15:52:03 +0100
parents 6834c236b36d
children 18b707fb8620
comparison
equal deleted inserted replaced
409:99c9b3238008 410:6decc0ba9da5
56 private: 56 private:
57 RadiographyScene& scene_; 57 RadiographyScene& scene_;
58 size_t layer_; 58 size_t layer_;
59 59
60 protected: 60 protected:
61 virtual void UndoInternal(RadiographyScene::Layer& layer) const = 0; 61 virtual void UndoInternal(RadiographyLayer& layer) const = 0;
62 62
63 virtual void RedoInternal(RadiographyScene::Layer& layer) const = 0; 63 virtual void RedoInternal(RadiographyLayer& layer) const = 0;
64 64
65 public: 65 public:
66 RadiographyLayerCommand(RadiographyScene& scene, 66 RadiographyLayerCommand(RadiographyScene& scene,
67 size_t layer) : 67 size_t layer) :
68 scene_(scene), 68 scene_(scene),
141 { 141 {
142 return boost::math::iround(angle * 180.0 / boost::math::constants::pi<double>()); 142 return boost::math::iround(angle * 180.0 / boost::math::constants::pi<double>());
143 } 143 }
144 144
145 protected: 145 protected:
146 virtual void UndoInternal(RadiographyScene::Layer& layer) const 146 virtual void UndoInternal(RadiographyLayer& layer) const
147 { 147 {
148 LOG(INFO) << "Undo - Set angle to " << ToDegrees(sourceAngle_) << " degrees"; 148 LOG(INFO) << "Undo - Set angle to " << ToDegrees(sourceAngle_) << " degrees";
149 layer.SetAngle(sourceAngle_); 149 layer.SetAngle(sourceAngle_);
150 } 150 }
151 151
152 virtual void RedoInternal(RadiographyScene::Layer& layer) const 152 virtual void RedoInternal(RadiographyLayer& layer) const
153 { 153 {
154 LOG(INFO) << "Redo - Set angle to " << ToDegrees(sourceAngle_) << " degrees"; 154 LOG(INFO) << "Redo - Set angle to " << ToDegrees(sourceAngle_) << " degrees";
155 layer.SetAngle(targetAngle_); 155 layer.SetAngle(targetAngle_);
156 } 156 }
157 157
254 double sourceY_; 254 double sourceY_;
255 double targetX_; 255 double targetX_;
256 double targetY_; 256 double targetY_;
257 257
258 protected: 258 protected:
259 virtual void UndoInternal(RadiographyScene::Layer& layer) const 259 virtual void UndoInternal(RadiographyLayer& layer) const
260 { 260 {
261 layer.SetPan(sourceX_, sourceY_); 261 layer.SetPan(sourceX_, sourceY_);
262 } 262 }
263 263
264 virtual void RedoInternal(RadiographyScene::Layer& layer) const 264 virtual void RedoInternal(RadiographyLayer& layer) const
265 { 265 {
266 layer.SetPan(targetX_, targetY_); 266 layer.SetPan(targetX_, targetY_);
267 } 267 }
268 268
269 public: 269 public:
350 class RadiographyLayerCropTracker : public IWorldSceneMouseTracker 350 class RadiographyLayerCropTracker : public IWorldSceneMouseTracker
351 { 351 {
352 private: 352 private:
353 UndoRedoStack& undoRedoStack_; 353 UndoRedoStack& undoRedoStack_;
354 RadiographyScene::LayerAccessor accessor_; 354 RadiographyScene::LayerAccessor accessor_;
355 RadiographyScene::Corner corner_; 355 Corner corner_;
356 unsigned int cropX_; 356 unsigned int cropX_;
357 unsigned int cropY_; 357 unsigned int cropY_;
358 unsigned int cropWidth_; 358 unsigned int cropWidth_;
359 unsigned int cropHeight_; 359 unsigned int cropHeight_;
360 360
369 unsigned int targetCropY_; 369 unsigned int targetCropY_;
370 unsigned int targetCropWidth_; 370 unsigned int targetCropWidth_;
371 unsigned int targetCropHeight_; 371 unsigned int targetCropHeight_;
372 372
373 protected: 373 protected:
374 virtual void UndoInternal(RadiographyScene::Layer& layer) const 374 virtual void UndoInternal(RadiographyLayer& layer) const
375 { 375 {
376 layer.SetCrop(sourceCropX_, sourceCropY_, sourceCropWidth_, sourceCropHeight_); 376 layer.SetCrop(sourceCropX_, sourceCropY_, sourceCropWidth_, sourceCropHeight_);
377 } 377 }
378 378
379 virtual void RedoInternal(RadiographyScene::Layer& layer) const 379 virtual void RedoInternal(RadiographyLayer& layer) const
380 { 380 {
381 layer.SetCrop(targetCropX_, targetCropY_, targetCropWidth_, targetCropHeight_); 381 layer.SetCrop(targetCropX_, targetCropY_, targetCropWidth_, targetCropHeight_);
382 } 382 }
383 383
384 public: 384 public:
400 RadiographyScene& scene, 400 RadiographyScene& scene,
401 const ViewportGeometry& view, 401 const ViewportGeometry& view,
402 size_t layer, 402 size_t layer,
403 double x, 403 double x,
404 double y, 404 double y,
405 RadiographyScene::Corner corner) : 405 Corner corner) :
406 undoRedoStack_(undoRedoStack), 406 undoRedoStack_(undoRedoStack),
407 accessor_(scene, layer), 407 accessor_(scene, layer),
408 corner_(corner) 408 corner_(corner)
409 { 409 {
410 if (accessor_.IsValid()) 410 if (accessor_.IsValid())
439 { 439 {
440 if (accessor_.IsValid()) 440 if (accessor_.IsValid())
441 { 441 {
442 unsigned int x, y; 442 unsigned int x, y;
443 443
444 RadiographyScene::Layer& layer = accessor_.GetLayer(); 444 RadiographyLayer& layer = accessor_.GetLayer();
445 if (layer.GetPixel(x, y, sceneX, sceneY)) 445 if (layer.GetPixel(x, y, sceneX, sceneY))
446 { 446 {
447 unsigned int targetX, targetWidth; 447 unsigned int targetX, targetWidth;
448 448
449 if (corner_ == RadiographyScene::Corner_TopLeft || 449 if (corner_ == Corner_TopLeft ||
450 corner_ == RadiographyScene::Corner_BottomLeft) 450 corner_ == Corner_BottomLeft)
451 { 451 {
452 targetX = std::min(x, cropX_ + cropWidth_); 452 targetX = std::min(x, cropX_ + cropWidth_);
453 targetWidth = cropX_ + cropWidth_ - targetX; 453 targetWidth = cropX_ + cropWidth_ - targetX;
454 } 454 }
455 else 455 else
458 targetWidth = std::max(x, cropX_) - cropX_; 458 targetWidth = std::max(x, cropX_) - cropX_;
459 } 459 }
460 460
461 unsigned int targetY, targetHeight; 461 unsigned int targetY, targetHeight;
462 462
463 if (corner_ == RadiographyScene::Corner_TopLeft || 463 if (corner_ == Corner_TopLeft ||
464 corner_ == RadiographyScene::Corner_TopRight) 464 corner_ == Corner_TopRight)
465 { 465 {
466 targetY = std::min(y, cropY_ + cropHeight_); 466 targetY = std::min(y, cropY_ + cropHeight_);
467 targetHeight = cropY_ + cropHeight_ - targetY; 467 targetHeight = cropY_ + cropHeight_ - targetY;
468 } 468 }
469 else 469 else
487 bool roundScaling_; 487 bool roundScaling_;
488 double originalSpacingX_; 488 double originalSpacingX_;
489 double originalSpacingY_; 489 double originalSpacingY_;
490 double originalPanX_; 490 double originalPanX_;
491 double originalPanY_; 491 double originalPanY_;
492 RadiographyScene::Corner oppositeCorner_; 492 Corner oppositeCorner_;
493 double oppositeX_; 493 double oppositeX_;
494 double oppositeY_; 494 double oppositeY_;
495 double baseScaling_; 495 double baseScaling_;
496 496
497 static double ComputeDistance(double x1, 497 static double ComputeDistance(double x1,
515 double targetSpacingY_; 515 double targetSpacingY_;
516 double targetPanX_; 516 double targetPanX_;
517 double targetPanY_; 517 double targetPanY_;
518 518
519 protected: 519 protected:
520 virtual void UndoInternal(RadiographyScene::Layer& layer) const 520 virtual void UndoInternal(RadiographyLayer& layer) const
521 { 521 {
522 layer.SetPixelSpacing(sourceSpacingX_, sourceSpacingY_); 522 layer.SetPixelSpacing(sourceSpacingX_, sourceSpacingY_);
523 layer.SetPan(sourcePanX_, sourcePanY_); 523 layer.SetPan(sourcePanX_, sourcePanY_);
524 } 524 }
525 525
526 virtual void RedoInternal(RadiographyScene::Layer& layer) const 526 virtual void RedoInternal(RadiographyLayer& layer) const
527 { 527 {
528 layer.SetPixelSpacing(targetSpacingX_, targetSpacingY_); 528 layer.SetPixelSpacing(targetSpacingX_, targetSpacingY_);
529 layer.SetPan(targetPanX_, targetPanY_); 529 layer.SetPan(targetPanX_, targetPanY_);
530 } 530 }
531 531
549 RadiographyLayerResizeTracker(UndoRedoStack& undoRedoStack, 549 RadiographyLayerResizeTracker(UndoRedoStack& undoRedoStack,
550 RadiographyScene& scene, 550 RadiographyScene& scene,
551 size_t layer, 551 size_t layer,
552 double x, 552 double x,
553 double y, 553 double y,
554 RadiographyScene::Corner corner, 554 Corner corner,
555 bool roundScaling) : 555 bool roundScaling) :
556 undoRedoStack_(undoRedoStack), 556 undoRedoStack_(undoRedoStack),
557 accessor_(scene, layer), 557 accessor_(scene, layer),
558 roundScaling_(roundScaling) 558 roundScaling_(roundScaling)
559 { 559 {
565 originalPanX_ = accessor_.GetLayer().GetPanX(); 565 originalPanX_ = accessor_.GetLayer().GetPanX();
566 originalPanY_ = accessor_.GetLayer().GetPanY(); 566 originalPanY_ = accessor_.GetLayer().GetPanY();
567 567
568 switch (corner) 568 switch (corner)
569 { 569 {
570 case RadiographyScene::Corner_TopLeft: 570 case Corner_TopLeft:
571 oppositeCorner_ = RadiographyScene::Corner_BottomRight; 571 oppositeCorner_ = Corner_BottomRight;
572 break; 572 break;
573 573
574 case RadiographyScene::Corner_TopRight: 574 case Corner_TopRight:
575 oppositeCorner_ = RadiographyScene::Corner_BottomLeft; 575 oppositeCorner_ = Corner_BottomLeft;
576 break; 576 break;
577 577
578 case RadiographyScene::Corner_BottomLeft: 578 case Corner_BottomLeft:
579 oppositeCorner_ = RadiographyScene::Corner_TopRight; 579 oppositeCorner_ = Corner_TopRight;
580 break; 580 break;
581 581
582 case RadiographyScene::Corner_BottomRight: 582 case Corner_BottomRight:
583 oppositeCorner_ = RadiographyScene::Corner_TopLeft; 583 oppositeCorner_ = Corner_TopLeft;
584 break; 584 break;
585 585
586 default: 586 default:
587 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); 587 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
588 } 588 }
637 if (roundScaling_) 637 if (roundScaling_)
638 { 638 {
639 scaling = boost::math::round<double>((scaling / ROUND_SCALING) * ROUND_SCALING); 639 scaling = boost::math::round<double>((scaling / ROUND_SCALING) * ROUND_SCALING);
640 } 640 }
641 641
642 RadiographyScene::Layer& layer = accessor_.GetLayer(); 642 RadiographyLayer& layer = accessor_.GetLayer();
643 layer.SetPixelSpacing(scaling * originalSpacingX_, 643 layer.SetPixelSpacing(scaling * originalSpacingX_,
644 scaling * originalSpacingY_); 644 scaling * originalSpacingY_);
645 645
646 // Keep the opposite corner at a fixed location 646 // Keep the opposite corner at a fixed location
647 double ox, oy; 647 double ox, oy;
1146 } 1146 }
1147 else if (tool_ == Tool_Crop || 1147 else if (tool_ == Tool_Crop ||
1148 tool_ == Tool_Resize) 1148 tool_ == Tool_Resize)
1149 { 1149 {
1150 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected); 1150 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected);
1151 RadiographyScene::Corner corner; 1151
1152 Corner corner;
1152 if (accessor.GetLayer().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize())) 1153 if (accessor.GetLayer().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize()))
1153 { 1154 {
1154 switch (tool_) 1155 switch (tool_)
1155 { 1156 {
1156 case Tool_Crop: 1157 case Tool_Crop:
1251 (tool_ == Tool_Crop || 1252 (tool_ == Tool_Crop ||
1252 tool_ == Tool_Resize)) 1253 tool_ == Tool_Resize))
1253 { 1254 {
1254 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected); 1255 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected);
1255 1256
1256 RadiographyScene::Corner corner; 1257 Corner corner;
1257 if (accessor.GetLayer().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize())) 1258 if (accessor.GetLayer().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize()))
1258 { 1259 {
1259 accessor.GetLayer().GetCorner(x, y, corner); 1260 accessor.GetLayer().GetCorner(x, y, corner);
1260 1261
1261 double z = 1.0 / view.GetZoom(); 1262 double z = 1.0 / view.GetZoom();
1463 scene_.reset(new RadiographyScene(GetBroker(), *orthancApiClient_)); 1464 scene_.reset(new RadiographyScene(GetBroker(), *orthancApiClient_));
1464 scene_->LoadDicomFrame(instance, frame, false); //.SetPan(200, 0); 1465 scene_->LoadDicomFrame(instance, frame, false); //.SetPan(200, 0);
1465 //scene_->LoadDicomFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", 0, false); 1466 //scene_->LoadDicomFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", 0, false);
1466 1467
1467 { 1468 {
1468 RadiographyScene::Layer& layer = scene_->LoadText(fonts.GetFont(0), "Hello\nworld"); 1469 RadiographyLayer& layer = scene_->LoadText(fonts.GetFont(0), "Hello\nworld");
1469 //dynamic_cast<RadiographyScene::Layer&>(layer).SetForegroundValue(256); 1470 layer.SetResizeable(true);
1470 dynamic_cast<RadiographyScene::Layer&>(layer).SetResizeable(true); 1471 }
1471 } 1472
1472 1473 {
1473 { 1474 RadiographyLayer& layer = scene_->LoadTestBlock(100, 50);
1474 RadiographyScene::Layer& layer = scene_->LoadTestBlock(100, 50); 1475 layer.SetResizeable(true);
1475 //dynamic_cast<RadiographyScene::Layer&>(layer).SetForegroundValue(256); 1476 layer.SetPan(0, 200);
1476 dynamic_cast<RadiographyScene::Layer&>(layer).SetResizeable(true);
1477 dynamic_cast<RadiographyScene::Layer&>(layer).SetPan(0, 200);
1478 } 1477 }
1479 1478
1480 1479
1481 mainWidget_ = new RadiographyWidget(GetBroker(), *scene_, "main-widget"); 1480 mainWidget_ = new RadiographyWidget(GetBroker(), *scene_, "main-widget");
1482 mainWidget_->SetTransmitMouseOver(true); 1481 mainWidget_->SetTransmitMouseOver(true);