annotate Applications/Samples/SingleFrameEditorApplication.h @ 357:ec4ad6c5eb99 am-2

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