annotate Applications/Samples/SingleFrameEditorApplication.h @ 353:92a159481900 am-2

removed useless variable
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 29 Oct 2018 11:53:34 +0100
parents d95e65ebe0b9
children f806779bd40f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
26 #include "../../Framework/Toolbox/GeometryToolbox.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
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
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
30 #include <Core/DicomFormat/DicomArray.h>
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
31 #include <Core/Images/FontRegistry.h>
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
32 #include <Core/Images/ImageProcessing.h>
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
33 #include <Core/Images/PamReader.h>
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
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
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
36 #include <Plugins/Samples/Common/FullOrthancDataset.h>
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
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
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
44 class BitmapStack :
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
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
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
49 typedef OriginMessage<MessageType_Widget_GeometryChanged, BitmapStack> GeometryChangedMessage;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
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 };
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
60
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
61
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
62 class Bitmap : public boost::noncopyable
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
63 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
64 private:
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
65 size_t index_;
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
66 bool hasSize_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
67 unsigned int width_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
68 unsigned int height_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
69 bool hasCrop_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
70 unsigned int cropX_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
71 unsigned int cropY_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
72 unsigned int cropWidth_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
73 unsigned int cropHeight_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
74 Matrix transform_;
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
75 Matrix transformInverse_;
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
76 double pixelSpacingX_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
77 double pixelSpacingY_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
78 double panX_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
79 double panY_;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
80 double angle_;
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
81 bool resizeable_;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
82
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
83
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
84 protected:
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
85 static Matrix CreateOffsetMatrix(double dx,
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
86 double dy)
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
87 {
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
88 Matrix m = LinearAlgebra::IdentityMatrix(3);
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
89 m(0, 2) = dx;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
90 m(1, 2) = dy;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
91 return m;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
92 }
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
93
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
94
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
95 static Matrix CreateScalingMatrix(double sx,
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
96 double sy)
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
97 {
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
98 Matrix m = LinearAlgebra::IdentityMatrix(3);
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
99 m(0, 0) = sx;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
100 m(1, 1) = sy;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
101 return m;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
102 }
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
103
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
104
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
105 static Matrix CreateRotationMatrix(double angle)
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
106 {
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
107 Matrix m;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
108 const double v[] = { cos(angle), -sin(angle), 0,
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
109 sin(angle), cos(angle), 0,
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
110 0, 0, 1 };
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
111 LinearAlgebra::FillMatrix(m, 3, 3, v);
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
112 return m;
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
113 }
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
114
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
115
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
116 const Matrix& GetTransform() const
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
117 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
118 return transform_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
119 }
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
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
122 private:
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
123 static void ApplyTransform(double& x /* inout */,
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
124 double& y /* inout */,
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
125 const Matrix& transform)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
126 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
127 Vector p;
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
128 LinearAlgebra::AssignVector(p, x, y, 1);
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
129
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
130 Vector q = LinearAlgebra::Product(transform, p);
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
131
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
132 if (!LinearAlgebra::IsNear(q[2], 1.0))
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
133 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
134 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
135 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
136 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
137 {
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
138 x = q[0];
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
139 y = q[1];
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
140 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
141 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
142
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
143
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
144 void UpdateTransform()
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
145 {
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
146 transform_ = CreateScalingMatrix(pixelSpacingX_, pixelSpacingY_);
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
147
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
148 double centerX, centerY;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
149 GetCenter(centerX, centerY);
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
150
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
151 transform_ = LinearAlgebra::Product(
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
152 CreateOffsetMatrix(panX_ + centerX, panY_ + centerY),
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
153 CreateRotationMatrix(angle_),
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
154 CreateOffsetMatrix(-centerX, -centerY),
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
155 transform_);
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
156
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
157 LinearAlgebra::InvertMatrix(transformInverse_, transform_);
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
158 }
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
159
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
160
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
161 void AddToExtent(Extent2D& extent,
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
162 double x,
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
163 double y) const
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
164 {
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
165 ApplyTransform(x, y, transform_);
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
166 extent.AddPoint(x, y);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
167 }
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
168
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 void GetCornerInternal(double& x,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
171 double& y,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
172 Corner corner,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
173 unsigned int cropX,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
174 unsigned int cropY,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
175 unsigned int cropWidth,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
176 unsigned int cropHeight) const
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
177 {
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
178 double dx = static_cast<double>(cropX);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
179 double dy = static_cast<double>(cropY);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
180 double dwidth = static_cast<double>(cropWidth);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
181 double dheight = static_cast<double>(cropHeight);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
182
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
183 switch (corner)
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
184 {
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
185 case Corner_TopLeft:
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
186 x = dx;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
187 y = dy;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
188 break;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
189
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
190 case Corner_TopRight:
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
191 x = dx + dwidth;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
192 y = dy;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
193 break;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
194
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
195 case Corner_BottomLeft:
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
196 x = dx;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
197 y = dy + dheight;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
198 break;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
199
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
200 case Corner_BottomRight:
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
201 x = dx + dwidth;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
202 y = dy + dheight;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
203 break;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
204
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
205 default:
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
206 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
207 }
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 ApplyTransform(x, y, transform_);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
210 }
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
211
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
212
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
213 public:
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
214 Bitmap(size_t index) :
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
215 index_(index),
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
216 hasSize_(false),
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
217 width_(0),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
218 height_(0),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
219 hasCrop_(false),
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
220 pixelSpacingX_(1),
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
221 pixelSpacingY_(1),
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
222 panX_(0),
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
223 panY_(0),
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
224 angle_(0),
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
225 resizeable_(false)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
226 {
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
227 UpdateTransform();
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
228 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
229
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
230 virtual ~Bitmap()
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
231 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
232 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
233
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
234 size_t GetIndex() const
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
235 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
236 return index_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
237 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
238
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
239 void ResetCrop()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
240 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
241 hasCrop_ = false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
242 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
243
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
244 void SetCrop(unsigned int x,
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
245 unsigned int y,
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
246 unsigned int width,
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
247 unsigned int height)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
248 {
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
249 if (!hasSize_)
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
250 {
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
251 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
252 }
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
253
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
254 if (x + width > width_ ||
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
255 y + height > height_)
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
256 {
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
257 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
258 }
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
259
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
260 hasCrop_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
261 cropX_ = x;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
262 cropY_ = y;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
263 cropWidth_ = width;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
264 cropHeight_ = height;
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
265
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
266 UpdateTransform();
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
267 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
268
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
269 void GetCrop(unsigned int& x,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
270 unsigned int& y,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
271 unsigned int& width,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
272 unsigned int& height) const
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
273 {
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
274 if (hasCrop_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
275 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
276 x = cropX_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
277 y = cropY_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
278 width = cropWidth_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
279 height = cropHeight_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
280 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
281 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
282 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
283 x = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
284 y = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
285 width = width_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
286 height = height_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
287 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
288 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
289
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
290 void SetAngle(double angle)
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
291 {
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
292 angle_ = angle;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
293 UpdateTransform();
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
294 }
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
295
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
296 double GetAngle() const
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
297 {
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
298 return angle_;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
299 }
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
300
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
301 void SetSize(unsigned int width,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
302 unsigned int height)
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
303 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
304 if (hasSize_ &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
305 (width != width_ ||
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
306 height != height_))
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
307 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
308 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
309 }
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
310
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
311 hasSize_ = true;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
312 width_ = width;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
313 height_ = height;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
314
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
315 UpdateTransform();
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
316 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
317
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
318
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
319 unsigned int GetWidth() const
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
320 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
321 return width_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
322 }
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 unsigned int GetHeight() const
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
326 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
327 return height_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
328 }
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
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
331 void CheckSize(unsigned int width,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
332 unsigned int height)
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
333 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
334 if (hasSize_ &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
335 (width != width_ ||
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
336 height != height_))
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
337 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
338 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
339 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
340 }
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
341
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
342
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
343 Extent2D GetExtent() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
344 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
345 Extent2D extent;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
346
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
347 unsigned int x, y, width, height;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
348 GetCrop(x, y, width, height);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
349
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
350 double dx = static_cast<double>(x);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
351 double dy = static_cast<double>(y);
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
352 double dwidth = static_cast<double>(width);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
353 double dheight = static_cast<double>(height);
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
354
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
355 AddToExtent(extent, dx, dy);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
356 AddToExtent(extent, dx + dwidth, dy);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
357 AddToExtent(extent, dx, dy + dheight);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
358 AddToExtent(extent, dx + dwidth, dy + dheight);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
359
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
360 return extent;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
361 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
362
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
363
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
364 virtual void Render(Orthanc::ImageAccessor& buffer,
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
365 const ViewportGeometry& view,
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
366 ImageInterpolation interpolation) const = 0;
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
367
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
368
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
369 bool Contains(double x,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
370 double y) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
371 {
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
372 ApplyTransform(x, y, transformInverse_);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
373
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
374 unsigned int cropX, cropY, cropWidth, cropHeight;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
375 GetCrop(cropX, cropY, cropWidth, cropHeight);
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
376
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
377 return (x >= cropX && x <= cropX + cropWidth &&
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
378 y >= cropY && y <= cropY + cropHeight);
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
379 }
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
380
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
381
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
382 bool GetPixel(unsigned int& pixelX,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
383 unsigned int& pixelY,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
384 double sceneX,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
385 double sceneY) const
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
386 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
387 if (width_ == 0 ||
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
388 height_ == 0)
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 return false;
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 else
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
393 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
394 ApplyTransform(sceneX, sceneY, transformInverse_);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
395
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
396 int x = static_cast<int>(std::floor(sceneX));
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
397 int y = static_cast<int>(std::floor(sceneY));
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 if (x < 0)
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
400 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
401 pixelX = 0;
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 if (x >= static_cast<int>(width_))
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
404 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
405 pixelX = width_;
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 else
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
408 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
409 pixelX = static_cast<unsigned int>(x);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
410 }
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 if (y < 0)
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
413 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
414 pixelY = 0;
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 if (y >= static_cast<int>(height_))
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
417 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
418 pixelY = height_;
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 else
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
421 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
422 pixelY = static_cast<unsigned int>(y);
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 return true;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
426 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
427 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
428
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
429
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
430 void SetPan(double x,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
431 double y)
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
432 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
433 panX_ = x;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
434 panY_ = y;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
435 UpdateTransform();
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
436 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
437
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
438
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
439 void SetPixelSpacing(double x,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
440 double y)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
441 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
442 pixelSpacingX_ = x;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
443 pixelSpacingY_ = y;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
444 UpdateTransform();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
445 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
446
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
447 double GetPixelSpacingX() const
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
448 {
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
449 return pixelSpacingX_;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
450 }
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
451
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
452 double GetPixelSpacingY() const
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
453 {
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
454 return pixelSpacingY_;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
455 }
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
456
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
457 double GetPanX() const
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
458 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
459 return panX_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
460 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
461
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
462 double GetPanY() const
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
463 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
464 return panY_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
465 }
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
466
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
467 virtual bool GetDefaultWindowing(float& center,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
468 float& width) const
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
469 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
470 return false;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
471 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
472
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
473 void GetCenter(double& centerX,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
474 double& centerY) const
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
475 {
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
476 #if 0
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
477 unsigned int x, y, width, height;
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
478 GetCrop(x, y, width, height);
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
479
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
480 centerX = static_cast<double>(width) / 2.0;
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
481 centerY = static_cast<double>(height) / 2.0;
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
482 #else
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
483 centerX = static_cast<double>(width_) / 2.0;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
484 centerY = static_cast<double>(height_) / 2.0;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
485 #endif
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
486
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
487 ApplyTransform(centerX, centerY, transform_);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
488 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
489
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
490
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
491 void DrawBorders(CairoContext& context,
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
492 double zoom)
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
493 {
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
494 unsigned int cx, cy, width, height;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
495 GetCrop(cx, cy, width, height);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
496
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
497 double dx = static_cast<double>(cx);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
498 double dy = static_cast<double>(cy);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
499 double dwidth = static_cast<double>(width);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
500 double dheight = static_cast<double>(height);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
501
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
502 cairo_t* cr = context.GetObject();
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
503 cairo_set_line_width(cr, 2.0 / zoom);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
504
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
505 double x, y;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
506 x = dx;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
507 y = dy;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
508 ApplyTransform(x, y, transform_);
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
509 cairo_move_to(cr, x, y);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
510
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
511 x = dx + dwidth;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
512 y = dy;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
513 ApplyTransform(x, y, transform_);
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
514 cairo_line_to(cr, x, y);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
515
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
516 x = dx + dwidth;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
517 y = dy + dheight;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
518 ApplyTransform(x, y, transform_);
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
519 cairo_line_to(cr, x, y);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
520
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
521 x = dx;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
522 y = dy + dheight;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
523 ApplyTransform(x, y, transform_);
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
524 cairo_line_to(cr, x, y);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
525
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
526 x = dx;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
527 y = dy;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
528 ApplyTransform(x, y, transform_);
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
529 cairo_line_to(cr, x, y);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
530
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
531 cairo_stroke(cr);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
532 }
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
533
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
534
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
535 static double Square(double x)
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
536 {
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
537 return x * x;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
538 }
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
539
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
540
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
541 void GetCorner(double& x /* out */,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
542 double& y /* out */,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
543 Corner corner) const
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 GetCornerInternal(x, y, corner, cropX, cropY, cropWidth, cropHeight);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
548 }
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
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
551 bool LookupCorner(Corner& corner /* out */,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
552 double x,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
553 double y,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
554 double zoom,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
555 double viewportDistance) const
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 static const Corner CORNERS[] = {
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
558 Corner_TopLeft,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
559 Corner_TopRight,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
560 Corner_BottomLeft,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
561 Corner_BottomRight
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 unsigned int cropX, cropY, cropWidth, cropHeight;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
565 GetCrop(cropX, cropY, cropWidth, cropHeight);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
566
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
567 double threshold = Square(viewportDistance / zoom);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
568
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
569 for (size_t i = 0; i < 4; i++)
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
570 {
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
571 double cx, cy;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
572 GetCornerInternal(cx, cy, CORNERS[i], cropX, cropY, cropWidth, cropHeight);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
573
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
574 double d = Square(cx - x) + Square(cy - y);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
575
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
576 if (d <= threshold)
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
577 {
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
578 corner = CORNERS[i];
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
579 return true;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
580 }
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
581 }
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
582
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
583 return false;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
584 }
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
585
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
586 bool IsResizeable() const
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
587 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
588 return resizeable_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
589 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
590
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
591 void SetResizeable(bool resizeable)
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
592 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
593 resizeable_ = resizeable;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
594 }
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
595 };
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
596
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
597
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
598 class BitmapAccessor : public boost::noncopyable
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
599 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
600 private:
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
601 size_t index_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
602 Bitmap* bitmap_;
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
603
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
604 public:
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
605 BitmapAccessor(BitmapStack& stack,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
606 size_t index) :
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
607 index_(index)
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
608 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
609 Bitmaps::iterator bitmap = stack.bitmaps_.find(index);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
610 if (bitmap == stack.bitmaps_.end())
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 bitmap_ = NULL;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
613 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
614 else
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 assert(bitmap->second != NULL);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
617 bitmap_ = bitmap->second;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
618 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
619 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
620
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
621 BitmapAccessor(BitmapStack& stack,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
622 double x,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
623 double y) :
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
624 index_(0) // Dummy initialization
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
625 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
626 if (stack.LookupBitmap(index_, x, y))
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
627 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
628 Bitmaps::iterator bitmap = stack.bitmaps_.find(index_);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
629
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
630 if (bitmap == stack.bitmaps_.end())
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
631 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
632 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
633 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
634 else
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 assert(bitmap->second != NULL);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
637 bitmap_ = bitmap->second;
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 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
640 else
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 bitmap_ = NULL;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
643 }
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
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
646 void Invalidate()
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 bitmap_ = NULL;
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
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
651 bool IsValid() const
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
652 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
653 return bitmap_ != NULL;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
654 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
655
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
656 size_t GetIndex() const
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
657 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
658 if (IsValid())
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
659 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
660 return index_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
661 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
662 else
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
663 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
664 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
665 }
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
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
668 Bitmap& GetBitmap() const
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
669 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
670 if (IsValid())
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
671 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
672 return *bitmap_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
673 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
674 else
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
677 }
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 };
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
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
682 private:
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
683 class DicomBitmap : public Bitmap
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
684 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
685 private:
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
686 std::auto_ptr<Orthanc::ImageAccessor> source_; // Content of PixelData
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
687 std::auto_ptr<DicomFrameConverter> converter_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
688 std::auto_ptr<Orthanc::ImageAccessor> converted_; // Float32 or RGB24
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
689
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
690 static OrthancPlugins::DicomTag ConvertTag(const Orthanc::DicomTag& tag)
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
691 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
692 return OrthancPlugins::DicomTag(tag.GetGroup(), tag.GetElement());
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
693 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
694
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
695
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
696 void ApplyConverter()
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
697 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
698 if (source_.get() != NULL &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
699 converter_.get() != NULL)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
700 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
701 converted_.reset(converter_->ConvertFrame(*source_));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
702 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
703 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
704
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
705 public:
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
706 DicomBitmap(size_t index) :
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
707 Bitmap(index)
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
708 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
709 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
710
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
711 void SetDicomTags(const OrthancPlugins::FullOrthancDataset& dataset)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
712 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
713 converter_.reset(new DicomFrameConverter);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
714 converter_->ReadParameters(dataset);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
715 ApplyConverter();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
716
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
717 std::string tmp;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
718 Vector pixelSpacing;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
719
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
720 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PIXEL_SPACING)) &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
721 LinearAlgebra::ParseVector(pixelSpacing, tmp) &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
722 pixelSpacing.size() == 2)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
723 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
724 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
725 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
726
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
727 //SetPan(-0.5 * GetPixelSpacingX(), -0.5 * GetPixelSpacingY());
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
728
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
729 static unsigned int c = 0;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
730 if (c == 0)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
731 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
732 SetPan(400, 0);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
733 c ++;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
734 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
735
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
736 OrthancPlugins::DicomDatasetReader reader(dataset);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
737
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
738 unsigned int width, height;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
739 if (!reader.GetUnsignedIntegerValue(width, ConvertTag(Orthanc::DICOM_TAG_COLUMNS)) ||
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
740 !reader.GetUnsignedIntegerValue(height, ConvertTag(Orthanc::DICOM_TAG_ROWS)))
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
741 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
742 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
743 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
744 else
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
745 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
746 SetSize(width, height);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
747 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
748 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
749
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
750
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
751 void SetSourceImage(Orthanc::ImageAccessor* image) // Takes ownership
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
752 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
753 std::auto_ptr<Orthanc::ImageAccessor> raii(image);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
754
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
755 if (image == NULL)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
756 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
757 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
758 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
759
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
760 SetSize(image->GetWidth(), image->GetHeight());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
761
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
762 source_ = raii;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
763 ApplyConverter();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
764 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
765
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
766
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
767 virtual void Render(Orthanc::ImageAccessor& buffer,
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
768 const ViewportGeometry& view,
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
769 ImageInterpolation interpolation) const
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
770 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
771 if (converted_.get() != NULL)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
772 {
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
773 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32)
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
774 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
775 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
776 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
777
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
778 unsigned int cropX, cropY, cropWidth, cropHeight;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
779 GetCrop(cropX, cropY, cropWidth, cropHeight);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
780
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
781 Matrix m = LinearAlgebra::Product(view.GetMatrix(),
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
782 GetTransform(),
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
783 CreateOffsetMatrix(cropX, cropY));
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
784
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
785 Orthanc::ImageAccessor cropped;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
786 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
787
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
788 ApplyProjectiveTransform(buffer, cropped, m, interpolation, false);
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
789 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
790 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
791
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
792
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
793 virtual bool GetDefaultWindowing(float& center,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
794 float& width) const
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
795 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
796 if (converter_.get() != NULL &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
797 converter_->HasDefaultWindow())
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
798 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
799 center = static_cast<float>(converter_->GetDefaultWindowCenter());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
800 width = static_cast<float>(converter_->GetDefaultWindowWidth());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
801 return true;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
802 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
803 else
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
804 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
805 return false;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
806 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
807 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
808 };
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
809
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
810
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
811
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
812
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
813 class AlphaBitmap : public Bitmap
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
814 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
815 private:
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
816 const BitmapStack& stack_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
817 std::auto_ptr<Orthanc::ImageAccessor> alpha_; // Grayscale8
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
818 bool useWindowing_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
819 float foreground_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
820
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
821 public:
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
822 AlphaBitmap(size_t index,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
823 const BitmapStack& stack) :
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
824 Bitmap(index),
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
825 stack_(stack),
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
826 useWindowing_(true),
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
827 foreground_(0)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
828 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
829 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
830
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
831
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
832 void SetForegroundValue(float foreground)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
833 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
834 useWindowing_ = false;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
835 foreground_ = foreground;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
836 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
837
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
838
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
839 void SetAlpha(Orthanc::ImageAccessor* image)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
840 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
841 std::auto_ptr<Orthanc::ImageAccessor> raii(image);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
842
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
843 if (image == NULL)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
844 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
845 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
846 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
847
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
848 if (image->GetFormat() != Orthanc::PixelFormat_Grayscale8)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
849 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
850 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
851 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
852
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
853 SetSize(image->GetWidth(), image->GetHeight());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
854 alpha_ = raii;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
855 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
856
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
857
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
858 void LoadText(const Orthanc::Font& font,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
859 const std::string& utf8)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
860 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
861 SetAlpha(font.RenderAlpha(utf8));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
862 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
863
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
864
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
865 virtual void Render(Orthanc::ImageAccessor& buffer,
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
866 const ViewportGeometry& view,
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
867 ImageInterpolation interpolation) const
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
868 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
869 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
870 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
871 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
872 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
873
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
874 unsigned int cropX, cropY, cropWidth, cropHeight;
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
875 GetCrop(cropX, cropY, cropWidth, cropHeight);
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
876
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
877 Matrix m = LinearAlgebra::Product(view.GetMatrix(),
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
878 GetTransform(),
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
879 CreateOffsetMatrix(cropX, cropY));
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
880
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
881 Orthanc::ImageAccessor cropped;
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
882 alpha_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight);
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
883
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
884 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false);
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
885 ApplyProjectiveTransform(tmp, cropped, m, interpolation, true /* clear */);
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
886
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
887 // Blit
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
888 const unsigned int width = buffer.GetWidth();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
889 const unsigned int height = buffer.GetHeight();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
890
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
891 float value = foreground_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
892
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
893 if (useWindowing_)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
894 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
895 float center, width;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
896 if (stack_.GetWindowing(center, width))
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
897 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
898 value = center + width / 2.0f;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
899 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
900 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
901
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
902 for (unsigned int y = 0; y < height; y++)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
903 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
904 float *q = reinterpret_cast<float*>(buffer.GetRow(y));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
905 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
906
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
907 for (unsigned int x = 0; x < width; x++, p++, q++)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
908 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
909 float a = static_cast<float>(*p) / 255.0f;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
910
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
911 *q = (a * value + (1.0f - a) * (*q));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
912 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
913 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
914 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
915 };
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
916
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
917
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
918
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
919 typedef std::map<size_t, Bitmap*> Bitmaps;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
920
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
921 OrthancApiClient& orthanc_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
922 size_t countBitmaps_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
923 bool hasWindowing_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
924 float windowingCenter_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
925 float windowingWidth_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
926 Bitmaps bitmaps_;
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
927 bool hasSelection_;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
928 size_t selectedBitmap_;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
929
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
930 public:
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
931 BitmapStack(MessageBroker& broker,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
932 OrthancApiClient& orthanc) :
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
933 IObserver(broker),
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
934 IObservable(broker),
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
935 orthanc_(orthanc),
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
936 countBitmaps_(0),
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
937 hasWindowing_(false),
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
938 windowingCenter_(0), // Dummy initialization
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
939 windowingWidth_(0), // Dummy initialization
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
940 hasSelection_(false),
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
941 selectedBitmap_(0) // Dummy initialization
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
942 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
943 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
944
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
945
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
946 void Unselect()
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
947 {
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
948 hasSelection_ = false;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
949 }
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
950
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
951
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
952 void Select(size_t bitmap)
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
953 {
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
954 hasSelection_ = true;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
955 selectedBitmap_ = bitmap;
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
956 }
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
957
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
958
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
959 bool GetSelectedBitmap(size_t& bitmap) const
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
960 {
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
961 if (hasSelection_)
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
962 {
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
963 bitmap = selectedBitmap_;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
964 return true;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
965 }
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
966 else
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
967 {
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
968 return false;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
969 }
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
970 }
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
971
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
972
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
973 virtual ~BitmapStack()
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
974 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
975 for (Bitmaps::iterator it = bitmaps_.begin(); it != bitmaps_.end(); it++)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
976 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
977 assert(it->second != NULL);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
978 delete it->second;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
979 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
980 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
981
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
982
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
983 bool GetWindowing(float& center,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
984 float& width) const
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
985 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
986 if (hasWindowing_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
987 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
988 center = windowingCenter_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
989 width = windowingWidth_;
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
990 return true;
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
991 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
992 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
993 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
994 return false;
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
995 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
996 }
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
997
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
998
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
999 void SetWindowing(float center,
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1000 float width)
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1001
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1002 {
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1003 hasWindowing_ = true;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1004 windowingCenter_ = center;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1005 windowingWidth_ = width;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1006
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1007 EmitMessage(ContentChangedMessage(*this));
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1008 }
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1009
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1010
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1011 Bitmap& LoadText(const Orthanc::Font& font,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1012 const std::string& utf8)
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1013 {
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1014 size_t bitmap = countBitmaps_++;
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1015
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1016 std::auto_ptr<AlphaBitmap> alpha(new AlphaBitmap(bitmap, *this));
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1017 alpha->LoadText(font, utf8);
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1018
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1019 AlphaBitmap* ptr = alpha.get();
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1020 bitmaps_[bitmap] = alpha.release();
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1021
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1022 return *ptr;
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1023 }
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1024
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1025
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1026 Bitmap& LoadTestBlock(unsigned int width,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1027 unsigned int height)
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1028 {
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1029 size_t bitmap = countBitmaps_++;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1030
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1031 std::auto_ptr<AlphaBitmap> alpha(new AlphaBitmap(bitmap, *this));
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1032
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1033 std::auto_ptr<Orthanc::Image> block(new Orthanc::Image(Orthanc::PixelFormat_Grayscale8, width, height, false));
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1034
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1035 for (unsigned int padding = 0;
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1036 (width > 2 * padding) && (height > 2 * padding);
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1037 padding++)
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1038 {
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1039 uint8_t color;
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1040 if (255 > 10 * padding)
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1041 {
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1042 color = 255 - 10 * padding;
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1043 }
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1044 else
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1045 {
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1046 color = 0;
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1047 }
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1048
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1049 Orthanc::ImageAccessor region;
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1050 block->GetRegion(region, padding, padding, width - 2 * padding, height - 2 * padding);
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1051 Orthanc::ImageProcessing::Set(region, color);
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1052 }
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1053
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1054 alpha->SetAlpha(block.release());
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1055
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1056 AlphaBitmap* ptr = alpha.get();
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1057 bitmaps_[bitmap] = alpha.release();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1058
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1059 return *ptr;
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1060 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1061
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1062
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1063 size_t LoadFrame(const std::string& instance,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1064 unsigned int frame,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1065 bool httpCompression)
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1066 {
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1067 size_t bitmap = countBitmaps_++;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1068
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1069 bitmaps_[bitmap] = new DicomBitmap(bitmap);
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1070
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1071
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1072 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1073 IWebService::Headers headers;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1074 std::string uri = "/instances/" + instance + "/tags";
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1075 orthanc_.GetBinaryAsync(uri, headers,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1076 new Callable<BitmapStack, OrthancApiClient::BinaryResponseReadyMessage>
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1077 (*this, &BitmapStack::OnTagsReceived), NULL,
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1078 new Orthanc::SingleValueObject<size_t>(bitmap));
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1079 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1080
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1081 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1082 IWebService::Headers headers;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1083 headers["Accept"] = "image/x-portable-arbitrarymap";
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1084
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1085 if (httpCompression)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1086 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1087 headers["Accept-Encoding"] = "gzip";
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1088 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1089
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1090 std::string uri = "/instances/" + instance + "/frames/" + boost::lexical_cast<std::string>(frame) + "/image-uint16";
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1091 orthanc_.GetBinaryAsync(uri, headers,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1092 new Callable<BitmapStack, OrthancApiClient::BinaryResponseReadyMessage>
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1093 (*this, &BitmapStack::OnFrameReceived), NULL,
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1094 new Orthanc::SingleValueObject<size_t>(bitmap));
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1095 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1096
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1097 return bitmap;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1098 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1099
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1100
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1101 void OnTagsReceived(const OrthancApiClient::BinaryResponseReadyMessage& message)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1102 {
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1103 size_t index = dynamic_cast<Orthanc::SingleValueObject<size_t>*>(message.Payload.get())->GetValue();
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1104
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1105 printf("JSON received: [%s] (%ld bytes) for bitmap %ld\n",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1106 message.Uri.c_str(), message.AnswerSize, index);
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1107
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1108 Bitmaps::iterator bitmap = bitmaps_.find(index);
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1109 if (bitmap != bitmaps_.end())
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1110 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1111 assert(bitmap->second != NULL);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1112
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1113 OrthancPlugins::FullOrthancDataset dicom(message.Answer, message.AnswerSize);
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1114 dynamic_cast<DicomBitmap*>(bitmap->second)->SetDicomTags(dicom);
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1115
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1116 float c, w;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1117 if (!hasWindowing_ &&
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1118 bitmap->second->GetDefaultWindowing(c, w))
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1119 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1120 hasWindowing_ = true;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1121 windowingCenter_ = c;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1122 windowingWidth_ = w;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1123 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1124
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1125 EmitMessage(GeometryChangedMessage(*this));
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1126 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1127 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1128
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1129
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1130 void OnFrameReceived(const OrthancApiClient::BinaryResponseReadyMessage& message)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1131 {
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1132 size_t index = dynamic_cast<Orthanc::SingleValueObject<size_t>*>(message.Payload.get())->GetValue();
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1133
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1134 printf("Frame received: [%s] (%ld bytes) for bitmap %ld\n",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1135 message.Uri.c_str(), message.AnswerSize, index);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1136
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1137 Bitmaps::iterator bitmap = bitmaps_.find(index);
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1138 if (bitmap != bitmaps_.end())
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1139 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1140 assert(bitmap->second != NULL);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1141
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1142 std::string content;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1143 if (message.AnswerSize > 0)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1144 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1145 content.assign(reinterpret_cast<const char*>(message.Answer), message.AnswerSize);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1146 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1147
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1148 std::auto_ptr<Orthanc::PamReader> reader(new Orthanc::PamReader);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1149 reader->ReadFromMemory(content);
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1150 dynamic_cast<DicomBitmap*>(bitmap->second)->SetSourceImage(reader.release());
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1151
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1152 EmitMessage(ContentChangedMessage(*this));
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1153 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1154 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1155
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1156
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1157 Extent2D GetSceneExtent() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1158 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1159 Extent2D extent;
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1160
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1161 for (Bitmaps::const_iterator it = bitmaps_.begin();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1162 it != bitmaps_.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1163 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1164 assert(it->second != NULL);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1165 extent.Union(it->second->GetExtent());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1166 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1167
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1168 return extent;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1169 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1170
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1171
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1172 void Render(Orthanc::ImageAccessor& buffer,
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1173 const ViewportGeometry& view,
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1174 ImageInterpolation interpolation) const
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1175 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1176 Orthanc::ImageProcessing::Set(buffer, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1177
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1178 // Render layers in the background-to-foreground order
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1179 for (size_t index = 0; index < countBitmaps_; index++)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1180 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1181 Bitmaps::const_iterator it = bitmaps_.find(index);
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1182 if (it != bitmaps_.end())
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1183 {
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1184 assert(it->second != NULL);
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1185 it->second->Render(buffer, view, interpolation);
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1186 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1187 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1188 }
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1189
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1190
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1191 bool LookupBitmap(size_t& index /* out */,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1192 double x,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1193 double y) const
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1194 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1195 // Render layers in the foreground-to-background order
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1196 for (size_t i = countBitmaps_; i > 0; i--)
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1197 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1198 index = i - 1;
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1199 Bitmaps::const_iterator it = bitmaps_.find(index);
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1200 if (it != bitmaps_.end())
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1201 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1202 assert(it->second != NULL);
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1203 if (it->second->Contains(x, y))
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1204 {
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1205 return true;
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1206 }
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1207 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1208 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1209
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1210 return false;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1211 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1212
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1213 void DrawControls(CairoSurface& surface,
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1214 const ViewportGeometry& view)
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1215 {
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1216 if (hasSelection_)
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1217 {
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1218 Bitmaps::const_iterator bitmap = bitmaps_.find(selectedBitmap_);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1219
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1220 if (bitmap != bitmaps_.end())
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1221 {
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1222 CairoContext context(surface);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1223
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1224 context.SetSourceColor(255, 0, 0);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1225 view.ApplyTransform(context);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1226 bitmap->second->DrawBorders(context, view.GetZoom());
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1227 }
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1228 }
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1229 }
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1230 };
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1231
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1232
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1233 class BitmapStackInteractor : public IWorldSceneInteractor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1234 {
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1235 private:
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1236 enum Tool
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1237 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1238 Tool_Move,
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1239 Tool_Rotate,
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1240 Tool_Crop,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1241 Tool_Resize
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1242 };
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1243
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1244 static double GetHandleSize()
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1245 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1246 return 10.0;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1247 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1248
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1249
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1250 BitmapStack& stack_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1251 Tool tool_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1252
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1253
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1254 class RotateBitmapTracker : public IWorldSceneMouseTracker
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1255 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1256 private:
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1257 BitmapStack::BitmapAccessor accessor_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1258 double centerX_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1259 double centerY_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1260 double originalAngle_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1261 double clickAngle_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1262 bool roundAngles_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1263
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1264 bool ComputeAngle(double& angle /* out */,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1265 double sceneX,
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1266 double sceneY) const
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1267 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1268 Vector u;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1269 LinearAlgebra::AssignVector(u, sceneX - centerX_, sceneY - centerY_);
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1270
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1271 double nu = boost::numeric::ublas::norm_2(u);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1272
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1273 if (!LinearAlgebra::IsCloseToZero(nu))
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1274 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1275 u /= nu;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1276 angle = atan2(u[1], u[0]);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1277 return true;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1278 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1279 else
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1280 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1281 return false;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1282 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1283 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1284
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1285
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1286 public:
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1287 RotateBitmapTracker(BitmapStack& stack,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1288 const ViewportGeometry& view,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1289 size_t bitmap,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1290 double x,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1291 double y,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1292 bool roundAngles) :
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1293 accessor_(stack, bitmap),
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1294 roundAngles_(roundAngles)
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1295 {
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1296 if (accessor_.IsValid())
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1297 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1298 accessor_.GetBitmap().GetCenter(centerX_, centerY_);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1299 originalAngle_ = accessor_.GetBitmap().GetAngle();
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1300
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1301 double sceneX, sceneY;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1302 view.MapDisplayToScene(sceneX, sceneY, x, y);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1303
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1304 if (!ComputeAngle(clickAngle_, x, y))
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1305 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1306 accessor_.Invalidate();
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1307 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1308 }
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1309 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1310
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1311 virtual bool HasRender() const
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1312 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1313 return false;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1314 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1315
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1316 virtual void Render(CairoContext& context,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1317 double zoom)
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1318 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1319 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1320 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1321
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1322 virtual void MouseUp()
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1323 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1324 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1325
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1326 virtual void MouseMove(int displayX,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1327 int displayY,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1328 double sceneX,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1329 double sceneY)
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1330 {
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1331 static const double ROUND_ANGLE = 15.0 / 180.0 * boost::math::constants::pi<double>();
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1332
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1333 double angle;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1334
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1335 if (accessor_.IsValid() &&
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1336 ComputeAngle(angle, sceneX, sceneY))
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1337 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1338 angle = angle - clickAngle_ + originalAngle_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1339
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1340 if (roundAngles_)
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1341 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1342 angle = round(angle / ROUND_ANGLE) * ROUND_ANGLE;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1343 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1344
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1345 accessor_.GetBitmap().SetAngle(angle);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1346 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1347 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1348 };
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1349
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1350
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1351 class MoveBitmapTracker : public IWorldSceneMouseTracker
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1352 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1353 private:
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1354 BitmapStack::BitmapAccessor accessor_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1355 double clickX_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1356 double clickY_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1357 double panX_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1358 double panY_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1359 bool oneAxis_;
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1360
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1361 public:
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1362 MoveBitmapTracker(BitmapStack& stack,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1363 size_t bitmap,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1364 double x,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1365 double y,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1366 bool oneAxis) :
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1367 accessor_(stack, bitmap),
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1368 clickX_(x),
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1369 clickY_(y),
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1370 oneAxis_(oneAxis)
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1371 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1372 if (accessor_.IsValid())
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1373 {
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1374 panX_ = accessor_.GetBitmap().GetPanX();
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1375 panY_ = accessor_.GetBitmap().GetPanY();
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1376 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1377 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1378
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1379 virtual bool HasRender() const
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1380 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1381 return false;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1382 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1383
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1384 virtual void Render(CairoContext& context,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1385 double zoom)
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1386 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1387 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1388 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1389
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1390 virtual void MouseUp()
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1391 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1392 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1393
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1394 virtual void MouseMove(int displayX,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1395 int displayY,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1396 double sceneX,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1397 double sceneY)
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1398 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1399 if (accessor_.IsValid())
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1400 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1401 double dx = sceneX - clickX_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1402 double dy = sceneY - clickY_;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1403
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1404 if (oneAxis_)
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1405 {
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1406 if (fabs(dx) > fabs(dy))
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1407 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1408 accessor_.GetBitmap().SetPan(dx + panX_, panY_);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1409 }
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1410 else
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1411 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1412 accessor_.GetBitmap().SetPan(panX_, dy + panY_);
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1413 }
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1414 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1415 else
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1416 {
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1417 accessor_.GetBitmap().SetPan(dx + panX_, dy + panY_);
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1418 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1419 }
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1420 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1421 };
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1422
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1423
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1424 class CropBitmapTracker : public IWorldSceneMouseTracker
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1425 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1426 private:
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1427 BitmapStack::BitmapAccessor accessor_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1428 BitmapStack::Corner corner_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1429 unsigned int cropX_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1430 unsigned int cropY_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1431 unsigned int cropWidth_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1432 unsigned int cropHeight_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1433
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1434 public:
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1435 CropBitmapTracker(BitmapStack& stack,
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1436 const ViewportGeometry& view,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1437 size_t bitmap,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1438 double x,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1439 double y,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1440 BitmapStack::Corner corner) :
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1441 accessor_(stack, bitmap),
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1442 corner_(corner)
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1443 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1444 if (accessor_.IsValid())
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1445 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1446 accessor_.GetBitmap().GetCrop(cropX_, cropY_, cropWidth_, cropHeight_);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1447 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1448 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1449
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1450 virtual bool HasRender() const
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1451 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1452 return false;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1453 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1454
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1455 virtual void Render(CairoContext& context,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1456 double zoom)
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1457 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1458 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1459 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1460
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1461 virtual void MouseUp()
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1462 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1463 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1464
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1465 virtual void MouseMove(int displayX,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1466 int displayY,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1467 double sceneX,
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1468 double sceneY)
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1469 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1470 if (accessor_.IsValid())
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1471 {
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1472 unsigned int x, y;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1473
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1474 BitmapStack::Bitmap& bitmap = accessor_.GetBitmap();
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1475 if (bitmap.GetPixel(x, y, sceneX, sceneY))
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1476 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1477 unsigned int targetX, targetWidth;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1478
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1479 if (corner_ == BitmapStack::Corner_TopLeft ||
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1480 corner_ == BitmapStack::Corner_BottomLeft)
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1481 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1482 targetX = std::min(x, cropX_ + cropWidth_);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1483 targetWidth = cropX_ + cropWidth_ - targetX;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1484 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1485 else
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1486 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1487 targetX = cropX_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1488 targetWidth = std::max(x, cropX_) - cropX_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1489 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1490
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1491 unsigned int targetY, targetHeight;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1492
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1493 if (corner_ == BitmapStack::Corner_TopLeft ||
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1494 corner_ == BitmapStack::Corner_TopRight)
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1495 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1496 targetY = std::min(y, cropY_ + cropHeight_);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1497 targetHeight = cropY_ + cropHeight_ - targetY;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1498 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1499 else
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1500 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1501 targetY = cropY_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1502 targetHeight = std::max(y, cropY_) - cropY_;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1503 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1504
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1505 bitmap.SetCrop(targetX, targetY, targetWidth, targetHeight);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1506 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1507 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1508 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1509 };
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1510
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1511
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1512 class ResizeBitmapTracker : public IWorldSceneMouseTracker
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1513 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1514 private:
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1515 BitmapStack::BitmapAccessor accessor_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1516 bool roundScaling_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1517 double originalSpacingX_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1518 double originalSpacingY_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1519 BitmapStack::Corner oppositeCorner_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1520 double oppositeX_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1521 double oppositeY_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1522 double baseScaling_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1523
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1524 static double ComputeDistance(double x1,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1525 double y1,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1526 double x2,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1527 double y2)
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1528 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1529 double dx = x1 - x2;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1530 double dy = y1 - y2;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1531 return sqrt(dx * dx + dy * dy);
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1532 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1533
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1534 public:
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1535 ResizeBitmapTracker(BitmapStack& stack,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1536 size_t bitmap,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1537 double x,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1538 double y,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1539 BitmapStack::Corner corner,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1540 bool roundScaling) :
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1541 accessor_(stack, bitmap),
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1542 roundScaling_(roundScaling)
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1543 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1544 if (accessor_.IsValid() &&
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1545 accessor_.GetBitmap().IsResizeable())
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1546 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1547 originalSpacingX_ = accessor_.GetBitmap().GetPixelSpacingX();
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1548 originalSpacingY_ = accessor_.GetBitmap().GetPixelSpacingY();
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1549
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1550 switch (corner)
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1551 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1552 case BitmapStack::Corner_TopLeft:
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1553 oppositeCorner_ = BitmapStack::Corner_BottomRight;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1554 break;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1555
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1556 case BitmapStack::Corner_TopRight:
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1557 oppositeCorner_ = BitmapStack::Corner_BottomLeft;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1558 break;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1559
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1560 case BitmapStack::Corner_BottomLeft:
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1561 oppositeCorner_ = BitmapStack::Corner_TopRight;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1562 break;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1563
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1564 case BitmapStack::Corner_BottomRight:
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1565 oppositeCorner_ = BitmapStack::Corner_TopLeft;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1566 break;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1567
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1568 default:
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1569 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1570 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1571
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1572 accessor_.GetBitmap().GetCorner(oppositeX_, oppositeY_, oppositeCorner_);
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1573
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1574 double d = ComputeDistance(x, y, oppositeX_, oppositeY_);
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1575 if (d >= std::numeric_limits<float>::epsilon())
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1576 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1577 baseScaling_ = 1.0 / d;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1578 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1579 else
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1580 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1581 // Avoid division by zero in extreme cases
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1582 accessor_.Invalidate();
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1583 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1584 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1585 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1586
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1587 virtual bool HasRender() const
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1588 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1589 return false;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1590 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1591
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1592 virtual void Render(CairoContext& context,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1593 double zoom)
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1594 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1595 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1596 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1597
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1598 virtual void MouseUp()
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1599 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1600 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1601
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1602 virtual void MouseMove(int displayX,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1603 int displayY,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1604 double sceneX,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1605 double sceneY)
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1606 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1607 static const double ROUND_SCALING = 0.1;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1608
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1609 if (accessor_.IsValid() &&
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1610 accessor_.GetBitmap().IsResizeable())
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1611 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1612 double scaling = ComputeDistance(oppositeX_, oppositeY_, sceneX, sceneY) * baseScaling_;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1613
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1614 if (roundScaling_)
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1615 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1616 scaling = round(scaling / ROUND_SCALING) * ROUND_SCALING;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1617 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1618
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1619 BitmapStack::Bitmap& bitmap = accessor_.GetBitmap();
353
92a159481900 removed useless variable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 352
diff changeset
1620 bitmap.SetPixelSpacing(scaling * originalSpacingX_,
92a159481900 removed useless variable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 352
diff changeset
1621 scaling * originalSpacingY_);
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1622
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1623 // Keep the opposite corner at a fixed location
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1624 double ox, oy;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1625 bitmap.GetCorner(ox, oy, oppositeCorner_);
353
92a159481900 removed useless variable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 352
diff changeset
1626 bitmap.SetPan(bitmap.GetPanX() + oppositeX_ - ox,
92a159481900 removed useless variable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 352
diff changeset
1627 bitmap.GetPanY() + oppositeY_ - oy);
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1628 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1629 }
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1630 };
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1631
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1632
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1633 public:
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1634 BitmapStackInteractor(BitmapStack& stack) :
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1635 stack_(stack),
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1636 tool_(Tool_Move)
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1637 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1638 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1639
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1640 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1641 const ViewportGeometry& view,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1642 MouseButton button,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1643 KeyboardModifiers modifiers,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1644 double x,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1645 double y,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1646 IStatusBar* statusBar)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1647 {
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1648 if (button == MouseButton_Left)
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1649 {
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1650 size_t selected;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
1651
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1652 if (!stack_.GetSelectedBitmap(selected))
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1653 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1654 size_t bitmap;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1655 if (stack_.LookupBitmap(bitmap, x, y))
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1656 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1657 printf("CLICK on bitmap %ld\n", bitmap);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1658 stack_.Select(bitmap);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1659 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1660
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1661 return NULL;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1662 }
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1663 else if (tool_ == Tool_Crop ||
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1664 tool_ == Tool_Resize)
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1665 {
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1666 BitmapStack::BitmapAccessor accessor(stack_, selected);
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1667 BitmapStack::Corner corner;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1668 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
1669 {
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1670 switch (tool_)
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1671 {
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1672 case Tool_Crop:
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1673 return new CropBitmapTracker(stack_, view, selected, x, y, corner);
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1674
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1675 case Tool_Resize:
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1676 return new ResizeBitmapTracker(stack_, selected, x, y, corner,
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1677 (modifiers & KeyboardModifiers_Shift));
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1678
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1679 default:
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1680 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1681 }
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1682 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1683 else
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1684 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1685 size_t bitmap;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1686
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1687 if (!stack_.LookupBitmap(bitmap, x, y) ||
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1688 bitmap != selected)
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1689 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1690 stack_.Unselect();
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1691 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1692
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1693 return NULL;
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1694 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1695 }
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1696 else
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1697 {
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1698 size_t bitmap;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
1699
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1700 if (stack_.LookupBitmap(bitmap, x, y) &&
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
1701 bitmap == selected)
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
1702 {
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1703 switch (tool_)
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1704 {
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1705 case Tool_Move:
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1706 return new MoveBitmapTracker(stack_, bitmap, x, y,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1707 (modifiers & KeyboardModifiers_Shift));
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1708
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1709 case Tool_Rotate:
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1710 return new RotateBitmapTracker(stack_, view, bitmap, x, y,
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1711 (modifiers & KeyboardModifiers_Shift));
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1712
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1713 default:
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1714 break;
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1715 }
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1716
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1717 return NULL;
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
1718 }
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
1719 else
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
1720 {
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1721 printf("CLICK outside\n");
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1722 stack_.Unselect();
346
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
1723 return NULL;
c2e040ea8fbe rotation transform
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 345
diff changeset
1724 }
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1725 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1726 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1727 else
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1728 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1729 return NULL;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1730 }
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1731 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1732
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1733 virtual void MouseOver(CairoContext& context,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1734 WorldSceneWidget& widget,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1735 const ViewportGeometry& view,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1736 double x,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1737 double y,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1738 IStatusBar* statusBar)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1739 {
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1740 size_t selected;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1741 if (stack_.GetSelectedBitmap(selected) &&
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1742 (tool_ == Tool_Crop ||
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1743 tool_ == Tool_Resize))
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1744 {
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1745 BitmapStack::BitmapAccessor accessor(stack_, selected);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1746
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1747 BitmapStack::Corner corner;
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1748 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
1749 {
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1750 accessor.GetBitmap().GetCorner(x, y, corner);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1751
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1752 double z = 1.0 / view.GetZoom();
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1753
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1754 context.SetSourceColor(255, 0, 0);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1755 cairo_t* cr = context.GetObject();
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1756 cairo_set_line_width(cr, 2.0 * z);
351
da25d2423314 CornerBitmapTracker to crop images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1757 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
1758 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
1759 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
1760 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
1761 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
1762 cairo_stroke(cr);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1763 }
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1764 }
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1765 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1766
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1767 virtual void MouseWheel(WorldSceneWidget& widget,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1768 MouseWheelDirection direction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1769 KeyboardModifiers modifiers,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1770 IStatusBar* statusBar)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1771 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1772 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1773
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1774 virtual void KeyPressed(WorldSceneWidget& widget,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1775 KeyboardKeys key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1776 char keyChar,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1777 KeyboardModifiers modifiers,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1778 IStatusBar* statusBar)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1779 {
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1780 switch (keyChar)
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1781 {
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1782 case 'c':
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1783 tool_ = Tool_Crop;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1784 break;
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1785
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1786 case 'a':
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1787 widget.FitContent();
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1788 break;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1789
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1790 case 'm':
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1791 tool_ = Tool_Move;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1792 break;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1793
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1794 case 'r':
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1795 tool_ = Tool_Rotate;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1796 break;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1797
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1798 case 's':
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1799 tool_ = Tool_Resize;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1800 break;
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
1801
347
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1802 default:
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1803 break;
cd65103c9172 RotateBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 346
diff changeset
1804 }
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1805 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1806 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1807
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1808
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1809
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1810 class BitmapStackWidget :
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1811 public WorldSceneWidget,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1812 public IObservable,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1813 public IObserver
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1814 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1815 private:
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1816 BitmapStack& stack_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1817 BitmapStackInteractor myInteractor_;
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
1818
336
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1819 protected:
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1820 virtual Extent2D GetSceneExtent()
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1821 {
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1822 return stack_.GetSceneExtent();
336
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1823 }
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1824
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1825 virtual bool RenderScene(CairoContext& context,
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1826 const ViewportGeometry& view)
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1827 {
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1828 // "Render()" has been replaced
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1829 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1830 }
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1831
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1832 public:
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1833 BitmapStackWidget(MessageBroker& broker,
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1834 BitmapStack& stack,
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1835 const std::string& name) :
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1836 WorldSceneWidget(name),
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1837 IObservable(broker),
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1838 IObserver(broker),
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1839 stack_(stack),
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
1840 myInteractor_(stack_)
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1841 {
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1842 stack.RegisterObserverCallback(new Callable<BitmapStackWidget, BitmapStack::GeometryChangedMessage>(*this, &BitmapStackWidget::OnGeometryChanged));
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1843 stack.RegisterObserverCallback(new Callable<BitmapStackWidget, BitmapStack::ContentChangedMessage>(*this, &BitmapStackWidget::OnContentChanged));
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1844
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1845 SetInteractor(myInteractor_);
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1846 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1847
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1848 void OnGeometryChanged(const BitmapStack::GeometryChangedMessage& message)
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1849 {
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1850 printf("Geometry has changed\n");
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1851 FitContent();
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1852 }
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1853
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1854 void OnContentChanged(const BitmapStack::ContentChangedMessage& message)
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1855 {
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1856 printf("Content has changed\n");
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1857 NotifyContentChanged();
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1858 }
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1859
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1860 virtual bool Render(Orthanc::ImageAccessor& target)
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1861 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1862 Orthanc::Image buffer(Orthanc::PixelFormat_Float32, target.GetWidth(),
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1863 target.GetHeight(), false);
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1864
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1865 // TODO => rendering quality
348
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1866 stack_.Render(buffer, GetView(), ImageInterpolation_Nearest);
dadee0f7f1b3 testing crop
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 347
diff changeset
1867 //stack_.Render(buffer, GetView(), ImageInterpolation_Bilinear);
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1868
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1869 // As in GrayscaleFrameRenderer => TODO MERGE?
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1870
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1871 float windowCenter, windowWidth;
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1872 if (!stack_.GetWindowing(windowCenter, windowWidth))
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1873 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1874 windowCenter = 128;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1875 windowWidth = 256;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1876 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1877
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1878 float x0 = windowCenter - windowWidth / 2.0f;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1879 float x1 = windowCenter + windowWidth / 2.0f;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1880
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1881 if (windowWidth >= 0.001f) // Avoid division by zero at (*)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1882 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1883 const unsigned int width = target.GetWidth();
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1884 const unsigned int height = target.GetHeight();
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1885
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1886 for (unsigned int y = 0; y < height; y++)
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1887 {
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1888 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
1889 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1890
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1891 for (unsigned int x = 0; x < width; x++, p++, q += 4)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1892 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1893 uint8_t v = 0;
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1894 if (*p >= x1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1895 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1896 v = 255;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1897 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1898 else if (*p <= x0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1899 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1900 v = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1901 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1902 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1903 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1904 // https://en.wikipedia.org/wiki/Linear_interpolation
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1905 v = static_cast<uint8_t>(255.0f * (*p - x0) / (x1 - x0)); // (*)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1906 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1907
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1908 // TODO MONOCHROME1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1909 /*if (invert_)
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1910 {
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1911 v = 255 - v;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1912 }*/
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1913
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1914 q[0] = v;
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1915 q[1] = v;
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1916 q[2] = v;
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1917 q[3] = 255;
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1918 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1919 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1920 }
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1921 else
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1922 {
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1923 Orthanc::ImageProcessing::Set(target, 0, 0, 0, 255);
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1924 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1925
345
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1926 {
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1927 // TODO => REFACTOR
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1928 CairoSurface surface(target);
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1929 stack_.DrawControls(surface, GetView());
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1930 }
55438b1ca317 drawing borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1931
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
1932 return true;
336
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1933 }
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1934
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1935 };
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1936
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1937
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1938 namespace Samples
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1939 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1940 class SingleFrameEditorApplication :
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1941 public SampleSingleCanvasApplicationBase,
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1942 public IObserver
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1943 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1944 enum Tools
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1945 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1946 Tools_Crop,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1947 Tools_Windowing,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1948 Tools_Zoom,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1949 Tools_Pan
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1950 };
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1951
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1952 enum Actions
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1953 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1954 Actions_Invert,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1955 Actions_RotateLeft,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1956 Actions_RotateRight
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1957 };
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1958
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1959 private:
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1960 class Interactor : public IWorldSceneInteractor
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1961 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1962 private:
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1963 SingleFrameEditorApplication& application_;
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1964
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1965 public:
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1966 Interactor(SingleFrameEditorApplication& application) :
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1967 application_(application)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1968 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1969 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1970
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1971 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1972 const ViewportGeometry& view,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1973 MouseButton button,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1974 KeyboardModifiers modifiers,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1975 double x,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1976 double y,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1977 IStatusBar* statusBar)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1978 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1979 switch (application_.currentTool_) {
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1980 case Tools_Zoom:
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1981 printf("ZOOM\n");
329
b10dfdb96866 removing WorldSceneWidget::IWorldObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
1982
b10dfdb96866 removing WorldSceneWidget::IWorldObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
1983 case Tools_Crop:
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1984 case Tools_Windowing:
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1985 case Tools_Pan:
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1986 // TODO return the right mouse tracker
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1987 return NULL;
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1988 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1989
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1990 return NULL;
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1991 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1992
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1993 virtual void MouseOver(CairoContext& context,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1994 WorldSceneWidget& widget,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1995 const ViewportGeometry& view,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1996 double x,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1997 double y,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1998 IStatusBar* statusBar)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1999 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2000 if (statusBar != NULL)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2001 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2002 char buf[64];
336
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
2003 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
2004 statusBar->SetMessage(buf);
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2005 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2006 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2007
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2008 virtual void MouseWheel(WorldSceneWidget& widget,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2009 MouseWheelDirection direction,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2010 KeyboardModifiers modifiers,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2011 IStatusBar* statusBar)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2012 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2013 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2014
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2015 virtual void KeyPressed(WorldSceneWidget& widget,
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 326
diff changeset
2016 KeyboardKeys key,
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 326
diff changeset
2017 char keyChar,
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2018 KeyboardModifiers modifiers,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2019 IStatusBar* statusBar)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2020 {
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 326
diff changeset
2021 switch (keyChar)
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2022 {
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2023 case 's':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2024 widget.FitContent();
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2025 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2026 case 'p':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2027 application_.currentTool_ = Tools_Pan;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2028 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2029 case 'z':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2030 application_.currentTool_ = Tools_Zoom;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2031 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2032 case 'c':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2033 application_.currentTool_ = Tools_Crop;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2034 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2035 case 'w':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2036 application_.currentTool_ = Tools_Windowing;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2037 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2038 case 'i':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2039 application_.Invert();
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2040 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2041 case 'r':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2042 if (modifiers == KeyboardModifiers_None)
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2043 application_.Rotate(90);
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2044 else
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2045 application_.Rotate(-90);
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2046 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2047 case 'e':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2048 application_.Export();
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2049 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2050 default:
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2051 break;
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2052 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2053 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2054 };
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2055
334
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
2056 std::auto_ptr<Interactor> mainWidgetInteractor_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
2057 std::auto_ptr<OrthancApiClient> orthancApiClient_;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
2058 std::auto_ptr<BitmapStack> stack_;
334
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
2059 Tools currentTool_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
2060 const OrthancFrameLayerSource* source_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
2061 unsigned int slice_;
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2062
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2063 public:
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2064 SingleFrameEditorApplication(MessageBroker& broker) :
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2065 IObserver(broker),
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2066 currentTool_(Tools_Zoom),
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2067 source_(NULL),
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2068 slice_(0)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2069 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2070 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2071
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2072 virtual void DeclareStartupOptions(boost::program_options::options_description& options)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2073 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2074 boost::program_options::options_description generic("Sample options");
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2075 generic.add_options()
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2076 ("instance", boost::program_options::value<std::string>(),
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2077 "Orthanc ID of the instance")
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2078 ("frame", boost::program_options::value<unsigned int>()->default_value(0),
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2079 "Number of the frame, for multi-frame DICOM instances")
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
2080 ;
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2081
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2082 options.add(generic);
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2083 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2084
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2085 virtual void Initialize(StoneApplicationContext* context,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2086 IStatusBar& statusBar,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2087 const boost::program_options::variables_map& parameters)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2088 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2089 using namespace OrthancStone;
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2090
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2091 context_ = context;
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2092
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2093 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
2094
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2095 if (parameters.count("instance") != 1)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2096 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2097 LOG(ERROR) << "The instance ID is missing";
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2098 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2099 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2100
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2101 std::string instance = parameters["instance"].as<std::string>();
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2102 int frame = parameters["frame"].as<unsigned int>();
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2103
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2104 orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService()));
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
2105
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
2106 Orthanc::FontRegistry fonts;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
2107 fonts.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
2108
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
2109 stack_.reset(new BitmapStack(IObserver::broker_, *orthancApiClient_));
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
2110 stack_->LoadFrame(instance, frame, false);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
2111 stack_->LoadFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", frame, false);
352
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
2112 stack_->LoadText(fonts.GetFont(0), "Hello\nworld\nBonjour, Alain").SetResizeable(true);
d95e65ebe0b9 ResizeBitmapTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
2113 stack_->LoadTestBlock(100, 50).SetResizeable(true);
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
2114
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
2115 mainWidget_ = new BitmapStackWidget(IObserver::broker_, *stack_, "main-widget");
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2116 mainWidget_->SetTransmitMouseOver(true);
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2117
350
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
2118 //stack_->SetWindowing(128, 256);
c57e049ed079 drawing corners for cropping
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
2119
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2120 mainWidgetInteractor_.reset(new Interactor(*this));
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
2121 //mainWidget_->SetInteractor(*mainWidgetInteractor_);
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2122 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2123
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2124
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2125 void Invert()
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2126 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2127 // TODO
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2128 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2129
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2130 void Rotate(int degrees)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2131 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2132 // TODO
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2133 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2134
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2135 void Export()
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2136 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2137 // TODO: export dicom file to a temporary file
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2138 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2139 };
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2140
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2141
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2142 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2143 }