annotate Framework/Radiography/RadiographyLayer.cpp @ 525:2549363fadc3 am-touch-events

Close branch am-touch-events.
author Alain Mazy <am@osimis.io>
date Tue, 12 Mar 2019 17:29:12 +0000
parents 77e0eb83ff63
children fd9b9d993fc7 42dadae61fa9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 410
diff changeset
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
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
35 RadiographyLayer::Geometry::Geometry() :
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
36 hasCrop_(false),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
37 panX_(0),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
38 panY_(0),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
39 angle_(0),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
40 resizeable_(false),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
41 pixelSpacingX_(1),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
42 pixelSpacingY_(1)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
43 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
44
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
45 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
46
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
47 void RadiographyLayer::Geometry::GetCrop(unsigned int &x, unsigned int &y, unsigned int &width, unsigned int &height) const
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
48 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
49 if (!hasCrop_)
436
04711a2e12cd fix crop + export photometric interpretation correctly
am@osimis.io
parents: 432
diff changeset
50 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); // you should probably use RadiographyLayer::GetCrop() or at least call HasCrop() before
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
51
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
52 x = cropX_;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
53 y = cropY_;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
54 width = cropWidth_;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
55 height = cropHeight_;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
56 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
57
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 void RadiographyLayer::UpdateTransform()
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
60 transform_ = AffineTransform2D::CreateScaling(geometry_.GetPixelSpacingX(), geometry_.GetPixelSpacingY());
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 double centerX, centerY;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 GetCenter(centerX, centerY);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 transform_ = AffineTransform2D::Combine(
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
66 AffineTransform2D::CreateOffset(geometry_.GetPanX() + centerX, geometry_.GetPanY() + centerY),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
67 AffineTransform2D::CreateRotation(geometry_.GetAngle()),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
68 AffineTransform2D::CreateOffset(-centerX, -centerY),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
69 transform_);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 transformInverse_ = AffineTransform2D::Invert(transform_);
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
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 void RadiographyLayer::AddToExtent(Extent2D& extent,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 double x,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 double y) const
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
79 GetTransform().Apply(x, y);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 extent.AddPoint(x, y);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 bool RadiographyLayer::Contains(double x,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 double y) const
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
86 GetTransformInverse().Apply(x, y);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
87
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 unsigned int cropX, cropY, cropWidth, cropHeight;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 GetCrop(cropX, cropY, cropWidth, cropHeight);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 return (x >= cropX && x <= cropX + cropWidth &&
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 y >= cropY && y <= cropY + cropHeight);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
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 void RadiographyLayer::DrawBorders(CairoContext& context,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 double zoom)
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
99 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
100 return;
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 cairo_t* cr = context.GetObject();
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 cairo_set_line_width(cr, 2.0 / zoom);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
104
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
105 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
106 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
107 cairo_move_to(cr, cp.x, cp.y);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
109 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
110 {
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
111 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
112 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
113 }
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
115 cairo_close_path(cr);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 cairo_stroke(cr);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
120 RadiographyLayer::RadiographyLayer(MessageBroker& broker, const RadiographyScene& scene) :
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
121 IObservable(broker),
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 index_(0),
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 hasSize_(false),
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 width_(0),
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 height_(0),
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
126 prefferedPhotometricDisplayMode_(PhotometricDisplayMode_Default),
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
127 scene_(scene)
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 UpdateTransform();
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
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
132 void RadiographyLayer::ResetCrop()
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
133 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
134 geometry_.ResetCrop();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
135 UpdateTransform();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
136 }
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
138 void RadiographyLayer::SetPreferredPhotomotricDisplayMode(PhotometricDisplayMode prefferedPhotometricDisplayMode)
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
139 {
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
140 prefferedPhotometricDisplayMode_ = prefferedPhotometricDisplayMode;
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 EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
143 }
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
144
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 void RadiographyLayer::SetCrop(unsigned int x,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 unsigned int y,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 unsigned int width,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 unsigned int height)
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 if (!hasSize_)
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
154
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 if (x + width > width_ ||
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 y + height > height_)
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
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
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
161 geometry_.SetCrop(x, y, width, height);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 UpdateTransform();
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
163
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
164 EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
167 void RadiographyLayer::SetGeometry(const Geometry& geometry)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
168 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
169 geometry_ = geometry;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
170
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
171 if (hasSize_)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
172 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
173 UpdateTransform();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
174 }
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
175
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
176 EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
177 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
178
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
179
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 void RadiographyLayer::GetCrop(unsigned int& x,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 unsigned int& y,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 unsigned int& width,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 unsigned int& height) const
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
185 if (GetGeometry().HasCrop())
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
187 GetGeometry().GetCrop(x, y, width, height);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
189 else
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 x = 0;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 y = 0;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 width = width_;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 height = height_;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
198
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 void RadiographyLayer::SetAngle(double angle)
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
201 geometry_.SetAngle(angle);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 UpdateTransform();
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
203
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
204 EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
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 void RadiographyLayer::SetSize(unsigned int width,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 unsigned int height)
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 if (hasSize_ &&
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 (width != width_ ||
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 height != height_))
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
217
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 hasSize_ = true;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 width_ = width;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 height_ = height;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 UpdateTransform();
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
223 EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
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
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 Extent2D RadiographyLayer::GetExtent() const
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 Extent2D extent;
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
230
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 unsigned int x, y, width, height;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 GetCrop(x, y, width, height);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 double dx = static_cast<double>(x);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 double dy = static_cast<double>(y);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 double dwidth = static_cast<double>(width);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 double dheight = static_cast<double>(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 AddToExtent(extent, dx, dy);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 AddToExtent(extent, dx + dwidth, dy);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 AddToExtent(extent, dx, dy + dheight);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 AddToExtent(extent, dx + dwidth, dy + dheight);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
243
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 return extent;
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
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 bool RadiographyLayer::GetPixel(unsigned int& imageX,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 unsigned int& imageY,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 double sceneX,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 double sceneY) const
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 if (width_ == 0 ||
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 height_ == 0)
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 return false;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 else
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
260 GetTransformInverse().Apply(sceneX, sceneY);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
261
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 int x = static_cast<int>(std::floor(sceneX));
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 int y = static_cast<int>(std::floor(sceneY));
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 if (x < 0)
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 imageX = 0;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 else if (x >= static_cast<int>(width_))
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 imageX = width_;
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 else
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 imageX = static_cast<unsigned int>(x);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 if (y < 0)
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 imageY = 0;
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 else if (y >= static_cast<int>(height_))
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 imageY = height_;
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
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 imageY = static_cast<unsigned int>(y);
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
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 return true;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 }
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
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 void RadiographyLayer::SetPan(double x,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 double y)
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
299 geometry_.SetPan(x, y);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 UpdateTransform();
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
301 EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
410
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
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 void RadiographyLayer::SetPixelSpacing(double x,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 double y)
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
308 geometry_.SetPixelSpacing(x, y);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 UpdateTransform();
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 480
diff changeset
310 EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
410
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
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 void RadiographyLayer::GetCenter(double& centerX,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 double& centerY) const
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 centerX = static_cast<double>(width_) / 2.0;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 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
319 GetTransform().Apply(centerX, centerY);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
321
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
322
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
323
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
324 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
325
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
326 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
327 size_t index) const
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 unsigned int cropX, cropY, cropWidth, cropHeight;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 GetCrop(cropX, cropY, cropWidth, cropHeight);
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
332 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
333 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
334 {
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
335 case ControlPoint_TopLeftCorner:
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
336 cp = ControlPoint(cropX, cropY, ControlPoint_TopLeftCorner);
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
337 break;
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
338
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
339 case ControlPoint_TopRightCorner:
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
340 cp = ControlPoint(cropX + cropWidth, cropY, ControlPoint_TopRightCorner);
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
341 break;
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
342
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
343 case ControlPoint_BottomLeftCorner:
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
344 cp = ControlPoint(cropX, cropY + cropHeight, ControlPoint_BottomLeftCorner);
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
345 break;
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
346
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
347 case ControlPoint_BottomRightCorner:
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
348 cp = ControlPoint(cropX + cropWidth, cropY + cropHeight, ControlPoint_BottomRightCorner);
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
349 break;
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
350
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
351 default:
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
352 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
353 }
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
354
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
355 // transforms image coordinates into scene coordinates
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
356 GetTransform().Apply(cp.x, cp.y);
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
357 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
358 }
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
359
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
360 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
361 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
362 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
363 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
364 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
365 {
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 double threshold = Square(viewportDistance / zoom);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
367
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
368 for (size_t i = 0; i < GetControlPointCount(); i++)
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 {
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
370 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
371 GetControlPoint(cp, i);
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 440
diff changeset
373 double d = Square(cp.x - x) + Square(cp.y - y);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
374
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 if (d <= threshold)
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 476
diff changeset
377 cpScene = cp;
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 return true;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 410
diff changeset
381
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 return false;
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 }
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 }