annotate Applications/Samples/SingleFrameEditorApplication.h @ 376:70256a53ff21

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