Mercurial > hg > orthanc-stone
annotate Applications/Samples/SingleFrameEditorApplication.h @ 414:f7616c010056
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 12 Nov 2018 18:00:48 +0100 |
parents | 18b707fb8620 |
children | c0589c3173fd |
rev | line source |
---|---|
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
1 /** |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2 * Stone of Orthanc |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
6 * |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
11 * |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
16 * |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
19 **/ |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
20 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
21 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
22 #pragma once |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
23 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
24 #include "SampleApplicationBase.h" |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
25 |
414 | 26 #include "../../Framework/Radiography/RadiographyLayerMoveTracker.h" |
27 #include "../../Framework/Radiography/RadiographyLayerRotateTracker.h" | |
408 | 28 #include "../../Framework/Radiography/RadiographyScene.h" |
414 | 29 #include "../../Framework/Radiography/RadiographySceneCommand.h" |
413 | 30 #include "../../Framework/Radiography/RadiographyWidget.h" |
408 | 31 |
32 #include "../../Framework/Toolbox/UndoRedoStack.h" | |
359
100df90bf0ea
preparing to implement Export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
358
diff
changeset
|
33 |
343 | 34 #include <Core/Images/FontRegistry.h> |
359
100df90bf0ea
preparing to implement Export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
358
diff
changeset
|
35 #include <Core/Images/Image.h> |
339 | 36 #include <Core/Images/ImageProcessing.h> |
338 | 37 #include <Core/Images/PamReader.h> |
361
f559ac66ef55
first export of a dicom image
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
360
diff
changeset
|
38 #include <Core/Images/PamWriter.h> |
362
12cec26d08ce
export of a valid DICOM CR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
361
diff
changeset
|
39 #include <Core/Images/PngWriter.h> |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
40 #include <Core/Logging.h> |
403 | 41 #include <Core/OrthancException.h> |
361
f559ac66ef55
first export of a dicom image
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
360
diff
changeset
|
42 #include <Core/Toolbox.h> |
359
100df90bf0ea
preparing to implement Export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
358
diff
changeset
|
43 #include <Plugins/Samples/Common/DicomDatasetReader.h> |
338 | 44 #include <Plugins/Samples/Common/FullOrthancDataset.h> |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
45 |
407 | 46 |
47 // Export using PAM is faster than using PNG, but requires Orthanc | |
48 // core >= 1.4.3 | |
362
12cec26d08ce
export of a valid DICOM CR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
361
diff
changeset
|
49 #define EXPORT_USING_PAM 1 |
12cec26d08ce
export of a valid DICOM CR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
361
diff
changeset
|
50 |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
51 |
376
70256a53ff21
fix compatibility with Visual Studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
369
diff
changeset
|
52 #include <boost/math/special_functions/round.hpp> |
70256a53ff21
fix compatibility with Visual Studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
369
diff
changeset
|
53 |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
54 |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
55 namespace OrthancStone |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
56 { |
408 | 57 class RadiographyLayerCropTracker : public IWorldSceneMouseTracker |
354 | 58 { |
59 private: | |
408 | 60 UndoRedoStack& undoRedoStack_; |
61 RadiographyScene::LayerAccessor accessor_; | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
62 Corner corner_; |
408 | 63 unsigned int cropX_; |
64 unsigned int cropY_; | |
65 unsigned int cropWidth_; | |
66 unsigned int cropHeight_; | |
407 | 67 |
413 | 68 class UndoRedoCommand : public RadiographySceneCommand |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
69 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
70 private: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
71 unsigned int sourceCropX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
72 unsigned int sourceCropY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
73 unsigned int sourceCropWidth_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
74 unsigned int sourceCropHeight_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
75 unsigned int targetCropX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
76 unsigned int targetCropY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
77 unsigned int targetCropWidth_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
78 unsigned int targetCropHeight_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
79 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
80 protected: |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
81 virtual void UndoInternal(RadiographyLayer& layer) const |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
82 { |
407 | 83 layer.SetCrop(sourceCropX_, sourceCropY_, sourceCropWidth_, sourceCropHeight_); |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
84 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
85 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
86 virtual void RedoInternal(RadiographyLayer& layer) const |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
87 { |
407 | 88 layer.SetCrop(targetCropX_, targetCropY_, targetCropWidth_, targetCropHeight_); |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
89 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
90 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
91 public: |
408 | 92 UndoRedoCommand(const RadiographyLayerCropTracker& tracker) : |
413 | 93 RadiographySceneCommand(tracker.accessor_), |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
94 sourceCropX_(tracker.cropX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
95 sourceCropY_(tracker.cropY_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
96 sourceCropWidth_(tracker.cropWidth_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
97 sourceCropHeight_(tracker.cropHeight_) |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
98 { |
407 | 99 tracker.accessor_.GetLayer().GetCrop(targetCropX_, targetCropY_, |
100 targetCropWidth_, targetCropHeight_); | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
101 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
102 }; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
103 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
104 |
354 | 105 public: |
408 | 106 RadiographyLayerCropTracker(UndoRedoStack& undoRedoStack, |
107 RadiographyScene& scene, | |
108 const ViewportGeometry& view, | |
109 size_t layer, | |
110 double x, | |
111 double y, | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
112 Corner corner) : |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
113 undoRedoStack_(undoRedoStack), |
407 | 114 accessor_(scene, layer), |
354 | 115 corner_(corner) |
116 { | |
117 if (accessor_.IsValid()) | |
118 { | |
407 | 119 accessor_.GetLayer().GetCrop(cropX_, cropY_, cropWidth_, cropHeight_); |
354 | 120 } |
121 } | |
122 | |
123 virtual bool HasRender() const | |
124 { | |
125 return false; | |
126 } | |
127 | |
128 virtual void Render(CairoContext& context, | |
129 double zoom) | |
130 { | |
131 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
132 } | |
133 | |
134 virtual void MouseUp() | |
135 { | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
136 if (accessor_.IsValid()) |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
137 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
138 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
139 } |
354 | 140 } |
141 | |
142 virtual void MouseMove(int displayX, | |
143 int displayY, | |
144 double sceneX, | |
145 double sceneY) | |
146 { | |
147 if (accessor_.IsValid()) | |
148 { | |
149 unsigned int x, y; | |
150 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
151 RadiographyLayer& layer = accessor_.GetLayer(); |
407 | 152 if (layer.GetPixel(x, y, sceneX, sceneY)) |
354 | 153 { |
154 unsigned int targetX, targetWidth; | |
155 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
156 if (corner_ == Corner_TopLeft || |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
157 corner_ == Corner_BottomLeft) |
354 | 158 { |
159 targetX = std::min(x, cropX_ + cropWidth_); | |
160 targetWidth = cropX_ + cropWidth_ - targetX; | |
161 } | |
162 else | |
163 { | |
164 targetX = cropX_; | |
165 targetWidth = std::max(x, cropX_) - cropX_; | |
166 } | |
167 | |
168 unsigned int targetY, targetHeight; | |
169 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
170 if (corner_ == Corner_TopLeft || |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
171 corner_ == Corner_TopRight) |
354 | 172 { |
173 targetY = std::min(y, cropY_ + cropHeight_); | |
174 targetHeight = cropY_ + cropHeight_ - targetY; | |
175 } | |
176 else | |
177 { | |
178 targetY = cropY_; | |
179 targetHeight = std::max(y, cropY_) - cropY_; | |
180 } | |
181 | |
407 | 182 layer.SetCrop(targetX, targetY, targetWidth, targetHeight); |
354 | 183 } |
184 } | |
185 } | |
186 }; | |
187 | |
188 | |
408 | 189 class RadiographyLayerResizeTracker : public IWorldSceneMouseTracker |
354 | 190 { |
191 private: | |
408 | 192 UndoRedoStack& undoRedoStack_; |
193 RadiographyScene::LayerAccessor accessor_; | |
194 bool roundScaling_; | |
195 double originalSpacingX_; | |
196 double originalSpacingY_; | |
197 double originalPanX_; | |
198 double originalPanY_; | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
199 Corner oppositeCorner_; |
408 | 200 double oppositeX_; |
201 double oppositeY_; | |
202 double baseScaling_; | |
354 | 203 |
204 static double ComputeDistance(double x1, | |
205 double y1, | |
206 double x2, | |
207 double y2) | |
208 { | |
209 double dx = x1 - x2; | |
210 double dy = y1 - y2; | |
211 return sqrt(dx * dx + dy * dy); | |
212 } | |
213 | |
413 | 214 class UndoRedoCommand : public RadiographySceneCommand |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
215 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
216 private: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
217 double sourceSpacingX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
218 double sourceSpacingY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
219 double sourcePanX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
220 double sourcePanY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
221 double targetSpacingX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
222 double targetSpacingY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
223 double targetPanX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
224 double targetPanY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
225 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
226 protected: |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
227 virtual void UndoInternal(RadiographyLayer& layer) const |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
228 { |
407 | 229 layer.SetPixelSpacing(sourceSpacingX_, sourceSpacingY_); |
230 layer.SetPan(sourcePanX_, sourcePanY_); | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
231 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
232 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
233 virtual void RedoInternal(RadiographyLayer& layer) const |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
234 { |
407 | 235 layer.SetPixelSpacing(targetSpacingX_, targetSpacingY_); |
236 layer.SetPan(targetPanX_, targetPanY_); | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
237 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
238 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
239 public: |
408 | 240 UndoRedoCommand(const RadiographyLayerResizeTracker& tracker) : |
413 | 241 RadiographySceneCommand(tracker.accessor_), |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
242 sourceSpacingX_(tracker.originalSpacingX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
243 sourceSpacingY_(tracker.originalSpacingY_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
244 sourcePanX_(tracker.originalPanX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
245 sourcePanY_(tracker.originalPanY_), |
407 | 246 targetSpacingX_(tracker.accessor_.GetLayer().GetPixelSpacingX()), |
247 targetSpacingY_(tracker.accessor_.GetLayer().GetPixelSpacingY()), | |
248 targetPanX_(tracker.accessor_.GetLayer().GetPanX()), | |
249 targetPanY_(tracker.accessor_.GetLayer().GetPanY()) | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
250 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
251 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
252 }; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
253 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
254 |
354 | 255 public: |
408 | 256 RadiographyLayerResizeTracker(UndoRedoStack& undoRedoStack, |
257 RadiographyScene& scene, | |
258 size_t layer, | |
259 double x, | |
260 double y, | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
261 Corner corner, |
408 | 262 bool roundScaling) : |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
263 undoRedoStack_(undoRedoStack), |
407 | 264 accessor_(scene, layer), |
354 | 265 roundScaling_(roundScaling) |
266 { | |
267 if (accessor_.IsValid() && | |
407 | 268 accessor_.GetLayer().IsResizeable()) |
354 | 269 { |
407 | 270 originalSpacingX_ = accessor_.GetLayer().GetPixelSpacingX(); |
271 originalSpacingY_ = accessor_.GetLayer().GetPixelSpacingY(); | |
272 originalPanX_ = accessor_.GetLayer().GetPanX(); | |
273 originalPanY_ = accessor_.GetLayer().GetPanY(); | |
354 | 274 |
275 switch (corner) | |
276 { | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
277 case Corner_TopLeft: |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
278 oppositeCorner_ = Corner_BottomRight; |
354 | 279 break; |
280 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
281 case Corner_TopRight: |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
282 oppositeCorner_ = Corner_BottomLeft; |
354 | 283 break; |
284 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
285 case Corner_BottomLeft: |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
286 oppositeCorner_ = Corner_TopRight; |
354 | 287 break; |
288 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
289 case Corner_BottomRight: |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
290 oppositeCorner_ = Corner_TopLeft; |
354 | 291 break; |
292 | |
293 default: | |
294 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
295 } | |
296 | |
407 | 297 accessor_.GetLayer().GetCorner(oppositeX_, oppositeY_, oppositeCorner_); |
354 | 298 |
299 double d = ComputeDistance(x, y, oppositeX_, oppositeY_); | |
300 if (d >= std::numeric_limits<float>::epsilon()) | |
301 { | |
302 baseScaling_ = 1.0 / d; | |
303 } | |
304 else | |
305 { | |
306 // Avoid division by zero in extreme cases | |
307 accessor_.Invalidate(); | |
308 } | |
309 } | |
310 } | |
311 | |
312 virtual bool HasRender() const | |
313 { | |
314 return false; | |
315 } | |
316 | |
317 virtual void Render(CairoContext& context, | |
318 double zoom) | |
319 { | |
320 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
321 } | |
322 | |
323 virtual void MouseUp() | |
324 { | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
325 if (accessor_.IsValid() && |
407 | 326 accessor_.GetLayer().IsResizeable()) |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
327 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
328 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
329 } |
354 | 330 } |
331 | |
332 virtual void MouseMove(int displayX, | |
333 int displayY, | |
334 double sceneX, | |
335 double sceneY) | |
336 { | |
337 static const double ROUND_SCALING = 0.1; | |
338 | |
339 if (accessor_.IsValid() && | |
407 | 340 accessor_.GetLayer().IsResizeable()) |
354 | 341 { |
342 double scaling = ComputeDistance(oppositeX_, oppositeY_, sceneX, sceneY) * baseScaling_; | |
343 | |
344 if (roundScaling_) | |
345 { | |
376
70256a53ff21
fix compatibility with Visual Studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
369
diff
changeset
|
346 scaling = boost::math::round<double>((scaling / ROUND_SCALING) * ROUND_SCALING); |
354 | 347 } |
348 | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
349 RadiographyLayer& layer = accessor_.GetLayer(); |
407 | 350 layer.SetPixelSpacing(scaling * originalSpacingX_, |
351 scaling * originalSpacingY_); | |
354 | 352 |
353 // Keep the opposite corner at a fixed location | |
354 double ox, oy; | |
407 | 355 layer.GetCorner(ox, oy, oppositeCorner_); |
356 layer.SetPan(layer.GetPanX() + oppositeX_ - ox, | |
357 layer.GetPanY() + oppositeY_ - oy); | |
354 | 358 } |
359 } | |
360 }; | |
361 | |
362 | |
408 | 363 class RadiographyWindowingTracker : public IWorldSceneMouseTracker |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
364 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
365 public: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
366 enum Action |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
367 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
368 Action_IncreaseWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
369 Action_DecreaseWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
370 Action_IncreaseCenter, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
371 Action_DecreaseCenter |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
372 }; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
373 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
374 private: |
408 | 375 UndoRedoStack& undoRedoStack_; |
376 RadiographyScene& scene_; | |
377 int clickX_; | |
378 int clickY_; | |
379 Action leftAction_; | |
380 Action rightAction_; | |
381 Action upAction_; | |
382 Action downAction_; | |
383 float strength_; | |
384 float sourceCenter_; | |
385 float sourceWidth_; | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
386 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
387 static void ComputeAxisEffect(int& deltaCenter, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
388 int& deltaWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
389 int delta, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
390 Action actionNegative, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
391 Action actionPositive) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
392 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
393 if (delta < 0) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
394 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
395 switch (actionNegative) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
396 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
397 case Action_IncreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
398 deltaWidth = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
399 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
400 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
401 case Action_DecreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
402 deltaWidth = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
403 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
404 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
405 case Action_IncreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
406 deltaCenter = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
407 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
408 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
409 case Action_DecreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
410 deltaCenter = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
411 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
412 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
413 default: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
414 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
415 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
416 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
417 else if (delta > 0) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
418 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
419 switch (actionPositive) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
420 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
421 case Action_IncreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
422 deltaWidth = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
423 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
424 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
425 case Action_DecreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
426 deltaWidth = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
427 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
428 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
429 case Action_IncreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
430 deltaCenter = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
431 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
432 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
433 case Action_DecreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
434 deltaCenter = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
435 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
436 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
437 default: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
438 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
439 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
440 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
441 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
442 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
443 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
444 class UndoRedoCommand : public UndoRedoStack::ICommand |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
445 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
446 private: |
408 | 447 RadiographyScene& scene_; |
448 float sourceCenter_; | |
449 float sourceWidth_; | |
450 float targetCenter_; | |
451 float targetWidth_; | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
452 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
453 public: |
408 | 454 UndoRedoCommand(const RadiographyWindowingTracker& tracker) : |
407 | 455 scene_(tracker.scene_), |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
456 sourceCenter_(tracker.sourceCenter_), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
457 sourceWidth_(tracker.sourceWidth_) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
458 { |
407 | 459 scene_.GetWindowingWithDefault(targetCenter_, targetWidth_); |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
460 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
461 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
462 virtual void Undo() const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
463 { |
407 | 464 scene_.SetWindowing(sourceCenter_, sourceWidth_); |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
465 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
466 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
467 virtual void Redo() const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
468 { |
407 | 469 scene_.SetWindowing(targetCenter_, targetWidth_); |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
470 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
471 }; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
472 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
473 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
474 public: |
408 | 475 RadiographyWindowingTracker(UndoRedoStack& undoRedoStack, |
476 RadiographyScene& scene, | |
477 int x, | |
478 int y, | |
479 Action leftAction, | |
480 Action rightAction, | |
481 Action upAction, | |
482 Action downAction) : | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
483 undoRedoStack_(undoRedoStack), |
407 | 484 scene_(scene), |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
485 clickX_(x), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
486 clickY_(y), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
487 leftAction_(leftAction), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
488 rightAction_(rightAction), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
489 upAction_(upAction), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
490 downAction_(downAction) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
491 { |
407 | 492 scene_.GetWindowingWithDefault(sourceCenter_, sourceWidth_); |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
493 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
494 float minValue, maxValue; |
407 | 495 scene.GetRange(minValue, maxValue); |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
496 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
497 assert(minValue <= maxValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
498 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
499 float tmp; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
500 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
501 float delta = (maxValue - minValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
502 if (delta <= 1) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
503 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
504 tmp = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
505 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
506 else |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
507 { |
376
70256a53ff21
fix compatibility with Visual Studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
369
diff
changeset
|
508 // NB: Visual Studio 2008 does not provide "log2f()", so we |
70256a53ff21
fix compatibility with Visual Studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
369
diff
changeset
|
509 // implement it by ourselves |
70256a53ff21
fix compatibility with Visual Studio 2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
369
diff
changeset
|
510 tmp = logf(delta) / logf(2.0f); |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
511 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
512 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
513 strength_ = tmp - 7; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
514 if (strength_ < 1) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
515 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
516 strength_ = 1; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
517 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
518 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
519 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
520 virtual bool HasRender() const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
521 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
522 return false; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
523 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
524 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
525 virtual void Render(CairoContext& context, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
526 double zoom) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
527 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
528 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
529 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
530 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
531 virtual void MouseUp() |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
532 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
533 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
534 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
535 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
536 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
537 virtual void MouseMove(int displayX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
538 int displayY, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
539 double sceneX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
540 double sceneY) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
541 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
542 // https://bitbucket.org/osimis/osimis-webviewer-plugin/src/master/frontend/src/app/viewport/image-plugins/windowing-viewport-tool.class.js |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
543 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
544 static const float SCALE = 1.0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
545 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
546 int deltaCenter = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
547 int deltaWidth = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
548 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
549 ComputeAxisEffect(deltaCenter, deltaWidth, displayX - clickX_, leftAction_, rightAction_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
550 ComputeAxisEffect(deltaCenter, deltaWidth, displayY - clickY_, upAction_, downAction_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
551 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
552 float newCenter = sourceCenter_ + (deltaCenter / SCALE * strength_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
553 float newWidth = sourceWidth_ + (deltaWidth / SCALE * strength_); |
407 | 554 scene_.SetWindowing(newCenter, newWidth); |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
555 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
556 }; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
557 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
558 |
358 | 559 |
560 | |
407 | 561 namespace Samples |
358 | 562 { |
408 | 563 class RadiographyEditorInteractor : |
407 | 564 public IWorldSceneInteractor, |
565 public IObserver | |
358 | 566 { |
407 | 567 private: |
568 enum Tool | |
569 { | |
570 Tool_Move, | |
571 Tool_Rotate, | |
572 Tool_Crop, | |
573 Tool_Resize, | |
574 Tool_Windowing | |
575 }; | |
358 | 576 |
577 | |
407 | 578 UndoRedoStack undoRedoStack_; |
579 Tool tool_; | |
580 | |
581 | |
582 static double GetHandleSize() | |
583 { | |
584 return 10.0; | |
585 } | |
358 | 586 |
384
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
587 |
407 | 588 public: |
408 | 589 RadiographyEditorInteractor(MessageBroker& broker) : |
407 | 590 IObserver(broker), |
591 tool_(Tool_Move) | |
592 { | |
593 } | |
358 | 594 |
407 | 595 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& worldWidget, |
596 const ViewportGeometry& view, | |
597 MouseButton button, | |
598 KeyboardModifiers modifiers, | |
599 int viewportX, | |
600 int viewportY, | |
601 double x, | |
602 double y, | |
603 IStatusBar* statusBar) | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
604 { |
408 | 605 RadiographyWidget& widget = dynamic_cast<RadiographyWidget&>(worldWidget); |
407 | 606 |
607 if (button == MouseButton_Left) | |
358 | 608 { |
407 | 609 size_t selected; |
610 | |
611 if (tool_ == Tool_Windowing) | |
358 | 612 { |
408 | 613 return new RadiographyWindowingTracker( |
614 undoRedoStack_, widget.GetScene(), | |
615 viewportX, viewportY, | |
616 RadiographyWindowingTracker::Action_DecreaseWidth, | |
617 RadiographyWindowingTracker::Action_IncreaseWidth, | |
618 RadiographyWindowingTracker::Action_DecreaseCenter, | |
619 RadiographyWindowingTracker::Action_IncreaseCenter); | |
358 | 620 } |
407 | 621 else if (!widget.LookupSelectedLayer(selected)) |
358 | 622 { |
407 | 623 // No layer is currently selected |
624 size_t layer; | |
625 if (widget.GetScene().LookupLayer(layer, x, y)) | |
358 | 626 { |
407 | 627 widget.Select(layer); |
358 | 628 } |
407 | 629 |
630 return NULL; | |
358 | 631 } |
407 | 632 else if (tool_ == Tool_Crop || |
633 tool_ == Tool_Resize) | |
358 | 634 { |
408 | 635 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected); |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
636 |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
637 Corner corner; |
407 | 638 if (accessor.GetLayer().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize())) |
358 | 639 { |
407 | 640 switch (tool_) |
641 { | |
642 case Tool_Crop: | |
408 | 643 return new RadiographyLayerCropTracker |
644 (undoRedoStack_, widget.GetScene(), view, selected, x, y, corner); | |
407 | 645 |
646 case Tool_Resize: | |
408 | 647 return new RadiographyLayerResizeTracker |
648 (undoRedoStack_, widget.GetScene(), selected, x, y, corner, | |
649 (modifiers & KeyboardModifiers_Shift)); | |
407 | 650 |
651 default: | |
652 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
653 } | |
384
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
654 } |
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
655 else |
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
656 { |
407 | 657 size_t layer; |
358 | 658 |
407 | 659 if (widget.GetScene().LookupLayer(layer, x, y)) |
384
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
660 { |
407 | 661 widget.Select(layer); |
384
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
662 } |
407 | 663 else |
664 { | |
665 widget.Unselect(); | |
666 } | |
667 | |
384
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
668 return NULL; |
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
669 } |
358 | 670 } |
671 else | |
672 { | |
407 | 673 size_t layer; |
674 | |
675 if (widget.GetScene().LookupLayer(layer, x, y)) | |
676 { | |
677 if (layer == selected) | |
678 { | |
679 switch (tool_) | |
680 { | |
681 case Tool_Move: | |
408 | 682 return new RadiographyLayerMoveTracker |
683 (undoRedoStack_, widget.GetScene(), layer, x, y, | |
684 (modifiers & KeyboardModifiers_Shift)); | |
407 | 685 |
686 case Tool_Rotate: | |
408 | 687 return new RadiographyLayerRotateTracker |
688 (undoRedoStack_, widget.GetScene(), view, layer, x, y, | |
689 (modifiers & KeyboardModifiers_Shift)); | |
407 | 690 |
691 default: | |
692 break; | |
693 } | |
694 | |
695 return NULL; | |
696 } | |
697 else | |
698 { | |
699 widget.Select(layer); | |
700 return NULL; | |
701 } | |
702 } | |
703 else | |
704 { | |
705 widget.Unselect(); | |
706 return NULL; | |
707 } | |
708 } | |
709 } | |
710 else | |
711 { | |
712 return NULL; | |
713 } | |
714 } | |
715 | |
716 virtual void MouseOver(CairoContext& context, | |
717 WorldSceneWidget& worldWidget, | |
718 const ViewportGeometry& view, | |
719 double x, | |
720 double y, | |
721 IStatusBar* statusBar) | |
722 { | |
408 | 723 RadiographyWidget& widget = dynamic_cast<RadiographyWidget&>(worldWidget); |
407 | 724 |
725 #if 0 | |
726 if (statusBar != NULL) | |
727 { | |
728 char buf[64]; | |
729 sprintf(buf, "X = %.02f Y = %.02f (in cm)", x / 10.0, y / 10.0); | |
730 statusBar->SetMessage(buf); | |
731 } | |
732 #endif | |
733 | |
734 size_t selected; | |
735 | |
736 if (widget.LookupSelectedLayer(selected) && | |
737 (tool_ == Tool_Crop || | |
738 tool_ == Tool_Resize)) | |
739 { | |
408 | 740 RadiographyScene::LayerAccessor accessor(widget.GetScene(), selected); |
407 | 741 |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
742 Corner corner; |
407 | 743 if (accessor.GetLayer().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize())) |
744 { | |
745 accessor.GetLayer().GetCorner(x, y, corner); | |
746 | |
747 double z = 1.0 / view.GetZoom(); | |
748 | |
749 context.SetSourceColor(255, 0, 0); | |
750 cairo_t* cr = context.GetObject(); | |
751 cairo_set_line_width(cr, 2.0 * z); | |
752 cairo_move_to(cr, x - GetHandleSize() * z, y - GetHandleSize() * z); | |
753 cairo_line_to(cr, x + GetHandleSize() * z, y - GetHandleSize() * z); | |
754 cairo_line_to(cr, x + GetHandleSize() * z, y + GetHandleSize() * z); | |
755 cairo_line_to(cr, x - GetHandleSize() * z, y + GetHandleSize() * z); | |
756 cairo_line_to(cr, x - GetHandleSize() * z, y - GetHandleSize() * z); | |
757 cairo_stroke(cr); | |
358 | 758 } |
759 } | |
339 | 760 } |
407 | 761 |
762 virtual void MouseWheel(WorldSceneWidget& widget, | |
763 MouseWheelDirection direction, | |
764 KeyboardModifiers modifiers, | |
765 IStatusBar* statusBar) | |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
766 { |
358 | 767 } |
407 | 768 |
769 virtual void KeyPressed(WorldSceneWidget& worldWidget, | |
770 KeyboardKeys key, | |
771 char keyChar, | |
772 KeyboardModifiers modifiers, | |
773 IStatusBar* statusBar) | |
345 | 774 { |
408 | 775 RadiographyWidget& widget = dynamic_cast<RadiographyWidget&>(worldWidget); |
407 | 776 |
777 switch (keyChar) | |
358 | 778 { |
407 | 779 case 'a': |
780 widget.FitContent(); | |
781 break; | |
782 | |
783 case 'c': | |
784 tool_ = Tool_Crop; | |
785 break; | |
786 | |
787 case 'e': | |
788 { | |
789 Orthanc::DicomMap tags; | |
790 | |
791 // Minimal set of tags to generate a valid CR image | |
792 tags.SetValue(Orthanc::DICOM_TAG_ACCESSION_NUMBER, "NOPE", false); | |
793 tags.SetValue(Orthanc::DICOM_TAG_BODY_PART_EXAMINED, "PELVIS", false); | |
794 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "1", false); | |
795 //tags.SetValue(Orthanc::DICOM_TAG_LATERALITY, "", false); | |
796 tags.SetValue(Orthanc::DICOM_TAG_MANUFACTURER, "OSIMIS", false); | |
797 tags.SetValue(Orthanc::DICOM_TAG_MODALITY, "CR", false); | |
798 tags.SetValue(Orthanc::DICOM_TAG_PATIENT_BIRTH_DATE, "20000101", false); | |
799 tags.SetValue(Orthanc::DICOM_TAG_PATIENT_ID, "hello", false); | |
800 tags.SetValue(Orthanc::DICOM_TAG_PATIENT_NAME, "HELLO^WORLD", false); | |
801 tags.SetValue(Orthanc::DICOM_TAG_PATIENT_ORIENTATION, "", false); | |
802 tags.SetValue(Orthanc::DICOM_TAG_PATIENT_SEX, "M", false); | |
803 tags.SetValue(Orthanc::DICOM_TAG_REFERRING_PHYSICIAN_NAME, "HOUSE^MD", false); | |
804 tags.SetValue(Orthanc::DICOM_TAG_SERIES_NUMBER, "1", false); | |
805 tags.SetValue(Orthanc::DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.1", false); | |
806 tags.SetValue(Orthanc::DICOM_TAG_STUDY_ID, "STUDY", false); | |
807 tags.SetValue(Orthanc::DICOM_TAG_VIEW_POSITION, "", false); | |
808 | |
408 | 809 widget.GetScene().ExportDicom(tags, 0.1, 0.1, widget.IsInverted(), |
810 widget.GetInterpolation(), EXPORT_USING_PAM); | |
407 | 811 break; |
812 } | |
813 | |
814 case 'i': | |
815 widget.SwitchInvert(); | |
816 break; | |
817 | |
818 case 'm': | |
819 tool_ = Tool_Move; | |
820 break; | |
821 | |
822 case 'n': | |
823 { | |
824 switch (widget.GetInterpolation()) | |
825 { | |
826 case ImageInterpolation_Nearest: | |
827 LOG(INFO) << "Switching to bilinear interpolation"; | |
828 widget.SetInterpolation(ImageInterpolation_Bilinear); | |
829 break; | |
830 | |
831 case ImageInterpolation_Bilinear: | |
832 LOG(INFO) << "Switching to nearest neighbor interpolation"; | |
833 widget.SetInterpolation(ImageInterpolation_Nearest); | |
834 break; | |
835 | |
836 default: | |
837 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
838 } | |
358 | 839 |
407 | 840 break; |
841 } | |
842 | |
843 case 'r': | |
844 tool_ = Tool_Rotate; | |
845 break; | |
846 | |
847 case 's': | |
848 tool_ = Tool_Resize; | |
849 break; | |
850 | |
851 case 'w': | |
852 tool_ = Tool_Windowing; | |
853 break; | |
854 | |
855 case 'y': | |
856 if (modifiers & KeyboardModifiers_Control) | |
857 { | |
858 undoRedoStack_.Redo(); | |
859 widget.NotifyContentChanged(); | |
860 } | |
861 break; | |
862 | |
863 case 'z': | |
864 if (modifiers & KeyboardModifiers_Control) | |
865 { | |
866 undoRedoStack_.Undo(); | |
867 widget.NotifyContentChanged(); | |
868 } | |
869 break; | |
870 | |
871 default: | |
872 break; | |
358 | 873 } |
345 | 874 } |
407 | 875 }; |
336
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
876 |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
877 |
358 | 878 |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
879 class SingleFrameEditorApplication : |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
880 public SampleSingleCanvasApplicationBase, |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
881 public IObserver |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
882 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
883 private: |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
884 std::auto_ptr<OrthancApiClient> orthancApiClient_; |
408 | 885 std::auto_ptr<RadiographyScene> scene_; |
886 RadiographyEditorInteractor interactor_; | |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
887 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
888 public: |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
889 SingleFrameEditorApplication(MessageBroker& broker) : |
362
12cec26d08ce
export of a valid DICOM CR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
361
diff
changeset
|
890 IObserver(broker), |
12cec26d08ce
export of a valid DICOM CR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
361
diff
changeset
|
891 interactor_(broker) |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
892 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
893 } |
384
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
894 |
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
895 virtual ~SingleFrameEditorApplication() |
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
896 { |
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
897 LOG(WARNING) << "Destroying the application"; |
d20d75f20c5d
better following of the MVC design pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
898 } |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
899 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
900 virtual void DeclareStartupOptions(boost::program_options::options_description& options) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
901 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
902 boost::program_options::options_description generic("Sample options"); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
903 generic.add_options() |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
904 ("instance", boost::program_options::value<std::string>(), |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
905 "Orthanc ID of the instance") |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
906 ("frame", boost::program_options::value<unsigned int>()->default_value(0), |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
907 "Number of the frame, for multi-frame DICOM instances") |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
908 ; |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
909 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
910 options.add(generic); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
911 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
912 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
913 virtual void Initialize(StoneApplicationContext* context, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
914 IStatusBar& statusBar, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
915 const boost::program_options::variables_map& parameters) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
916 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
917 using namespace OrthancStone; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
918 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
919 context_ = context; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
920 |
358 | 921 statusBar.SetMessage("Use the key \"a\" to reinitialize the layout"); |
922 statusBar.SetMessage("Use the key \"c\" to crop"); | |
359
100df90bf0ea
preparing to implement Export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
358
diff
changeset
|
923 statusBar.SetMessage("Use the key \"e\" to export DICOM to the Orthanc server"); |
358 | 924 statusBar.SetMessage("Use the key \"f\" to switch full screen"); |
925 statusBar.SetMessage("Use the key \"i\" to invert contrast"); | |
926 statusBar.SetMessage("Use the key \"m\" to move objects"); | |
359
100df90bf0ea
preparing to implement Export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
358
diff
changeset
|
927 statusBar.SetMessage("Use the key \"n\" to switch between nearest neighbor and bilinear interpolation"); |
358 | 928 statusBar.SetMessage("Use the key \"r\" to rotate objects"); |
407 | 929 statusBar.SetMessage("Use the key \"s\" to resize objects (not applicable to DICOM layers)"); |
358 | 930 statusBar.SetMessage("Use the key \"w\" to change windowing"); |
931 | |
932 statusBar.SetMessage("Use the key \"ctrl-z\" to undo action"); | |
933 statusBar.SetMessage("Use the key \"ctrl-y\" to redo action"); | |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
934 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
935 if (parameters.count("instance") != 1) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
936 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
937 LOG(ERROR) << "The instance ID is missing"; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
938 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
939 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
940 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
941 std::string instance = parameters["instance"].as<std::string>(); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
942 int frame = parameters["frame"].as<unsigned int>(); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
943 |
393
e7a494bdd956
removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
392
diff
changeset
|
944 orthancApiClient_.reset(new OrthancApiClient(GetBroker(), context_->GetWebService())); |
337 | 945 |
343 | 946 Orthanc::FontRegistry fonts; |
947 fonts.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16); | |
948 | |
408 | 949 scene_.reset(new RadiographyScene(GetBroker(), *orthancApiClient_)); |
407 | 950 scene_->LoadDicomFrame(instance, frame, false); //.SetPan(200, 0); |
951 //scene_->LoadDicomFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", 0, false); | |
354 | 952 |
953 { | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
954 RadiographyLayer& layer = scene_->LoadText(fonts.GetFont(0), "Hello\nworld"); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
955 layer.SetResizeable(true); |
354 | 956 } |
957 | |
958 { | |
410
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
959 RadiographyLayer& layer = scene_->LoadTestBlock(100, 50); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
960 layer.SetResizeable(true); |
6decc0ba9da5
rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
408
diff
changeset
|
961 layer.SetPan(0, 200); |
354 | 962 } |
963 | |
337 | 964 |
408 | 965 mainWidget_ = new RadiographyWidget(GetBroker(), *scene_, "main-widget"); |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
966 mainWidget_->SetTransmitMouseOver(true); |
358 | 967 mainWidget_->SetInteractor(interactor_); |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
968 |
407 | 969 //scene_->SetWindowing(128, 256); |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
970 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
971 }; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
972 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
973 } |