Mercurial > hg > orthanc-stone
comparison Framework/Deprecated/Widgets/SliceViewerWidget.cpp @ 1299:c38c89684d83 broker
replacing std::auto_ptr by std::unique_ptr
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 02 Mar 2020 17:21:24 +0100 |
parents | 7ec8fea061b9 |
children | 257f2c9a02ac |
comparison
equal
deleted
inserted
replaced
1297:6ab03e429f06 | 1299:c38c89684d83 |
---|---|
33 | 33 |
34 static const double THIN_SLICE_THICKNESS = 100.0 * std::numeric_limits<double>::epsilon(); | 34 static const double THIN_SLICE_THICKNESS = 100.0 * std::numeric_limits<double>::epsilon(); |
35 | 35 |
36 namespace Deprecated | 36 namespace Deprecated |
37 { | 37 { |
38 class SliceViewerWidget::Scene : public boost::noncopyable | 38 void SliceViewerWidget::Scene::DeleteLayer(size_t index) |
39 { | 39 { |
40 private: | 40 if (index >= renderers_.size()) |
41 OrthancStone::CoordinateSystem3D plane_; | 41 { |
42 double thickness_; | 42 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
43 size_t countMissing_; | 43 } |
44 std::vector<ILayerRenderer*> renderers_; | 44 |
45 | 45 assert(countMissing_ <= renderers_.size()); |
46 public: | 46 |
47 void DeleteLayer(size_t index) | 47 if (renderers_[index] != NULL) |
48 { | 48 { |
49 if (index >= renderers_.size()) | 49 assert(countMissing_ < renderers_.size()); |
50 { | 50 delete renderers_[index]; |
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 51 renderers_[index] = NULL; |
52 } | 52 countMissing_++; |
53 | 53 } |
54 assert(countMissing_ <= renderers_.size()); | 54 } |
55 | 55 |
56 if (renderers_[index] != NULL) | 56 |
57 { | 57 SliceViewerWidget::Scene::Scene(const OrthancStone::CoordinateSystem3D& plane, |
58 assert(countMissing_ < renderers_.size()); | 58 double thickness, |
59 delete renderers_[index]; | 59 size_t countLayers) : |
60 renderers_[index] = NULL; | 60 plane_(plane), |
61 countMissing_++; | 61 thickness_(thickness), |
62 } | 62 countMissing_(countLayers), |
63 } | 63 renderers_(countLayers, NULL) |
64 | 64 { |
65 Scene(const OrthancStone::CoordinateSystem3D& plane, | 65 if (thickness <= 0) |
66 double thickness, | 66 { |
67 size_t countLayers) : | 67 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
68 plane_(plane), | 68 } |
69 thickness_(thickness), | 69 } |
70 countMissing_(countLayers), | 70 |
71 renderers_(countLayers, NULL) | 71 |
72 { | 72 SliceViewerWidget::Scene::~Scene() |
73 if (thickness <= 0) | 73 { |
74 { | 74 for (size_t i = 0; i < renderers_.size(); i++) |
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 75 { |
76 } | 76 DeleteLayer(i); |
77 } | 77 } |
78 | 78 } |
79 ~Scene() | 79 |
80 { | 80 void SliceViewerWidget::Scene::SetLayer(size_t index, |
81 for (size_t i = 0; i < renderers_.size(); i++) | 81 ILayerRenderer* renderer) // Takes ownership |
82 { | 82 { |
83 DeleteLayer(i); | 83 if (renderer == NULL) |
84 } | 84 { |
85 } | 85 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
86 | 86 } |
87 void SetLayer(size_t index, | 87 |
88 ILayerRenderer* renderer) // Takes ownership | 88 DeleteLayer(index); |
89 { | 89 |
90 if (renderer == NULL) | 90 renderers_[index] = renderer; |
91 { | 91 countMissing_--; |
92 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | 92 } |
93 } | 93 |
94 | 94 |
95 DeleteLayer(index); | 95 bool SliceViewerWidget::Scene::RenderScene(OrthancStone::CairoContext& context, |
96 | 96 const ViewportGeometry& view, |
97 renderers_[index] = renderer; | 97 const OrthancStone::CoordinateSystem3D& viewportPlane) |
98 countMissing_--; | 98 { |
99 } | 99 bool fullQuality = true; |
100 | 100 cairo_t *cr = context.GetObject(); |
101 const OrthancStone::CoordinateSystem3D& GetPlane() const | 101 |
102 { | 102 for (size_t i = 0; i < renderers_.size(); i++) |
103 return plane_; | 103 { |
104 } | 104 if (renderers_[i] != NULL) |
105 | 105 { |
106 bool HasRenderer(size_t index) | 106 const OrthancStone::CoordinateSystem3D& framePlane = renderers_[i]->GetLayerPlane(); |
107 { | 107 |
108 return renderers_[index] != NULL; | 108 double x0, y0, x1, y1, x2, y2; |
109 } | 109 viewportPlane.ProjectPoint(x0, y0, framePlane.GetOrigin()); |
110 | 110 viewportPlane.ProjectPoint(x1, y1, framePlane.GetOrigin() + framePlane.GetAxisX()); |
111 bool IsComplete() const | 111 viewportPlane.ProjectPoint(x2, y2, framePlane.GetOrigin() + framePlane.GetAxisY()); |
112 { | 112 |
113 return countMissing_ == 0; | 113 /** |
114 } | 114 * Now we solve the system of linear equations Ax + b = x', given: |
115 | 115 * A [0 ; 0] + b = [x0 ; y0] |
116 unsigned int GetCountMissing() const | 116 * A [1 ; 0] + b = [x1 ; y1] |
117 { | 117 * A [0 ; 1] + b = [x2 ; y2] |
118 return static_cast<unsigned int>(countMissing_); | 118 * <=> |
119 } | 119 * b = [x0 ; y0] |
120 | 120 * A [1 ; 0] = [x1 ; y1] - b = [x1 - x0 ; y1 - y0] |
121 bool RenderScene(OrthancStone::CairoContext& context, | 121 * A [0 ; 1] = [x2 ; y2] - b = [x2 - x0 ; y2 - y0] |
122 const ViewportGeometry& view, | 122 * <=> |
123 const OrthancStone::CoordinateSystem3D& viewportPlane) | 123 * b = [x0 ; y0] |
124 { | 124 * [a11 ; a21] = [x1 - x0 ; y1 - y0] |
125 bool fullQuality = true; | 125 * [a12 ; a22] = [x2 - x0 ; y2 - y0] |
126 cairo_t *cr = context.GetObject(); | 126 **/ |
127 | 127 |
128 for (size_t i = 0; i < renderers_.size(); i++) | 128 cairo_matrix_t transform; |
129 { | 129 cairo_matrix_init(&transform, x1 - x0, y1 - y0, x2 - x0, y2 - y0, x0, y0); |
130 if (renderers_[i] != NULL) | 130 |
131 cairo_save(cr); | |
132 cairo_transform(cr, &transform); | |
133 | |
134 if (!renderers_[i]->RenderLayer(context, view)) | |
131 { | 135 { |
132 const OrthancStone::CoordinateSystem3D& framePlane = renderers_[i]->GetLayerPlane(); | |
133 | |
134 double x0, y0, x1, y1, x2, y2; | |
135 viewportPlane.ProjectPoint(x0, y0, framePlane.GetOrigin()); | |
136 viewportPlane.ProjectPoint(x1, y1, framePlane.GetOrigin() + framePlane.GetAxisX()); | |
137 viewportPlane.ProjectPoint(x2, y2, framePlane.GetOrigin() + framePlane.GetAxisY()); | |
138 | |
139 /** | |
140 * Now we solve the system of linear equations Ax + b = x', given: | |
141 * A [0 ; 0] + b = [x0 ; y0] | |
142 * A [1 ; 0] + b = [x1 ; y1] | |
143 * A [0 ; 1] + b = [x2 ; y2] | |
144 * <=> | |
145 * b = [x0 ; y0] | |
146 * A [1 ; 0] = [x1 ; y1] - b = [x1 - x0 ; y1 - y0] | |
147 * A [0 ; 1] = [x2 ; y2] - b = [x2 - x0 ; y2 - y0] | |
148 * <=> | |
149 * b = [x0 ; y0] | |
150 * [a11 ; a21] = [x1 - x0 ; y1 - y0] | |
151 * [a12 ; a22] = [x2 - x0 ; y2 - y0] | |
152 **/ | |
153 | |
154 cairo_matrix_t transform; | |
155 cairo_matrix_init(&transform, x1 - x0, y1 - y0, x2 - x0, y2 - y0, x0, y0); | |
156 | |
157 cairo_save(cr); | |
158 cairo_transform(cr, &transform); | |
159 | |
160 if (!renderers_[i]->RenderLayer(context, view)) | |
161 { | |
162 cairo_restore(cr); | |
163 return false; | |
164 } | |
165 | |
166 cairo_restore(cr); | 136 cairo_restore(cr); |
137 return false; | |
167 } | 138 } |
168 | 139 |
169 if (renderers_[i] != NULL && | 140 cairo_restore(cr); |
170 !renderers_[i]->IsFullQuality()) | 141 } |
171 { | 142 |
172 fullQuality = false; | 143 if (renderers_[i] != NULL && |
173 } | 144 !renderers_[i]->IsFullQuality()) |
174 } | 145 { |
175 | 146 fullQuality = false; |
176 if (!fullQuality) | 147 } |
177 { | 148 } |
178 double x, y; | 149 |
179 view.MapDisplayToScene(x, y, static_cast<double>(view.GetDisplayWidth()) / 2.0, 10); | 150 if (!fullQuality) |
180 | 151 { |
181 cairo_translate(cr, x, y); | 152 double x, y; |
153 view.MapDisplayToScene(x, y, static_cast<double>(view.GetDisplayWidth()) / 2.0, 10); | |
154 | |
155 cairo_translate(cr, x, y); | |
182 | 156 |
183 #if 1 | 157 #if 1 |
184 double s = 5.0 / view.GetZoom(); | 158 double s = 5.0 / view.GetZoom(); |
185 cairo_rectangle(cr, -s, -s, 2.0 * s, 2.0 * s); | 159 cairo_rectangle(cr, -s, -s, 2.0 * s, 2.0 * s); |
186 #else | 160 #else |
187 // TODO Drawing filled circles makes WebAssembly crash! | 161 // TODO Drawing filled circles makes WebAssembly crash! |
188 cairo_arc(cr, 0, 0, 5.0 / view.GetZoom(), 0, 2.0 * boost::math::constants::pi<double>()); | 162 cairo_arc(cr, 0, 0, 5.0 / view.GetZoom(), 0, 2.0 * boost::math::constants::pi<double>()); |
189 #endif | 163 #endif |
190 | 164 |
191 cairo_set_line_width(cr, 2.0 / view.GetZoom()); | 165 cairo_set_line_width(cr, 2.0 / view.GetZoom()); |
192 cairo_set_source_rgb(cr, 1, 1, 1); | 166 cairo_set_source_rgb(cr, 1, 1, 1); |
193 cairo_stroke_preserve(cr); | 167 cairo_stroke_preserve(cr); |
194 cairo_set_source_rgb(cr, 1, 0, 0); | 168 cairo_set_source_rgb(cr, 1, 0, 0); |
195 cairo_fill(cr); | 169 cairo_fill(cr); |
196 } | 170 } |
197 | 171 |
198 return true; | 172 return true; |
199 } | 173 } |
200 | 174 |
201 void SetLayerStyle(size_t index, | 175 void SliceViewerWidget::Scene::SetLayerStyle(size_t index, |
202 const RenderStyle& style) | 176 const RenderStyle& style) |
203 { | 177 { |
204 if (renderers_[index] != NULL) | 178 if (renderers_[index] != NULL) |
205 { | 179 { |
206 renderers_[index]->SetLayerStyle(style); | 180 renderers_[index]->SetLayerStyle(style); |
207 } | 181 } |
208 } | 182 } |
209 | 183 |
210 bool ContainsPlane(const OrthancStone::CoordinateSystem3D& plane) const | 184 bool SliceViewerWidget::Scene::ContainsPlane(const OrthancStone::CoordinateSystem3D& plane) const |
211 { | 185 { |
212 bool isOpposite; | 186 bool isOpposite; |
213 if (!OrthancStone::GeometryToolbox::IsParallelOrOpposite(isOpposite, | 187 if (!OrthancStone::GeometryToolbox::IsParallelOrOpposite(isOpposite, |
214 plane.GetNormal(), | 188 plane.GetNormal(), |
215 plane_.GetNormal())) | 189 plane_.GetNormal())) |
216 { | 190 { |
217 return false; | 191 return false; |
218 } | 192 } |
219 else | 193 else |
220 { | 194 { |
221 double z = (plane_.ProjectAlongNormal(plane.GetOrigin()) - | 195 double z = (plane_.ProjectAlongNormal(plane.GetOrigin()) - |
222 plane_.ProjectAlongNormal(plane_.GetOrigin())); | 196 plane_.ProjectAlongNormal(plane_.GetOrigin())); |
223 | 197 |
224 if (z < 0) | 198 if (z < 0) |
225 { | 199 { |
226 z = -z; | 200 z = -z; |
227 } | 201 } |
228 | 202 |
229 return z <= thickness_; | 203 return z <= thickness_; |
230 } | 204 } |
231 } | 205 } |
232 | |
233 double GetThickness() const | |
234 { | |
235 return thickness_; | |
236 } | |
237 }; | |
238 | 206 |
239 | 207 |
240 bool SliceViewerWidget::LookupLayer(size_t& index /* out */, | 208 bool SliceViewerWidget::LookupLayer(size_t& index /* out */, |
241 const IVolumeSlicer& layer) const | 209 const IVolumeSlicer& layer) const |
242 { | 210 { |
325 ILayerRenderer* renderer, | 293 ILayerRenderer* renderer, |
326 const OrthancStone::CoordinateSystem3D& plane) | 294 const OrthancStone::CoordinateSystem3D& plane) |
327 { | 295 { |
328 LOG(INFO) << "Updating layer " << index; | 296 LOG(INFO) << "Updating layer " << index; |
329 | 297 |
330 std::auto_ptr<ILayerRenderer> tmp(renderer); | 298 std::unique_ptr<ILayerRenderer> tmp(renderer); |
331 | 299 |
332 if (renderer == NULL) | 300 if (renderer == NULL) |
333 { | 301 { |
334 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | 302 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
335 } | 303 } |
355 | 323 |
356 if (currentScene_.get() == NULL || | 324 if (currentScene_.get() == NULL || |
357 !currentScene_->IsComplete() || | 325 !currentScene_->IsComplete() || |
358 pendingScene_->IsComplete()) | 326 pendingScene_->IsComplete()) |
359 { | 327 { |
360 currentScene_ = pendingScene_; | 328 #if __cplusplus < 201103L |
329 currentScene_.reset(pendingScene_.release()); | |
330 #else | |
331 currentScene_ = std::move(pendingScene_); | |
332 #endif | |
333 | |
361 NotifyContentChanged(); | 334 NotifyContentChanged(); |
362 } | 335 } |
363 } | 336 } |
364 } | 337 } |
365 | 338 |
501 { | 474 { |
502 if (currentScene_.get() == NULL || | 475 if (currentScene_.get() == NULL || |
503 (pendingScene_.get() != NULL && | 476 (pendingScene_.get() != NULL && |
504 pendingScene_->IsComplete())) | 477 pendingScene_->IsComplete())) |
505 { | 478 { |
506 currentScene_ = pendingScene_; | 479 #if __cplusplus < 201103L |
480 currentScene_.reset(pendingScene_.release()); | |
481 #else | |
482 currentScene_ = std::move(pendingScene_); | |
483 #endif | |
507 } | 484 } |
508 | 485 |
509 plane_ = plane; | 486 plane_ = plane; |
510 ResetPendingScene(); | 487 ResetPendingScene(); |
511 | 488 |