Mercurial > hg > orthanc-stone
annotate Applications/Samples/SingleFrameEditorApplication.h @ 356:885f0a5eaa49 am-2
mouse tracker to set windowing
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 29 Oct 2018 17:21:40 +0100 |
parents | d2468dd75b3f |
children | ec4ad6c5eb99 |
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 | |
345 | 1278 void DrawControls(CairoSurface& surface, |
1279 const ViewportGeometry& view) | |
1280 { | |
1281 if (hasSelection_) | |
1282 { | |
1283 Bitmaps::const_iterator bitmap = bitmaps_.find(selectedBitmap_); | |
1284 | |
1285 if (bitmap != bitmaps_.end()) | |
1286 { | |
1287 CairoContext context(surface); | |
1288 | |
1289 context.SetSourceColor(255, 0, 0); | |
1290 view.ApplyTransform(context); | |
1291 bitmap->second->DrawBorders(context, view.GetZoom()); | |
1292 } | |
1293 } | |
1294 } | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1295 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1296 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1297 void GetRange(float& minValue, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1298 float& maxValue) const |
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 bool first = true; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1301 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1302 for (Bitmaps::const_iterator it = bitmaps_.begin(); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1303 it != bitmaps_.end(); it++) |
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 assert(it->second != NULL); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1306 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1307 float a, b; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1308 if (it->second->GetRange(a, b)) |
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 if (first) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1311 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1312 minValue = a; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1313 maxValue = b; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1314 first = false; |
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 else |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1317 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1318 minValue = std::min(a, minValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1319 maxValue = std::max(b, maxValue); |
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 } |
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 if (first) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1325 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1326 minValue = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1327 maxValue = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1328 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
1329 } |
338 | 1330 }; |
1331 | |
341 | 1332 |
354 | 1333 class UndoRedoStack : public boost::noncopyable |
1334 { | |
1335 public: | |
1336 class ICommand : public boost::noncopyable | |
1337 { | |
1338 public: | |
1339 virtual ~ICommand() | |
1340 { | |
1341 } | |
1342 | |
1343 virtual void Undo() const = 0; | |
1344 | |
1345 virtual void Redo() const = 0; | |
1346 }; | |
1347 | |
1348 private: | |
1349 typedef std::list<ICommand*> Stack; | |
1350 | |
1351 Stack stack_; | |
1352 Stack::iterator current_; | |
1353 | |
1354 void Clear(Stack::iterator from) | |
1355 { | |
1356 for (Stack::iterator it = from; it != stack_.end(); ++it) | |
1357 { | |
1358 assert(*it != NULL); | |
1359 delete *it; | |
1360 } | |
1361 | |
1362 stack_.erase(from, stack_.end()); | |
1363 } | |
1364 | |
1365 public: | |
1366 UndoRedoStack() : | |
1367 current_(stack_.end()) | |
1368 { | |
1369 } | |
1370 | |
1371 ~UndoRedoStack() | |
1372 { | |
1373 Clear(stack_.begin()); | |
1374 } | |
1375 | |
1376 void Add(ICommand* command) | |
1377 { | |
1378 if (command == NULL) | |
1379 { | |
1380 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
1381 } | |
1382 | |
1383 Clear(current_); | |
1384 | |
1385 stack_.push_back(command); | |
1386 current_ = stack_.end(); | |
1387 } | |
1388 | |
1389 void Undo() | |
1390 { | |
1391 if (current_ != stack_.begin()) | |
1392 { | |
1393 --current_; | |
1394 | |
1395 assert(*current_ != NULL); | |
1396 (*current_)->Undo(); | |
1397 } | |
1398 } | |
1399 | |
1400 void Redo() | |
1401 { | |
1402 if (current_ != stack_.end()) | |
1403 { | |
1404 assert(*current_ != NULL); | |
1405 (*current_)->Redo(); | |
1406 | |
1407 ++current_; | |
1408 } | |
1409 } | |
1410 }; | |
1411 | |
1412 | |
1413 class BitmapCommandBase : public UndoRedoStack::ICommand | |
1414 { | |
1415 private: | |
1416 BitmapStack& stack_; | |
1417 size_t bitmap_; | |
1418 | |
1419 protected: | |
1420 virtual void UndoInternal(BitmapStack::Bitmap& bitmap) const = 0; | |
1421 | |
1422 virtual void RedoInternal(BitmapStack::Bitmap& bitmap) const = 0; | |
1423 | |
1424 public: | |
1425 BitmapCommandBase(BitmapStack& stack, | |
1426 size_t bitmap) : | |
1427 stack_(stack), | |
1428 bitmap_(bitmap) | |
1429 { | |
1430 } | |
1431 | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1432 BitmapCommandBase(const BitmapStack::BitmapAccessor& accessor) : |
354 | 1433 stack_(accessor.GetStack()), |
1434 bitmap_(accessor.GetIndex()) | |
1435 { | |
1436 } | |
1437 | |
1438 virtual void Undo() const | |
1439 { | |
1440 BitmapStack::BitmapAccessor accessor(stack_, bitmap_); | |
1441 | |
1442 if (accessor.IsValid()) | |
1443 { | |
1444 UndoInternal(accessor.GetBitmap()); | |
1445 } | |
1446 } | |
1447 | |
1448 virtual void Redo() const | |
1449 { | |
1450 BitmapStack::BitmapAccessor accessor(stack_, bitmap_); | |
1451 | |
1452 if (accessor.IsValid()) | |
1453 { | |
1454 RedoInternal(accessor.GetBitmap()); | |
1455 } | |
1456 } | |
1457 }; | |
1458 | |
1459 | |
1460 class RotateBitmapTracker : public IWorldSceneMouseTracker | |
1461 { | |
1462 private: | |
1463 UndoRedoStack& undoRedoStack_; | |
1464 BitmapStack::BitmapAccessor accessor_; | |
1465 double centerX_; | |
1466 double centerY_; | |
1467 double originalAngle_; | |
1468 double clickAngle_; | |
1469 bool roundAngles_; | |
1470 | |
1471 bool ComputeAngle(double& angle /* out */, | |
1472 double sceneX, | |
1473 double sceneY) const | |
1474 { | |
1475 Vector u; | |
1476 LinearAlgebra::AssignVector(u, sceneX - centerX_, sceneY - centerY_); | |
1477 | |
1478 double nu = boost::numeric::ublas::norm_2(u); | |
1479 | |
1480 if (!LinearAlgebra::IsCloseToZero(nu)) | |
1481 { | |
1482 u /= nu; | |
1483 angle = atan2(u[1], u[0]); | |
1484 return true; | |
1485 } | |
1486 else | |
1487 { | |
1488 return false; | |
1489 } | |
1490 } | |
1491 | |
1492 | |
1493 class UndoRedoCommand : public BitmapCommandBase | |
1494 { | |
1495 private: | |
1496 double sourceAngle_; | |
1497 double targetAngle_; | |
1498 | |
1499 static int ToDegrees(double angle) | |
1500 { | |
1501 return static_cast<int>(round(angle * 180.0 / boost::math::constants::pi<double>())); | |
1502 } | |
1503 | |
1504 protected: | |
1505 virtual void UndoInternal(BitmapStack::Bitmap& bitmap) const | |
1506 { | |
1507 LOG(INFO) << "Undo - Set angle to " << ToDegrees(sourceAngle_) << " degrees"; | |
1508 bitmap.SetAngle(sourceAngle_); | |
1509 } | |
1510 | |
1511 virtual void RedoInternal(BitmapStack::Bitmap& bitmap) const | |
1512 { | |
1513 LOG(INFO) << "Redo - Set angle to " << ToDegrees(sourceAngle_) << " degrees"; | |
1514 bitmap.SetAngle(targetAngle_); | |
1515 } | |
1516 | |
1517 public: | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1518 UndoRedoCommand(const RotateBitmapTracker& tracker) : |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1519 BitmapCommandBase(tracker.accessor_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1520 sourceAngle_(tracker.originalAngle_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1521 targetAngle_(tracker.accessor_.GetBitmap().GetAngle()) |
354 | 1522 { |
1523 } | |
1524 }; | |
1525 | |
1526 | |
1527 public: | |
1528 RotateBitmapTracker(UndoRedoStack& undoRedoStack, | |
1529 BitmapStack& stack, | |
1530 const ViewportGeometry& view, | |
1531 size_t bitmap, | |
1532 double x, | |
1533 double y, | |
1534 bool roundAngles) : | |
1535 undoRedoStack_(undoRedoStack), | |
1536 accessor_(stack, bitmap), | |
1537 roundAngles_(roundAngles) | |
1538 { | |
1539 if (accessor_.IsValid()) | |
1540 { | |
1541 accessor_.GetBitmap().GetCenter(centerX_, centerY_); | |
1542 originalAngle_ = accessor_.GetBitmap().GetAngle(); | |
1543 | |
1544 double sceneX, sceneY; | |
1545 view.MapDisplayToScene(sceneX, sceneY, x, y); | |
1546 | |
1547 if (!ComputeAngle(clickAngle_, x, y)) | |
1548 { | |
1549 accessor_.Invalidate(); | |
1550 } | |
1551 } | |
1552 } | |
1553 | |
1554 virtual bool HasRender() const | |
1555 { | |
1556 return false; | |
1557 } | |
1558 | |
1559 virtual void Render(CairoContext& context, | |
1560 double zoom) | |
1561 { | |
1562 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1563 } | |
1564 | |
1565 virtual void MouseUp() | |
1566 { | |
1567 if (accessor_.IsValid()) | |
1568 { | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1569 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
354 | 1570 } |
1571 } | |
1572 | |
1573 virtual void MouseMove(int displayX, | |
1574 int displayY, | |
1575 double sceneX, | |
1576 double sceneY) | |
1577 { | |
1578 static const double ROUND_ANGLE = 15.0 / 180.0 * boost::math::constants::pi<double>(); | |
1579 | |
1580 double angle; | |
1581 | |
1582 if (accessor_.IsValid() && | |
1583 ComputeAngle(angle, sceneX, sceneY)) | |
1584 { | |
1585 angle = angle - clickAngle_ + originalAngle_; | |
1586 | |
1587 if (roundAngles_) | |
1588 { | |
1589 angle = round(angle / ROUND_ANGLE) * ROUND_ANGLE; | |
1590 } | |
1591 | |
1592 accessor_.GetBitmap().SetAngle(angle); | |
1593 } | |
1594 } | |
1595 }; | |
1596 | |
1597 | |
1598 class MoveBitmapTracker : public IWorldSceneMouseTracker | |
1599 { | |
1600 private: | |
1601 UndoRedoStack& undoRedoStack_; | |
1602 BitmapStack::BitmapAccessor accessor_; | |
1603 double clickX_; | |
1604 double clickY_; | |
1605 double panX_; | |
1606 double panY_; | |
1607 bool oneAxis_; | |
1608 | |
1609 class UndoRedoCommand : public BitmapCommandBase | |
1610 { | |
1611 private: | |
1612 double sourceX_; | |
1613 double sourceY_; | |
1614 double targetX_; | |
1615 double targetY_; | |
1616 | |
1617 protected: | |
1618 virtual void UndoInternal(BitmapStack::Bitmap& bitmap) const | |
1619 { | |
1620 bitmap.SetPan(sourceX_, sourceY_); | |
1621 } | |
1622 | |
1623 virtual void RedoInternal(BitmapStack::Bitmap& bitmap) const | |
1624 { | |
1625 bitmap.SetPan(targetX_, targetY_); | |
1626 } | |
1627 | |
1628 public: | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1629 UndoRedoCommand(const MoveBitmapTracker& tracker) : |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1630 BitmapCommandBase(tracker.accessor_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1631 sourceX_(tracker.panX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1632 sourceY_(tracker.panY_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1633 targetX_(tracker.accessor_.GetBitmap().GetPanX()), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1634 targetY_(tracker.accessor_.GetBitmap().GetPanY()) |
354 | 1635 { |
1636 } | |
1637 }; | |
1638 | |
1639 | |
1640 public: | |
1641 MoveBitmapTracker(UndoRedoStack& undoRedoStack, | |
1642 BitmapStack& stack, | |
1643 size_t bitmap, | |
1644 double x, | |
1645 double y, | |
1646 bool oneAxis) : | |
1647 undoRedoStack_(undoRedoStack), | |
1648 accessor_(stack, bitmap), | |
1649 clickX_(x), | |
1650 clickY_(y), | |
1651 oneAxis_(oneAxis) | |
1652 { | |
1653 if (accessor_.IsValid()) | |
1654 { | |
1655 panX_ = accessor_.GetBitmap().GetPanX(); | |
1656 panY_ = accessor_.GetBitmap().GetPanY(); | |
1657 } | |
1658 } | |
1659 | |
1660 virtual bool HasRender() const | |
1661 { | |
1662 return false; | |
1663 } | |
1664 | |
1665 virtual void Render(CairoContext& context, | |
1666 double zoom) | |
1667 { | |
1668 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1669 } | |
1670 | |
1671 virtual void MouseUp() | |
1672 { | |
1673 if (accessor_.IsValid()) | |
1674 { | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1675 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
354 | 1676 } |
1677 } | |
1678 | |
1679 virtual void MouseMove(int displayX, | |
1680 int displayY, | |
1681 double sceneX, | |
1682 double sceneY) | |
1683 { | |
1684 if (accessor_.IsValid()) | |
1685 { | |
1686 double dx = sceneX - clickX_; | |
1687 double dy = sceneY - clickY_; | |
1688 | |
1689 if (oneAxis_) | |
1690 { | |
1691 if (fabs(dx) > fabs(dy)) | |
1692 { | |
1693 accessor_.GetBitmap().SetPan(dx + panX_, panY_); | |
1694 } | |
1695 else | |
1696 { | |
1697 accessor_.GetBitmap().SetPan(panX_, dy + panY_); | |
1698 } | |
1699 } | |
1700 else | |
1701 { | |
1702 accessor_.GetBitmap().SetPan(dx + panX_, dy + panY_); | |
1703 } | |
1704 } | |
1705 } | |
1706 }; | |
1707 | |
1708 | |
1709 class CropBitmapTracker : public IWorldSceneMouseTracker | |
1710 { | |
1711 private: | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1712 UndoRedoStack& undoRedoStack_; |
354 | 1713 BitmapStack::BitmapAccessor accessor_; |
1714 BitmapStack::Corner corner_; | |
1715 unsigned int cropX_; | |
1716 unsigned int cropY_; | |
1717 unsigned int cropWidth_; | |
1718 unsigned int cropHeight_; | |
1719 | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1720 class UndoRedoCommand : public BitmapCommandBase |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1721 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1722 private: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1723 unsigned int sourceCropX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1724 unsigned int sourceCropY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1725 unsigned int sourceCropWidth_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1726 unsigned int sourceCropHeight_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1727 unsigned int targetCropX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1728 unsigned int targetCropY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1729 unsigned int targetCropWidth_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1730 unsigned int targetCropHeight_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1731 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1732 protected: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1733 virtual void UndoInternal(BitmapStack::Bitmap& bitmap) const |
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 bitmap.SetCrop(sourceCropX_, sourceCropY_, sourceCropWidth_, sourceCropHeight_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1736 } |
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 virtual void RedoInternal(BitmapStack::Bitmap& bitmap) const |
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 bitmap.SetCrop(targetCropX_, targetCropY_, targetCropWidth_, targetCropHeight_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1741 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1742 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1743 public: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1744 UndoRedoCommand(const CropBitmapTracker& tracker) : |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1745 BitmapCommandBase(tracker.accessor_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1746 sourceCropX_(tracker.cropX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1747 sourceCropY_(tracker.cropY_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1748 sourceCropWidth_(tracker.cropWidth_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1749 sourceCropHeight_(tracker.cropHeight_) |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1750 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1751 tracker.accessor_.GetBitmap().GetCrop(targetCropX_, targetCropY_, |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1752 targetCropWidth_, targetCropHeight_); |
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 }; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1755 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1756 |
354 | 1757 public: |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1758 CropBitmapTracker(UndoRedoStack& undoRedoStack, |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1759 BitmapStack& stack, |
354 | 1760 const ViewportGeometry& view, |
1761 size_t bitmap, | |
1762 double x, | |
1763 double y, | |
1764 BitmapStack::Corner corner) : | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1765 undoRedoStack_(undoRedoStack), |
354 | 1766 accessor_(stack, bitmap), |
1767 corner_(corner) | |
1768 { | |
1769 if (accessor_.IsValid()) | |
1770 { | |
1771 accessor_.GetBitmap().GetCrop(cropX_, cropY_, cropWidth_, cropHeight_); | |
1772 } | |
1773 } | |
1774 | |
1775 virtual bool HasRender() const | |
1776 { | |
1777 return false; | |
1778 } | |
1779 | |
1780 virtual void Render(CairoContext& context, | |
1781 double zoom) | |
1782 { | |
1783 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1784 } | |
1785 | |
1786 virtual void MouseUp() | |
1787 { | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1788 if (accessor_.IsValid()) |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1789 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1790 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1791 } |
354 | 1792 } |
1793 | |
1794 virtual void MouseMove(int displayX, | |
1795 int displayY, | |
1796 double sceneX, | |
1797 double sceneY) | |
1798 { | |
1799 if (accessor_.IsValid()) | |
1800 { | |
1801 unsigned int x, y; | |
1802 | |
1803 BitmapStack::Bitmap& bitmap = accessor_.GetBitmap(); | |
1804 if (bitmap.GetPixel(x, y, sceneX, sceneY)) | |
1805 { | |
1806 unsigned int targetX, targetWidth; | |
1807 | |
1808 if (corner_ == BitmapStack::Corner_TopLeft || | |
1809 corner_ == BitmapStack::Corner_BottomLeft) | |
1810 { | |
1811 targetX = std::min(x, cropX_ + cropWidth_); | |
1812 targetWidth = cropX_ + cropWidth_ - targetX; | |
1813 } | |
1814 else | |
1815 { | |
1816 targetX = cropX_; | |
1817 targetWidth = std::max(x, cropX_) - cropX_; | |
1818 } | |
1819 | |
1820 unsigned int targetY, targetHeight; | |
1821 | |
1822 if (corner_ == BitmapStack::Corner_TopLeft || | |
1823 corner_ == BitmapStack::Corner_TopRight) | |
1824 { | |
1825 targetY = std::min(y, cropY_ + cropHeight_); | |
1826 targetHeight = cropY_ + cropHeight_ - targetY; | |
1827 } | |
1828 else | |
1829 { | |
1830 targetY = cropY_; | |
1831 targetHeight = std::max(y, cropY_) - cropY_; | |
1832 } | |
1833 | |
1834 bitmap.SetCrop(targetX, targetY, targetWidth, targetHeight); | |
1835 } | |
1836 } | |
1837 } | |
1838 }; | |
1839 | |
1840 | |
1841 class ResizeBitmapTracker : public IWorldSceneMouseTracker | |
1842 { | |
1843 private: | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1844 UndoRedoStack& undoRedoStack_; |
354 | 1845 BitmapStack::BitmapAccessor accessor_; |
1846 bool roundScaling_; | |
1847 double originalSpacingX_; | |
1848 double originalSpacingY_; | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1849 double originalPanX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1850 double originalPanY_; |
354 | 1851 BitmapStack::Corner oppositeCorner_; |
1852 double oppositeX_; | |
1853 double oppositeY_; | |
1854 double baseScaling_; | |
1855 | |
1856 static double ComputeDistance(double x1, | |
1857 double y1, | |
1858 double x2, | |
1859 double y2) | |
1860 { | |
1861 double dx = x1 - x2; | |
1862 double dy = y1 - y2; | |
1863 return sqrt(dx * dx + dy * dy); | |
1864 } | |
1865 | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1866 class UndoRedoCommand : public BitmapCommandBase |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1867 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1868 private: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1869 double sourceSpacingX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1870 double sourceSpacingY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1871 double sourcePanX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1872 double sourcePanY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1873 double targetSpacingX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1874 double targetSpacingY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1875 double targetPanX_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1876 double targetPanY_; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1877 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1878 protected: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1879 virtual void UndoInternal(BitmapStack::Bitmap& bitmap) const |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1880 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1881 bitmap.SetPixelSpacing(sourceSpacingX_, sourceSpacingY_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1882 bitmap.SetPan(sourcePanX_, sourcePanY_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1883 } |
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 virtual void RedoInternal(BitmapStack::Bitmap& bitmap) const |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1886 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1887 bitmap.SetPixelSpacing(targetSpacingX_, targetSpacingY_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1888 bitmap.SetPan(targetPanX_, targetPanY_); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1889 } |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1890 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1891 public: |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1892 UndoRedoCommand(const ResizeBitmapTracker& tracker) : |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1893 BitmapCommandBase(tracker.accessor_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1894 sourceSpacingX_(tracker.originalSpacingX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1895 sourceSpacingY_(tracker.originalSpacingY_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1896 sourcePanX_(tracker.originalPanX_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1897 sourcePanY_(tracker.originalPanY_), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1898 targetSpacingX_(tracker.accessor_.GetBitmap().GetPixelSpacingX()), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1899 targetSpacingY_(tracker.accessor_.GetBitmap().GetPixelSpacingY()), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1900 targetPanX_(tracker.accessor_.GetBitmap().GetPanX()), |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1901 targetPanY_(tracker.accessor_.GetBitmap().GetPanY()) |
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 }; |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1905 |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1906 |
354 | 1907 public: |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1908 ResizeBitmapTracker(UndoRedoStack& undoRedoStack, |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1909 BitmapStack& stack, |
354 | 1910 size_t bitmap, |
1911 double x, | |
1912 double y, | |
1913 BitmapStack::Corner corner, | |
1914 bool roundScaling) : | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1915 undoRedoStack_(undoRedoStack), |
354 | 1916 accessor_(stack, bitmap), |
1917 roundScaling_(roundScaling) | |
1918 { | |
1919 if (accessor_.IsValid() && | |
1920 accessor_.GetBitmap().IsResizeable()) | |
1921 { | |
1922 originalSpacingX_ = accessor_.GetBitmap().GetPixelSpacingX(); | |
1923 originalSpacingY_ = accessor_.GetBitmap().GetPixelSpacingY(); | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1924 originalPanX_ = accessor_.GetBitmap().GetPanX(); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1925 originalPanY_ = accessor_.GetBitmap().GetPanY(); |
354 | 1926 |
1927 switch (corner) | |
1928 { | |
1929 case BitmapStack::Corner_TopLeft: | |
1930 oppositeCorner_ = BitmapStack::Corner_BottomRight; | |
1931 break; | |
1932 | |
1933 case BitmapStack::Corner_TopRight: | |
1934 oppositeCorner_ = BitmapStack::Corner_BottomLeft; | |
1935 break; | |
1936 | |
1937 case BitmapStack::Corner_BottomLeft: | |
1938 oppositeCorner_ = BitmapStack::Corner_TopRight; | |
1939 break; | |
1940 | |
1941 case BitmapStack::Corner_BottomRight: | |
1942 oppositeCorner_ = BitmapStack::Corner_TopLeft; | |
1943 break; | |
1944 | |
1945 default: | |
1946 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1947 } | |
1948 | |
1949 accessor_.GetBitmap().GetCorner(oppositeX_, oppositeY_, oppositeCorner_); | |
1950 | |
1951 double d = ComputeDistance(x, y, oppositeX_, oppositeY_); | |
1952 if (d >= std::numeric_limits<float>::epsilon()) | |
1953 { | |
1954 baseScaling_ = 1.0 / d; | |
1955 } | |
1956 else | |
1957 { | |
1958 // Avoid division by zero in extreme cases | |
1959 accessor_.Invalidate(); | |
1960 } | |
1961 } | |
1962 } | |
1963 | |
1964 virtual bool HasRender() const | |
1965 { | |
1966 return false; | |
1967 } | |
1968 | |
1969 virtual void Render(CairoContext& context, | |
1970 double zoom) | |
1971 { | |
1972 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1973 } | |
1974 | |
1975 virtual void MouseUp() | |
1976 { | |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1977 if (accessor_.IsValid()) |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1978 { |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1979 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
1980 } |
354 | 1981 } |
1982 | |
1983 virtual void MouseMove(int displayX, | |
1984 int displayY, | |
1985 double sceneX, | |
1986 double sceneY) | |
1987 { | |
1988 static const double ROUND_SCALING = 0.1; | |
1989 | |
1990 if (accessor_.IsValid() && | |
1991 accessor_.GetBitmap().IsResizeable()) | |
1992 { | |
1993 double scaling = ComputeDistance(oppositeX_, oppositeY_, sceneX, sceneY) * baseScaling_; | |
1994 | |
1995 if (roundScaling_) | |
1996 { | |
1997 scaling = round(scaling / ROUND_SCALING) * ROUND_SCALING; | |
1998 } | |
1999 | |
2000 BitmapStack::Bitmap& bitmap = accessor_.GetBitmap(); | |
2001 bitmap.SetPixelSpacing(scaling * originalSpacingX_, | |
2002 scaling * originalSpacingY_); | |
2003 | |
2004 // Keep the opposite corner at a fixed location | |
2005 double ox, oy; | |
2006 bitmap.GetCorner(ox, oy, oppositeCorner_); | |
2007 bitmap.SetPan(bitmap.GetPanX() + oppositeX_ - ox, | |
2008 bitmap.GetPanY() + oppositeY_ - oy); | |
2009 } | |
2010 } | |
2011 }; | |
2012 | |
2013 | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2014 class WindowingTracker : public IWorldSceneMouseTracker |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2015 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2016 public: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2017 enum Action |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2018 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2019 Action_IncreaseWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2020 Action_DecreaseWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2021 Action_IncreaseCenter, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2022 Action_DecreaseCenter |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2025 private: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2026 UndoRedoStack& undoRedoStack_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2027 BitmapStack& stack_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2028 int clickX_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2029 int clickY_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2030 Action leftAction_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2031 Action rightAction_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2032 Action upAction_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2033 Action downAction_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2034 float strength_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2035 float sourceCenter_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2036 float sourceWidth_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2037 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2038 static void ComputeAxisEffect(int& deltaCenter, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2039 int& deltaWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2040 int delta, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2041 Action actionNegative, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2042 Action actionPositive) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2043 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2044 if (delta < 0) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2045 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2046 switch (actionNegative) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2047 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2048 case Action_IncreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2049 deltaWidth = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2050 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2051 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2052 case Action_DecreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2053 deltaWidth = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2054 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2055 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2056 case Action_IncreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2057 deltaCenter = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2058 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2059 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2060 case Action_DecreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2061 deltaCenter = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2062 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2063 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2064 default: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2065 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
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 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2068 else if (delta > 0) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2069 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2070 switch (actionPositive) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2071 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2072 case Action_IncreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2073 deltaWidth = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2074 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2075 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2076 case Action_DecreaseWidth: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2077 deltaWidth = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2078 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2079 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2080 case Action_IncreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2081 deltaCenter = delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2082 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2083 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2084 case Action_DecreaseCenter: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2085 deltaCenter = -delta; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2086 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2087 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2088 default: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2089 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2095 class UndoRedoCommand : public UndoRedoStack::ICommand |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2096 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2097 private: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2098 BitmapStack& stack_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2099 float sourceCenter_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2100 float sourceWidth_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2101 float targetCenter_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2102 float targetWidth_; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2103 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2104 public: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2105 UndoRedoCommand(const WindowingTracker& tracker) : |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2106 stack_(tracker.stack_), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2107 sourceCenter_(tracker.sourceCenter_), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2108 sourceWidth_(tracker.sourceWidth_) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2109 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2110 stack_.GetWindowingWithDefault(targetCenter_, targetWidth_); |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2113 virtual void Undo() const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2114 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2115 stack_.SetWindowing(sourceCenter_, sourceWidth_); |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2118 virtual void Redo() const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2119 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2120 stack_.SetWindowing(targetCenter_, targetWidth_); |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2125 public: |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2126 WindowingTracker(UndoRedoStack& undoRedoStack, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2127 BitmapStack& stack, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2128 int x, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2129 int y, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2130 Action leftAction, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2131 Action rightAction, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2132 Action upAction, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2133 Action downAction) : |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2134 undoRedoStack_(undoRedoStack), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2135 stack_(stack), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2136 clickX_(x), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2137 clickY_(y), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2138 leftAction_(leftAction), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2139 rightAction_(rightAction), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2140 upAction_(upAction), |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2141 downAction_(downAction) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2142 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2143 stack_.GetWindowingWithDefault(sourceCenter_, sourceWidth_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2144 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2145 float minValue, maxValue; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2146 stack.GetRange(minValue, maxValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2147 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2148 assert(minValue <= maxValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2149 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2150 float tmp; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2151 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2152 float delta = (maxValue - minValue); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2153 if (delta <= 1) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2154 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2155 tmp = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2156 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2157 else |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2158 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2159 tmp = log2(delta); |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2162 strength_ = tmp - 7; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2163 if (strength_ < 1) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2164 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2165 strength_ = 1; |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2169 virtual bool HasRender() const |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2170 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2171 return false; |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2174 virtual void Render(CairoContext& context, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2175 double zoom) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2176 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2177 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2180 virtual void MouseUp() |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2181 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2182 undoRedoStack_.Add(new UndoRedoCommand(*this)); |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2186 virtual void MouseMove(int displayX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2187 int displayY, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2188 double sceneX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2189 double sceneY) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2190 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2191 // 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
|
2192 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2193 static const float SCALE = 1.0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2194 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2195 int deltaCenter = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2196 int deltaWidth = 0; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2197 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2198 ComputeAxisEffect(deltaCenter, deltaWidth, displayX - clickX_, leftAction_, rightAction_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2199 ComputeAxisEffect(deltaCenter, deltaWidth, displayY - clickY_, upAction_, downAction_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2200 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2201 float newCenter = sourceCenter_ + (deltaCenter / SCALE * strength_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2202 float newWidth = sourceWidth_ + (deltaWidth / SCALE * strength_); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2203 stack_.SetWindowing(newCenter, newWidth); |
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 |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2207 |
341 | 2208 class BitmapStackInteractor : public IWorldSceneInteractor |
2209 { | |
342 | 2210 private: |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2211 enum Tool |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2212 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2213 Tool_Move, |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2214 Tool_Rotate, |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2215 Tool_Crop, |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2216 Tool_Resize, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2217 Tool_Windowing |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2218 }; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2219 |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2220 static double GetHandleSize() |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2221 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2222 return 10.0; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2223 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2224 |
342 | 2225 |
354 | 2226 BitmapStack& stack_; |
2227 UndoRedoStack undoRedoStack_; | |
2228 Tool tool_; | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2229 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2230 |
341 | 2231 public: |
342 | 2232 BitmapStackInteractor(BitmapStack& stack) : |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2233 stack_(stack), |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2234 tool_(Tool_Move) |
342 | 2235 { |
2236 } | |
2237 | |
341 | 2238 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, |
2239 const ViewportGeometry& view, | |
2240 MouseButton button, | |
2241 KeyboardModifiers modifiers, | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2242 int viewportX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2243 int viewportY, |
341 | 2244 double x, |
2245 double y, | |
2246 IStatusBar* statusBar) | |
2247 { | |
342 | 2248 if (button == MouseButton_Left) |
2249 { | |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2250 size_t selected; |
346 | 2251 |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2252 if (tool_ == Tool_Windowing) |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2253 { |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2254 return new WindowingTracker(undoRedoStack_, stack_, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2255 viewportX, viewportY, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2256 WindowingTracker::Action_DecreaseWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2257 WindowingTracker::Action_IncreaseWidth, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2258 WindowingTracker::Action_DecreaseCenter, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2259 WindowingTracker::Action_IncreaseCenter); |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2260 } |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2261 else if (!stack_.GetSelectedBitmap(selected)) |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2262 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2263 size_t bitmap; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2264 if (stack_.LookupBitmap(bitmap, x, y)) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2265 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2266 printf("CLICK on bitmap %ld\n", bitmap); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2267 stack_.Select(bitmap); |
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 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2270 return NULL; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2271 } |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2272 else if (tool_ == Tool_Crop || |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2273 tool_ == Tool_Resize) |
342 | 2274 { |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2275 BitmapStack::BitmapAccessor accessor(stack_, selected); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2276 BitmapStack::Corner corner; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2277 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
|
2278 { |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2279 switch (tool_) |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2280 { |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2281 case Tool_Crop: |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
2282 return new CropBitmapTracker(undoRedoStack_, stack_, view, selected, x, y, corner); |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2283 |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2284 case Tool_Resize: |
355
d2468dd75b3f
undo redo for all tools
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
354
diff
changeset
|
2285 return new ResizeBitmapTracker(undoRedoStack_, stack_, selected, x, y, corner, |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2286 (modifiers & KeyboardModifiers_Shift)); |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2287 |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2288 default: |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2289 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2290 } |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2291 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2292 else |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2293 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2294 size_t bitmap; |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2295 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2296 if (!stack_.LookupBitmap(bitmap, x, y) || |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2297 bitmap != selected) |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2298 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2299 stack_.Unselect(); |
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 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2302 return NULL; |
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 } |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2305 else |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2306 { |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2307 size_t bitmap; |
346 | 2308 |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2309 if (stack_.LookupBitmap(bitmap, x, y) && |
346 | 2310 bitmap == selected) |
2311 { | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2312 switch (tool_) |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2313 { |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2314 case Tool_Move: |
354 | 2315 return new MoveBitmapTracker(undoRedoStack_, stack_, bitmap, x, y, |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2316 (modifiers & KeyboardModifiers_Shift)); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2317 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2318 case Tool_Rotate: |
354 | 2319 return new RotateBitmapTracker(undoRedoStack_, stack_, view, bitmap, x, y, |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2320 (modifiers & KeyboardModifiers_Shift)); |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2321 |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2322 default: |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2323 break; |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2324 } |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2325 |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2326 return NULL; |
346 | 2327 } |
2328 else | |
2329 { | |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2330 printf("CLICK outside\n"); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2331 stack_.Unselect(); |
346 | 2332 return NULL; |
2333 } | |
342 | 2334 } |
2335 } | |
2336 else | |
2337 { | |
2338 return NULL; | |
2339 } | |
341 | 2340 } |
2341 | |
2342 virtual void MouseOver(CairoContext& context, | |
2343 WorldSceneWidget& widget, | |
2344 const ViewportGeometry& view, | |
2345 double x, | |
2346 double y, | |
2347 IStatusBar* statusBar) | |
2348 { | |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2349 size_t selected; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2350 if (stack_.GetSelectedBitmap(selected) && |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2351 (tool_ == Tool_Crop || |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2352 tool_ == Tool_Resize)) |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2353 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2354 BitmapStack::BitmapAccessor accessor(stack_, selected); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2355 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2356 BitmapStack::Corner corner; |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2357 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
|
2358 { |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2359 accessor.GetBitmap().GetCorner(x, y, corner); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2360 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2361 double z = 1.0 / view.GetZoom(); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2362 |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2363 context.SetSourceColor(255, 0, 0); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2364 cairo_t* cr = context.GetObject(); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2365 cairo_set_line_width(cr, 2.0 * z); |
351
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2366 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
|
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); |
da25d2423314
CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
350
diff
changeset
|
2370 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
|
2371 cairo_stroke(cr); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2372 } |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2373 } |
341 | 2374 } |
2375 | |
2376 virtual void MouseWheel(WorldSceneWidget& widget, | |
2377 MouseWheelDirection direction, | |
2378 KeyboardModifiers modifiers, | |
2379 IStatusBar* statusBar) | |
2380 { | |
2381 } | |
2382 | |
2383 virtual void KeyPressed(WorldSceneWidget& widget, | |
2384 KeyboardKeys key, | |
2385 char keyChar, | |
2386 KeyboardModifiers modifiers, | |
2387 IStatusBar* statusBar) | |
2388 { | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2389 switch (keyChar) |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2390 { |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2391 case 'c': |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2392 tool_ = Tool_Crop; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2393 break; |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2394 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2395 case 'a': |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2396 widget.FitContent(); |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2397 break; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2398 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2399 case 'm': |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2400 tool_ = Tool_Move; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2401 break; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2402 |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2403 case 'r': |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2404 tool_ = Tool_Rotate; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2405 break; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2406 |
352
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2407 case 's': |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2408 tool_ = Tool_Resize; |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2409 break; |
d95e65ebe0b9
ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
2410 |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2411 case 'w': |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2412 tool_ = Tool_Windowing; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2413 break; |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2414 |
354 | 2415 case 'z': |
2416 if (modifiers & KeyboardModifiers_Control) | |
2417 { | |
2418 undoRedoStack_.Undo(); | |
2419 widget.NotifyContentChanged(); | |
2420 } | |
2421 break; | |
2422 | |
2423 case 'y': | |
2424 if (modifiers & KeyboardModifiers_Control) | |
2425 { | |
2426 undoRedoStack_.Redo(); | |
2427 widget.NotifyContentChanged(); | |
2428 } | |
2429 break; | |
2430 | |
347
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2431 default: |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2432 break; |
cd65103c9172
RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
346
diff
changeset
|
2433 } |
341 | 2434 } |
2435 }; | |
2436 | |
2437 | |
338 | 2438 |
2439 class BitmapStackWidget : | |
2440 public WorldSceneWidget, | |
2441 public IObservable, | |
2442 public IObserver | |
2443 { | |
2444 private: | |
341 | 2445 BitmapStack& stack_; |
2446 BitmapStackInteractor myInteractor_; | |
337 | 2447 |
336
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2448 protected: |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2449 virtual Extent2D GetSceneExtent() |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2450 { |
339 | 2451 return stack_.GetSceneExtent(); |
336
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2452 } |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2453 |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2454 virtual bool RenderScene(CairoContext& context, |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2455 const ViewportGeometry& view) |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2456 { |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2457 // "Render()" has been replaced |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2458 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2459 } |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2460 |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2461 public: |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2462 BitmapStackWidget(MessageBroker& broker, |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2463 BitmapStack& stack, |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2464 const std::string& name) : |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2465 WorldSceneWidget(name), |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2466 IObservable(broker), |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2467 IObserver(broker), |
342 | 2468 stack_(stack), |
2469 myInteractor_(stack_) | |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2470 { |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2471 stack.RegisterObserverCallback(new Callable<BitmapStackWidget, BitmapStack::GeometryChangedMessage>(*this, &BitmapStackWidget::OnGeometryChanged)); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2472 stack.RegisterObserverCallback(new Callable<BitmapStackWidget, BitmapStack::ContentChangedMessage>(*this, &BitmapStackWidget::OnContentChanged)); |
341 | 2473 |
2474 SetInteractor(myInteractor_); | |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2475 } |
339 | 2476 |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2477 void OnGeometryChanged(const BitmapStack::GeometryChangedMessage& message) |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2478 { |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2479 printf("Geometry has changed\n"); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2480 FitContent(); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2481 } |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2482 |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2483 void OnContentChanged(const BitmapStack::ContentChangedMessage& message) |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2484 { |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2485 printf("Content has changed\n"); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2486 NotifyContentChanged(); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2487 } |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2488 |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2489 virtual bool Render(Orthanc::ImageAccessor& target) |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2490 { |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2491 Orthanc::Image buffer(Orthanc::PixelFormat_Float32, target.GetWidth(), |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2492 target.GetHeight(), false); |
345 | 2493 |
2494 // TODO => rendering quality | |
348 | 2495 stack_.Render(buffer, GetView(), ImageInterpolation_Nearest); |
2496 //stack_.Render(buffer, GetView(), ImageInterpolation_Bilinear); | |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2497 |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2498 // As in GrayscaleFrameRenderer => TODO MERGE? |
339 | 2499 |
2500 float windowCenter, windowWidth; | |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2501 stack_.GetWindowingWithDefault(windowCenter, windowWidth); |
339 | 2502 |
2503 float x0 = windowCenter - windowWidth / 2.0f; | |
2504 float x1 = windowCenter + windowWidth / 2.0f; | |
2505 | |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2506 if (windowWidth >= 0.001f) // Avoid division by zero at (*) |
339 | 2507 { |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2508 const unsigned int width = target.GetWidth(); |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2509 const unsigned int height = target.GetHeight(); |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2510 |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2511 for (unsigned int y = 0; y < height; y++) |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2512 { |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2513 const float* p = reinterpret_cast<const float*>(buffer.GetConstRow(y)); |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2514 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
339 | 2515 |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2516 for (unsigned int x = 0; x < width; x++, p++, q += 4) |
339 | 2517 { |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2518 uint8_t v = 0; |
339 | 2519 if (*p >= x1) |
2520 { | |
2521 v = 255; | |
2522 } | |
2523 else if (*p <= x0) | |
2524 { | |
2525 v = 0; | |
2526 } | |
2527 else | |
2528 { | |
2529 // https://en.wikipedia.org/wiki/Linear_interpolation | |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2530 v = static_cast<uint8_t>(255.0f * (*p - x0) / (x1 - x0)); // (*) |
339 | 2531 } |
2532 | |
2533 // TODO MONOCHROME1 | |
2534 /*if (invert_) | |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2535 { |
339 | 2536 v = 255 - v; |
2537 }*/ | |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2538 |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2539 q[0] = v; |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2540 q[1] = v; |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2541 q[2] = v; |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2542 q[3] = 255; |
339 | 2543 } |
2544 } | |
2545 } | |
344
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2546 else |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2547 { |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2548 Orthanc::ImageProcessing::Set(target, 0, 0, 0, 255); |
fdec8e6893cb
ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
2549 } |
339 | 2550 |
345 | 2551 { |
2552 // TODO => REFACTOR | |
2553 CairoSurface surface(target); | |
2554 stack_.DrawControls(surface, GetView()); | |
2555 } | |
2556 | |
337 | 2557 return true; |
336
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2558 } |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2559 |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2560 }; |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2561 |
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2562 |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2563 namespace Samples |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2564 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2565 class SingleFrameEditorApplication : |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2566 public SampleSingleCanvasApplicationBase, |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2567 public IObserver |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2568 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2569 enum Tools |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2570 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2571 Tools_Crop, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2572 Tools_Windowing, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2573 Tools_Zoom, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2574 Tools_Pan |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2575 }; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2576 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2577 enum Actions |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2578 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2579 Actions_Invert, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2580 Actions_RotateLeft, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2581 Actions_RotateRight |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2582 }; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2583 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2584 private: |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2585 class Interactor : public IWorldSceneInteractor |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2586 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2587 private: |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2588 SingleFrameEditorApplication& application_; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2589 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2590 public: |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2591 Interactor(SingleFrameEditorApplication& application) : |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2592 application_(application) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2593 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2594 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2595 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2596 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2597 const ViewportGeometry& view, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2598 MouseButton button, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2599 KeyboardModifiers modifiers, |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2600 int viewportX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
355
diff
changeset
|
2601 int viewportY, |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2602 double x, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2603 double y, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2604 IStatusBar* statusBar) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2605 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2606 switch (application_.currentTool_) { |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2607 case Tools_Zoom: |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2608 printf("ZOOM\n"); |
329
b10dfdb96866
removing WorldSceneWidget::IWorldObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
2609 |
b10dfdb96866
removing WorldSceneWidget::IWorldObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
2610 case Tools_Crop: |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2611 case Tools_Windowing: |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2612 case Tools_Pan: |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2613 // TODO return the right mouse tracker |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2614 return NULL; |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2615 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2616 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2617 return NULL; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2618 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2619 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2620 virtual void MouseOver(CairoContext& context, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2621 WorldSceneWidget& widget, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2622 const ViewportGeometry& view, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2623 double x, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2624 double y, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2625 IStatusBar* statusBar) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2626 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2627 if (statusBar != NULL) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2628 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2629 char buf[64]; |
336
c7fdc8bac581
creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
334
diff
changeset
|
2630 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
|
2631 statusBar->SetMessage(buf); |
325
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 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2635 virtual void MouseWheel(WorldSceneWidget& widget, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2636 MouseWheelDirection direction, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2637 KeyboardModifiers modifiers, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2638 IStatusBar* statusBar) |
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 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2642 virtual void KeyPressed(WorldSceneWidget& widget, |
327 | 2643 KeyboardKeys key, |
2644 char keyChar, | |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2645 KeyboardModifiers modifiers, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2646 IStatusBar* statusBar) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2647 { |
327 | 2648 switch (keyChar) |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2649 { |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2650 case 's': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2651 widget.FitContent(); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2652 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2653 case 'p': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2654 application_.currentTool_ = Tools_Pan; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2655 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2656 case 'z': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2657 application_.currentTool_ = Tools_Zoom; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2658 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2659 case 'c': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2660 application_.currentTool_ = Tools_Crop; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2661 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2662 case 'w': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2663 application_.currentTool_ = Tools_Windowing; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2664 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2665 case 'i': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2666 application_.Invert(); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2667 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2668 case 'r': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2669 if (modifiers == KeyboardModifiers_None) |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2670 application_.Rotate(90); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2671 else |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2672 application_.Rotate(-90); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2673 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2674 case 'e': |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2675 application_.Export(); |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2676 break; |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2677 default: |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2678 break; |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2679 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2680 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2681 }; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2682 |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
2683 std::auto_ptr<Interactor> mainWidgetInteractor_; |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
2684 std::auto_ptr<OrthancApiClient> orthancApiClient_; |
338 | 2685 std::auto_ptr<BitmapStack> stack_; |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
2686 Tools currentTool_; |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
2687 const OrthancFrameLayerSource* source_; |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
2688 unsigned int slice_; |
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 public: |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2691 SingleFrameEditorApplication(MessageBroker& broker) : |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2692 IObserver(broker), |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2693 currentTool_(Tools_Zoom), |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2694 source_(NULL), |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2695 slice_(0) |
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 DeclareStartupOptions(boost::program_options::options_description& options) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2700 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2701 boost::program_options::options_description generic("Sample options"); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2702 generic.add_options() |
340
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2703 ("instance", boost::program_options::value<std::string>(), |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2704 "Orthanc ID of the instance") |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2705 ("frame", boost::program_options::value<unsigned int>()->default_value(0), |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2706 "Number of the frame, for multi-frame DICOM instances") |
f5d5814a41a0
rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
2707 ; |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2708 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2709 options.add(generic); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2710 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2711 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2712 virtual void Initialize(StoneApplicationContext* context, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2713 IStatusBar& statusBar, |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2714 const boost::program_options::variables_map& parameters) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2715 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2716 using namespace OrthancStone; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2717 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2718 context_ = context; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2719 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2720 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
|
2721 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2722 if (parameters.count("instance") != 1) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2723 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2724 LOG(ERROR) << "The instance ID is missing"; |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2725 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2726 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2727 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2728 std::string instance = parameters["instance"].as<std::string>(); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2729 int frame = parameters["frame"].as<unsigned int>(); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2730 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2731 orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService())); |
337 | 2732 |
343 | 2733 Orthanc::FontRegistry fonts; |
2734 fonts.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16); | |
2735 | |
338 | 2736 stack_.reset(new BitmapStack(IObserver::broker_, *orthancApiClient_)); |
354 | 2737 //stack_->LoadFrame(instance, frame, false); |
2738 //stack_->LoadFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", frame, false); | |
2739 | |
2740 { | |
2741 BitmapStack::Bitmap& bitmap = stack_->LoadText(fonts.GetFont(0), "Hello\nworld\nBonjour, Alain"); | |
2742 dynamic_cast<BitmapStack::AlphaBitmap&>(bitmap).SetForegroundValue(256); | |
2743 dynamic_cast<BitmapStack::AlphaBitmap&>(bitmap).SetResizeable(true); | |
2744 } | |
2745 | |
2746 { | |
2747 BitmapStack::Bitmap& bitmap = stack_->LoadTestBlock(100, 50); | |
2748 dynamic_cast<BitmapStack::AlphaBitmap&>(bitmap).SetForegroundValue(256); | |
2749 dynamic_cast<BitmapStack::AlphaBitmap&>(bitmap).SetResizeable(true); | |
2750 } | |
2751 | |
337 | 2752 |
338 | 2753 mainWidget_ = new BitmapStackWidget(IObserver::broker_, *stack_, "main-widget"); |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2754 mainWidget_->SetTransmitMouseOver(true); |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2755 |
350
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2756 //stack_->SetWindowing(128, 256); |
c57e049ed079
drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
2757 |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2758 mainWidgetInteractor_.reset(new Interactor(*this)); |
341 | 2759 //mainWidget_->SetInteractor(*mainWidgetInteractor_); |
325
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2760 } |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2761 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2762 |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2763 void Invert() |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2764 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2765 // TODO |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2766 } |
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 void Rotate(int degrees) |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2769 { |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2770 // TODO |
37ab9d83dc9b
reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff
changeset
|
2771 } |
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 void Export() |
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 // TODO: export dicom file to a temporary file |
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 }; |
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 |
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 } |