Mercurial > hg > orthanc-stone
annotate Applications/Samples/SingleFrameEditorApplication.h @ 357:ec4ad6c5eb99 am-2
avoid breaking class hierarchy
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 29 Oct 2018 17:59:04 +0100 |
parents | 885f0a5eaa49 |
children | b8eeb49f3e65 |
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 |
339 | 26 #include "../../Framework/Toolbox/GeometryToolbox.h" |
27 #include "../../Framework/Toolbox/ImageGeometry.h" | |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
28 #include "../../Framework/Layers/OrthancFrameLayerSource.h" |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
29 |
338 | 30 #include <Core/DicomFormat/DicomArray.h> |
343 | 31 #include <Core/Images/FontRegistry.h> |
339 | 32 #include <Core/Images/ImageProcessing.h> |
338 | 33 #include <Core/Images/PamReader.h> |
343 | 34 #include <Core/Images/PngWriter.h> //TODO |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
35 #include <Core/Logging.h> |
338 | 36 #include <Plugins/Samples/Common/FullOrthancDataset.h> |
339 | 37 #include <Plugins/Samples/Common/DicomDatasetReader.h> |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
38 |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
39 |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
40 #include <boost/math/constants/constants.hpp> |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
41 |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
42 namespace OrthancStone |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
43 { |
338 | 44 class BitmapStack : |
337 | 45 public IObserver, |
336
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
46 public IObservable |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
47 { |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
48 public: |
338 | 49 typedef OriginMessage<MessageType_Widget_GeometryChanged, BitmapStack> GeometryChangedMessage; |
50 typedef OriginMessage<MessageType_Widget_ContentChanged, BitmapStack> ContentChangedMessage; | |
336
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
51 |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
52 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
53 enum Corner |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
54 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
55 Corner_TopLeft, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
56 Corner_TopRight, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
57 Corner_BottomLeft, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
58 Corner_BottomRight |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
59 }; |
354 | 60 |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
61 |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
62 |
338 | 63 class Bitmap : public boost::noncopyable |
64 { | |
65 private: | |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
66 size_t index_; |
343 | 67 bool hasSize_; |
68 unsigned int width_; | |
69 unsigned int height_; | |
70 bool hasCrop_; | |
71 unsigned int cropX_; | |
72 unsigned int cropY_; | |
73 unsigned int cropWidth_; | |
74 unsigned int cropHeight_; | |
75 Matrix transform_; | |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
76 Matrix transformInverse_; |
343 | 77 double pixelSpacingX_; |
78 double pixelSpacingY_; | |
79 double panX_; | |
80 double panY_; | |
346 | 81 double angle_; |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
82 bool resizeable_; |
338 | 83 |
342 | 84 |
348 | 85 protected: |
346 | 86 static Matrix CreateOffsetMatrix(double dx, |
87 double dy) | |
342 | 88 { |
346 | 89 Matrix m = LinearAlgebra::IdentityMatrix(3); |
90 m(0, 2) = dx; | |
91 m(1, 2) = dy; | |
92 return m; | |
93 } | |
94 | |
342 | 95 |
346 | 96 static Matrix CreateScalingMatrix(double sx, |
97 double sy) | |
98 { | |
99 Matrix m = LinearAlgebra::IdentityMatrix(3); | |
100 m(0, 0) = sx; | |
101 m(1, 1) = sy; | |
102 return m; | |
103 } | |
104 | |
105 | |
106 static Matrix CreateRotationMatrix(double angle) | |
107 { | |
342 | 108 Matrix m; |
346 | 109 const double v[] = { cos(angle), -sin(angle), 0, |
110 sin(angle), cos(angle), 0, | |
342 | 111 0, 0, 1 }; |
112 LinearAlgebra::FillMatrix(m, 3, 3, v); | |
346 | 113 return m; |
342 | 114 } |
346 | 115 |
345 | 116 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
117 const Matrix& GetTransform() const |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
118 { |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
119 return transform_; |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
120 } |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
121 |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
122 |
348 | 123 private: |
346 | 124 static void ApplyTransform(double& x /* inout */, |
125 double& y /* inout */, | |
126 const Matrix& transform) | |
339 | 127 { |
128 Vector p; | |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
129 LinearAlgebra::AssignVector(p, x, y, 1); |
339 | 130 |
346 | 131 Vector q = LinearAlgebra::Product(transform, p); |
339 | 132 |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
133 if (!LinearAlgebra::IsNear(q[2], 1.0)) |
339 | 134 { |
135 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
136 } | |
137 else | |
138 { | |
345 | 139 x = q[0]; |
140 y = q[1]; | |
339 | 141 } |
142 } | |
143 | |
345 | 144 |
346 | 145 void UpdateTransform() |
146 { | |
147 transform_ = CreateScalingMatrix(pixelSpacingX_, pixelSpacingY_); | |
148 | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
149 double centerX, centerY; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
150 GetCenter(centerX, centerY); |
346 | 151 |
152 transform_ = LinearAlgebra::Product( | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
153 CreateOffsetMatrix(panX_ + centerX, panY_ + centerY), |
346 | 154 CreateRotationMatrix(angle_), |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
155 CreateOffsetMatrix(-centerX, -centerY), |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
156 transform_); |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
157 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
158 LinearAlgebra::InvertMatrix(transformInverse_, transform_); |
346 | 159 } |
160 | |
161 | |
345 | 162 void AddToExtent(Extent2D& extent, |
163 double x, | |
164 double y) const | |
165 { | |
346 | 166 ApplyTransform(x, y, transform_); |
345 | 167 extent.AddPoint(x, y); |
168 } | |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
169 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
170 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
171 void GetCornerInternal(double& x, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
172 double& y, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
173 Corner corner, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
174 unsigned int cropX, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
175 unsigned int cropY, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
176 unsigned int cropWidth, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
177 unsigned int cropHeight) const |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
178 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
179 double dx = static_cast<double>(cropX); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
180 double dy = static_cast<double>(cropY); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
181 double dwidth = static_cast<double>(cropWidth); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
182 double dheight = static_cast<double>(cropHeight); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
183 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
184 switch (corner) |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
185 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
186 case Corner_TopLeft: |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
187 x = dx; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
188 y = dy; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
189 break; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
190 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
191 case Corner_TopRight: |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
192 x = dx + dwidth; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
193 y = dy; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
194 break; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
195 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
196 case Corner_BottomLeft: |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
197 x = dx; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
198 y = dy + dheight; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
199 break; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
200 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
201 case Corner_BottomRight: |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
202 x = dx + dwidth; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
203 y = dy + dheight; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
204 break; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
205 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
206 default: |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
207 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
208 } |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
209 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
210 ApplyTransform(x, y, transform_); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
211 } |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
212 |
339 | 213 |
338 | 214 public: |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
215 Bitmap(size_t index) : |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
216 index_(index), |
343 | 217 hasSize_(false), |
339 | 218 width_(0), |
219 height_(0), | |
220 hasCrop_(false), | |
342 | 221 pixelSpacingX_(1), |
222 pixelSpacingY_(1), | |
223 panX_(0), | |
346 | 224 panY_(0), |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
225 angle_(0), |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
226 resizeable_(false) |
339 | 227 { |
342 | 228 UpdateTransform(); |
339 | 229 } |
230 | |
343 | 231 virtual ~Bitmap() |
232 { | |
233 } | |
234 | |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
235 size_t GetIndex() const |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
236 { |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
237 return index_; |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
238 } |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
239 |
339 | 240 void ResetCrop() |
241 { | |
242 hasCrop_ = false; | |
243 } | |
244 | |
348 | 245 void SetCrop(unsigned int x, |
246 unsigned int y, | |
247 unsigned int width, | |
248 unsigned int height) | |
339 | 249 { |
348 | 250 if (!hasSize_) |
251 { | |
252 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
253 } | |
254 | |
255 if (x + width > width_ || | |
256 y + height > height_) | |
257 { | |
258 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
259 } | |
260 | |
339 | 261 hasCrop_ = true; |
262 cropX_ = x; | |
263 cropY_ = y; | |
264 cropWidth_ = width; | |
265 cropHeight_ = height; | |
348 | 266 |
267 UpdateTransform(); | |
339 | 268 } |
269 | |
270 void GetCrop(unsigned int& x, | |
271 unsigned int& y, | |
272 unsigned int& width, | |
273 unsigned int& height) const | |
338 | 274 { |
339 | 275 if (hasCrop_) |
276 { | |
277 x = cropX_; | |
278 y = cropY_; | |
279 width = cropWidth_; | |
280 height = cropHeight_; | |
281 } | |
282 else | |
283 { | |
284 x = 0; | |
285 y = 0; | |
286 width = width_; | |
287 height = height_; | |
288 } | |
289 } | |
290 | |
346 | 291 void SetAngle(double angle) |
292 { | |
293 angle_ = angle; | |
294 UpdateTransform(); | |
295 } | |
296 | |
297 double GetAngle() const | |
298 { | |
299 return angle_; | |
300 } | |
301 | |
343 | 302 void SetSize(unsigned int width, |
303 unsigned int height) | |
338 | 304 { |
343 | 305 if (hasSize_ && |
306 (width != width_ || | |
307 height != height_)) | |
339 | 308 { |
343 | 309 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
310 } |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
311 |
343 | 312 hasSize_ = true; |
313 width_ = width; | |
314 height_ = height; | |
346 | 315 |
316 UpdateTransform(); | |
338 | 317 } |
318 | |
343 | 319 |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
320 unsigned int GetWidth() const |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
321 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
322 return width_; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
323 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
324 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
325 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
326 unsigned int GetHeight() const |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
327 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
328 return height_; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
329 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
330 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
331 |
343 | 332 void CheckSize(unsigned int width, |
333 unsigned int height) | |
338 | 334 { |
343 | 335 if (hasSize_ && |
336 (width != width_ || | |
337 height != height_)) | |
338 | 338 { |
343 | 339 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); |
339 | 340 } |
341 } | |
343 | 342 |
339 | 343 |
344 Extent2D GetExtent() const | |
345 { | |
346 Extent2D extent; | |
347 | |
348 unsigned int x, y, width, height; | |
349 GetCrop(x, y, width, height); | |
350 | |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
351 double dx = static_cast<double>(x); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
352 double dy = static_cast<double>(y); |
339 | 353 double dwidth = static_cast<double>(width); |
354 double dheight = static_cast<double>(height); | |
342 | 355 |
339 | 356 AddToExtent(extent, dx, dy); |
357 AddToExtent(extent, dx + dwidth, dy); | |
358 AddToExtent(extent, dx, dy + dheight); | |
359 AddToExtent(extent, dx + dwidth, dy + dheight); | |
360 | |
361 return extent; | |
362 } | |
363 | |
364 | |
341 | 365 bool Contains(double x, |
366 double y) const | |
367 { | |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
368 ApplyTransform(x, y, transformInverse_); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
369 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
370 unsigned int cropX, cropY, cropWidth, cropHeight; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
371 GetCrop(cropX, cropY, cropWidth, cropHeight); |
341 | 372 |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
373 return (x >= cropX && x <= cropX + cropWidth && |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
374 y >= cropY && y <= cropY + cropHeight); |
341 | 375 } |
342 | 376 |
377 | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
378 bool GetPixel(unsigned int& imageX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
379 unsigned int& imageY, |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
380 double sceneX, |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
381 double sceneY) const |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
382 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
383 if (width_ == 0 || |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
384 height_ == 0) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
385 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
386 return false; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
387 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
388 else |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
389 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
390 ApplyTransform(sceneX, sceneY, transformInverse_); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
391 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
392 int x = static_cast<int>(std::floor(sceneX)); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
393 int y = static_cast<int>(std::floor(sceneY)); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
394 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
395 if (x < 0) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
396 { |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
397 imageX = 0; |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
398 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
399 else if (x >= static_cast<int>(width_)) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
400 { |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
401 imageX = width_; |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
402 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
403 else |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
404 { |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
405 imageX = static_cast<unsigned int>(x); |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
406 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
407 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
408 if (y < 0) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
409 { |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
410 imageY = 0; |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
411 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
412 else if (y >= static_cast<int>(height_)) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
413 { |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
414 imageY = height_; |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
415 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
416 else |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
417 { |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
418 imageY = static_cast<unsigned int>(y); |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
419 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
420 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
421 return true; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
422 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
423 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
424 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
425 |
342 | 426 void SetPan(double x, |
427 double y) | |
428 { | |
429 panX_ = x; | |
430 panY_ = y; | |
431 UpdateTransform(); | |
432 } | |
433 | |
434 | |
343 | 435 void SetPixelSpacing(double x, |
436 double y) | |
437 { | |
438 pixelSpacingX_ = x; | |
439 pixelSpacingY_ = y; | |
440 UpdateTransform(); | |
441 } | |
442 | |
345 | 443 double GetPixelSpacingX() const |
444 { | |
445 return pixelSpacingX_; | |
446 } | |
447 | |
448 double GetPixelSpacingY() const | |
449 { | |
450 return pixelSpacingY_; | |
451 } | |
343 | 452 |
342 | 453 double GetPanX() const |
454 { | |
455 return panX_; | |
456 } | |
457 | |
458 double GetPanY() const | |
459 { | |
460 return panY_; | |
461 } | |
343 | 462 |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
463 void GetCenter(double& centerX, |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
464 double& centerY) const |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
465 { |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
466 centerX = static_cast<double>(width_) / 2.0; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
467 centerY = static_cast<double>(height_) / 2.0; |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
468 ApplyTransform(centerX, centerY, transform_); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
469 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
470 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
471 |
345 | 472 void DrawBorders(CairoContext& context, |
473 double zoom) | |
474 { | |
475 unsigned int cx, cy, width, height; | |
476 GetCrop(cx, cy, width, height); | |
477 | |
478 double dx = static_cast<double>(cx); | |
479 double dy = static_cast<double>(cy); | |
480 double dwidth = static_cast<double>(width); | |
481 double dheight = static_cast<double>(height); | |
482 | |
483 cairo_t* cr = context.GetObject(); | |
484 cairo_set_line_width(cr, 2.0 / zoom); | |
485 | |
486 double x, y; | |
487 x = dx; | |
488 y = dy; | |
346 | 489 ApplyTransform(x, y, transform_); |
345 | 490 cairo_move_to(cr, x, y); |
491 | |
492 x = dx + dwidth; | |
493 y = dy; | |
346 | 494 ApplyTransform(x, y, transform_); |
345 | 495 cairo_line_to(cr, x, y); |
496 | |
497 x = dx + dwidth; | |
498 y = dy + dheight; | |
346 | 499 ApplyTransform(x, y, transform_); |
345 | 500 cairo_line_to(cr, x, y); |
501 | |
502 x = dx; | |
503 y = dy + dheight; | |
346 | 504 ApplyTransform(x, y, transform_); |
345 | 505 cairo_line_to(cr, x, y); |
506 | |
507 x = dx; | |
508 y = dy; | |
346 | 509 ApplyTransform(x, y, transform_); |
345 | 510 cairo_line_to(cr, x, y); |
511 | |
512 cairo_stroke(cr); | |
513 } | |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
514 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
515 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
516 static double Square(double x) |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
517 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
518 return x * x; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
519 } |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
520 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
521 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
522 void GetCorner(double& x /* out */, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
523 double& y /* out */, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
524 Corner corner) const |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
525 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
526 unsigned int cropX, cropY, cropWidth, cropHeight; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
527 GetCrop(cropX, cropY, cropWidth, cropHeight); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
528 GetCornerInternal(x, y, corner, cropX, cropY, cropWidth, cropHeight); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
529 } |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
530 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
531 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
532 bool LookupCorner(Corner& corner /* out */, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
533 double x, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
534 double y, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
535 double zoom, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
536 double viewportDistance) const |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
537 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
538 static const Corner CORNERS[] = { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
539 Corner_TopLeft, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
540 Corner_TopRight, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
541 Corner_BottomLeft, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
542 Corner_BottomRight |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
543 }; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
544 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
545 unsigned int cropX, cropY, cropWidth, cropHeight; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
546 GetCrop(cropX, cropY, cropWidth, cropHeight); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
547 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
548 double threshold = Square(viewportDistance / zoom); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
549 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
550 for (size_t i = 0; i < 4; i++) |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
551 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
552 double cx, cy; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
553 GetCornerInternal(cx, cy, CORNERS[i], cropX, cropY, cropWidth, cropHeight); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
554 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
555 double d = Square(cx - x) + Square(cy - y); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
556 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
557 if (d <= threshold) |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
558 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
559 corner = CORNERS[i]; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
560 return true; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
561 } |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
562 } |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
563 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
564 return false; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
565 } |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
566 |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
567 bool IsResizeable() const |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
568 { |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
569 return resizeable_; |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
570 } |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
571 |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
572 void SetResizeable(bool resizeable) |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
573 { |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
574 resizeable_ = resizeable; |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
575 } |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
576 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
577 virtual bool GetDefaultWindowing(float& center, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
578 float& width) const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
579 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
580 return false; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
581 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
582 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
583 virtual void Render(Orthanc::ImageAccessor& buffer, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
584 const ViewportGeometry& view, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
585 ImageInterpolation interpolation) const = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
586 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
587 virtual bool GetRange(float& minValue, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
588 float& maxValue) const = 0; |
338 | 589 }; |
590 | |
591 | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
592 class BitmapAccessor : public boost::noncopyable |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
593 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
594 private: |
354 | 595 BitmapStack& stack_; |
596 size_t index_; | |
597 Bitmap* bitmap_; | |
343 | 598 |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
599 public: |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
600 BitmapAccessor(BitmapStack& stack, |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
601 size_t index) : |
354 | 602 stack_(stack), |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
603 index_(index) |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
604 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
605 Bitmaps::iterator bitmap = stack.bitmaps_.find(index); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
606 if (bitmap == stack.bitmaps_.end()) |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
607 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
608 bitmap_ = NULL; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
609 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
610 else |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
611 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
612 assert(bitmap->second != NULL); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
613 bitmap_ = bitmap->second; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
614 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
615 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
616 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
617 BitmapAccessor(BitmapStack& stack, |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
618 double x, |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
619 double y) : |
354 | 620 stack_(stack), |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
621 index_(0) // Dummy initialization |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
622 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
623 if (stack.LookupBitmap(index_, x, y)) |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
624 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
625 Bitmaps::iterator bitmap = stack.bitmaps_.find(index_); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
626 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
627 if (bitmap == stack.bitmaps_.end()) |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
628 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
629 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
630 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
631 else |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
632 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
633 assert(bitmap->second != NULL); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
634 bitmap_ = bitmap->second; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
635 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
636 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
637 else |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
638 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
639 bitmap_ = NULL; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
640 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
641 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
642 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
643 void Invalidate() |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
644 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
645 bitmap_ = NULL; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
646 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
647 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
648 bool IsValid() const |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
649 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
650 return bitmap_ != NULL; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
651 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
652 |
354 | 653 BitmapStack& GetStack() const |
654 { | |
655 if (IsValid()) | |
656 { | |
657 return stack_; | |
658 } | |
659 else | |
660 { | |
661 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
662 } | |
663 } | |
664 | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
665 size_t GetIndex() const |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
666 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
667 if (IsValid()) |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
668 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
669 return index_; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
670 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
671 else |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
672 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
673 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
674 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
675 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
676 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
677 Bitmap& GetBitmap() const |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
678 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
679 if (IsValid()) |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
680 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
681 return *bitmap_; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
682 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
683 else |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
684 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
685 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
686 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
687 } |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
688 }; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
689 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
690 |
354 | 691 class AlphaBitmap : public Bitmap |
692 { | |
693 private: | |
694 const BitmapStack& stack_; | |
695 std::auto_ptr<Orthanc::ImageAccessor> alpha_; // Grayscale8 | |
696 bool useWindowing_; | |
697 float foreground_; | |
698 | |
699 public: | |
700 AlphaBitmap(size_t index, | |
701 const BitmapStack& stack) : | |
702 Bitmap(index), | |
703 stack_(stack), | |
704 useWindowing_(true), | |
705 foreground_(0) | |
706 { | |
707 } | |
708 | |
709 | |
710 void SetForegroundValue(float foreground) | |
711 { | |
712 useWindowing_ = false; | |
713 foreground_ = foreground; | |
714 } | |
715 | |
716 | |
717 void SetAlpha(Orthanc::ImageAccessor* image) | |
718 { | |
719 std::auto_ptr<Orthanc::ImageAccessor> raii(image); | |
720 | |
721 if (image == NULL) | |
722 { | |
723 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
724 } | |
725 | |
726 if (image->GetFormat() != Orthanc::PixelFormat_Grayscale8) | |
727 { | |
728 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | |
729 } | |
730 | |
731 SetSize(image->GetWidth(), image->GetHeight()); | |
732 alpha_ = raii; | |
733 } | |
734 | |
735 | |
736 void LoadText(const Orthanc::Font& font, | |
737 const std::string& utf8) | |
738 { | |
739 SetAlpha(font.RenderAlpha(utf8)); | |
740 } | |
741 | |
742 | |
743 virtual void Render(Orthanc::ImageAccessor& buffer, | |
744 const ViewportGeometry& view, | |
745 ImageInterpolation interpolation) const | |
746 { | |
747 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32) | |
748 { | |
749 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | |
750 } | |
751 | |
752 unsigned int cropX, cropY, cropWidth, cropHeight; | |
753 GetCrop(cropX, cropY, cropWidth, cropHeight); | |
754 | |
755 Matrix m = LinearAlgebra::Product(view.GetMatrix(), | |
756 GetTransform(), | |
757 CreateOffsetMatrix(cropX, cropY)); | |
758 | |
759 Orthanc::ImageAccessor cropped; | |
760 alpha_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); | |
761 | |
762 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); | |
763 ApplyProjectiveTransform(tmp, cropped, m, interpolation, true /* clear */); | |
764 | |
765 // Blit | |
766 const unsigned int width = buffer.GetWidth(); | |
767 const unsigned int height = buffer.GetHeight(); | |
768 | |
769 float value = foreground_; | |
770 | |
771 if (useWindowing_) | |
772 { | |
773 float center, width; | |
774 if (stack_.GetWindowing(center, width)) | |
775 { | |
776 value = center + width / 2.0f; | |
777 } | |
778 } | |
779 | |
780 for (unsigned int y = 0; y < height; y++) | |
781 { | |
782 float *q = reinterpret_cast<float*>(buffer.GetRow(y)); | |
783 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y)); | |
784 | |
785 for (unsigned int x = 0; x < width; x++, p++, q++) | |
786 { | |
787 float a = static_cast<float>(*p) / 255.0f; | |
788 | |
789 *q = (a * value + (1.0f - a) * (*q)); | |
790 } | |
791 } | |
792 } | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
793 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
794 virtual bool GetRange(float& minValue, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
795 float& maxValue) const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
796 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
797 if (useWindowing_) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
798 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
799 return false; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
800 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
801 else |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
802 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
803 minValue = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
804 maxValue = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
805 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
806 if (foreground_ < 0) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
807 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
808 minValue = foreground_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
809 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
810 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
811 if (foreground_ > 0) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
812 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
813 maxValue = foreground_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
814 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
815 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
816 return true; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
817 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
818 } |
354 | 819 }; |
820 | |
821 | |
822 | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
823 private: |
343 | 824 class DicomBitmap : public Bitmap |
825 { | |
826 private: | |
827 std::auto_ptr<Orthanc::ImageAccessor> source_; // Content of PixelData | |
828 std::auto_ptr<DicomFrameConverter> converter_; | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
829 std::auto_ptr<Orthanc::ImageAccessor> converted_; // Float32 |
343 | 830 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
831 static OrthancPlugins::DicomTag ConvertTag(const Orthanc::DicomTag& tag) |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
832 { |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
833 return OrthancPlugins::DicomTag(tag.GetGroup(), tag.GetElement()); |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
834 } |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
835 |
343 | 836 |
837 void ApplyConverter() | |
838 { | |
839 if (source_.get() != NULL && | |
840 converter_.get() != NULL) | |
841 { | |
842 converted_.reset(converter_->ConvertFrame(*source_)); | |
843 } | |
844 } | |
845 | |
846 public: | |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
847 DicomBitmap(size_t index) : |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
848 Bitmap(index) |
343 | 849 { |
850 } | |
851 | |
852 void SetDicomTags(const OrthancPlugins::FullOrthancDataset& dataset) | |
853 { | |
854 converter_.reset(new DicomFrameConverter); | |
855 converter_->ReadParameters(dataset); | |
856 ApplyConverter(); | |
857 | |
858 std::string tmp; | |
859 Vector pixelSpacing; | |
860 | |
861 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PIXEL_SPACING)) && | |
862 LinearAlgebra::ParseVector(pixelSpacing, tmp) && | |
863 pixelSpacing.size() == 2) | |
864 { | |
865 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]); | |
866 } | |
867 | |
348 | 868 //SetPan(-0.5 * GetPixelSpacingX(), -0.5 * GetPixelSpacingY()); |
345 | 869 |
343 | 870 static unsigned int c = 0; |
871 if (c == 0) | |
872 { | |
873 SetPan(400, 0); | |
874 c ++; | |
875 } | |
876 | |
877 OrthancPlugins::DicomDatasetReader reader(dataset); | |
878 | |
879 unsigned int width, height; | |
880 if (!reader.GetUnsignedIntegerValue(width, ConvertTag(Orthanc::DICOM_TAG_COLUMNS)) || | |
881 !reader.GetUnsignedIntegerValue(height, ConvertTag(Orthanc::DICOM_TAG_ROWS))) | |
882 { | |
883 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
884 } | |
885 else | |
886 { | |
887 SetSize(width, height); | |
888 } | |
889 } | |
890 | |
891 | |
892 void SetSourceImage(Orthanc::ImageAccessor* image) // Takes ownership | |
893 { | |
894 std::auto_ptr<Orthanc::ImageAccessor> raii(image); | |
895 | |
896 if (image == NULL) | |
897 { | |
898 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
899 } | |
900 | |
901 SetSize(image->GetWidth(), image->GetHeight()); | |
902 | |
903 source_ = raii; | |
904 ApplyConverter(); | |
905 } | |
906 | |
907 | |
908 virtual void Render(Orthanc::ImageAccessor& buffer, | |
345 | 909 const ViewportGeometry& view, |
910 ImageInterpolation interpolation) const | |
343 | 911 { |
912 if (converted_.get() != NULL) | |
913 { | |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
914 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
915 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
916 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
917 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
918 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
919 unsigned int cropX, cropY, cropWidth, cropHeight; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
920 GetCrop(cropX, cropY, cropWidth, cropHeight); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
921 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
922 Matrix m = LinearAlgebra::Product(view.GetMatrix(), |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
923 GetTransform(), |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
924 CreateOffsetMatrix(cropX, cropY)); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
925 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
926 Orthanc::ImageAccessor cropped; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
927 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
928 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
929 ApplyProjectiveTransform(buffer, cropped, m, interpolation, false); |
343 | 930 } |
931 } | |
932 | |
933 | |
934 virtual bool GetDefaultWindowing(float& center, | |
935 float& width) const | |
936 { | |
937 if (converter_.get() != NULL && | |
938 converter_->HasDefaultWindow()) | |
939 { | |
940 center = static_cast<float>(converter_->GetDefaultWindowCenter()); | |
941 width = static_cast<float>(converter_->GetDefaultWindowWidth()); | |
942 return true; | |
943 } | |
944 else | |
945 { | |
946 return false; | |
947 } | |
948 } | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
949 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
950 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
951 virtual bool GetRange(float& minValue, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
952 float& maxValue) const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
953 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
954 if (converted_.get() != NULL) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
955 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
956 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
957 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
958 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
959 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
960 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
961 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, *converted_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
962 return true; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
963 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
964 else |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
965 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
966 return false; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
967 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
968 } |
343 | 969 }; |
970 | |
971 | |
972 | |
973 | |
341 | 974 typedef std::map<size_t, Bitmap*> Bitmaps; |
338 | 975 |
341 | 976 OrthancApiClient& orthanc_; |
977 size_t countBitmaps_; | |
978 bool hasWindowing_; | |
979 float windowingCenter_; | |
980 float windowingWidth_; | |
981 Bitmaps bitmaps_; | |
345 | 982 bool hasSelection_; |
983 size_t selectedBitmap_; | |
338 | 984 |
985 public: | |
986 BitmapStack(MessageBroker& broker, | |
987 OrthancApiClient& orthanc) : | |
988 IObserver(broker), | |
989 IObservable(broker), | |
990 orthanc_(orthanc), | |
341 | 991 countBitmaps_(0), |
338 | 992 hasWindowing_(false), |
993 windowingCenter_(0), // Dummy initialization | |
345 | 994 windowingWidth_(0), // Dummy initialization |
995 hasSelection_(false), | |
996 selectedBitmap_(0) // Dummy initialization | |
338 | 997 { |
998 } | |
999 | |
345 | 1000 |
1001 void Unselect() | |
1002 { | |
1003 hasSelection_ = false; | |
1004 } | |
1005 | |
1006 | |
1007 void Select(size_t bitmap) | |
1008 { | |
1009 hasSelection_ = true; | |
1010 selectedBitmap_ = bitmap; | |
1011 } | |
346 | 1012 |
1013 | |
1014 bool GetSelectedBitmap(size_t& bitmap) const | |
1015 { | |
1016 if (hasSelection_) | |
1017 { | |
1018 bitmap = selectedBitmap_; | |
1019 return true; | |
1020 } | |
1021 else | |
1022 { | |
1023 return false; | |
1024 } | |
1025 } | |
345 | 1026 |
338 | 1027 |
1028 virtual ~BitmapStack() | |
1029 { | |
1030 for (Bitmaps::iterator it = bitmaps_.begin(); it != bitmaps_.end(); it++) | |
1031 { | |
1032 assert(it->second != NULL); | |
1033 delete it->second; | |
1034 } | |
1035 } | |
339 | 1036 |
1037 | |
343 | 1038 bool GetWindowing(float& center, |
1039 float& width) const | |
339 | 1040 { |
1041 if (hasWindowing_) | |
1042 { | |
1043 center = windowingCenter_; | |
1044 width = windowingWidth_; | |
343 | 1045 return true; |
339 | 1046 } |
1047 else | |
1048 { | |
343 | 1049 return false; |
339 | 1050 } |
1051 } | |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1052 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1053 |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1054 void GetWindowingWithDefault(float& center, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1055 float& width) const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1056 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1057 if (!GetWindowing(center, width)) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1058 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1059 center = 128; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1060 width = 256; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1061 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1062 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1063 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1064 |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1065 void SetWindowing(float center, |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1066 float width) |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1067 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1068 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1069 hasWindowing_ = true; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1070 windowingCenter_ = center; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1071 windowingWidth_ = width; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1072 |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1073 //EmitMessage(ContentChangedMessage(*this)); |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1074 } |
338 | 1075 |
1076 | |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1077 Bitmap& LoadText(const Orthanc::Font& font, |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1078 const std::string& utf8) |
343 | 1079 { |
348 | 1080 size_t bitmap = countBitmaps_++; |
1081 | |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1082 std::auto_ptr<AlphaBitmap> alpha(new AlphaBitmap(bitmap, *this)); |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1083 alpha->LoadText(font, utf8); |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1084 |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1085 AlphaBitmap* ptr = alpha.get(); |
348 | 1086 bitmaps_[bitmap] = alpha.release(); |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1087 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1088 return *ptr; |
348 | 1089 } |
1090 | |
1091 | |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1092 Bitmap& LoadTestBlock(unsigned int width, |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1093 unsigned int height) |
348 | 1094 { |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1095 size_t bitmap = countBitmaps_++; |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1096 |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1097 std::auto_ptr<AlphaBitmap> alpha(new AlphaBitmap(bitmap, *this)); |
348 | 1098 |
1099 std::auto_ptr<Orthanc::Image> block(new Orthanc::Image(Orthanc::PixelFormat_Grayscale8, width, height, false)); | |
1100 | |
1101 for (unsigned int padding = 0; | |
1102 (width > 2 * padding) && (height > 2 * padding); | |
1103 padding++) | |
1104 { | |
1105 uint8_t color; | |
1106 if (255 > 10 * padding) | |
1107 { | |
1108 color = 255 - 10 * padding; | |
1109 } | |
1110 else | |
1111 { | |
1112 color = 0; | |
1113 } | |
1114 | |
1115 Orthanc::ImageAccessor region; | |
1116 block->GetRegion(region, padding, padding, width - 2 * padding, height - 2 * padding); | |
1117 Orthanc::ImageProcessing::Set(region, color); | |
1118 } | |
1119 | |
1120 alpha->SetAlpha(block.release()); | |
343 | 1121 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1122 AlphaBitmap* ptr = alpha.get(); |
343 | 1123 bitmaps_[bitmap] = alpha.release(); |
1124 | |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1125 return *ptr; |
343 | 1126 } |
1127 | |
1128 | |
354 | 1129 Bitmap& LoadFrame(const std::string& instance, |
341 | 1130 unsigned int frame, |
1131 bool httpCompression) | |
338 | 1132 { |
341 | 1133 size_t bitmap = countBitmaps_++; |
338 | 1134 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1135 bitmaps_[bitmap] = new DicomBitmap(bitmap); |
338 | 1136 |
1137 { | |
1138 IWebService::Headers headers; | |
1139 std::string uri = "/instances/" + instance + "/tags"; | |
1140 orthanc_.GetBinaryAsync(uri, headers, | |
1141 new Callable<BitmapStack, OrthancApiClient::BinaryResponseReadyMessage> | |
1142 (*this, &BitmapStack::OnTagsReceived), NULL, | |
341 | 1143 new Orthanc::SingleValueObject<size_t>(bitmap)); |
338 | 1144 } |
1145 | |
1146 { | |
1147 IWebService::Headers headers; | |
1148 headers["Accept"] = "image/x-portable-arbitrarymap"; | |
1149 | |
1150 if (httpCompression) | |
1151 { | |
1152 headers["Accept-Encoding"] = "gzip"; | |
1153 } | |
1154 | |
1155 std::string uri = "/instances/" + instance + "/frames/" + boost::lexical_cast<std::string>(frame) + "/image-uint16"; | |
1156 orthanc_.GetBinaryAsync(uri, headers, | |
1157 new Callable<BitmapStack, OrthancApiClient::BinaryResponseReadyMessage> | |
1158 (*this, &BitmapStack::OnFrameReceived), NULL, | |
341 | 1159 new Orthanc::SingleValueObject<size_t>(bitmap)); |
338 | 1160 } |
1161 | |
354 | 1162 return *bitmaps_[bitmap]; |
338 | 1163 } |
1164 | |
1165 | |
1166 void OnTagsReceived(const OrthancApiClient::BinaryResponseReadyMessage& message) | |
1167 { | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
1168 size_t index = dynamic_cast<Orthanc::SingleValueObject<size_t>*>(message.Payload.get())->GetValue(); |
338 | 1169 |
341 | 1170 printf("JSON received: [%s] (%ld bytes) for bitmap %ld\n", |
1171 message.Uri.c_str(), message.AnswerSize, index); | |
338 | 1172 |
341 | 1173 Bitmaps::iterator bitmap = bitmaps_.find(index); |
338 | 1174 if (bitmap != bitmaps_.end()) |
1175 { | |
1176 assert(bitmap->second != NULL); | |
1177 | |
1178 OrthancPlugins::FullOrthancDataset dicom(message.Answer, message.AnswerSize); | |
343 | 1179 dynamic_cast<DicomBitmap*>(bitmap->second)->SetDicomTags(dicom); |
338 | 1180 |
1181 float c, w; | |
1182 if (!hasWindowing_ && | |
1183 bitmap->second->GetDefaultWindowing(c, w)) | |
1184 { | |
1185 hasWindowing_ = true; | |
1186 windowingCenter_ = c; | |
1187 windowingWidth_ = w; | |
1188 } | |
1189 | |
1190 EmitMessage(GeometryChangedMessage(*this)); | |
1191 } | |
1192 } | |
1193 | |
1194 | |
1195 void OnFrameReceived(const OrthancApiClient::BinaryResponseReadyMessage& message) | |
1196 { | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
1197 size_t index = dynamic_cast<Orthanc::SingleValueObject<size_t>*>(message.Payload.get())->GetValue(); |
338 | 1198 |
341 | 1199 printf("Frame received: [%s] (%ld bytes) for bitmap %ld\n", |
1200 message.Uri.c_str(), message.AnswerSize, index); | |
1201 | |
1202 Bitmaps::iterator bitmap = bitmaps_.find(index); | |
338 | 1203 if (bitmap != bitmaps_.end()) |
1204 { | |
1205 assert(bitmap->second != NULL); | |
1206 | |
1207 std::string content; | |
1208 if (message.AnswerSize > 0) | |
1209 { | |
1210 content.assign(reinterpret_cast<const char*>(message.Answer), message.AnswerSize); | |
1211 } | |
1212 | |
1213 std::auto_ptr<Orthanc::PamReader> reader(new Orthanc::PamReader); | |
1214 reader->ReadFromMemory(content); | |
343 | 1215 dynamic_cast<DicomBitmap*>(bitmap->second)->SetSourceImage(reader.release()); |
338 | 1216 |
1217 EmitMessage(ContentChangedMessage(*this)); | |
1218 } | |
1219 } | |
339 | 1220 |
1221 | |
1222 Extent2D GetSceneExtent() const | |
1223 { | |
1224 Extent2D extent; | |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
1225 |
339 | 1226 for (Bitmaps::const_iterator it = bitmaps_.begin(); |
1227 it != bitmaps_.end(); ++it) | |
1228 { | |
1229 assert(it->second != NULL); | |
1230 extent.Union(it->second->GetExtent()); | |
1231 } | |
1232 | |
1233 return extent; | |
1234 } | |
1235 | |
1236 | |
1237 void Render(Orthanc::ImageAccessor& buffer, | |
345 | 1238 const ViewportGeometry& view, |
1239 ImageInterpolation interpolation) const | |
339 | 1240 { |
1241 Orthanc::ImageProcessing::Set(buffer, 0); | |
1242 | |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1243 // Render layers in the background-to-foreground order |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1244 for (size_t index = 0; index < countBitmaps_; index++) |
339 | 1245 { |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1246 Bitmaps::const_iterator it = bitmaps_.find(index); |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1247 if (it != bitmaps_.end()) |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1248 { |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1249 assert(it->second != NULL); |
345 | 1250 it->second->Render(buffer, view, interpolation); |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1251 } |
339 | 1252 } |
1253 } | |
342 | 1254 |
1255 | |
1256 bool LookupBitmap(size_t& index /* out */, | |
1257 double x, | |
1258 double y) const | |
1259 { | |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1260 // Render layers in the foreground-to-background order |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1261 for (size_t i = countBitmaps_; i > 0; i--) |
342 | 1262 { |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1263 index = i - 1; |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1264 Bitmaps::const_iterator it = bitmaps_.find(index); |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1265 if (it != bitmaps_.end()) |
342 | 1266 { |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1267 assert(it->second != NULL); |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1268 if (it->second->Contains(x, y)) |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1269 { |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1270 return true; |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
1271 } |
342 | 1272 } |
1273 } | |
1274 | |
1275 return false; | |
1276 } | |
1277 | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
1278 void DrawControls(CairoContext& context, |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
1279 double zoom) |
345 | 1280 { |
1281 if (hasSelection_) | |
1282 { | |
1283 Bitmaps::const_iterator bitmap = bitmaps_.find(selectedBitmap_); | |
1284 | |
1285 if (bitmap != bitmaps_.end()) | |
1286 { | |
1287 context.SetSourceColor(255, 0, 0); | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
1288 //view.ApplyTransform(context); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
1289 bitmap->second->DrawBorders(context, zoom); |
345 | 1290 } |
1291 } | |
1292 } | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1293 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1294 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1295 void GetRange(float& minValue, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1296 float& maxValue) const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1297 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1298 bool first = true; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1299 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1300 for (Bitmaps::const_iterator it = bitmaps_.begin(); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1301 it != bitmaps_.end(); it++) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1302 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1303 assert(it->second != NULL); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1304 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1305 float a, b; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1306 if (it->second->GetRange(a, b)) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1307 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1308 if (first) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1309 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1310 minValue = a; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1311 maxValue = b; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1312 first = false; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1313 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1314 else |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1315 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1316 minValue = std::min(a, minValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1317 maxValue = std::max(b, maxValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1318 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1319 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1320 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1321 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1322 if (first) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1323 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1324 minValue = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1325 maxValue = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1326 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1327 } |
338 | 1328 }; |
1329 | |
341 | 1330 |
354 | 1331 class UndoRedoStack : public boost::noncopyable |
1332 { | |
1333 public: | |
1334 class ICommand : public boost::noncopyable | |
1335 { | |
1336 public: | |
1337 virtual ~ICommand() | |
1338 { | |
1339 } | |
1340 | |
1341 virtual void Undo() const = 0; | |
1342 | |
1343 virtual void Redo() const = 0; | |
1344 }; | |
1345 | |
1346 private: | |
1347 typedef std::list<ICommand*> Stack; | |
1348 | |
1349 Stack stack_; | |
1350 Stack::iterator current_; | |
1351 | |
1352 void Clear(Stack::iterator from) | |
1353 { | |
1354 for (Stack::iterator it = from; it != stack_.end(); ++it) | |
1355 { | |
1356 assert(*it != NULL); | |
1357 delete *it; | |
1358 } | |
1359 | |
1360 stack_.erase(from, stack_.end()); | |
1361 } | |
1362 | |
1363 public: | |
1364 UndoRedoStack() : | |
1365 current_(stack_.end()) | |
1366 { | |
1367 } | |
1368 | |
1369 ~UndoRedoStack() | |
1370 { | |
1371 Clear(stack_.begin()); | |
1372 } | |
1373 | |
1374 void Add(ICommand* command) | |
1375 { | |
1376 if (command == NULL) | |
1377 { | |
1378 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
1379 } | |
1380 | |
1381 Clear(current_); | |
1382 | |
1383 stack_.push_back(command); | |
1384 current_ = stack_.end(); | |
1385 } | |
1386 | |
1387 void Undo() | |
1388 { | |
1389 if (current_ != stack_.begin()) | |
1390 { | |
1391 --current_; | |
1392 | |
1393 assert(*current_ != NULL); | |
1394 (*current_)->Undo(); | |
1395 } | |
1396 } | |
1397 | |
1398 void Redo() | |
1399 { | |
1400 if (current_ != stack_.end()) | |
1401 { | |
1402 assert(*current_ != NULL); | |
1403 (*current_)->Redo(); | |
1404 | |
1405 ++current_; | |
1406 } | |
1407 } | |
1408 }; | |
1409 | |
1410 | |
1411 class BitmapCommandBase : public UndoRedoStack::ICommand | |
1412 { | |
1413 private: | |
1414 BitmapStack& stack_; | |
1415 size_t bitmap_; | |
1416 | |
1417 protected: | |
1418 virtual void UndoInternal(BitmapStack::Bitmap& bitmap) const = 0; | |
1419 | |
1420 virtual void RedoInternal(BitmapStack::Bitmap& bitmap) const = 0; | |
1421 | |
1422 public: | |
1423 BitmapCommandBase(BitmapStack& stack, | |
1424 size_t bitmap) : | |
1425 stack_(stack), | |
1426 bitmap_(bitmap) | |
1427 { | |
1428 } | |
1429 | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1430 BitmapCommandBase(const BitmapStack::BitmapAccessor& accessor) : |
354 | 1431 stack_(accessor.GetStack()), |
1432 bitmap_(accessor.GetIndex()) | |
1433 { | |
1434 } | |
1435 | |
1436 virtual void Undo() const | |
1437 { | |
1438 BitmapStack::BitmapAccessor accessor(stack_, bitmap_); | |
1439 | |
1440 if (accessor.IsValid()) | |
1441 { | |
1442 UndoInternal(accessor.GetBitmap()); | |
1443 } | |
1444 } | |
1445 | |
1446 virtual void Redo() const | |
1447 { | |
1448 BitmapStack::BitmapAccessor accessor(stack_, bitmap_); | |
1449 | |
1450 if (accessor.IsValid()) | |
1451 { | |
1452 RedoInternal(accessor.GetBitmap()); | |
1453 } | |
1454 } | |
1455 }; | |
1456 | |
1457 | |
1458 class RotateBitmapTracker : public IWorldSceneMouseTracker | |
1459 { | |
1460 private: | |
1461 UndoRedoStack& undoRedoStack_; | |
1462 BitmapStack::BitmapAccessor accessor_; | |
1463 double centerX_; | |
1464 double centerY_; | |
1465 double originalAngle_; | |
1466 double clickAngle_; | |
1467 bool roundAngles_; | |
1468 | |
1469 bool ComputeAngle(double& angle /* out */, | |
1470 double sceneX, | |
1471 double sceneY) const | |
1472 { | |
1473 Vector u; | |
1474 LinearAlgebra::AssignVector(u, sceneX - centerX_, sceneY - centerY_); | |
1475 | |
1476 double nu = boost::numeric::ublas::norm_2(u); | |
1477 | |
1478 if (!LinearAlgebra::IsCloseToZero(nu)) | |
1479 { | |
1480 u /= nu; | |
1481 angle = atan2(u[1], u[0]); | |
1482 return true; | |
1483 } | |
1484 else | |
1485 { | |
1486 return false; | |
1487 } | |
1488 } | |
1489 | |
1490 | |
1491 class UndoRedoCommand : public BitmapCommandBase | |
1492 { | |
1493 private: | |
1494 double sourceAngle_; | |
1495 double targetAngle_; | |
1496 | |
1497 static int ToDegrees(double angle) | |
1498 { | |
1499 return static_cast<int>(round(angle * 180.0 / boost::math::constants::pi<double>())); | |
1500 } | |
1501 | |
1502 protected: | |
1503 virtual void UndoInternal(BitmapStack::Bitmap& bitmap) const | |
1504 { | |
1505 LOG(INFO) << "Undo - Set angle to " << ToDegrees(sourceAngle_) << " degrees"; | |
1506 bitmap.SetAngle(sourceAngle_); | |
1507 } | |
1508 | |
1509 virtual void RedoInternal(BitmapStack::Bitmap& bitmap) const | |
1510 { | |
1511 LOG(INFO) << "Redo - Set angle to " << ToDegrees(sourceAngle_) << " degrees"; | |
1512 bitmap.SetAngle(targetAngle_); | |
1513 } | |
1514 | |
1515 public: | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1516 UndoRedoCommand(const RotateBitmapTracker& tracker) : |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1517 BitmapCommandBase(tracker.accessor_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1518 sourceAngle_(tracker.originalAngle_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1519 targetAngle_(tracker.accessor_.GetBitmap().GetAngle()) |
354 | 1520 { |
1521 } | |
1522 }; | |
1523 | |
1524 | |
1525 public: | |
1526 RotateBitmapTracker(UndoRedoStack& undoRedoStack, | |
1527 BitmapStack& stack, | |
1528 const ViewportGeometry& view, | |
1529 size_t bitmap, | |
1530 double x, | |
1531 double y, | |
1532 bool roundAngles) : | |
1533 undoRedoStack_(undoRedoStack), | |
1534 accessor_(stack, bitmap), | |
1535 roundAngles_(roundAngles) | |
1536 { | |
1537 if (accessor_.IsValid()) | |
1538 { | |
1539 accessor_.GetBitmap().GetCenter(centerX_, centerY_); | |
1540 originalAngle_ = accessor_.GetBitmap().GetAngle(); | |
1541 | |
1542 double sceneX, sceneY; | |
1543 view.MapDisplayToScene(sceneX, sceneY, x, y); | |
1544 | |
1545 if (!ComputeAngle(clickAngle_, x, y)) | |
1546 { | |
1547 accessor_.Invalidate(); | |
1548 } | |
1549 } | |
1550 } | |
1551 | |
1552 virtual bool HasRender() const | |
1553 { | |
1554 return false; | |
1555 } | |
1556 | |
1557 virtual void Render(CairoContext& context, | |
1558 double zoom) | |
1559 { | |
1560 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1561 } | |
1562 | |
1563 virtual void MouseUp() | |
1564 { | |
1565 if (accessor_.IsValid()) | |
1566 { | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1567 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
354 | 1568 } |
1569 } | |
1570 | |
1571 virtual void MouseMove(int displayX, | |
1572 int displayY, | |
1573 double sceneX, | |
1574 double sceneY) | |
1575 { | |
1576 static const double ROUND_ANGLE = 15.0 / 180.0 * boost::math::constants::pi<double>(); | |
1577 | |
1578 double angle; | |
1579 | |
1580 if (accessor_.IsValid() && | |
1581 ComputeAngle(angle, sceneX, sceneY)) | |
1582 { | |
1583 angle = angle - clickAngle_ + originalAngle_; | |
1584 | |
1585 if (roundAngles_) | |
1586 { | |
1587 angle = round(angle / ROUND_ANGLE) * ROUND_ANGLE; | |
1588 } | |
1589 | |
1590 accessor_.GetBitmap().SetAngle(angle); | |
1591 } | |
1592 } | |
1593 }; | |
1594 | |
1595 | |
1596 class MoveBitmapTracker : public IWorldSceneMouseTracker | |
1597 { | |
1598 private: | |
1599 UndoRedoStack& undoRedoStack_; | |
1600 BitmapStack::BitmapAccessor accessor_; | |
1601 double clickX_; | |
1602 double clickY_; | |
1603 double panX_; | |
1604 double panY_; | |
1605 bool oneAxis_; | |
1606 | |
1607 class UndoRedoCommand : public BitmapCommandBase | |
1608 { | |
1609 private: | |
1610 double sourceX_; | |
1611 double sourceY_; | |
1612 double targetX_; | |
1613 double targetY_; | |
1614 | |
1615 protected: | |
1616 virtual void UndoInternal(BitmapStack::Bitmap& bitmap) const | |
1617 { | |
1618 bitmap.SetPan(sourceX_, sourceY_); | |
1619 } | |
1620 | |
1621 virtual void RedoInternal(BitmapStack::Bitmap& bitmap) const | |
1622 { | |
1623 bitmap.SetPan(targetX_, targetY_); | |
1624 } | |
1625 | |
1626 public: | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1627 UndoRedoCommand(const MoveBitmapTracker& tracker) : |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1628 BitmapCommandBase(tracker.accessor_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1629 sourceX_(tracker.panX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1630 sourceY_(tracker.panY_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1631 targetX_(tracker.accessor_.GetBitmap().GetPanX()), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1632 targetY_(tracker.accessor_.GetBitmap().GetPanY()) |
354 | 1633 { |
1634 } | |
1635 }; | |
1636 | |
1637 | |
1638 public: | |
1639 MoveBitmapTracker(UndoRedoStack& undoRedoStack, | |
1640 BitmapStack& stack, | |
1641 size_t bitmap, | |
1642 double x, | |
1643 double y, | |
1644 bool oneAxis) : | |
1645 undoRedoStack_(undoRedoStack), | |
1646 accessor_(stack, bitmap), | |
1647 clickX_(x), | |
1648 clickY_(y), | |
1649 oneAxis_(oneAxis) | |
1650 { | |
1651 if (accessor_.IsValid()) | |
1652 { | |
1653 panX_ = accessor_.GetBitmap().GetPanX(); | |
1654 panY_ = accessor_.GetBitmap().GetPanY(); | |
1655 } | |
1656 } | |
1657 | |
1658 virtual bool HasRender() const | |
1659 { | |
1660 return false; | |
1661 } | |
1662 | |
1663 virtual void Render(CairoContext& context, | |
1664 double zoom) | |
1665 { | |
1666 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1667 } | |
1668 | |
1669 virtual void MouseUp() | |
1670 { | |
1671 if (accessor_.IsValid()) | |
1672 { | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1673 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
354 | 1674 } |
1675 } | |
1676 | |
1677 virtual void MouseMove(int displayX, | |
1678 int displayY, | |
1679 double sceneX, | |
1680 double sceneY) | |
1681 { | |
1682 if (accessor_.IsValid()) | |
1683 { | |
1684 double dx = sceneX - clickX_; | |
1685 double dy = sceneY - clickY_; | |
1686 | |
1687 if (oneAxis_) | |
1688 { | |
1689 if (fabs(dx) > fabs(dy)) | |
1690 { | |
1691 accessor_.GetBitmap().SetPan(dx + panX_, panY_); | |
1692 } | |
1693 else | |
1694 { | |
1695 accessor_.GetBitmap().SetPan(panX_, dy + panY_); | |
1696 } | |
1697 } | |
1698 else | |
1699 { | |
1700 accessor_.GetBitmap().SetPan(dx + panX_, dy + panY_); | |
1701 } | |
1702 } | |
1703 } | |
1704 }; | |
1705 | |
1706 | |
1707 class CropBitmapTracker : public IWorldSceneMouseTracker | |
1708 { | |
1709 private: | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1710 UndoRedoStack& undoRedoStack_; |
354 | 1711 BitmapStack::BitmapAccessor accessor_; |
1712 BitmapStack::Corner corner_; | |
1713 unsigned int cropX_; | |
1714 unsigned int cropY_; | |
1715 unsigned int cropWidth_; | |
1716 unsigned int cropHeight_; | |
1717 | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1718 class UndoRedoCommand : public BitmapCommandBase |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1719 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1720 private: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1721 unsigned int sourceCropX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1722 unsigned int sourceCropY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1723 unsigned int sourceCropWidth_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1724 unsigned int sourceCropHeight_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1725 unsigned int targetCropX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1726 unsigned int targetCropY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1727 unsigned int targetCropWidth_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1728 unsigned int targetCropHeight_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1729 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1730 protected: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1731 virtual void UndoInternal(BitmapStack::Bitmap& bitmap) const |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1732 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1733 bitmap.SetCrop(sourceCropX_, sourceCropY_, sourceCropWidth_, sourceCropHeight_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1734 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1735 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1736 virtual void RedoInternal(BitmapStack::Bitmap& bitmap) const |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1737 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1738 bitmap.SetCrop(targetCropX_, targetCropY_, targetCropWidth_, targetCropHeight_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1739 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1740 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1741 public: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1742 UndoRedoCommand(const CropBitmapTracker& tracker) : |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1743 BitmapCommandBase(tracker.accessor_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1744 sourceCropX_(tracker.cropX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1745 sourceCropY_(tracker.cropY_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1746 sourceCropWidth_(tracker.cropWidth_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1747 sourceCropHeight_(tracker.cropHeight_) |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1748 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1749 tracker.accessor_.GetBitmap().GetCrop(targetCropX_, targetCropY_, |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1750 targetCropWidth_, targetCropHeight_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1751 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1752 }; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1753 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1754 |
354 | 1755 public: |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1756 CropBitmapTracker(UndoRedoStack& undoRedoStack, |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1757 BitmapStack& stack, |
354 | 1758 const ViewportGeometry& view, |
1759 size_t bitmap, | |
1760 double x, | |
1761 double y, | |
1762 BitmapStack::Corner corner) : | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1763 undoRedoStack_(undoRedoStack), |
354 | 1764 accessor_(stack, bitmap), |
1765 corner_(corner) | |
1766 { | |
1767 if (accessor_.IsValid()) | |
1768 { | |
1769 accessor_.GetBitmap().GetCrop(cropX_, cropY_, cropWidth_, cropHeight_); | |
1770 } | |
1771 } | |
1772 | |
1773 virtual bool HasRender() const | |
1774 { | |
1775 return false; | |
1776 } | |
1777 | |
1778 virtual void Render(CairoContext& context, | |
1779 double zoom) | |
1780 { | |
1781 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1782 } | |
1783 | |
1784 virtual void MouseUp() | |
1785 { | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1786 if (accessor_.IsValid()) |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1787 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1788 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1789 } |
354 | 1790 } |
1791 | |
1792 virtual void MouseMove(int displayX, | |
1793 int displayY, | |
1794 double sceneX, | |
1795 double sceneY) | |
1796 { | |
1797 if (accessor_.IsValid()) | |
1798 { | |
1799 unsigned int x, y; | |
1800 | |
1801 BitmapStack::Bitmap& bitmap = accessor_.GetBitmap(); | |
1802 if (bitmap.GetPixel(x, y, sceneX, sceneY)) | |
1803 { | |
1804 unsigned int targetX, targetWidth; | |
1805 | |
1806 if (corner_ == BitmapStack::Corner_TopLeft || | |
1807 corner_ == BitmapStack::Corner_BottomLeft) | |
1808 { | |
1809 targetX = std::min(x, cropX_ + cropWidth_); | |
1810 targetWidth = cropX_ + cropWidth_ - targetX; | |
1811 } | |
1812 else | |
1813 { | |
1814 targetX = cropX_; | |
1815 targetWidth = std::max(x, cropX_) - cropX_; | |
1816 } | |
1817 | |
1818 unsigned int targetY, targetHeight; | |
1819 | |
1820 if (corner_ == BitmapStack::Corner_TopLeft || | |
1821 corner_ == BitmapStack::Corner_TopRight) | |
1822 { | |
1823 targetY = std::min(y, cropY_ + cropHeight_); | |
1824 targetHeight = cropY_ + cropHeight_ - targetY; | |
1825 } | |
1826 else | |
1827 { | |
1828 targetY = cropY_; | |
1829 targetHeight = std::max(y, cropY_) - cropY_; | |
1830 } | |
1831 | |
1832 bitmap.SetCrop(targetX, targetY, targetWidth, targetHeight); | |
1833 } | |
1834 } | |
1835 } | |
1836 }; | |
1837 | |
1838 | |
1839 class ResizeBitmapTracker : public IWorldSceneMouseTracker | |
1840 { | |
1841 private: | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1842 UndoRedoStack& undoRedoStack_; |
354 | 1843 BitmapStack::BitmapAccessor accessor_; |
1844 bool roundScaling_; | |
1845 double originalSpacingX_; | |
1846 double originalSpacingY_; | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1847 double originalPanX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1848 double originalPanY_; |
354 | 1849 BitmapStack::Corner oppositeCorner_; |
1850 double oppositeX_; | |
1851 double oppositeY_; | |
1852 double baseScaling_; | |
1853 | |
1854 static double ComputeDistance(double x1, | |
1855 double y1, | |
1856 double x2, | |
1857 double y2) | |
1858 { | |
1859 double dx = x1 - x2; | |
1860 double dy = y1 - y2; | |
1861 return sqrt(dx * dx + dy * dy); | |
1862 } | |
1863 | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1864 class UndoRedoCommand : public BitmapCommandBase |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1865 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1866 private: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1867 double sourceSpacingX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1868 double sourceSpacingY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1869 double sourcePanX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1870 double sourcePanY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1871 double targetSpacingX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1872 double targetSpacingY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1873 double targetPanX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1874 double targetPanY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1875 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1876 protected: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1877 virtual void UndoInternal(BitmapStack::Bitmap& bitmap) const |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1878 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1879 bitmap.SetPixelSpacing(sourceSpacingX_, sourceSpacingY_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1880 bitmap.SetPan(sourcePanX_, sourcePanY_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1881 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1882 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1883 virtual void RedoInternal(BitmapStack::Bitmap& bitmap) const |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1884 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1885 bitmap.SetPixelSpacing(targetSpacingX_, targetSpacingY_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1886 bitmap.SetPan(targetPanX_, targetPanY_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1887 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1888 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1889 public: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1890 UndoRedoCommand(const ResizeBitmapTracker& tracker) : |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1891 BitmapCommandBase(tracker.accessor_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1892 sourceSpacingX_(tracker.originalSpacingX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1893 sourceSpacingY_(tracker.originalSpacingY_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1894 sourcePanX_(tracker.originalPanX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1895 sourcePanY_(tracker.originalPanY_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1896 targetSpacingX_(tracker.accessor_.GetBitmap().GetPixelSpacingX()), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1897 targetSpacingY_(tracker.accessor_.GetBitmap().GetPixelSpacingY()), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1898 targetPanX_(tracker.accessor_.GetBitmap().GetPanX()), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1899 targetPanY_(tracker.accessor_.GetBitmap().GetPanY()) |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1900 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1901 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1902 }; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1903 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1904 |
354 | 1905 public: |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1906 ResizeBitmapTracker(UndoRedoStack& undoRedoStack, |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1907 BitmapStack& stack, |
354 | 1908 size_t bitmap, |
1909 double x, | |
1910 double y, | |
1911 BitmapStack::Corner corner, | |
1912 bool roundScaling) : | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1913 undoRedoStack_(undoRedoStack), |
354 | 1914 accessor_(stack, bitmap), |
1915 roundScaling_(roundScaling) | |
1916 { | |
1917 if (accessor_.IsValid() && | |
1918 accessor_.GetBitmap().IsResizeable()) | |
1919 { | |
1920 originalSpacingX_ = accessor_.GetBitmap().GetPixelSpacingX(); | |
1921 originalSpacingY_ = accessor_.GetBitmap().GetPixelSpacingY(); | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1922 originalPanX_ = accessor_.GetBitmap().GetPanX(); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1923 originalPanY_ = accessor_.GetBitmap().GetPanY(); |
354 | 1924 |
1925 switch (corner) | |
1926 { | |
1927 case BitmapStack::Corner_TopLeft: | |
1928 oppositeCorner_ = BitmapStack::Corner_BottomRight; | |
1929 break; | |
1930 | |
1931 case BitmapStack::Corner_TopRight: | |
1932 oppositeCorner_ = BitmapStack::Corner_BottomLeft; | |
1933 break; | |
1934 | |
1935 case BitmapStack::Corner_BottomLeft: | |
1936 oppositeCorner_ = BitmapStack::Corner_TopRight; | |
1937 break; | |
1938 | |
1939 case BitmapStack::Corner_BottomRight: | |
1940 oppositeCorner_ = BitmapStack::Corner_TopLeft; | |
1941 break; | |
1942 | |
1943 default: | |
1944 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1945 } | |
1946 | |
1947 accessor_.GetBitmap().GetCorner(oppositeX_, oppositeY_, oppositeCorner_); | |
1948 | |
1949 double d = ComputeDistance(x, y, oppositeX_, oppositeY_); | |
1950 if (d >= std::numeric_limits<float>::epsilon()) | |
1951 { | |
1952 baseScaling_ = 1.0 / d; | |
1953 } | |
1954 else | |
1955 { | |
1956 // Avoid division by zero in extreme cases | |
1957 accessor_.Invalidate(); | |
1958 } | |
1959 } | |
1960 } | |
1961 | |
1962 virtual bool HasRender() const | |
1963 { | |
1964 return false; | |
1965 } | |
1966 | |
1967 virtual void Render(CairoContext& context, | |
1968 double zoom) | |
1969 { | |
1970 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1971 } | |
1972 | |
1973 virtual void MouseUp() | |
1974 { | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
1975 if (accessor_.IsValid() && |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
1976 accessor_.GetBitmap().IsResizeable()) |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1977 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1978 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1979 } |
354 | 1980 } |
1981 | |
1982 virtual void MouseMove(int displayX, | |
1983 int displayY, | |
1984 double sceneX, | |
1985 double sceneY) | |
1986 { | |
1987 static const double ROUND_SCALING = 0.1; | |
1988 | |
1989 if (accessor_.IsValid() && | |
1990 accessor_.GetBitmap().IsResizeable()) | |
1991 { | |
1992 double scaling = ComputeDistance(oppositeX_, oppositeY_, sceneX, sceneY) * baseScaling_; | |
1993 | |
1994 if (roundScaling_) | |
1995 { | |
1996 scaling = round(scaling / ROUND_SCALING) * ROUND_SCALING; | |
1997 } | |
1998 | |
1999 BitmapStack::Bitmap& bitmap = accessor_.GetBitmap(); | |
2000 bitmap.SetPixelSpacing(scaling * originalSpacingX_, | |
2001 scaling * originalSpacingY_); | |
2002 | |
2003 // Keep the opposite corner at a fixed location | |
2004 double ox, oy; | |
2005 bitmap.GetCorner(ox, oy, oppositeCorner_); | |
2006 bitmap.SetPan(bitmap.GetPanX() + oppositeX_ - ox, | |
2007 bitmap.GetPanY() + oppositeY_ - oy); | |
2008 } | |
2009 } | |
2010 }; | |
2011 | |
2012 | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2013 class WindowingTracker : public IWorldSceneMouseTracker |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2014 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2015 public: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2016 enum Action |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2017 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2018 Action_IncreaseWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2019 Action_DecreaseWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2020 Action_IncreaseCenter, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2021 Action_DecreaseCenter |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2022 }; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2023 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2024 private: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2025 UndoRedoStack& undoRedoStack_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2026 BitmapStack& stack_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2027 int clickX_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2028 int clickY_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2029 Action leftAction_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2030 Action rightAction_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2031 Action upAction_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2032 Action downAction_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2033 float strength_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2034 float sourceCenter_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2035 float sourceWidth_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2036 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2037 static void ComputeAxisEffect(int& deltaCenter, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2038 int& deltaWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2039 int delta, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2040 Action actionNegative, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2041 Action actionPositive) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2042 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2043 if (delta < 0) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2044 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2045 switch (actionNegative) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2046 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2047 case Action_IncreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2048 deltaWidth = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2049 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2050 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2051 case Action_DecreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2052 deltaWidth = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2053 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2054 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2055 case Action_IncreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2056 deltaCenter = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2057 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2058 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2059 case Action_DecreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2060 deltaCenter = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2061 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2062 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2063 default: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2064 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2065 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2066 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2067 else if (delta > 0) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2068 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2069 switch (actionPositive) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2070 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2071 case Action_IncreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2072 deltaWidth = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2073 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2074 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2075 case Action_DecreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2076 deltaWidth = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2077 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2078 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2079 case Action_IncreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2080 deltaCenter = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2081 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2082 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2083 case Action_DecreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2084 deltaCenter = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2085 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2086 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2087 default: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2088 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2089 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2090 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2091 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2092 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2093 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2094 class UndoRedoCommand : public UndoRedoStack::ICommand |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2095 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2096 private: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2097 BitmapStack& stack_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2098 float sourceCenter_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2099 float sourceWidth_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2100 float targetCenter_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2101 float targetWidth_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2102 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2103 public: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2104 UndoRedoCommand(const WindowingTracker& tracker) : |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2105 stack_(tracker.stack_), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2106 sourceCenter_(tracker.sourceCenter_), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2107 sourceWidth_(tracker.sourceWidth_) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2108 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2109 stack_.GetWindowingWithDefault(targetCenter_, targetWidth_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2110 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2111 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2112 virtual void Undo() const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2113 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2114 stack_.SetWindowing(sourceCenter_, sourceWidth_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2115 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2116 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2117 virtual void Redo() const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2118 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2119 stack_.SetWindowing(targetCenter_, targetWidth_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2120 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2121 }; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2122 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2123 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2124 public: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2125 WindowingTracker(UndoRedoStack& undoRedoStack, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2126 BitmapStack& stack, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2127 int x, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2128 int y, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2129 Action leftAction, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2130 Action rightAction, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2131 Action upAction, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2132 Action downAction) : |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2133 undoRedoStack_(undoRedoStack), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2134 stack_(stack), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2135 clickX_(x), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2136 clickY_(y), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2137 leftAction_(leftAction), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2138 rightAction_(rightAction), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2139 upAction_(upAction), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2140 downAction_(downAction) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2141 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2142 stack_.GetWindowingWithDefault(sourceCenter_, sourceWidth_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2143 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2144 float minValue, maxValue; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2145 stack.GetRange(minValue, maxValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2146 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2147 assert(minValue <= maxValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2148 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2149 float tmp; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2150 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2151 float delta = (maxValue - minValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2152 if (delta <= 1) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2153 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2154 tmp = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2155 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2156 else |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2157 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2158 tmp = log2(delta); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2159 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2160 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2161 strength_ = tmp - 7; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2162 if (strength_ < 1) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2163 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2164 strength_ = 1; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2165 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2166 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2167 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2168 virtual bool HasRender() const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2169 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2170 return false; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2171 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2172 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2173 virtual void Render(CairoContext& context, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2174 double zoom) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2175 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2176 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2177 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2178 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2179 virtual void MouseUp() |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2180 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2181 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2182 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2183 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2184 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2185 virtual void MouseMove(int displayX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2186 int displayY, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2187 double sceneX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2188 double sceneY) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2189 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2190 // 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
|
2191 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2192 static const float SCALE = 1.0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2193 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2194 int deltaCenter = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2195 int deltaWidth = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2196 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2197 ComputeAxisEffect(deltaCenter, deltaWidth, displayX - clickX_, leftAction_, rightAction_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2198 ComputeAxisEffect(deltaCenter, deltaWidth, displayY - clickY_, upAction_, downAction_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2199 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2200 float newCenter = sourceCenter_ + (deltaCenter / SCALE * strength_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2201 float newWidth = sourceWidth_ + (deltaWidth / SCALE * strength_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2202 stack_.SetWindowing(newCenter, newWidth); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2203 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2204 }; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2205 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2206 |
341 | 2207 class BitmapStackInteractor : public IWorldSceneInteractor |
2208 { | |
342 | 2209 private: |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2210 enum Tool |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2211 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2212 Tool_Move, |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2213 Tool_Rotate, |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2214 Tool_Crop, |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2215 Tool_Resize, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2216 Tool_Windowing |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2217 }; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2218 |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2219 static double GetHandleSize() |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2220 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2221 return 10.0; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2222 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2223 |
342 | 2224 |
354 | 2225 BitmapStack& stack_; |
2226 UndoRedoStack undoRedoStack_; | |
2227 Tool tool_; | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2228 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2229 |
341 | 2230 public: |
342 | 2231 BitmapStackInteractor(BitmapStack& stack) : |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2232 stack_(stack), |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2233 tool_(Tool_Move) |
342 | 2234 { |
2235 } | |
2236 | |
341 | 2237 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, |
2238 const ViewportGeometry& view, | |
2239 MouseButton button, | |
2240 KeyboardModifiers modifiers, | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2241 int viewportX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2242 int viewportY, |
341 | 2243 double x, |
2244 double y, | |
2245 IStatusBar* statusBar) | |
2246 { | |
342 | 2247 if (button == MouseButton_Left) |
2248 { | |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2249 size_t selected; |
346 | 2250 |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2251 if (tool_ == Tool_Windowing) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2252 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2253 return new WindowingTracker(undoRedoStack_, stack_, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2254 viewportX, viewportY, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2255 WindowingTracker::Action_DecreaseWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2256 WindowingTracker::Action_IncreaseWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2257 WindowingTracker::Action_DecreaseCenter, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2258 WindowingTracker::Action_IncreaseCenter); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2259 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2260 else if (!stack_.GetSelectedBitmap(selected)) |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2261 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2262 size_t bitmap; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2263 if (stack_.LookupBitmap(bitmap, x, y)) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2264 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2265 printf("CLICK on bitmap %ld\n", bitmap); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2266 stack_.Select(bitmap); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2267 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2268 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2269 return NULL; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2270 } |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2271 else if (tool_ == Tool_Crop || |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2272 tool_ == Tool_Resize) |
342 | 2273 { |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2274 BitmapStack::BitmapAccessor accessor(stack_, selected); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2275 BitmapStack::Corner corner; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2276 if (accessor.GetBitmap().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize())) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2277 { |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2278 switch (tool_) |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2279 { |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2280 case Tool_Crop: |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
2281 return new CropBitmapTracker(undoRedoStack_, stack_, view, selected, x, y, corner); |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2282 |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2283 case Tool_Resize: |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
2284 return new ResizeBitmapTracker(undoRedoStack_, stack_, selected, x, y, corner, |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2285 (modifiers & KeyboardModifiers_Shift)); |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2286 |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2287 default: |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2288 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2289 } |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2290 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2291 else |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2292 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2293 size_t bitmap; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2294 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2295 if (!stack_.LookupBitmap(bitmap, x, y) || |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2296 bitmap != selected) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2297 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2298 stack_.Unselect(); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2299 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2300 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2301 return NULL; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2302 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2303 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2304 else |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2305 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2306 size_t bitmap; |
346 | 2307 |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2308 if (stack_.LookupBitmap(bitmap, x, y) && |
346 | 2309 bitmap == selected) |
2310 { | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2311 switch (tool_) |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2312 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2313 case Tool_Move: |
354 | 2314 return new MoveBitmapTracker(undoRedoStack_, stack_, bitmap, x, y, |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2315 (modifiers & KeyboardModifiers_Shift)); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2316 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2317 case Tool_Rotate: |
354 | 2318 return new RotateBitmapTracker(undoRedoStack_, stack_, view, bitmap, x, y, |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2319 (modifiers & KeyboardModifiers_Shift)); |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2320 |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2321 default: |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2322 break; |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2323 } |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2324 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2325 return NULL; |
346 | 2326 } |
2327 else | |
2328 { | |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2329 printf("CLICK outside\n"); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2330 stack_.Unselect(); |
346 | 2331 return NULL; |
2332 } | |
342 | 2333 } |
2334 } | |
2335 else | |
2336 { | |
2337 return NULL; | |
2338 } | |
341 | 2339 } |
2340 | |
2341 virtual void MouseOver(CairoContext& context, | |
2342 WorldSceneWidget& widget, | |
2343 const ViewportGeometry& view, | |
2344 double x, | |
2345 double y, | |
2346 IStatusBar* statusBar) | |
2347 { | |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2348 size_t selected; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2349 if (stack_.GetSelectedBitmap(selected) && |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2350 (tool_ == Tool_Crop || |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2351 tool_ == Tool_Resize)) |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2352 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2353 BitmapStack::BitmapAccessor accessor(stack_, selected); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2354 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2355 BitmapStack::Corner corner; |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2356 if (accessor.GetBitmap().LookupCorner(corner, x, y, view.GetZoom(), GetHandleSize())) |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2357 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2358 accessor.GetBitmap().GetCorner(x, y, corner); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2359 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2360 double z = 1.0 / view.GetZoom(); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2361 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2362 context.SetSourceColor(255, 0, 0); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2363 cairo_t* cr = context.GetObject(); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2364 cairo_set_line_width(cr, 2.0 * z); |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2365 cairo_move_to(cr, x - GetHandleSize() * z, y - GetHandleSize() * z); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2366 cairo_line_to(cr, x + GetHandleSize() * z, y - GetHandleSize() * z); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2367 cairo_line_to(cr, x + GetHandleSize() * z, y + GetHandleSize() * z); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2368 cairo_line_to(cr, x - GetHandleSize() * z, y + GetHandleSize() * z); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2369 cairo_line_to(cr, x - GetHandleSize() * z, y - GetHandleSize() * z); |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2370 cairo_stroke(cr); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2371 } |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2372 } |
341 | 2373 } |
2374 | |
2375 virtual void MouseWheel(WorldSceneWidget& widget, | |
2376 MouseWheelDirection direction, | |
2377 KeyboardModifiers modifiers, | |
2378 IStatusBar* statusBar) | |
2379 { | |
2380 } | |
2381 | |
2382 virtual void KeyPressed(WorldSceneWidget& widget, | |
2383 KeyboardKeys key, | |
2384 char keyChar, | |
2385 KeyboardModifiers modifiers, | |
2386 IStatusBar* statusBar) | |
2387 { | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2388 switch (keyChar) |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2389 { |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2390 case 'c': |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2391 tool_ = Tool_Crop; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2392 break; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2393 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2394 case 'a': |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2395 widget.FitContent(); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2396 break; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2397 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2398 case 'm': |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2399 tool_ = Tool_Move; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2400 break; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2401 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2402 case 'r': |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2403 tool_ = Tool_Rotate; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2404 break; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2405 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2406 case 's': |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2407 tool_ = Tool_Resize; |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2408 break; |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2409 |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2410 case 'w': |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2411 tool_ = Tool_Windowing; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2412 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2413 |
354 | 2414 case 'z': |
2415 if (modifiers & KeyboardModifiers_Control) | |
2416 { | |
2417 undoRedoStack_.Undo(); | |
2418 widget.NotifyContentChanged(); | |
2419 } | |
2420 break; | |
2421 | |
2422 case 'y': | |
2423 if (modifiers & KeyboardModifiers_Control) | |
2424 { | |
2425 undoRedoStack_.Redo(); | |
2426 widget.NotifyContentChanged(); | |
2427 } | |
2428 break; | |
2429 | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2430 default: |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2431 break; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2432 } |
341 | 2433 } |
2434 }; | |
2435 | |
2436 | |
338 | 2437 |
2438 class BitmapStackWidget : | |
2439 public WorldSceneWidget, | |
2440 public IObservable, | |
2441 public IObserver | |
2442 { | |
2443 private: | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2444 BitmapStack& stack_; |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2445 BitmapStackInteractor myInteractor_; |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2446 std::auto_ptr<Orthanc::Image> floatBuffer_; |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2447 std::auto_ptr<CairoSurface> cairoBuffer_; |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2448 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2449 virtual bool RenderInternal(unsigned int width, |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2450 unsigned int height, |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2451 ImageInterpolation interpolation) |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2452 { |
339 | 2453 float windowCenter, windowWidth; |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2454 stack_.GetWindowingWithDefault(windowCenter, windowWidth); |
339 | 2455 |
2456 float x0 = windowCenter - windowWidth / 2.0f; | |
2457 float x1 = windowCenter + windowWidth / 2.0f; | |
2458 | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2459 if (windowWidth <= 0.001f) // Avoid division by zero at (*) |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2460 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2461 return false; |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2462 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2463 else |
339 | 2464 { |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2465 if (floatBuffer_.get() == NULL || |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2466 floatBuffer_->GetWidth() != width || |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2467 floatBuffer_->GetHeight() != height) |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2468 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2469 floatBuffer_.reset(new Orthanc::Image(Orthanc::PixelFormat_Float32, width, height, false)); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2470 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2471 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2472 if (cairoBuffer_.get() == NULL || |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2473 cairoBuffer_->GetWidth() != width || |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2474 cairoBuffer_->GetHeight() != height) |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2475 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2476 cairoBuffer_.reset(new CairoSurface(width, height)); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2477 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2478 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2479 stack_.Render(*floatBuffer_, GetView(), interpolation); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2480 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2481 // TODO => rendering quality |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2482 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2483 // As in GrayscaleFrameRenderer => TODO MERGE? |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2484 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2485 Orthanc::ImageAccessor target; |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2486 cairoBuffer_->GetAccessor(target); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2487 |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2488 for (unsigned int y = 0; y < height; y++) |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2489 { |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2490 const float* p = reinterpret_cast<const float*>(floatBuffer_->GetConstRow(y)); |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2491 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
339 | 2492 |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2493 for (unsigned int x = 0; x < width; x++, p++, q += 4) |
339 | 2494 { |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2495 uint8_t v = 0; |
339 | 2496 if (*p >= x1) |
2497 { | |
2498 v = 255; | |
2499 } | |
2500 else if (*p <= x0) | |
2501 { | |
2502 v = 0; | |
2503 } | |
2504 else | |
2505 { | |
2506 // https://en.wikipedia.org/wiki/Linear_interpolation | |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2507 v = static_cast<uint8_t>(255.0f * (*p - x0) / (x1 - x0)); // (*) |
339 | 2508 } |
2509 | |
2510 // TODO MONOCHROME1 | |
2511 /*if (invert_) | |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2512 { |
339 | 2513 v = 255 - v; |
2514 }*/ | |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2515 |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2516 q[0] = v; |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2517 q[1] = v; |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2518 q[2] = v; |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2519 q[3] = 255; |
339 | 2520 } |
2521 } | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2522 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2523 return true; |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2524 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2525 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2526 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2527 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2528 protected: |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2529 virtual Extent2D GetSceneExtent() |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2530 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2531 return stack_.GetSceneExtent(); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2532 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2533 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2534 virtual bool RenderScene(CairoContext& context, |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2535 const ViewportGeometry& view) |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2536 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2537 ImageInterpolation interpolation = ImageInterpolation_Nearest; // TODO PARAMETER? |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2538 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2539 cairo_t* cr = context.GetObject(); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2540 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2541 if (RenderInternal(context.GetWidth(), context.GetHeight(), interpolation)) |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2542 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2543 // https://www.cairographics.org/FAQ/#paint_from_a_surface |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2544 cairo_save(cr); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2545 cairo_identity_matrix(cr); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2546 cairo_set_source_surface(cr, cairoBuffer_->GetObject(), 0, 0); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2547 cairo_paint(cr); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2548 cairo_restore(cr); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2549 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2550 else |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2551 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2552 // https://www.cairographics.org/FAQ/#clear_a_surface |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2553 context.SetSourceColor(0, 0, 0); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2554 cairo_paint(cr); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2555 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2556 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2557 stack_.DrawControls(context, view.GetZoom()); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2558 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2559 return true; |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2560 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2561 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2562 public: |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2563 BitmapStackWidget(MessageBroker& broker, |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2564 BitmapStack& stack, |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2565 const std::string& name) : |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2566 WorldSceneWidget(name), |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2567 IObservable(broker), |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2568 IObserver(broker), |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2569 stack_(stack), |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2570 myInteractor_(stack_) |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2571 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2572 stack.RegisterObserverCallback(new Callable<BitmapStackWidget, BitmapStack::GeometryChangedMessage>(*this, &BitmapStackWidget::OnGeometryChanged)); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2573 stack.RegisterObserverCallback(new Callable<BitmapStackWidget, BitmapStack::ContentChangedMessage>(*this, &BitmapStackWidget::OnContentChanged)); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2574 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2575 SetInteractor(myInteractor_); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2576 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2577 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2578 void OnGeometryChanged(const BitmapStack::GeometryChangedMessage& message) |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2579 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2580 printf("Geometry has changed\n"); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2581 FitContent(); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2582 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2583 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2584 void OnContentChanged(const BitmapStack::ContentChangedMessage& message) |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2585 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2586 printf("Content has changed\n"); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2587 NotifyContentChanged(); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2588 } |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2589 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2590 #if 0 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2591 virtual bool Render(Orthanc::ImageAccessor& target) |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2592 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2593 if (RenderInternal(target.GetWidth(), target.GetHeight(), ImageInterpolation_Nearest)) |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2594 { |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2595 assert(cairoBuffer_.get() != NULL); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2596 |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2597 Orthanc::ImageAccessor source; |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2598 cairoBuffer_->GetAccessor(source); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2599 Orthanc::ImageProcessing::Copy(target, source); |
339 | 2600 } |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2601 else |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2602 { |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2603 Orthanc::ImageProcessing::Set(target, 0, 0, 0, 255); |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2604 } |
339 | 2605 |
345 | 2606 { |
2607 // TODO => REFACTOR | |
2608 CairoSurface surface(target); | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2609 CairoContext context(surface); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2610 GetView().ApplyTransform(context); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2611 stack_.DrawControls(context, GetView().GetZoom()); |
345 | 2612 } |
2613 | |
337 | 2614 return true; |
336
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2615 } |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2616 #endif |
336
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2617 }; |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2618 |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2619 |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2620 namespace Samples |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2621 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2622 class SingleFrameEditorApplication : |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2623 public SampleSingleCanvasApplicationBase, |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2624 public IObserver |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2625 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2626 enum Tools |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2627 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2628 Tools_Crop, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2629 Tools_Windowing, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2630 Tools_Zoom, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2631 Tools_Pan |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2632 }; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2633 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2634 enum Actions |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2635 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2636 Actions_Invert, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2637 Actions_RotateLeft, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2638 Actions_RotateRight |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2639 }; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2640 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2641 private: |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2642 class Interactor : public IWorldSceneInteractor |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2643 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2644 private: |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2645 SingleFrameEditorApplication& application_; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2646 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2647 public: |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2648 Interactor(SingleFrameEditorApplication& application) : |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2649 application_(application) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2650 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2651 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2652 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2653 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2654 const ViewportGeometry& view, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2655 MouseButton button, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2656 KeyboardModifiers modifiers, |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2657 int viewportX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2658 int viewportY, |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2659 double x, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2660 double y, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2661 IStatusBar* statusBar) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2662 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2663 switch (application_.currentTool_) { |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2664 case Tools_Zoom: |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2665 printf("ZOOM\n"); |
329
b10dfdb96866
removing WorldSceneWidget::IWorldObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
2666 |
b10dfdb96866
removing WorldSceneWidget::IWorldObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
2667 case Tools_Crop: |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2668 case Tools_Windowing: |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2669 case Tools_Pan: |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2670 // TODO return the right mouse tracker |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2671 return NULL; |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2672 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2673 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2674 return NULL; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2675 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2676 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2677 virtual void MouseOver(CairoContext& context, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2678 WorldSceneWidget& widget, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2679 const ViewportGeometry& view, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2680 double x, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2681 double y, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2682 IStatusBar* statusBar) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2683 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2684 if (statusBar != NULL) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2685 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2686 char buf[64]; |
336
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2687 sprintf(buf, "X = %.02f Y = %.02f (in cm)", x / 10.0, y / 10.0); |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2688 statusBar->SetMessage(buf); |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2689 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2690 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2691 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2692 virtual void MouseWheel(WorldSceneWidget& widget, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2693 MouseWheelDirection direction, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2694 KeyboardModifiers modifiers, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2695 IStatusBar* statusBar) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2696 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2697 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2698 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2699 virtual void KeyPressed(WorldSceneWidget& widget, |
327 | 2700 KeyboardKeys key, |
2701 char keyChar, | |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2702 KeyboardModifiers modifiers, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2703 IStatusBar* statusBar) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2704 { |
327 | 2705 switch (keyChar) |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2706 { |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2707 case 's': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2708 widget.FitContent(); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2709 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2710 case 'p': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2711 application_.currentTool_ = Tools_Pan; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2712 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2713 case 'z': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2714 application_.currentTool_ = Tools_Zoom; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2715 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2716 case 'c': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2717 application_.currentTool_ = Tools_Crop; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2718 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2719 case 'w': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2720 application_.currentTool_ = Tools_Windowing; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2721 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2722 case 'i': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2723 application_.Invert(); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2724 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2725 case 'r': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2726 if (modifiers == KeyboardModifiers_None) |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2727 application_.Rotate(90); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2728 else |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2729 application_.Rotate(-90); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2730 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2731 case 'e': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2732 application_.Export(); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2733 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2734 default: |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2735 break; |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2736 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2737 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2738 }; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2739 |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
2740 std::auto_ptr<Interactor> mainWidgetInteractor_; |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
2741 std::auto_ptr<OrthancApiClient> orthancApiClient_; |
338 | 2742 std::auto_ptr<BitmapStack> stack_; |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
2743 Tools currentTool_; |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
2744 const OrthancFrameLayerSource* source_; |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
2745 unsigned int slice_; |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2746 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2747 public: |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2748 SingleFrameEditorApplication(MessageBroker& broker) : |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2749 IObserver(broker), |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2750 currentTool_(Tools_Zoom), |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2751 source_(NULL), |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2752 slice_(0) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2753 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2754 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2755 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2756 virtual void DeclareStartupOptions(boost::program_options::options_description& options) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2757 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2758 boost::program_options::options_description generic("Sample options"); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2759 generic.add_options() |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2760 ("instance", boost::program_options::value<std::string>(), |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2761 "Orthanc ID of the instance") |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2762 ("frame", boost::program_options::value<unsigned int>()->default_value(0), |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2763 "Number of the frame, for multi-frame DICOM instances") |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2764 ; |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2765 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2766 options.add(generic); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2767 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2768 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2769 virtual void Initialize(StoneApplicationContext* context, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2770 IStatusBar& statusBar, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2771 const boost::program_options::variables_map& parameters) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2772 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2773 using namespace OrthancStone; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2774 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2775 context_ = context; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2776 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2777 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout, \"p\" to pan, \"z\" to zoom, \"c\" to crop, \"i\" to invert, \"w\" to change windowing, \"r\" to rotate cw, \"shift+r\" to rotate ccw"); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2778 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2779 if (parameters.count("instance") != 1) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2780 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2781 LOG(ERROR) << "The instance ID is missing"; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2782 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2783 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2784 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2785 std::string instance = parameters["instance"].as<std::string>(); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2786 int frame = parameters["frame"].as<unsigned int>(); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2787 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2788 orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService())); |
337 | 2789 |
343 | 2790 Orthanc::FontRegistry fonts; |
2791 fonts.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16); | |
2792 | |
338 | 2793 stack_.reset(new BitmapStack(IObserver::broker_, *orthancApiClient_)); |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2794 stack_->LoadFrame(instance, frame, false); |
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2795 stack_->LoadFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", frame, false); |
354 | 2796 |
2797 { | |
2798 BitmapStack::Bitmap& bitmap = stack_->LoadText(fonts.GetFont(0), "Hello\nworld\nBonjour, Alain"); | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2799 //dynamic_cast<BitmapStack::AlphaBitmap&>(bitmap).SetForegroundValue(256); |
354 | 2800 dynamic_cast<BitmapStack::AlphaBitmap&>(bitmap).SetResizeable(true); |
2801 } | |
2802 | |
2803 { | |
2804 BitmapStack::Bitmap& bitmap = stack_->LoadTestBlock(100, 50); | |
357
ec4ad6c5eb99
avoid breaking class hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
2805 //dynamic_cast<BitmapStack::AlphaBitmap&>(bitmap).SetForegroundValue(256); |
354 | 2806 dynamic_cast<BitmapStack::AlphaBitmap&>(bitmap).SetResizeable(true); |
2807 } | |
2808 | |
337 | 2809 |
338 | 2810 mainWidget_ = new BitmapStackWidget(IObserver::broker_, *stack_, "main-widget"); |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2811 mainWidget_->SetTransmitMouseOver(true); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2812 |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2813 //stack_->SetWindowing(128, 256); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2814 |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2815 mainWidgetInteractor_.reset(new Interactor(*this)); |
341 | 2816 //mainWidget_->SetInteractor(*mainWidgetInteractor_); |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2817 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2818 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2819 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2820 void Invert() |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2821 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2822 // TODO |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2823 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2824 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2825 void Rotate(int degrees) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2826 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2827 // TODO |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2828 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2829 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2830 void Export() |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2831 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2832 // TODO: export dicom file to a temporary file |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2833 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2834 }; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2835 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2836 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2837 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2838 } |