annotate Applications/Samples/SingleFrameEditorApplication.h @ 344:fdec8e6893cb am-2

ordering of bitmap layers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 22 Oct 2018 14:48:18 +0200
parents 712acc87fa2e
children 55438b1ca317
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1 /**
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
6 *
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
11 *
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
16 *
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
19 **/
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
20
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
21
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
22 #pragma once
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
23
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
24 #include "SampleApplicationBase.h"
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
25
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
26 #include "../../Framework/Toolbox/GeometryToolbox.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
27 #include "../../Framework/Toolbox/ImageGeometry.h"
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
28 #include "../../Framework/Layers/OrthancFrameLayerSource.h"
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
29
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
30 #include <Core/DicomFormat/DicomArray.h>
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
31 #include <Core/Images/FontRegistry.h>
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
32 #include <Core/Images/ImageProcessing.h>
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
33 #include <Core/Images/PamReader.h>
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
34 #include <Core/Images/PngWriter.h> //TODO
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
35 #include <Core/Logging.h>
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
36 #include <Plugins/Samples/Common/FullOrthancDataset.h>
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
37 #include <Plugins/Samples/Common/DicomDatasetReader.h>
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
38
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
39
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
40 #include <boost/math/constants/constants.hpp>
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
41
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
42 namespace OrthancStone
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
43 {
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
44 class BitmapStack :
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
45 public IObserver,
336
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
46 public IObservable
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
47 {
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
48 public:
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
49 typedef OriginMessage<MessageType_Widget_GeometryChanged, BitmapStack> GeometryChangedMessage;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
50 typedef OriginMessage<MessageType_Widget_ContentChanged, BitmapStack> ContentChangedMessage;
336
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
51
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
52 private:
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
53 class Bitmap : public boost::noncopyable
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
54 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
55 private:
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
56 bool visible_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
57 bool hasSize_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
58 unsigned int width_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
59 unsigned int height_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
60 bool hasCrop_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
61 unsigned int cropX_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
62 unsigned int cropY_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
63 unsigned int cropWidth_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
64 unsigned int cropHeight_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
65 Matrix transform_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
66 double pixelSpacingX_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
67 double pixelSpacingY_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
68 double panX_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
69 double panY_;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
70
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
71
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
72 void UpdateTransform()
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
73 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
74 transform_ = LinearAlgebra::IdentityMatrix(3);
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
75
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
76 transform_(0, 0) = pixelSpacingX_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
77 transform_(1, 1) = pixelSpacingY_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
78 transform_(0, 2) = panX_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
79 transform_(1, 2) = panY_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
80
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
81
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
82 #if 0
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
83 double a = 10.0 / 180.0 * boost::math::constants::pi<double>();
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
84 Matrix m;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
85 const double v[] = { cos(a), -sin(a), 0,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
86 sin(a), cos(a), 0,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
87 0, 0, 1 };
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
88 LinearAlgebra::FillMatrix(m, 3, 3, v);
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
89 transform_ = LinearAlgebra::Product(m, transform_);
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
90 #endif
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
91 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
92
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
93
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
94 void AddToExtent(Extent2D& extent,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
95 double x,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
96 double y) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
97 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
98 Vector p;
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
99 LinearAlgebra::AssignVector(p, x, y, 1);
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
100
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
101 Vector q = LinearAlgebra::Product(transform_, p);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
102
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
103 if (!LinearAlgebra::IsNear(q[2], 1.0))
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
104 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
105 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
106 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
107 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
108 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
109 extent.AddPoint(q[0], q[1]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
110 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
111 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
112
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
113
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
114 public:
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
115 Bitmap() :
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
116 visible_(true),
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
117 hasSize_(false),
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
118 width_(0),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
119 height_(0),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
120 hasCrop_(false),
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
121 pixelSpacingX_(1),
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
122 pixelSpacingY_(1),
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
123 panX_(0),
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
124 panY_(0)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
125 {
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
126 UpdateTransform();
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
127 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
128
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
129 virtual ~Bitmap()
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
130 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
131 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
132
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
133 void ResetCrop()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
134 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
135 hasCrop_ = false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
136 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
137
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
138 void Crop(unsigned int x,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
139 unsigned int y,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
140 unsigned int width,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
141 unsigned int height)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
142 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
143 hasCrop_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
144 cropX_ = x;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
145 cropY_ = y;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
146 cropWidth_ = width;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
147 cropHeight_ = height;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
148 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
149
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
150 void GetCrop(unsigned int& x,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
151 unsigned int& y,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
152 unsigned int& width,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
153 unsigned int& height) const
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
154 {
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
155 if (hasCrop_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
156 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
157 x = cropX_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
158 y = cropY_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
159 width = cropWidth_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
160 height = cropHeight_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
161 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
162 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
163 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
164 x = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
165 y = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
166 width = width_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
167 height = height_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
168 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
169 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
170
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
171 bool IsVisible() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
172 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
173 return visible_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
174 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
175
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
176 void SetVisible(bool visible)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
177 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
178 visible_ = visible;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
179 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
180
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
181
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
182 void SetSize(unsigned int width,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
183 unsigned int height)
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
184 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
185 if (hasSize_ &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
186 (width != width_ ||
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
187 height != height_))
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
188 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
189 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
190 }
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
191
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
192 hasSize_ = true;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
193 width_ = width;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
194 height_ = height;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
195 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
196
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
197
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
198 void CheckSize(unsigned int width,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
199 unsigned int height)
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
200 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
201 if (hasSize_ &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
202 (width != width_ ||
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
203 height != height_))
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
204 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
205 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
206 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
207 }
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
208
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
209
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
210 Extent2D GetExtent() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
211 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
212 Extent2D extent;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
213
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
214 unsigned int x, y, width, height;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
215 GetCrop(x, y, width, height);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
216
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
217 double dx = static_cast<double>(x) - 0.5;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
218 double dy = static_cast<double>(y) - 0.5;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
219 double dwidth = static_cast<double>(width);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
220 double dheight = static_cast<double>(height);
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
221
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
222 AddToExtent(extent, dx, dy);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
223 AddToExtent(extent, dx + dwidth, dy);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
224 AddToExtent(extent, dx, dy + dheight);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
225 AddToExtent(extent, dx + dwidth, dy + dheight);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
226
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
227 return extent;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
228 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
229
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
230
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
231 virtual void Render(Orthanc::ImageAccessor& buffer,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
232 const ViewportGeometry& view) const = 0;
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
234
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
235 bool Contains(double x,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
236 double y) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
237 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
238 Matrix inv;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
239 LinearAlgebra::InvertMatrix(inv, transform_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
240
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
241 Vector p;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
242 LinearAlgebra::AssignVector(p, x, y, 1);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
243
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
244 Vector q = LinearAlgebra::Product(inv, p);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
245
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
246 if (!LinearAlgebra::IsNear(q[2], 1.0))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
247 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
248 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
249 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
250 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
251 {
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
252 printf("at: (%.02f, %.02f)\n", q[0], q[1]);
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
253 return (q[0] >= 0 &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
254 q[1] >= 0 &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
255 q[0] <= static_cast<double>(width_) &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
256 q[1] <= static_cast<double>(height_));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
257 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
258 }
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
259
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
260
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
261 void SetPan(double x,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
262 double y)
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
263 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
264 panX_ = x;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
265 panY_ = y;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
266 UpdateTransform();
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
267 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
268
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
269
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
270 void SetPixelSpacing(double x,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
271 double y)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
272 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
273 pixelSpacingX_ = x;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
274 pixelSpacingY_ = y;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
275 UpdateTransform();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
276 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
277
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
278
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
279 double GetPanX() const
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
280 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
281 return panX_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
282 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
283
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
284
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
285 double GetPanY() const
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
286 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
287 return panY_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
288 }
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
289
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
290
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
291 virtual bool GetDefaultWindowing(float& center,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
292 float& width) const
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
293 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
294 return false;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
295 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
296
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
297
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
298 const Matrix& GetTransform() const
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
299 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
300 return transform_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
301 }
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
302 };
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
303
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
304
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
305
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
306 class DicomBitmap : public Bitmap
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
307 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
308 private:
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
309 std::auto_ptr<Orthanc::ImageAccessor> source_; // Content of PixelData
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
310 std::auto_ptr<DicomFrameConverter> converter_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
311 std::auto_ptr<Orthanc::ImageAccessor> converted_; // Float32 or RGB24
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
312
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
313
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
314 void ApplyConverter()
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
315 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
316 if (source_.get() != NULL &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
317 converter_.get() != NULL)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
318 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
319 converted_.reset(converter_->ConvertFrame(*source_));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
320 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
321 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
322
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
323 public:
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
324 static OrthancPlugins::DicomTag ConvertTag(const Orthanc::DicomTag& tag)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
325 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
326 return OrthancPlugins::DicomTag(tag.GetGroup(), tag.GetElement());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
327 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
328
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
329 void SetDicomTags(const OrthancPlugins::FullOrthancDataset& dataset)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
330 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
331 converter_.reset(new DicomFrameConverter);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
332 converter_->ReadParameters(dataset);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
333 ApplyConverter();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
334
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
335 std::string tmp;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
336 Vector pixelSpacing;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
337
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
338 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PIXEL_SPACING)) &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
339 LinearAlgebra::ParseVector(pixelSpacing, tmp) &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
340 pixelSpacing.size() == 2)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
341 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
342 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
343 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
344
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
345 static unsigned int c = 0;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
346 if (c == 0)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
347 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
348 SetPan(400, 0);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
349 c ++;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
350 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
351
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
352 OrthancPlugins::DicomDatasetReader reader(dataset);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
353
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
354 unsigned int width, height;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
355 if (!reader.GetUnsignedIntegerValue(width, ConvertTag(Orthanc::DICOM_TAG_COLUMNS)) ||
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
356 !reader.GetUnsignedIntegerValue(height, ConvertTag(Orthanc::DICOM_TAG_ROWS)))
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
357 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
358 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
359 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
360 else
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
361 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
362 SetSize(width, height);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
363 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
364 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
365
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
366
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
367 void SetSourceImage(Orthanc::ImageAccessor* image) // Takes ownership
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
368 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
369 std::auto_ptr<Orthanc::ImageAccessor> raii(image);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
370
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
371 if (image == NULL)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
372 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
373 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
374 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
375
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
376 SetSize(image->GetWidth(), image->GetHeight());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
377
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
378 source_ = raii;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
379 ApplyConverter();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
380 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
381
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
382
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
383 virtual void Render(Orthanc::ImageAccessor& buffer,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
384 const ViewportGeometry& view) const
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
385 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
386 if (converted_.get() != NULL)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
387 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
388 Matrix m = LinearAlgebra::Product(view.GetMatrix(), GetTransform());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
389 //ApplyProjectiveTransform(buffer, *converted_, m, ImageInterpolation_Bilinear, false);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
390 ApplyProjectiveTransform(buffer, *converted_, m, ImageInterpolation_Nearest, false);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
391 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
392 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
393
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
394
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
395 virtual bool GetDefaultWindowing(float& center,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
396 float& width) const
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
397 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
398 if (converter_.get() != NULL &&
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
399 converter_->HasDefaultWindow())
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
400 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
401 center = static_cast<float>(converter_->GetDefaultWindowCenter());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
402 width = static_cast<float>(converter_->GetDefaultWindowWidth());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
403 return true;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
404 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
405 else
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
406 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
407 return false;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
408 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
409 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
410 };
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
411
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
412
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
413
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
414
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
415 class AlphaBitmap : public Bitmap
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
416 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
417 private:
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
418 const BitmapStack& stack_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
419 std::auto_ptr<Orthanc::ImageAccessor> alpha_; // Grayscale8
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
420 bool useWindowing_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
421 float foreground_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
422
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
423 public:
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
424 AlphaBitmap(const BitmapStack& stack) :
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
425 stack_(stack),
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
426 useWindowing_(true),
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
427 foreground_(0)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
428 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
429 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
430
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
431
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
432 void SetForegroundValue(float foreground)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
433 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
434 useWindowing_ = false;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
435 foreground_ = foreground;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
436 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
437
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
438
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
439 void SetAlpha(Orthanc::ImageAccessor* image)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
440 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
441 std::auto_ptr<Orthanc::ImageAccessor> raii(image);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
442
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
443 if (image == NULL)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
444 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
445 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
446 }
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 if (image->GetFormat() != Orthanc::PixelFormat_Grayscale8)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
449 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
450 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
451 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
452
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
453 SetSize(image->GetWidth(), image->GetHeight());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
454 alpha_ = raii;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
455 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
456
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
457
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
458 void LoadText(const Orthanc::Font& font,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
459 const std::string& utf8)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
460 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
461 SetAlpha(font.RenderAlpha(utf8));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
462 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
463
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
464
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
465 virtual void Render(Orthanc::ImageAccessor& buffer,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
466 const ViewportGeometry& view) const
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
467 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
468 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
469 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
470 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
471 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
472
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
473 Matrix m = LinearAlgebra::Product(view.GetMatrix(), GetTransform());
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
474
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
475 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
476 ApplyProjectiveTransform(tmp, *alpha_, m, ImageInterpolation_Nearest, true /* clear */);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
477
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
478 // Blit
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
479 const unsigned int width = buffer.GetWidth();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
480 const unsigned int height = buffer.GetHeight();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
481
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
482 float value = foreground_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
483
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
484 if (useWindowing_)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
485 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
486 float center, width;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
487 if (stack_.GetWindowing(center, width))
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
488 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
489 value = center + width / 2.0f;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
490 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
491 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
492
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
493 for (unsigned int y = 0; y < height; y++)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
494 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
495 float *q = reinterpret_cast<float*>(buffer.GetRow(y));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
496 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
497
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
498 for (unsigned int x = 0; x < width; x++, p++, q++)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
499 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
500 float a = static_cast<float>(*p) / 255.0f;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
501
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
502 *q = (a * value + (1.0f - a) * (*q));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
503 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
504 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
505 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
506 };
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
507
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
508
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
509
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
510 typedef std::map<size_t, Bitmap*> Bitmaps;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
511
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
512 OrthancApiClient& orthanc_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
513 size_t countBitmaps_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
514 bool hasWindowing_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
515 float windowingCenter_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
516 float windowingWidth_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
517 Bitmaps bitmaps_;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
518
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
519 public:
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
520 BitmapStack(MessageBroker& broker,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
521 OrthancApiClient& orthanc) :
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
522 IObserver(broker),
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
523 IObservable(broker),
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
524 orthanc_(orthanc),
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
525 countBitmaps_(0),
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
526 hasWindowing_(false),
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
527 windowingCenter_(0), // Dummy initialization
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
528 windowingWidth_(0) // Dummy initialization
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
529 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
530 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
531
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
532
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
533 virtual ~BitmapStack()
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
534 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
535 for (Bitmaps::iterator it = bitmaps_.begin(); it != bitmaps_.end(); it++)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
536 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
537 assert(it->second != NULL);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
538 delete it->second;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
539 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
540 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
541
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
542
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
543 bool GetWindowing(float& center,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
544 float& width) const
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
545 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
546 if (hasWindowing_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
547 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
548 center = windowingCenter_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
549 width = windowingWidth_;
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
550 return true;
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
551 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
552 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
553 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
554 return false;
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
555 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
556 }
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
557
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
558
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
559 size_t LoadText(const Orthanc::Font& font,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
560 const std::string& utf8,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
561 double x,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
562 double y)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
563 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
564 std::auto_ptr<AlphaBitmap> alpha(new AlphaBitmap(*this));
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
565 alpha->LoadText(font, utf8);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
566
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
567 size_t bitmap = countBitmaps_++;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
568
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
569 bitmaps_[bitmap] = alpha.release();
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
570
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
571 return bitmap;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
572 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
573
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
574
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
575 size_t LoadFrame(const std::string& instance,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
576 unsigned int frame,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
577 bool httpCompression)
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
578 {
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
579 size_t bitmap = countBitmaps_++;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
580
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
581 bitmaps_[bitmap] = new DicomBitmap;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
582
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
583
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
584 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
585 IWebService::Headers headers;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
586 std::string uri = "/instances/" + instance + "/tags";
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
587 orthanc_.GetBinaryAsync(uri, headers,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
588 new Callable<BitmapStack, OrthancApiClient::BinaryResponseReadyMessage>
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
589 (*this, &BitmapStack::OnTagsReceived), NULL,
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
590 new Orthanc::SingleValueObject<size_t>(bitmap));
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
591 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
592
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
593 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
594 IWebService::Headers headers;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
595 headers["Accept"] = "image/x-portable-arbitrarymap";
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 if (httpCompression)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
598 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
599 headers["Accept-Encoding"] = "gzip";
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
600 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
601
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
602 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
603 orthanc_.GetBinaryAsync(uri, headers,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
604 new Callable<BitmapStack, OrthancApiClient::BinaryResponseReadyMessage>
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
605 (*this, &BitmapStack::OnFrameReceived), NULL,
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
606 new Orthanc::SingleValueObject<size_t>(bitmap));
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
607 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
608
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
609 return bitmap;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
610 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
611
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
612
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
613 void OnTagsReceived(const OrthancApiClient::BinaryResponseReadyMessage& message)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
614 {
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
615 size_t index = dynamic_cast<Orthanc::SingleValueObject<size_t>*>(message.Payload)->GetValue();
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
616
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
617 printf("JSON received: [%s] (%ld bytes) for bitmap %ld\n",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
618 message.Uri.c_str(), message.AnswerSize, index);
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
619
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
620 Bitmaps::iterator bitmap = bitmaps_.find(index);
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
621 if (bitmap != bitmaps_.end())
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
622 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
623 assert(bitmap->second != NULL);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
624
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
625 OrthancPlugins::FullOrthancDataset dicom(message.Answer, message.AnswerSize);
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
626 dynamic_cast<DicomBitmap*>(bitmap->second)->SetDicomTags(dicom);
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
627
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
628 float c, w;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
629 if (!hasWindowing_ &&
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
630 bitmap->second->GetDefaultWindowing(c, w))
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
631 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
632 hasWindowing_ = true;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
633 windowingCenter_ = c;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
634 windowingWidth_ = w;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
635 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
636
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
637 EmitMessage(GeometryChangedMessage(*this));
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
638 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
639 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
640
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
641
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
642 void OnFrameReceived(const OrthancApiClient::BinaryResponseReadyMessage& message)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
643 {
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
644 size_t index = dynamic_cast<Orthanc::SingleValueObject<size_t>*>(message.Payload)->GetValue();
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
645
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
646 printf("Frame received: [%s] (%ld bytes) for bitmap %ld\n",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
647 message.Uri.c_str(), message.AnswerSize, index);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
648
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
649 Bitmaps::iterator bitmap = bitmaps_.find(index);
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
650 if (bitmap != bitmaps_.end())
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
651 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
652 assert(bitmap->second != NULL);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
653
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
654 std::string content;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
655 if (message.AnswerSize > 0)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
656 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
657 content.assign(reinterpret_cast<const char*>(message.Answer), message.AnswerSize);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
658 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
659
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
660 std::auto_ptr<Orthanc::PamReader> reader(new Orthanc::PamReader);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
661 reader->ReadFromMemory(content);
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
662 dynamic_cast<DicomBitmap*>(bitmap->second)->SetSourceImage(reader.release());
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
663
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
664 EmitMessage(ContentChangedMessage(*this));
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
665 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
666 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
667
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
668
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
669 Extent2D GetSceneExtent() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
670 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
671 Extent2D extent;
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
672
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
673 for (Bitmaps::const_iterator it = bitmaps_.begin();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
674 it != bitmaps_.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
675 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
676 assert(it->second != NULL);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
677 extent.Union(it->second->GetExtent());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
678 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
679
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
680 return extent;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
681 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
682
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
683
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
684 void Render(Orthanc::ImageAccessor& buffer,
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
685 const ViewportGeometry& view) const
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
686 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
687 Orthanc::ImageProcessing::Set(buffer, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
688
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
689 // Render layers in the background-to-foreground order
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
690 for (size_t index = 0; index < countBitmaps_; index++)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
691 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
692 Bitmaps::const_iterator it = bitmaps_.find(index);
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
693 if (it != bitmaps_.end())
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
694 {
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
695 assert(it->second != NULL);
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
696 it->second->Render(buffer, view);
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
697 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
698 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
699 }
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
700
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
701
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
702 bool LookupBitmap(size_t& index /* out */,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
703 double x,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
704 double y) const
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
705 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
706 // Render layers in the foreground-to-background order
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
707 for (size_t i = countBitmaps_; i > 0; i--)
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
708 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
709 index = i - 1;
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
710 Bitmaps::const_iterator it = bitmaps_.find(index);
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
711 if (it != bitmaps_.end())
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
712 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
713 assert(it->second != NULL);
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
714 if (it->second->Contains(x, y))
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
715 {
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
716 return true;
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
717 }
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
718 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
719 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
720
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
721 return false;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
722 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
723
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
724
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
725 void SetPan(size_t index,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
726 double panX,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
727 double panY)
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
728 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
729 Bitmaps::iterator bitmap = bitmaps_.find(index);
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
730 if (bitmap != bitmaps_.end())
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
731 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
732 assert(bitmap->second != NULL);
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
733 bitmap->second->SetPan(panX, panY);
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
734 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
735 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
736
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
737
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
738 void GetPan(double& panX,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
739 double& panY,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
740 size_t index) const
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
741 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
742 Bitmaps::const_iterator bitmap = bitmaps_.find(index);
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
743 if (bitmap != bitmaps_.end())
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
744 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
745 assert(bitmap->second != NULL);
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
746 panX = bitmap->second->GetPanX();
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
747 panY = bitmap->second->GetPanY();
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
748 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
749 else
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
750 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
751 panX = 0;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
752 panY = 0;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
753 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
754 }
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
755 };
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
756
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
757
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
758 class BitmapStackInteractor : public IWorldSceneInteractor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
759 {
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
760 private:
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
761 BitmapStack& stack_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
762
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
763
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
764 class MoveBitmapTracker : public IWorldSceneMouseTracker
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
765 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
766 private:
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
767 BitmapStack& stack_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
768 size_t bitmap_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
769 double clickX_;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
770 double clickY_;
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
771 double panX_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
772 double panY_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
773 bool oneAxis_;
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
774
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
775 public:
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
776 MoveBitmapTracker(BitmapStack& stack,
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
777 size_t bitmap,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
778 double x,
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
779 double y,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
780 bool oneAxis) :
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
781 stack_(stack),
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
782 bitmap_(bitmap),
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
783 clickX_(x),
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
784 clickY_(y),
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
785 oneAxis_(oneAxis)
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
786 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
787 stack.GetPan(panX_, panY_, bitmap_);
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
788 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
789
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
790 virtual bool HasRender() const
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
791 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
792 return false;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
793 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
794
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
795 virtual void Render(CairoContext& context,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
796 double zoom)
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
797 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
798 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
799 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
800
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
801 virtual void MouseUp()
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
802 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
803 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
804
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
805 virtual void MouseMove(int displayX,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
806 int displayY,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
807 double sceneX,
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
808 double sceneY)
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
809 {
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
810 double dx = sceneX - clickX_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
811 double dy = sceneY - clickY_;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
812
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
813 if (oneAxis_)
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
814 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
815 if (fabs(dx) > fabs(dy))
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
816 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
817 stack_.SetPan(bitmap_, dx + panX_, panY_);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
818 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
819 else
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
820 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
821 stack_.SetPan(bitmap_, panX_, dy + panY_);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
822 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
823 }
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
824 else
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
825 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
826 stack_.SetPan(bitmap_, dx + panX_, dy + panY_);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
827 }
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
828 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
829 };
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
830
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
831
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
832 public:
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
833 BitmapStackInteractor(BitmapStack& stack) :
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
834 stack_(stack)
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
835 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
836 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
837
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
838 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
839 const ViewportGeometry& view,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
840 MouseButton button,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
841 KeyboardModifiers modifiers,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
842 double x,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
843 double y,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
844 IStatusBar* statusBar)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
845 {
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
846 if (button == MouseButton_Left)
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
847 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
848 size_t bitmap;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
849 if (stack_.LookupBitmap(bitmap, x, y))
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
850 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
851 printf("CLICK on bitmap %ld\n", bitmap);
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
852 return new MoveBitmapTracker(stack_, bitmap, x, y,
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
853 (modifiers & KeyboardModifiers_Shift));
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
854 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
855 else
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
856 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
857 printf("CLICK outside\n");
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
858 return NULL;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
859 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
860 }
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
861 else
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
862 {
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
863 return NULL;
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
864 }
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
865 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
866
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
867 virtual void MouseOver(CairoContext& context,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
868 WorldSceneWidget& widget,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
869 const ViewportGeometry& view,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
870 double x,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
871 double y,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
872 IStatusBar* statusBar)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
873 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
874 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
875
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
876 virtual void MouseWheel(WorldSceneWidget& widget,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
877 MouseWheelDirection direction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
878 KeyboardModifiers modifiers,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
879 IStatusBar* statusBar)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
880 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
881 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
882
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
883 virtual void KeyPressed(WorldSceneWidget& widget,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
884 KeyboardKeys key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
885 char keyChar,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
886 KeyboardModifiers modifiers,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
887 IStatusBar* statusBar)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
888 {
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
889 if (keyChar == 's')
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
890 widget.FitContent();
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
891 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
892 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
893
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
894
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
895
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
896 class BitmapStackWidget :
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
897 public WorldSceneWidget,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
898 public IObservable,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
899 public IObserver
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
900 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
901 private:
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
902 BitmapStack& stack_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
903 BitmapStackInteractor myInteractor_;
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
904
336
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
905 protected:
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
906 virtual Extent2D GetSceneExtent()
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
907 {
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
908 return stack_.GetSceneExtent();
336
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
909 }
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
910
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
911 virtual bool RenderScene(CairoContext& context,
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
912 const ViewportGeometry& view)
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
913 {
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
914 // "Render()" has been replaced
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
915 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
916 }
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
917
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
918 public:
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
919 BitmapStackWidget(MessageBroker& broker,
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
920 BitmapStack& stack,
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
921 const std::string& name) :
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
922 WorldSceneWidget(name),
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
923 IObservable(broker),
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
924 IObserver(broker),
342
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
925 stack_(stack),
4297d6c5eef9 moving bitmap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 341
diff changeset
926 myInteractor_(stack_)
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
927 {
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
928 stack.RegisterObserverCallback(new Callable<BitmapStackWidget, BitmapStack::GeometryChangedMessage>(*this, &BitmapStackWidget::OnGeometryChanged));
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
929 stack.RegisterObserverCallback(new Callable<BitmapStackWidget, BitmapStack::ContentChangedMessage>(*this, &BitmapStackWidget::OnContentChanged));
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
930
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
931 SetInteractor(myInteractor_);
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
932 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
933
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
934 void OnGeometryChanged(const BitmapStack::GeometryChangedMessage& message)
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
935 {
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
936 printf("Geometry has changed\n");
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
937 FitContent();
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
938 }
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
939
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
940 void OnContentChanged(const BitmapStack::ContentChangedMessage& message)
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
941 {
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
942 printf("Content has changed\n");
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
943 NotifyContentChanged();
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
944 }
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
945
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
946 virtual bool Render(Orthanc::ImageAccessor& target)
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
947 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
948 Orthanc::Image buffer(Orthanc::PixelFormat_Float32, target.GetWidth(),
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
949 target.GetHeight(), false);
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
950 stack_.Render(buffer, GetView());
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
951
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
952 // As in GrayscaleFrameRenderer => TODO MERGE?
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
953
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
954 float windowCenter, windowWidth;
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
955 if (!stack_.GetWindowing(windowCenter, windowWidth))
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
956 {
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
957 windowCenter = 128;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
958 windowWidth = 256;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
959 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
960
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
961 float x0 = windowCenter - windowWidth / 2.0f;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
962 float x1 = windowCenter + windowWidth / 2.0f;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
963
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
964 if (windowWidth >= 0.001f) // Avoid division by zero at (*)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
965 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
966 const unsigned int width = target.GetWidth();
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
967 const unsigned int height = target.GetHeight();
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
968
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
969 for (unsigned int y = 0; y < height; y++)
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
970 {
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
971 const float* p = reinterpret_cast<const float*>(buffer.GetConstRow(y));
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
972 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
973
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
974 for (unsigned int x = 0; x < width; x++, p++, q += 4)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
975 {
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
976 uint8_t v = 0;
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
977 if (*p >= x1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
978 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
979 v = 255;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
980 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
981 else if (*p <= x0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
982 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
983 v = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
984 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
985 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
986 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
987 // https://en.wikipedia.org/wiki/Linear_interpolation
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
988 v = static_cast<uint8_t>(255.0f * (*p - x0) / (x1 - x0)); // (*)
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
989 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
990
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
991 // TODO MONOCHROME1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
992 /*if (invert_)
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
993 {
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
994 v = 255 - v;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
995 }*/
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
996
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
997 q[0] = v;
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
998 q[1] = v;
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
999 q[2] = v;
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1000 q[3] = 255;
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1001 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1002 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1003 }
344
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1004 else
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1005 {
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1006 Orthanc::ImageProcessing::Set(target, 0, 0, 0, 255);
fdec8e6893cb ordering of bitmap layers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
1007 }
339
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
1008
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
1009 return true;
336
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1010 }
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1011
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1012 };
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1013
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1014
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1015 namespace Samples
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1016 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1017 class SingleFrameEditorApplication :
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1018 public SampleSingleCanvasApplicationBase,
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1019 public IObserver
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1020 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1021 enum Tools
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1022 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1023 Tools_Crop,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1024 Tools_Windowing,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1025 Tools_Zoom,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1026 Tools_Pan
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1027 };
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1028
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1029 enum Actions
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1030 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1031 Actions_Invert,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1032 Actions_RotateLeft,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1033 Actions_RotateRight
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1034 };
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1035
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1036 private:
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1037 class Interactor : public IWorldSceneInteractor
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1038 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1039 private:
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1040 SingleFrameEditorApplication& application_;
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1041
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1042 public:
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1043 Interactor(SingleFrameEditorApplication& application) :
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1044 application_(application)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1045 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1046 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1047
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1048 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1049 const ViewportGeometry& view,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1050 MouseButton button,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1051 KeyboardModifiers modifiers,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1052 double x,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1053 double y,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1054 IStatusBar* statusBar)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1055 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1056 switch (application_.currentTool_) {
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1057 case Tools_Zoom:
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1058 printf("ZOOM\n");
329
b10dfdb96866 removing WorldSceneWidget::IWorldObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
1059
b10dfdb96866 removing WorldSceneWidget::IWorldObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
1060 case Tools_Crop:
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1061 case Tools_Windowing:
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1062 case Tools_Pan:
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1063 // TODO return the right mouse tracker
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1064 return NULL;
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1065 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1066
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1067 return NULL;
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1068 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1069
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1070 virtual void MouseOver(CairoContext& context,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1071 WorldSceneWidget& widget,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1072 const ViewportGeometry& view,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1073 double x,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1074 double y,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1075 IStatusBar* statusBar)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1076 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1077 if (statusBar != NULL)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1078 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1079 char buf[64];
336
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1080 sprintf(buf, "X = %.02f Y = %.02f (in cm)", x / 10.0, y / 10.0);
c7fdc8bac581 creating GrayscaleBitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
1081 statusBar->SetMessage(buf);
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1082 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1083 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1084
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1085 virtual void MouseWheel(WorldSceneWidget& widget,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1086 MouseWheelDirection direction,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1087 KeyboardModifiers modifiers,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1088 IStatusBar* statusBar)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1089 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1090 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1091
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1092 virtual void KeyPressed(WorldSceneWidget& widget,
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 326
diff changeset
1093 KeyboardKeys key,
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 326
diff changeset
1094 char keyChar,
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1095 KeyboardModifiers modifiers,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1096 IStatusBar* statusBar)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1097 {
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 326
diff changeset
1098 switch (keyChar)
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1099 {
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1100 case 's':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1101 widget.FitContent();
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1102 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1103 case 'p':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1104 application_.currentTool_ = Tools_Pan;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1105 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1106 case 'z':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1107 application_.currentTool_ = Tools_Zoom;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1108 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1109 case 'c':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1110 application_.currentTool_ = Tools_Crop;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1111 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1112 case 'w':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1113 application_.currentTool_ = Tools_Windowing;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1114 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1115 case 'i':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1116 application_.Invert();
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1117 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1118 case 'r':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1119 if (modifiers == KeyboardModifiers_None)
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1120 application_.Rotate(90);
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1121 else
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1122 application_.Rotate(-90);
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1123 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1124 case 'e':
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1125 application_.Export();
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1126 break;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1127 default:
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1128 break;
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1129 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1130 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1131 };
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1132
334
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
1133 std::auto_ptr<Interactor> mainWidgetInteractor_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
1134 std::auto_ptr<OrthancApiClient> orthancApiClient_;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1135 std::auto_ptr<BitmapStack> stack_;
334
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
1136 Tools currentTool_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
1137 const OrthancFrameLayerSource* source_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
1138 unsigned int slice_;
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1139
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1140 public:
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1141 SingleFrameEditorApplication(MessageBroker& broker) :
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1142 IObserver(broker),
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1143 currentTool_(Tools_Zoom),
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1144 source_(NULL),
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1145 slice_(0)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1146 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1147 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1148
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1149 virtual void DeclareStartupOptions(boost::program_options::options_description& options)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1150 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1151 boost::program_options::options_description generic("Sample options");
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1152 generic.add_options()
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1153 ("instance", boost::program_options::value<std::string>(),
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1154 "Orthanc ID of the instance")
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1155 ("frame", boost::program_options::value<unsigned int>()->default_value(0),
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1156 "Number of the frame, for multi-frame DICOM instances")
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1157 ;
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1158
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1159 options.add(generic);
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1160 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1161
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1162 virtual void Initialize(StoneApplicationContext* context,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1163 IStatusBar& statusBar,
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1164 const boost::program_options::variables_map& parameters)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1165 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1166 using namespace OrthancStone;
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1167
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1168 context_ = context;
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1169
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1170 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout, \"p\" to pan, \"z\" to zoom, \"c\" to crop, \"i\" to invert, \"w\" to change windowing, \"r\" to rotate cw, \"shift+r\" to rotate ccw");
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1171
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1172 if (parameters.count("instance") != 1)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1173 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1174 LOG(ERROR) << "The instance ID is missing";
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1175 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1176 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1177
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1178 std::string instance = parameters["instance"].as<std::string>();
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1179 int frame = parameters["frame"].as<unsigned int>();
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1180
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1181 orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService()));
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
1182
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1183 Orthanc::FontRegistry fonts;
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1184 fonts.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16);
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1185
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1186 stack_.reset(new BitmapStack(IObserver::broker_, *orthancApiClient_));
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1187 stack_->LoadFrame(instance, frame, false);
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
1188 stack_->LoadFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", frame, false);
343
712acc87fa2e text layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
1189 stack_->LoadText(fonts.GetFont(0), "Hello\nworld\nBonjour, Alain", 0, -50);
337
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
1190
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
1191 mainWidget_ = new BitmapStackWidget(IObserver::broker_, *stack_, "main-widget");
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1192 mainWidget_->SetTransmitMouseOver(true);
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1193
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1194 mainWidgetInteractor_.reset(new Interactor(*this));
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
1195 //mainWidget_->SetInteractor(*mainWidgetInteractor_);
325
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1196 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1197
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1198
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1199 void Invert()
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1200 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1201 // TODO
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1202 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1203
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1204 void Rotate(int degrees)
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1205 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1206 // TODO
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1207 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1208
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1209 void Export()
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1210 {
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1211 // TODO: export dicom file to a temporary file
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1212 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1213 };
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1214
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1215
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1216 }
37ab9d83dc9b reactivate SingleFrameApplication sample + Added SingleFrameEditorApplication (SDL only)
am@osimis.io
parents:
diff changeset
1217 }