Mercurial > hg > orthanc-stone
annotate Framework/Widgets/LayerWidget.cpp @ 284:38b0ac8055b9 am-2
Qt: catch and forward keyboard events
author | am@osimis.io |
---|---|
date | Tue, 28 Aug 2018 11:09:37 +0200 |
parents | 8a86695fcbc3 |
children | 3897f9f28cfa |
rev | line source |
---|---|
66 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
135
e2fe9352f240
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
66 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
16 * |
66 | 17 * You should have received a copy of the GNU Affero General Public License |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "LayerWidget.h" | |
23 | |
99 | 24 #include "../Layers/SliceOutlineRenderer.h" |
159
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
25 #include "../Toolbox/GeometryToolbox.h" |
85 | 26 |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
27 #include <Core/Logging.h> |
113
2eca030792aa
using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
111
diff
changeset
|
28 |
85 | 29 static const double THIN_SLICE_THICKNESS = 100.0 * std::numeric_limits<double>::epsilon(); |
66 | 30 |
31 namespace OrthancStone | |
32 { | |
33 class LayerWidget::Scene : public boost::noncopyable | |
34 { | |
35 private: | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
36 CoordinateSystem3D slice_; |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
37 double thickness_; |
66 | 38 size_t countMissing_; |
39 std::vector<ILayerRenderer*> renderers_; | |
40 | |
41 void DeleteLayer(size_t index) | |
42 { | |
43 if (index >= renderers_.size()) | |
44 { | |
45 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
46 } | |
47 | |
48 assert(countMissing_ <= renderers_.size()); | |
49 | |
50 if (renderers_[index] != NULL) | |
51 { | |
52 assert(countMissing_ < renderers_.size()); | |
53 delete renderers_[index]; | |
54 renderers_[index] = NULL; | |
55 countMissing_++; | |
56 } | |
57 } | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
58 |
66 | 59 public: |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
60 Scene(const CoordinateSystem3D& slice, |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
61 double thickness, |
66 | 62 size_t countLayers) : |
63 slice_(slice), | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
64 thickness_(thickness), |
66 | 65 countMissing_(countLayers), |
66 renderers_(countLayers, NULL) | |
67 { | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
68 if (thickness <= 0) |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
69 { |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
71 } |
66 | 72 } |
73 | |
74 ~Scene() | |
75 { | |
76 for (size_t i = 0; i < renderers_.size(); i++) | |
77 { | |
78 DeleteLayer(i); | |
79 } | |
80 } | |
81 | |
82 void SetLayer(size_t index, | |
83 ILayerRenderer* renderer) // Takes ownership | |
84 { | |
85 if (renderer == NULL) | |
86 { | |
87 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
88 } | |
89 | |
90 DeleteLayer(index); | |
91 | |
92 renderers_[index] = renderer; | |
93 countMissing_--; | |
94 } | |
95 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
96 const CoordinateSystem3D& GetSlice() const |
66 | 97 { |
98 return slice_; | |
99 } | |
100 | |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
101 bool HasRenderer(size_t index) |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
102 { |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
103 return renderers_[index] != NULL; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
104 } |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
105 |
66 | 106 bool IsComplete() const |
107 { | |
108 return countMissing_ == 0; | |
109 } | |
110 | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
111 unsigned int GetCountMissing() const |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
112 { |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
113 return countMissing_; |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
114 } |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
115 |
66 | 116 bool RenderScene(CairoContext& context, |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
117 const ViewportGeometry& view, |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
118 const CoordinateSystem3D& viewportSlice) |
66 | 119 { |
120 bool fullQuality = true; | |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
121 cairo_t *cr = context.GetObject(); |
66 | 122 |
123 for (size_t i = 0; i < renderers_.size(); i++) | |
124 { | |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
125 if (renderers_[i] != NULL) |
66 | 126 { |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
127 const CoordinateSystem3D& frameSlice = renderers_[i]->GetLayerSlice(); |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
128 |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
129 double x0, y0, x1, y1, x2, y2; |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
130 viewportSlice.ProjectPoint(x0, y0, frameSlice.GetOrigin()); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
131 viewportSlice.ProjectPoint(x1, y1, frameSlice.GetOrigin() + frameSlice.GetAxisX()); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
132 viewportSlice.ProjectPoint(x2, y2, frameSlice.GetOrigin() + frameSlice.GetAxisY()); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
133 |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
134 /** |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
135 * Now we solve the system of linear equations Ax + b = x', given: |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
136 * A [0 ; 0] + b = [x0 ; y0] |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
137 * A [1 ; 0] + b = [x1 ; y1] |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
138 * A [0 ; 1] + b = [x2 ; y2] |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
139 * <=> |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
140 * b = [x0 ; y0] |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
141 * A [1 ; 0] = [x1 ; y1] - b = [x1 - x0 ; y1 - y0] |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
142 * A [0 ; 1] = [x2 ; y2] - b = [x2 - x0 ; y2 - y0] |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
143 * <=> |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
144 * b = [x0 ; y0] |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
145 * [a11 ; a21] = [x1 - x0 ; y1 - y0] |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
146 * [a12 ; a22] = [x2 - x0 ; y2 - y0] |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
147 **/ |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
148 |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
149 cairo_matrix_t transform; |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
150 cairo_matrix_init(&transform, x1 - x0, y1 - y0, x2 - x0, y2 - y0, x0, y0); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
151 |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
152 cairo_save(cr); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
153 cairo_transform(cr, &transform); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
154 |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
155 if (!renderers_[i]->RenderLayer(context, view)) |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
156 { |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
157 cairo_restore(cr); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
158 return false; |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
159 } |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
160 |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
161 cairo_restore(cr); |
66 | 162 } |
163 | |
164 if (renderers_[i] != NULL && | |
165 !renderers_[i]->IsFullQuality()) | |
166 { | |
167 fullQuality = false; | |
168 } | |
169 } | |
170 | |
171 if (!fullQuality) | |
172 { | |
173 double x, y; | |
174 view.MapDisplayToScene(x, y, static_cast<double>(view.GetDisplayWidth()) / 2.0, 10); | |
175 | |
176 cairo_translate(cr, x, y); | |
95 | 177 |
178 #if 1 | |
179 double s = 5.0 / view.GetZoom(); | |
180 cairo_rectangle(cr, -s, -s, 2.0 * s, 2.0 * s); | |
181 #else | |
182 // TODO Drawing circles makes WebAssembly crash! | |
66 | 183 cairo_arc(cr, 0, 0, 5.0 / view.GetZoom(), 0, 2 * M_PI); |
95 | 184 #endif |
185 | |
66 | 186 cairo_set_line_width(cr, 2.0 / view.GetZoom()); |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
187 cairo_set_source_rgb(cr, 1, 1, 1); |
66 | 188 cairo_stroke_preserve(cr); |
95 | 189 cairo_set_source_rgb(cr, 1, 0, 0); |
66 | 190 cairo_fill(cr); |
191 } | |
192 | |
193 return true; | |
194 } | |
195 | |
196 void SetLayerStyle(size_t index, | |
197 const RenderStyle& style) | |
198 { | |
199 if (renderers_[index] != NULL) | |
200 { | |
201 renderers_[index]->SetLayerStyle(style); | |
202 } | |
203 } | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
204 |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
205 bool ContainsPlane(const CoordinateSystem3D& slice) const |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
206 { |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
207 bool isOpposite; |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
208 if (!GeometryToolbox::IsParallelOrOpposite(isOpposite, |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
209 slice.GetNormal(), |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
210 slice_.GetNormal())) |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
211 { |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
212 return false; |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
213 } |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
214 else |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
215 { |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
216 double z = (slice_.ProjectAlongNormal(slice.GetOrigin()) - |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
217 slice_.ProjectAlongNormal(slice_.GetOrigin())); |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
218 |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
219 if (z < 0) |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
220 { |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
221 z = -z; |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
222 } |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
223 |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
224 return z <= thickness_; |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
225 } |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
226 } |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
227 |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
228 double GetThickness() const |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
229 { |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
230 return thickness_; |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
231 } |
66 | 232 }; |
233 | |
234 | |
235 bool LayerWidget::LookupLayer(size_t& index /* out */, | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
236 const ILayerSource& layer) const |
66 | 237 { |
238 LayersIndex::const_iterator found = layersIndex_.find(&layer); | |
239 | |
240 if (found == layersIndex_.end()) | |
241 { | |
242 return false; | |
243 } | |
244 else | |
245 { | |
246 index = found->second; | |
247 assert(index < layers_.size() && | |
248 layers_[index] == &layer); | |
249 return true; | |
250 } | |
251 } | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
252 |
85 | 253 |
111
7665ccbf33db
rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
254 void LayerWidget::GetLayerExtent(Extent2D& extent, |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
255 ILayerSource& source) const |
85 | 256 { |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
257 extent.Reset(); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
258 |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
259 std::vector<Vector> points; |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
260 if (source.GetExtent(points, slice_)) |
85 | 261 { |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
262 for (size_t i = 0; i < points.size(); i++) |
85 | 263 { |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
264 double x, y; |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
265 slice_.ProjectPoint(x, y, points[i]); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
266 extent.AddPoint(x, y); |
85 | 267 } |
268 } | |
269 } | |
270 | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
271 |
111
7665ccbf33db
rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
272 Extent2D LayerWidget::GetSceneExtent() |
66 | 273 { |
111
7665ccbf33db
rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
274 Extent2D sceneExtent; |
66 | 275 |
276 for (size_t i = 0; i < layers_.size(); i++) | |
277 { | |
278 assert(layers_[i] != NULL); | |
111
7665ccbf33db
rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
279 Extent2D layerExtent; |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
280 GetLayerExtent(layerExtent, *layers_[i]); |
66 | 281 |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
282 sceneExtent.Union(layerExtent); |
66 | 283 } |
284 | |
109
53bd9277b025
using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
103
diff
changeset
|
285 return sceneExtent; |
66 | 286 } |
287 | |
288 | |
289 bool LayerWidget::RenderScene(CairoContext& context, | |
290 const ViewportGeometry& view) | |
291 { | |
292 if (currentScene_.get() != NULL) | |
293 { | |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
294 return currentScene_->RenderScene(context, view, slice_); |
66 | 295 } |
296 else | |
297 { | |
298 return true; | |
299 } | |
300 } | |
301 | |
302 | |
303 void LayerWidget::ResetPendingScene() | |
304 { | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
305 double thickness; |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
306 if (pendingScene_.get() == NULL) |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
307 { |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
308 thickness = 1.0; |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
309 } |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
310 else |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
311 { |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
312 thickness = pendingScene_->GetThickness(); |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
313 } |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
314 |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
315 pendingScene_.reset(new Scene(slice_, thickness, layers_.size())); |
66 | 316 } |
317 | |
318 | |
319 void LayerWidget::UpdateLayer(size_t index, | |
320 ILayerRenderer* renderer, | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
321 const CoordinateSystem3D& slice) |
66 | 322 { |
71
30c768873d47
OrthancSliceLoader::ScheduleLoadInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
66
diff
changeset
|
323 LOG(INFO) << "Updating layer " << index; |
66 | 324 |
325 std::auto_ptr<ILayerRenderer> tmp(renderer); | |
326 | |
327 if (renderer == NULL) | |
328 { | |
329 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
330 } | |
331 | |
332 if (index >= layers_.size()) | |
333 { | |
334 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
335 } | |
336 | |
337 assert(layers_.size() == styles_.size()); | |
338 renderer->SetLayerStyle(styles_[index]); | |
339 | |
340 if (currentScene_.get() != NULL && | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
341 currentScene_->ContainsPlane(slice)) |
66 | 342 { |
343 currentScene_->SetLayer(index, tmp.release()); | |
278 | 344 NotifyContentChanged(); |
66 | 345 } |
346 else if (pendingScene_.get() != NULL && | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
347 pendingScene_->ContainsPlane(slice)) |
66 | 348 { |
349 pendingScene_->SetLayer(index, tmp.release()); | |
350 | |
351 if (currentScene_.get() == NULL || | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
352 !currentScene_->IsComplete() || |
66 | 353 pendingScene_->IsComplete()) |
354 { | |
355 currentScene_ = pendingScene_; | |
278 | 356 NotifyContentChanged(); |
66 | 357 } |
358 } | |
359 } | |
360 | |
361 | |
271
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
268
diff
changeset
|
362 LayerWidget::LayerWidget(MessageBroker& broker, const std::string& name) : |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
272
diff
changeset
|
363 WorldSceneWidget(name), |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
364 IObserver(broker), |
267 | 365 IObservable(broker), |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
272
diff
changeset
|
366 started_(false) |
66 | 367 { |
267 | 368 DeclareHandledMessage(MessageType_LayerSource_GeometryReady); |
369 DeclareHandledMessage(MessageType_LayerSource_ContentChanged); | |
370 DeclareHandledMessage(MessageType_LayerSource_LayerReady); | |
371 DeclareHandledMessage(MessageType_LayerSource_SliceChanged); | |
372 DeclareHandledMessage(MessageType_LayerSource_GeometryError); | |
373 | |
374 DeclareEmittableMessage(MessageType_Widget_GeometryChanged); | |
375 DeclareEmittableMessage(MessageType_Widget_ContentChanged); | |
376 | |
66 | 377 SetBackgroundCleared(true); |
378 } | |
379 | |
380 | |
381 LayerWidget::~LayerWidget() | |
382 { | |
383 for (size_t i = 0; i < layers_.size(); i++) | |
384 { | |
385 delete layers_[i]; | |
386 } | |
387 } | |
388 | |
389 | |
390 size_t LayerWidget::AddLayer(ILayerSource* layer) // Takes ownership | |
391 { | |
392 if (layer == NULL) | |
393 { | |
394 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
395 } | |
396 | |
397 size_t index = layers_.size(); | |
398 layers_.push_back(layer); | |
399 styles_.push_back(RenderStyle()); | |
400 layersIndex_[layer] = index; | |
401 | |
402 ResetPendingScene(); | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
403 layer->RegisterObserver(*this); |
66 | 404 |
103 | 405 ResetChangedLayers(); |
406 | |
66 | 407 return index; |
408 } | |
409 | |
219 | 410 void LayerWidget::ReplaceLayer(size_t index, ILayerSource* layer) // Takes ownership |
411 { | |
412 if (layer == NULL) | |
413 { | |
414 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
415 } | |
416 | |
417 if (index >= layers_.size()) | |
418 { | |
419 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
420 } | |
421 | |
422 delete layers_[index]; | |
423 layers_[index] = layer; | |
424 layersIndex_[layer] = index; | |
425 | |
426 ResetPendingScene(); | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
427 layer->RegisterObserver(*this); |
219 | 428 |
429 InvalidateLayer(index); | |
430 } | |
431 | |
432 | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
433 const RenderStyle& LayerWidget::GetLayerStyle(size_t layer) const |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
434 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
435 if (layer >= layers_.size()) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
436 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
437 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
438 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
439 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
440 assert(layers_.size() == styles_.size()); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
441 return styles_[layer]; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
442 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
443 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
444 |
66 | 445 void LayerWidget::SetLayerStyle(size_t layer, |
446 const RenderStyle& style) | |
447 { | |
448 if (layer >= layers_.size()) | |
449 { | |
450 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
451 } | |
452 | |
453 assert(layers_.size() == styles_.size()); | |
454 styles_[layer] = style; | |
455 | |
456 if (currentScene_.get() != NULL) | |
457 { | |
458 currentScene_->SetLayerStyle(layer, style); | |
459 } | |
460 | |
461 if (pendingScene_.get() != NULL) | |
462 { | |
463 pendingScene_->SetLayerStyle(layer, style); | |
464 } | |
465 | |
278 | 466 NotifyContentChanged(); |
66 | 467 } |
468 | |
469 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
470 void LayerWidget::SetSlice(const CoordinateSystem3D& slice) |
66 | 471 { |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
472 LOG(INFO) << "Setting slice origin: (" << slice.GetOrigin()[0] |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
473 << "," << slice.GetOrigin()[1] |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
474 << "," << slice.GetOrigin()[2] << ")"; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
475 |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
476 Slice displayedSlice(slice_, THIN_SLICE_THICKNESS); |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
477 |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
478 //if (!displayedSlice.ContainsPlane(slice)) |
66 | 479 { |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
480 if (currentScene_.get() == NULL || |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
481 (pendingScene_.get() != NULL && |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
482 pendingScene_->IsComplete())) |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
483 { |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
484 currentScene_ = pendingScene_; |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
485 } |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
486 |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
487 slice_ = slice; |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
488 ResetPendingScene(); |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
489 |
92 | 490 InvalidateAllLayers(); // TODO Removing this line avoid loading twice the image in WASM |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
491 } |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
492 } |
66 | 493 |
268
5bd4161bf11b
removed constness of the observable when emitting a message
am@osimis.io
parents:
267
diff
changeset
|
494 void LayerWidget::HandleMessage(IObservable& from, const IMessage& message) |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
495 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
496 switch (message.GetType()) { |
267 | 497 case MessageType_LayerSource_GeometryReady: |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
252
diff
changeset
|
498 OnGeometryReady(dynamic_cast<const ILayerSource&>(from)); |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
499 break; |
267 | 500 case MessageType_LayerSource_GeometryError: |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
501 LOG(ERROR) << "Cannot get geometry"; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
502 break; |
267 | 503 case MessageType_LayerSource_ContentChanged: |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
252
diff
changeset
|
504 OnContentChanged(dynamic_cast<const ILayerSource&>(from)); |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
505 break; |
267 | 506 case MessageType_LayerSource_SliceChanged: |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
252
diff
changeset
|
507 OnSliceChanged(dynamic_cast<const ILayerSource&>(from), dynamic_cast<const ILayerSource::SliceChangedMessage&>(message).slice_); |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
508 break; |
267 | 509 case MessageType_LayerSource_LayerReady: |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
510 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
511 const ILayerSource::LayerReadyMessage& layerReadyMessage = dynamic_cast<const ILayerSource::LayerReadyMessage&>(message); |
252 | 512 OnLayerReady(layerReadyMessage.layer_, |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
252
diff
changeset
|
513 dynamic_cast<const ILayerSource&>(from), |
252 | 514 layerReadyMessage.slice_, |
515 layerReadyMessage.isError_); | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
516 }; break; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
517 default: |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
518 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
519 } |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
520 } |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
521 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
522 void LayerWidget::OnGeometryReady(const ILayerSource& source) |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
523 { |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
524 size_t i; |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
525 if (LookupLayer(i, source)) |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
526 { |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
272
diff
changeset
|
527 LOG(INFO) << ": Geometry ready for layer " << i << " in " << GetName(); |
103 | 528 |
529 changedLayers_[i] = true; | |
530 //layers_[i]->ScheduleLayerCreation(slice_); | |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
531 } |
267 | 532 EmitMessage(IMessage(MessageType_Widget_GeometryChanged)); |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
533 } |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
534 |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
535 void LayerWidget::InvalidateAllLayers() |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
536 { |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
537 for (size_t i = 0; i < layers_.size(); i++) |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
538 { |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
539 assert(layers_[i] != NULL); |
103 | 540 changedLayers_[i] = true; |
541 | |
542 //layers_[i]->ScheduleLayerCreation(slice_); | |
66 | 543 } |
544 } | |
545 | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
546 |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
547 void LayerWidget::InvalidateLayer(size_t layer) |
66 | 548 { |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
549 if (layer >= layers_.size()) |
83 | 550 { |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
551 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
83 | 552 } |
66 | 553 |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
554 assert(layers_[layer] != NULL); |
103 | 555 changedLayers_[layer] = true; |
556 | |
557 //layers_[layer]->ScheduleLayerCreation(slice_); | |
77 | 558 } |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
559 |
77 | 560 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
561 void LayerWidget::OnContentChanged(const ILayerSource& source) |
66 | 562 { |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
563 size_t index; |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
564 if (LookupLayer(index, source)) |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
565 { |
103 | 566 InvalidateLayer(index); |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
567 } |
66 | 568 } |
569 | |
570 | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
571 void LayerWidget::OnSliceChanged(const ILayerSource& source, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
572 const Slice& slice) |
66 | 573 { |
77 | 574 if (slice.ContainsPlane(slice_)) |
66 | 575 { |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
576 size_t index; |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
577 if (LookupLayer(index, source)) |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
578 { |
103 | 579 InvalidateLayer(index); |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
580 } |
66 | 581 } |
582 } | |
583 | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
584 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
585 void LayerWidget::OnLayerReady(std::auto_ptr<ILayerRenderer>& renderer, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
586 const ILayerSource& source, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
587 const CoordinateSystem3D& slice, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
588 bool isError) |
66 | 589 { |
590 size_t index; | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
591 if (LookupLayer(index, source)) |
66 | 592 { |
96
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
593 if (isError) |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
594 { |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
595 LOG(ERROR) << "Using error renderer on layer " << index; |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
596 } |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
597 else |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
598 { |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
599 LOG(INFO) << "Renderer ready for layer " << index; |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
600 } |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
601 |
99 | 602 if (renderer.get() != NULL) |
603 { | |
604 UpdateLayer(index, renderer.release(), slice); | |
605 } | |
606 else if (isError) | |
607 { | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
608 // TODO |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
609 //UpdateLayer(index, new SliceOutlineRenderer(slice), slice); |
99 | 610 } |
66 | 611 } |
612 } | |
103 | 613 |
614 | |
615 void LayerWidget::ResetChangedLayers() | |
616 { | |
617 changedLayers_.resize(layers_.size()); | |
618 | |
619 for (size_t i = 0; i < changedLayers_.size(); i++) | |
620 { | |
621 changedLayers_[i] = false; | |
622 } | |
623 } | |
624 | |
625 | |
626 void LayerWidget::UpdateContent() | |
627 { | |
628 assert(changedLayers_.size() <= layers_.size()); | |
629 | |
630 for (size_t i = 0; i < changedLayers_.size(); i++) | |
631 { | |
632 if (changedLayers_[i]) | |
633 { | |
634 layers_[i]->ScheduleLayerCreation(slice_); | |
635 } | |
636 } | |
637 | |
638 ResetChangedLayers(); | |
639 } | |
66 | 640 } |