Mercurial > hg > orthanc-stone
annotate Framework/Widgets/LayerWidget.cpp @ 262:77fdab5b5d6e am-2
cleanup + todos
author | am@osimis.io |
---|---|
date | Tue, 17 Jul 2018 18:28:12 +0200 |
parents | 40b21c1f8b8d |
children | c9cf95b49a86 |
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()); | |
344 NotifyChange(); | |
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_; | |
356 NotifyChange(); | |
357 } | |
358 } | |
359 } | |
360 | |
361 | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
362 LayerWidget::LayerWidget(MessageBroker& broker) : |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
363 IObserver(broker), |
78 | 364 started_(false) |
66 | 365 { |
366 SetBackgroundCleared(true); | |
367 } | |
368 | |
369 | |
370 LayerWidget::~LayerWidget() | |
371 { | |
372 for (size_t i = 0; i < layers_.size(); i++) | |
373 { | |
374 delete layers_[i]; | |
375 } | |
376 } | |
377 | |
378 | |
379 size_t LayerWidget::AddLayer(ILayerSource* layer) // Takes ownership | |
380 { | |
381 if (layer == NULL) | |
382 { | |
383 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
384 } | |
385 | |
386 size_t index = layers_.size(); | |
387 layers_.push_back(layer); | |
388 styles_.push_back(RenderStyle()); | |
389 layersIndex_[layer] = index; | |
390 | |
391 ResetPendingScene(); | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
392 layer->RegisterObserver(*this); |
66 | 393 |
103 | 394 ResetChangedLayers(); |
395 | |
66 | 396 return index; |
397 } | |
398 | |
219 | 399 void LayerWidget::ReplaceLayer(size_t index, ILayerSource* layer) // Takes ownership |
400 { | |
401 if (layer == NULL) | |
402 { | |
403 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
404 } | |
405 | |
406 if (index >= layers_.size()) | |
407 { | |
408 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
409 } | |
410 | |
411 delete layers_[index]; | |
412 layers_[index] = layer; | |
413 layersIndex_[layer] = index; | |
414 | |
415 ResetPendingScene(); | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
416 layer->RegisterObserver(*this); |
219 | 417 |
418 InvalidateLayer(index); | |
419 } | |
420 | |
421 | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
422 const RenderStyle& LayerWidget::GetLayerStyle(size_t layer) const |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
423 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
424 if (layer >= layers_.size()) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
425 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
426 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
427 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
428 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
429 assert(layers_.size() == styles_.size()); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
430 return styles_[layer]; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
431 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
432 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
433 |
66 | 434 void LayerWidget::SetLayerStyle(size_t layer, |
435 const RenderStyle& style) | |
436 { | |
437 if (layer >= layers_.size()) | |
438 { | |
439 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
440 } | |
441 | |
442 assert(layers_.size() == styles_.size()); | |
443 styles_[layer] = style; | |
444 | |
445 if (currentScene_.get() != NULL) | |
446 { | |
447 currentScene_->SetLayerStyle(layer, style); | |
448 } | |
449 | |
450 if (pendingScene_.get() != NULL) | |
451 { | |
452 pendingScene_->SetLayerStyle(layer, style); | |
453 } | |
454 | |
455 NotifyChange(); | |
456 } | |
457 | |
458 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
459 void LayerWidget::SetSlice(const CoordinateSystem3D& slice) |
66 | 460 { |
93
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
461 LOG(INFO) << "Setting slice origin: (" << slice.GetOrigin()[0] |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
462 << "," << slice.GetOrigin()[1] |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
463 << "," << slice.GetOrigin()[2] << ")"; |
5945e81734a3
decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
464 |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
465 Slice displayedSlice(slice_, THIN_SLICE_THICKNESS); |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
466 |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
96
diff
changeset
|
467 //if (!displayedSlice.ContainsPlane(slice)) |
66 | 468 { |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
469 if (currentScene_.get() == NULL || |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
470 (pendingScene_.get() != NULL && |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
471 pendingScene_->IsComplete())) |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
472 { |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
473 currentScene_ = pendingScene_; |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
474 } |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
475 |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
476 slice_ = slice; |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
477 ResetPendingScene(); |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
478 |
92 | 479 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
|
480 } |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
481 } |
66 | 482 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
483 void LayerWidget::HandleMessage(IObservable& from, const IMessage& message) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
484 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
485 switch (message.GetType()) { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
486 case MessageType_GeometryReady: |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
487 OnGeometryReady(dynamic_cast<ILayerSource&>(from)); |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
488 break; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
489 case MessageType_GeometryError: |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
490 LOG(ERROR) << "Cannot get geometry"; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
491 break; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
492 case MessageType_ContentChanged: |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
493 OnContentChanged(dynamic_cast<ILayerSource&>(from)); |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
494 break; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
495 case MessageType_SliceChanged: |
252 | 496 OnSliceChanged(dynamic_cast<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
|
497 break; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
498 case MessageType_LayerReady: |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
499 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
500 const ILayerSource::LayerReadyMessage& layerReadyMessage = dynamic_cast<const ILayerSource::LayerReadyMessage&>(message); |
252 | 501 OnLayerReady(layerReadyMessage.layer_, |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
502 dynamic_cast<ILayerSource&>(from), |
252 | 503 layerReadyMessage.slice_, |
504 layerReadyMessage.isError_); | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
505 }; break; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
506 default: |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
507 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
508 } |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
509 } |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
510 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
511 void LayerWidget::OnGeometryReady(const ILayerSource& source) |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
512 { |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
513 size_t i; |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
514 if (LookupLayer(i, source)) |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
515 { |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
516 LOG(INFO) << "Geometry ready for layer " << i; |
103 | 517 |
518 changedLayers_[i] = true; | |
519 //layers_[i]->ScheduleLayerCreation(slice_); | |
90
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
520 } |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
521 } |
64e60018943f
fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
522 |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
523 void LayerWidget::InvalidateAllLayers() |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
524 { |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
525 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
|
526 { |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
527 assert(layers_[i] != NULL); |
103 | 528 changedLayers_[i] = true; |
529 | |
530 //layers_[i]->ScheduleLayerCreation(slice_); | |
66 | 531 } |
532 } | |
533 | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
534 |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
535 void LayerWidget::InvalidateLayer(size_t layer) |
66 | 536 { |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
537 if (layer >= layers_.size()) |
83 | 538 { |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
539 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
83 | 540 } |
66 | 541 |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
542 assert(layers_[layer] != NULL); |
103 | 543 changedLayers_[layer] = true; |
544 | |
545 //layers_[layer]->ScheduleLayerCreation(slice_); | |
77 | 546 } |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
547 |
77 | 548 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
549 void LayerWidget::OnContentChanged(const ILayerSource& source) |
66 | 550 { |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
551 size_t index; |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
552 if (LookupLayer(index, source)) |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
553 { |
103 | 554 InvalidateLayer(index); |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
555 } |
66 | 556 } |
557 | |
558 | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
559 void LayerWidget::OnSliceChanged(const ILayerSource& source, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
560 const Slice& slice) |
66 | 561 { |
77 | 562 if (slice.ContainsPlane(slice_)) |
66 | 563 { |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
564 size_t index; |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
565 if (LookupLayer(index, source)) |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
566 { |
103 | 567 InvalidateLayer(index); |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
86
diff
changeset
|
568 } |
66 | 569 } |
570 } | |
571 | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
572 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
573 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
|
574 const ILayerSource& source, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
575 const CoordinateSystem3D& slice, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
219
diff
changeset
|
576 bool isError) |
66 | 577 { |
578 size_t index; | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
579 if (LookupLayer(index, source)) |
66 | 580 { |
96
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
581 if (isError) |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
582 { |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
583 LOG(ERROR) << "Using error renderer on layer " << index; |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
584 } |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
585 else |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
586 { |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
587 LOG(INFO) << "Renderer ready for layer " << index; |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
588 } |
f8bce1bebe01
removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
589 |
99 | 590 if (renderer.get() != NULL) |
591 { | |
592 UpdateLayer(index, renderer.release(), slice); | |
593 } | |
594 else if (isError) | |
595 { | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
596 // TODO |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
597 //UpdateLayer(index, new SliceOutlineRenderer(slice), slice); |
99 | 598 } |
66 | 599 } |
600 } | |
103 | 601 |
602 | |
603 void LayerWidget::ResetChangedLayers() | |
604 { | |
605 changedLayers_.resize(layers_.size()); | |
606 | |
607 for (size_t i = 0; i < changedLayers_.size(); i++) | |
608 { | |
609 changedLayers_[i] = false; | |
610 } | |
611 } | |
612 | |
613 | |
614 void LayerWidget::UpdateContent() | |
615 { | |
616 assert(changedLayers_.size() <= layers_.size()); | |
617 | |
618 for (size_t i = 0; i < changedLayers_.size(); i++) | |
619 { | |
620 if (changedLayers_[i]) | |
621 { | |
622 layers_[i]->ScheduleLayerCreation(slice_); | |
623 } | |
624 } | |
625 | |
626 ResetChangedLayers(); | |
627 } | |
66 | 628 } |