Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyLayerResizeTracker.cpp @ 1092:5a35688c4874
Added tag toa2019102301 for changeset 5a18e6a395bc
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 23 Oct 2019 15:34:58 +0200 |
parents | be9c1530d40a |
children | 2d8ab34c8c91 |
rev | line source |
---|---|
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
c0589c3173fd
finished reorganization
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 |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "RadiographyLayerResizeTracker.h" |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "RadiographySceneCommand.h" |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include <Core/OrthancException.h> |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include <boost/math/special_functions/round.hpp> |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 namespace OrthancStone |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 static double ComputeDistance(double x1, |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 double y1, |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 double x2, |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 double y2) |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 double dx = x1 - x2; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 double dy = y1 - y2; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 return sqrt(dx * dx + dy * dy); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 class RadiographyLayerResizeTracker::UndoRedoCommand : public RadiographySceneCommand |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 private: |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 double sourceSpacingX_; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 double sourceSpacingY_; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 double sourcePanX_; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 double sourcePanY_; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 double targetSpacingX_; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 double targetSpacingY_; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 double targetPanX_; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 double targetPanY_; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 protected: |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 virtual void UndoInternal(RadiographyLayer& layer) const |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 layer.SetPixelSpacing(sourceSpacingX_, sourceSpacingY_); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 layer.SetPan(sourcePanX_, sourcePanY_); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 virtual void RedoInternal(RadiographyLayer& layer) const |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 layer.SetPixelSpacing(targetSpacingX_, targetSpacingY_); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 layer.SetPan(targetPanX_, targetPanY_); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 public: |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 UndoRedoCommand(const RadiographyLayerResizeTracker& tracker) : |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 RadiographySceneCommand(tracker.accessor_), |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 sourceSpacingX_(tracker.originalSpacingX_), |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 sourceSpacingY_(tracker.originalSpacingY_), |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 sourcePanX_(tracker.originalPanX_), |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 sourcePanY_(tracker.originalPanY_), |
430 | 76 targetSpacingX_(tracker.accessor_.GetLayer().GetGeometry().GetPixelSpacingX()), |
77 targetSpacingY_(tracker.accessor_.GetLayer().GetGeometry().GetPixelSpacingY()), | |
78 targetPanX_(tracker.accessor_.GetLayer().GetGeometry().GetPanX()), | |
79 targetPanY_(tracker.accessor_.GetLayer().GetGeometry().GetPanY()) | |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 }; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 RadiographyLayerResizeTracker::RadiographyLayerResizeTracker(UndoRedoStack& undoRedoStack, |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 RadiographyScene& scene, |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 size_t layer, |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
457
diff
changeset
|
88 const ControlPoint& startControlPoint, |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 bool roundScaling) : |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 undoRedoStack_(undoRedoStack), |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 accessor_(scene, layer), |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 roundScaling_(roundScaling) |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 if (accessor_.IsValid() && |
430 | 95 accessor_.GetLayer().GetGeometry().IsResizeable()) |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 { |
430 | 97 originalSpacingX_ = accessor_.GetLayer().GetGeometry().GetPixelSpacingX(); |
98 originalSpacingY_ = accessor_.GetLayer().GetGeometry().GetPixelSpacingY(); | |
99 originalPanX_ = accessor_.GetLayer().GetGeometry().GetPanX(); | |
100 originalPanY_ = accessor_.GetLayer().GetGeometry().GetPanY(); | |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
457
diff
changeset
|
102 size_t oppositeControlPointType; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
457
diff
changeset
|
103 switch (startControlPoint.index) |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 { |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
105 case RadiographyControlPointType_TopLeftCorner: |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
106 oppositeControlPointType = RadiographyControlPointType_BottomRightCorner; |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 break; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
109 case RadiographyControlPointType_TopRightCorner: |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
110 oppositeControlPointType = RadiographyControlPointType_BottomLeftCorner; |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 break; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
113 case RadiographyControlPointType_BottomLeftCorner: |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
114 oppositeControlPointType = RadiographyControlPointType_TopRightCorner; |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 break; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
117 case RadiographyControlPointType_BottomRightCorner: |
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
118 oppositeControlPointType = RadiographyControlPointType_TopLeftCorner; |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 break; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 default: |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
457
diff
changeset
|
125 accessor_.GetLayer().GetControlPoint(startOppositeControlPoint_, oppositeControlPointType); |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
457
diff
changeset
|
127 double d = ComputeDistance(startControlPoint.x, startControlPoint.y, startOppositeControlPoint_.x, startOppositeControlPoint_.y); |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 if (d >= std::numeric_limits<float>::epsilon()) |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 baseScaling_ = 1.0 / d; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 else |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 // Avoid division by zero in extreme cases |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 accessor_.Invalidate(); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 void RadiographyLayerResizeTracker::Render(CairoContext& context, |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 double zoom) |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 void RadiographyLayerResizeTracker::MouseUp() |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 if (accessor_.IsValid() && |
430 | 151 accessor_.GetLayer().GetGeometry().IsResizeable()) |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 void RadiographyLayerResizeTracker::MouseMove(int displayX, |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 int displayY, |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 double sceneX, |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
440
diff
changeset
|
161 double sceneY, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
162 const std::vector<Deprecated::Touch>& displayTouches, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
163 const std::vector<Deprecated::Touch>& sceneTouches) |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 static const double ROUND_SCALING = 0.1; |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 if (accessor_.IsValid() && |
430 | 168 accessor_.GetLayer().GetGeometry().IsResizeable()) |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
457
diff
changeset
|
170 double scaling = ComputeDistance(startOppositeControlPoint_.x, startOppositeControlPoint_.y, sceneX, sceneY) * baseScaling_; |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 if (roundScaling_) |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 { |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 scaling = boost::math::round<double>((scaling / ROUND_SCALING) * ROUND_SCALING); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 RadiographyLayer& layer = accessor_.GetLayer(); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 layer.SetPixelSpacing(scaling * originalSpacingX_, |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 scaling * originalSpacingY_); |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 // Keep the opposite corner at a fixed location |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
457
diff
changeset
|
182 ControlPoint currentOppositeCorner; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
457
diff
changeset
|
183 layer.GetControlPoint(currentOppositeCorner, startOppositeControlPoint_.index); |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
457
diff
changeset
|
184 layer.SetPan(layer.GetGeometry().GetPanX() + startOppositeControlPoint_.x - currentOppositeCorner.x, |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
457
diff
changeset
|
185 layer.GetGeometry().GetPanY() + startOppositeControlPoint_.y - currentOppositeCorner.y); |
415
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 } |
c0589c3173fd
finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 } |