Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographyWindowingTracker.cpp @ 415:c0589c3173fd
finished reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 13 Nov 2018 10:36:53 +0100 |
parents | |
children | b70e9be013e4 |
comparison
equal
deleted
inserted
replaced
414:f7616c010056 | 415:c0589c3173fd |
---|---|
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-2018 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 | |
24 #include <Core/OrthancException.h> | |
25 | |
26 | |
27 namespace OrthancStone | |
28 { | |
29 class RadiographyWindowingTracker::UndoRedoCommand : public UndoRedoStack::ICommand | |
30 { | |
31 private: | |
32 RadiographyScene& scene_; | |
33 float sourceCenter_; | |
34 float sourceWidth_; | |
35 float targetCenter_; | |
36 float targetWidth_; | |
37 | |
38 public: | |
39 UndoRedoCommand(const RadiographyWindowingTracker& tracker) : | |
40 scene_(tracker.scene_), | |
41 sourceCenter_(tracker.sourceCenter_), | |
42 sourceWidth_(tracker.sourceWidth_) | |
43 { | |
44 scene_.GetWindowingWithDefault(targetCenter_, targetWidth_); | |
45 } | |
46 | |
47 virtual void Undo() const | |
48 { | |
49 scene_.SetWindowing(sourceCenter_, sourceWidth_); | |
50 } | |
51 | |
52 virtual void Redo() const | |
53 { | |
54 scene_.SetWindowing(targetCenter_, targetWidth_); | |
55 } | |
56 }; | |
57 | |
58 | |
59 void RadiographyWindowingTracker::ComputeAxisEffect(int& deltaCenter, | |
60 int& deltaWidth, | |
61 int delta, | |
62 Action actionNegative, | |
63 Action actionPositive) | |
64 { | |
65 if (delta < 0) | |
66 { | |
67 switch (actionNegative) | |
68 { | |
69 case Action_IncreaseWidth: | |
70 deltaWidth = -delta; | |
71 break; | |
72 | |
73 case Action_DecreaseWidth: | |
74 deltaWidth = delta; | |
75 break; | |
76 | |
77 case Action_IncreaseCenter: | |
78 deltaCenter = -delta; | |
79 break; | |
80 | |
81 case Action_DecreaseCenter: | |
82 deltaCenter = delta; | |
83 break; | |
84 | |
85 default: | |
86 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
87 } | |
88 } | |
89 else if (delta > 0) | |
90 { | |
91 switch (actionPositive) | |
92 { | |
93 case Action_IncreaseWidth: | |
94 deltaWidth = delta; | |
95 break; | |
96 | |
97 case Action_DecreaseWidth: | |
98 deltaWidth = -delta; | |
99 break; | |
100 | |
101 case Action_IncreaseCenter: | |
102 deltaCenter = delta; | |
103 break; | |
104 | |
105 case Action_DecreaseCenter: | |
106 deltaCenter = -delta; | |
107 break; | |
108 | |
109 default: | |
110 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
111 } | |
112 } | |
113 } | |
114 | |
115 | |
116 RadiographyWindowingTracker::RadiographyWindowingTracker(UndoRedoStack& undoRedoStack, | |
117 RadiographyScene& scene, | |
118 int x, | |
119 int y, | |
120 Action leftAction, | |
121 Action rightAction, | |
122 Action upAction, | |
123 Action downAction) : | |
124 undoRedoStack_(undoRedoStack), | |
125 scene_(scene), | |
126 clickX_(x), | |
127 clickY_(y), | |
128 leftAction_(leftAction), | |
129 rightAction_(rightAction), | |
130 upAction_(upAction), | |
131 downAction_(downAction) | |
132 { | |
133 scene_.GetWindowingWithDefault(sourceCenter_, sourceWidth_); | |
134 | |
135 float minValue, maxValue; | |
136 scene.GetRange(minValue, maxValue); | |
137 | |
138 assert(minValue <= maxValue); | |
139 | |
140 float tmp; | |
141 | |
142 float delta = (maxValue - minValue); | |
143 if (delta <= 1) | |
144 { | |
145 tmp = 0; | |
146 } | |
147 else | |
148 { | |
149 // NB: Visual Studio 2008 does not provide "log2f()", so we | |
150 // implement it by ourselves | |
151 tmp = logf(delta) / logf(2.0f); | |
152 } | |
153 | |
154 strength_ = tmp - 7; | |
155 if (strength_ < 1) | |
156 { | |
157 strength_ = 1; | |
158 } | |
159 } | |
160 | |
161 | |
162 void RadiographyWindowingTracker::Render(CairoContext& context, | |
163 double zoom) | |
164 { | |
165 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
166 } | |
167 | |
168 | |
169 void RadiographyWindowingTracker::MouseUp() | |
170 { | |
171 undoRedoStack_.Add(new UndoRedoCommand(*this)); | |
172 } | |
173 | |
174 | |
175 void RadiographyWindowingTracker::MouseMove(int displayX, | |
176 int displayY, | |
177 double sceneX, | |
178 double sceneY) | |
179 { | |
180 // This follows the behavior of the Osimis Web viewer: | |
181 // https://bitbucket.org/osimis/osimis-webviewer-plugin/src/master/frontend/src/app/viewport/image-plugins/windowing-viewport-tool.class.js | |
182 | |
183 static const float SCALE = 1.0; | |
184 | |
185 int deltaCenter = 0; | |
186 int deltaWidth = 0; | |
187 | |
188 ComputeAxisEffect(deltaCenter, deltaWidth, displayX - clickX_, leftAction_, rightAction_); | |
189 ComputeAxisEffect(deltaCenter, deltaWidth, displayY - clickY_, upAction_, downAction_); | |
190 | |
191 float newCenter = sourceCenter_ + (deltaCenter / SCALE * strength_); | |
192 float newWidth = sourceWidth_ + (deltaWidth / SCALE * strength_); | |
193 scene_.SetWindowing(newCenter, newWidth); | |
194 } | |
195 } |