comparison Framework/Deprecated/Radiography/RadiographyWindowingTracker.cpp @ 1398:c5403d52078c

moved Radiography into Deprecated
author Alain Mazy <alain@mazy.be>
date Wed, 29 Apr 2020 20:43:09 +0200
parents Framework/Radiography/RadiographyWindowingTracker.cpp@2d8ab34c8c91
children 30deba7bc8e2
comparison
equal deleted inserted replaced
1397:1c2d065ba372 1398:c5403d52078c
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "RadiographyWindowingTracker.h"
23 #include "RadiographyWidget.h"
24
25 #include <Core/OrthancException.h>
26
27
28 namespace OrthancStone
29 {
30 class RadiographyWindowingTracker::UndoRedoCommand : public UndoRedoStack::ICommand
31 {
32 private:
33 RadiographyScene& scene_;
34 float sourceCenter_;
35 float sourceWidth_;
36 float targetCenter_;
37 float targetWidth_;
38
39 public:
40 UndoRedoCommand(const RadiographyWindowingTracker& tracker) :
41 scene_(tracker.scene_),
42 sourceCenter_(tracker.sourceCenter_),
43 sourceWidth_(tracker.sourceWidth_)
44 {
45 scene_.GetWindowingWithDefault(targetCenter_, targetWidth_);
46 }
47
48 virtual void Undo() const
49 {
50 scene_.SetWindowing(sourceCenter_, sourceWidth_);
51 }
52
53 virtual void Redo() const
54 {
55 scene_.SetWindowing(targetCenter_, targetWidth_);
56 }
57 };
58
59
60 void RadiographyWindowingTracker::ComputeAxisEffect(int& deltaCenter,
61 int& deltaWidth,
62 int delta,
63 Action actionNegative,
64 Action actionPositive)
65 {
66 if (delta < 0)
67 {
68 switch (actionNegative)
69 {
70 case Action_IncreaseWidth:
71 deltaWidth = -delta;
72 break;
73
74 case Action_DecreaseWidth:
75 deltaWidth = delta;
76 break;
77
78 case Action_IncreaseCenter:
79 deltaCenter = -delta;
80 break;
81
82 case Action_DecreaseCenter:
83 deltaCenter = delta;
84 break;
85
86 default:
87 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
88 }
89 }
90 else if (delta > 0)
91 {
92 switch (actionPositive)
93 {
94 case Action_IncreaseWidth:
95 deltaWidth = delta;
96 break;
97
98 case Action_DecreaseWidth:
99 deltaWidth = -delta;
100 break;
101
102 case Action_IncreaseCenter:
103 deltaCenter = delta;
104 break;
105
106 case Action_DecreaseCenter:
107 deltaCenter = -delta;
108 break;
109
110 default:
111 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
112 }
113 }
114 }
115
116
117 RadiographyWindowingTracker::RadiographyWindowingTracker(UndoRedoStack& undoRedoStack,
118 RadiographyScene& scene,
119 RadiographyWidget& widget,
120 ImageInterpolation interpolationDuringTracking,
121 int x,
122 int y,
123 Action leftAction,
124 Action rightAction,
125 Action upAction,
126 Action downAction) :
127 undoRedoStack_(undoRedoStack),
128 scene_(scene),
129 widget_(widget),
130 initialWidgetInterpolation_(widget.GetInterpolation()),
131 clickX_(x),
132 clickY_(y),
133 leftAction_(leftAction),
134 rightAction_(rightAction),
135 upAction_(upAction),
136 downAction_(downAction)
137 {
138 scene_.GetWindowingWithDefault(sourceCenter_, sourceWidth_);
139 widget_.SetInterpolation(interpolationDuringTracking);
140
141 float minValue, maxValue;
142 scene.GetRange(minValue, maxValue);
143
144 assert(minValue <= maxValue);
145
146 float delta = (maxValue - minValue);
147 strength_ = delta / 1000.0f; // 1px move will change the ww/wc by 0.1%
148
149 if (strength_ < 1)
150 {
151 strength_ = 1;
152 }
153 }
154
155
156 void RadiographyWindowingTracker::Render(CairoContext& context,
157 double zoom)
158 {
159 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
160 }
161
162
163 void RadiographyWindowingTracker::MouseUp()
164 {
165 widget_.SetInterpolation(initialWidgetInterpolation_);
166 undoRedoStack_.Add(new UndoRedoCommand(*this));
167 }
168
169
170 void RadiographyWindowingTracker::MouseMove(int displayX,
171 int displayY,
172 double sceneX,
173 double sceneY,
174 const std::vector<Deprecated::Touch>& displayTouches,
175 const std::vector<Deprecated::Touch>& sceneTouches)
176 {
177 // This follows the behavior of the Osimis Web viewer:
178 // https://bitbucket.org/osimis/osimis-webviewer-plugin/src/master/frontend/src/app/viewport/image-plugins/windowing-viewport-tool.class.js
179
180 static const float SCALE = 1.0;
181
182 int deltaCenter = 0;
183 int deltaWidth = 0;
184
185 ComputeAxisEffect(deltaCenter, deltaWidth, displayX - clickX_, leftAction_, rightAction_);
186 ComputeAxisEffect(deltaCenter, deltaWidth, displayY - clickY_, upAction_, downAction_);
187
188 float newCenter = sourceCenter_ + (deltaCenter / SCALE * strength_);
189 float newWidth = sourceWidth_ + (deltaWidth / SCALE * strength_);
190 scene_.SetWindowing(newCenter, newWidth);
191 }
192 }