Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyLayer.cpp @ 1036:d7d3227c11a9
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Oct 2019 15:26:29 +0200 |
parents | be9c1530d40a |
children | b537002f83a9 d33ae2b0db9d |
rev | line source |
---|---|
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "RadiographyLayer.h" |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include <Core/OrthancException.h> |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 namespace OrthancStone |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 static double Square(double x) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 return x * x; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
430 | 35 RadiographyLayer::Geometry::Geometry() : |
36 hasCrop_(false), | |
629 | 37 flipVertical_(false), |
38 flipHorizontal_(false), | |
430 | 39 panX_(0), |
40 panY_(0), | |
41 angle_(0), | |
42 resizeable_(false), | |
43 pixelSpacingX_(1), | |
44 pixelSpacingY_(1) | |
45 { | |
46 | |
47 } | |
48 | |
49 void RadiographyLayer::Geometry::GetCrop(unsigned int &x, unsigned int &y, unsigned int &width, unsigned int &height) const | |
50 { | |
51 if (!hasCrop_) | |
436
04711a2e12cd
fix crop + export photometric interpretation correctly
am@osimis.io
parents:
432
diff
changeset
|
52 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); // you should probably use RadiographyLayer::GetCrop() or at least call HasCrop() before |
430 | 53 |
54 x = cropX_; | |
55 y = cropY_; | |
56 width = cropWidth_; | |
57 height = cropHeight_; | |
58 } | |
59 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 void RadiographyLayer::UpdateTransform() |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 { |
620 | 62 transform_ = AffineTransform2D::CreateScaling(geometry_.GetScalingX(), geometry_.GetScalingY()); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 double centerX, centerY; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 GetCenter(centerX, centerY); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 transform_ = AffineTransform2D::Combine( |
430 | 68 AffineTransform2D::CreateOffset(geometry_.GetPanX() + centerX, geometry_.GetPanY() + centerY), |
69 AffineTransform2D::CreateRotation(geometry_.GetAngle()), | |
70 AffineTransform2D::CreateOffset(-centerX, -centerY), | |
71 transform_); | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 transformInverse_ = AffineTransform2D::Invert(transform_); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 void RadiographyLayer::AddToExtent(Extent2D& extent, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 double x, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 double y) const |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
81 GetTransform().Apply(x, y); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 extent.AddPoint(x, y); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 bool RadiographyLayer::Contains(double x, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 double y) const |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
88 GetTransformInverse().Apply(x, y); |
430 | 89 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 unsigned int cropX, cropY, cropWidth, cropHeight; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 GetCrop(cropX, cropY, cropWidth, cropHeight); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 return (x >= cropX && x <= cropX + cropWidth && |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 y >= cropY && y <= cropY + cropHeight); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 void RadiographyLayer::DrawBorders(CairoContext& context, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 double zoom) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
101 if (GetControlPointCount() < 3 ) |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
102 return; |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 cairo_t* cr = context.GetObject(); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 cairo_set_line_width(cr, 2.0 / zoom); |
430 | 106 |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
107 ControlPoint cp; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
108 GetControlPoint(cp, 0); |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
109 cairo_move_to(cr, cp.x, cp.y); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
111 for (size_t i = 0; i < GetControlPointCount(); i++) |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
112 { |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
113 GetControlPoint(cp, i); |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
114 cairo_line_to(cr, cp.x, cp.y); |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
115 } |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
117 cairo_close_path(cr); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 cairo_stroke(cr); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
122 RadiographyLayer::RadiographyLayer(MessageBroker& broker, const RadiographyScene& scene) : |
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
123 IObservable(broker), |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 index_(0), |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 hasSize_(false), |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 width_(0), |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 height_(0), |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
128 prefferedPhotometricDisplayMode_(RadiographyPhotometricDisplayMode_Default), |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
129 scene_(scene) |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 UpdateTransform(); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 |
430 | 134 void RadiographyLayer::ResetCrop() |
135 { | |
136 geometry_.ResetCrop(); | |
137 UpdateTransform(); | |
138 } | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
140 void RadiographyLayer::SetPreferredPhotomotricDisplayMode(RadiographyPhotometricDisplayMode prefferedPhotometricDisplayMode) |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
141 { |
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
142 prefferedPhotometricDisplayMode_ = prefferedPhotometricDisplayMode; |
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
143 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
144 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
145 } |
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
146 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 void RadiographyLayer::SetCrop(unsigned int x, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 unsigned int y, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 unsigned int width, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 unsigned int height) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 if (!hasSize_) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 } |
430 | 156 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 if (x + width > width_ || |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 y + height > height_) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 |
430 | 163 geometry_.SetCrop(x, y, width, height); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 UpdateTransform(); |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
165 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
166 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 |
430 | 169 void RadiographyLayer::SetGeometry(const Geometry& geometry) |
170 { | |
171 geometry_ = geometry; | |
172 | |
173 if (hasSize_) | |
174 { | |
175 UpdateTransform(); | |
176 } | |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
177 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
178 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
430 | 179 } |
180 | |
181 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 void RadiographyLayer::GetCrop(unsigned int& x, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 unsigned int& y, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 unsigned int& width, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 unsigned int& height) const |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 { |
430 | 187 if (GetGeometry().HasCrop()) |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 { |
430 | 189 GetGeometry().GetCrop(x, y, width, height); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 } |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
191 else |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 x = 0; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 y = 0; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 width = width_; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 height = height_; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 |
430 | 200 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 void RadiographyLayer::SetAngle(double angle) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 { |
430 | 203 geometry_.SetAngle(angle); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 UpdateTransform(); |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
480
diff
changeset
|
205 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
206 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 |
629 | 209 void RadiographyLayer::SetFlipVertical(bool flip) |
620 | 210 { |
629 | 211 geometry_.SetFlipVertical(flip); |
620 | 212 UpdateTransform(); |
213 | |
659
68b5688241d5
Fixed broken previous merge
Benjamin Golinvaux <bgo@osimis.io>
parents:
658
diff
changeset
|
214 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
620 | 215 } |
216 | |
629 | 217 void RadiographyLayer::SetFlipHorizontal(bool flip) |
620 | 218 { |
629 | 219 geometry_.SetFlipHorizontal(flip); |
620 | 220 UpdateTransform(); |
221 | |
659
68b5688241d5
Fixed broken previous merge
Benjamin Golinvaux <bgo@osimis.io>
parents:
658
diff
changeset
|
222 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
620 | 223 } |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 void RadiographyLayer::SetSize(unsigned int width, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 unsigned int height) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 if (hasSize_ && |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 (width != width_ || |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 height != height_)) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 } |
430 | 234 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 hasSize_ = true; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 width_ = width; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 height_ = height; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 UpdateTransform(); |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
240 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 Extent2D RadiographyLayer::GetExtent() const |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 Extent2D extent; |
430 | 247 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 unsigned int x, y, width, height; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 GetCrop(x, y, width, height); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 double dx = static_cast<double>(x); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 double dy = static_cast<double>(y); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 double dwidth = static_cast<double>(width); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 double dheight = static_cast<double>(height); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 AddToExtent(extent, dx, dy); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 AddToExtent(extent, dx + dwidth, dy); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 AddToExtent(extent, dx, dy + dheight); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 AddToExtent(extent, dx + dwidth, dy + dheight); |
430 | 260 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 return extent; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 bool RadiographyLayer::GetPixel(unsigned int& imageX, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 unsigned int& imageY, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 double sceneX, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 double sceneY) const |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 if (width_ == 0 || |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 height_ == 0) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 return false; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 else |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
277 GetTransformInverse().Apply(sceneX, sceneY); |
430 | 278 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 int x = static_cast<int>(std::floor(sceneX)); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 int y = static_cast<int>(std::floor(sceneY)); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
281 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 if (x < 0) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
284 imageX = 0; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 else if (x >= static_cast<int>(width_)) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 imageX = width_; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 else |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 imageX = static_cast<unsigned int>(x); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 if (y < 0) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 imageY = 0; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 else if (y >= static_cast<int>(height_)) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 imageY = height_; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 else |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 imageY = static_cast<unsigned int>(y); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 return true; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
311 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 void RadiographyLayer::SetPan(double x, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 double y) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 { |
430 | 316 geometry_.SetPan(x, y); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 UpdateTransform(); |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
318 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
321 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 void RadiographyLayer::SetPixelSpacing(double x, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 double y) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 { |
430 | 325 geometry_.SetPixelSpacing(x, y); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
326 UpdateTransform(); |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
327 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
328 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
329 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 void RadiographyLayer::GetCenter(double& centerX, |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 double& centerY) const |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
333 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
334 centerX = static_cast<double>(width_) / 2.0; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
335 centerY = static_cast<double>(height_) / 2.0; |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
336 GetTransform().Apply(centerX, centerY); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 } |
430 | 338 |
339 | |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
340 |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
341 size_t RadiographyLayer::GetControlPointCount() const {return 4;} |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
342 |
480
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
476
diff
changeset
|
343 void RadiographyLayer::GetControlPoint(ControlPoint& cpScene /* out in scene coordinates */, |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
476
diff
changeset
|
344 size_t index) const |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
345 { |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
346 unsigned int cropX, cropY, cropWidth, cropHeight; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 GetCrop(cropX, cropY, cropWidth, cropHeight); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
348 |
480
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
476
diff
changeset
|
349 ControlPoint cp; |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
350 switch (index) |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
351 { |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
352 case RadiographyControlPointType_TopLeftCorner: |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
353 cp = ControlPoint(cropX, cropY, RadiographyControlPointType_TopLeftCorner); |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
354 break; |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
355 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
356 case RadiographyControlPointType_TopRightCorner: |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
357 cp = ControlPoint(cropX + cropWidth, cropY, RadiographyControlPointType_TopRightCorner); |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
358 break; |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
359 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
360 case RadiographyControlPointType_BottomLeftCorner: |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
361 cp = ControlPoint(cropX, cropY + cropHeight, RadiographyControlPointType_BottomLeftCorner); |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
362 break; |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
363 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
364 case RadiographyControlPointType_BottomRightCorner: |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
365 cp = ControlPoint(cropX + cropWidth, cropY + cropHeight, RadiographyControlPointType_BottomRightCorner); |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
659
diff
changeset
|
366 break; |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
367 |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
368 default: |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
369 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
370 } |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
371 |
480
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
476
diff
changeset
|
372 // transforms image coordinates into scene coordinates |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
476
diff
changeset
|
373 GetTransform().Apply(cp.x, cp.y); |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
476
diff
changeset
|
374 cpScene = cp; |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
375 } |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
376 |
480
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
476
diff
changeset
|
377 bool RadiographyLayer::LookupControlPoint(ControlPoint& cpScene /* out */, |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
378 double x, |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
379 double y, |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
380 double zoom, |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
381 double viewportDistance) const |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
382 { |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 double threshold = Square(viewportDistance / zoom); |
430 | 384 |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
385 for (size_t i = 0; i < GetControlPointCount(); i++) |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
387 ControlPoint cp; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
388 GetControlPoint(cp, i); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
389 |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
440
diff
changeset
|
390 double d = Square(cp.x - x) + Square(cp.y - y); |
430 | 391 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
392 if (d <= threshold) |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
393 { |
480
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
476
diff
changeset
|
394 cpScene = cp; |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
395 return true; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
396 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 } |
430 | 398 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
399 return false; |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
400 } |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
401 } |