comparison Framework/Widgets/LayerWidget.cpp @ 85:bd48431ac285 wasm

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 May 2017 12:20:26 +0200
parents c75377306598
children 02c3a7a4938f
comparison
equal deleted inserted replaced
83:c75377306598 85:bd48431ac285
20 20
21 21
22 #include "LayerWidget.h" 22 #include "LayerWidget.h"
23 23
24 #include "../../Resources/Orthanc/Core/Logging.h" 24 #include "../../Resources/Orthanc/Core/Logging.h"
25 #include "../Layers/MissingLayerRenderer.h"
26
27 static const double THIN_SLICE_THICKNESS = 100.0 * std::numeric_limits<double>::epsilon();
25 28
26 namespace OrthancStone 29 namespace OrthancStone
27 { 30 {
28 class LayerWidget::Scene : public boost::noncopyable 31 class LayerWidget::Scene : public boost::noncopyable
29 { 32 {
156 layers_[index] == &layer); 159 layers_[index] == &layer);
157 return true; 160 return true;
158 } 161 }
159 } 162 }
160 163
164
165 bool LayerWidget::GetAndFixExtent(double& x1,
166 double& y1,
167 double& x2,
168 double& y2,
169 ILayerSource& source) const
170 {
171 if (source.GetExtent(x1, y1, x2, y2, slice_))
172 {
173 if (x1 > x2)
174 {
175 std::swap(x1, x2);
176 }
177
178 if (y1 > y2)
179 {
180 std::swap(y1, y2);
181 }
182
183 return true;
184 }
185 else
186 {
187 return false;
188 }
189 }
190
161 191
162 void LayerWidget::GetSceneExtent(double& x1, 192 void LayerWidget::GetSceneExtent(double& x1,
163 double& y1, 193 double& y1,
164 double& x2, 194 double& x2,
165 double& y2) 195 double& y2)
169 for (size_t i = 0; i < layers_.size(); i++) 199 for (size_t i = 0; i < layers_.size(); i++)
170 { 200 {
171 double ax, ay, bx, by; 201 double ax, ay, bx, by;
172 202
173 assert(layers_[i] != NULL); 203 assert(layers_[i] != NULL);
174 if (layers_[i]->GetExtent(ax, ay, bx, by, slice_)) 204 if (GetAndFixExtent(ax, ay, bx, by, *layers_[i]))
175 { 205 {
176 if (ax > bx)
177 {
178 std::swap(ax, bx);
179 }
180
181 if (ay > by)
182 {
183 std::swap(ay, by);
184 }
185
186 LOG(INFO) << "Extent of layer " << i << ": (" << ax << "," << ay << ")->(" << bx << "," << by << ")"; 206 LOG(INFO) << "Extent of layer " << i << ": (" << ax << "," << ay << ")->(" << bx << "," << by << ")";
187 207
188 if (first) 208 if (first)
189 { 209 {
190 x1 = ax; 210 x1 = ax;
351 } 371 }
352 372
353 373
354 void LayerWidget::SetSlice(const SliceGeometry& slice) 374 void LayerWidget::SetSlice(const SliceGeometry& slice)
355 { 375 {
356 if (!slice_.IsSamePlane(slice, 100.0 * std::numeric_limits<double>::epsilon())) 376 if (!slice_.IsSamePlane(slice, THIN_SLICE_THICKNESS))
357 { 377 {
358 if (currentScene_.get() == NULL || 378 if (currentScene_.get() == NULL ||
359 (pendingScene_.get() != NULL && 379 (pendingScene_.get() != NULL &&
360 pendingScene_->IsComplete())) 380 pendingScene_->IsComplete()))
361 { 381 {
363 } 383 }
364 384
365 slice_ = slice; 385 slice_ = slice;
366 ResetPendingScene(); 386 ResetPendingScene();
367 387
368 if (started_) 388 for (size_t i = 0; i < layers_.size(); i++)
369 { 389 {
370 for (size_t i = 0; i < layers_.size(); i++) 390 assert(layers_[i] != NULL);
371 { 391 layers_[i]->ScheduleLayerCreation(slice_);
372 assert(layers_[i] != NULL);
373 layers_[i]->ScheduleLayerCreation(slice_);
374 }
375 } 392 }
376 } 393 }
377 } 394 }
378 395
379 396
381 { 398 {
382 size_t i; 399 size_t i;
383 if (LookupLayer(i, source)) 400 if (LookupLayer(i, source))
384 { 401 {
385 LOG(INFO) << "Geometry ready for layer " << i; 402 LOG(INFO) << "Geometry ready for layer " << i;
386 SetDefaultView();
387 layers_[i]->ScheduleLayerCreation(slice_); 403 layers_[i]->ScheduleLayerCreation(slice_);
388 } 404 }
389 } 405 }
390 406
391 407
416 const Slice& slice) 432 const Slice& slice)
417 { 433 {
418 std::auto_ptr<ILayerRenderer> tmp(renderer); 434 std::auto_ptr<ILayerRenderer> tmp(renderer);
419 435
420 size_t index; 436 size_t index;
421 if (LookupLayer(index, source)) 437 if (LookupLayer(index, source) &&
438 slice.ContainsPlane(slice_)) // Whether the slice comes from an older request
422 { 439 {
423 LOG(INFO) << "Renderer ready for layer " << index; 440 LOG(INFO) << "Renderer ready for layer " << index;
424 UpdateLayer(index, tmp.release(), slice); 441 UpdateLayer(index, tmp.release(), slice);
425 } 442 }
426 } 443 }
427 444
428 445
429 void LayerWidget::NotifyLayerError(ILayerSource& source, 446 void LayerWidget::NotifyLayerError(ILayerSource& source,
430 const SliceGeometry& viewportSlice) 447 const SliceGeometry& slice)
431 { 448 {
432 size_t i; 449 size_t index;
433 if (LookupLayer(i, source)) 450
434 LOG(ERROR) << "Error on layer " << i; 451 if (LookupLayer(index, source) &&
452 slice.IsSamePlane(slice_, THIN_SLICE_THICKNESS)) // Whether the slice comes from an older request
453 {
454 LOG(ERROR) << "Error on layer " << index;
455
456 double x1, y1, x2, y2;
457 if (GetAndFixExtent(x1, y1, x2, y2, source))
458 {
459 UpdateLayer(index, new MissingLayerRenderer(x1, y1, x2, y2), Slice(slice, THIN_SLICE_THICKNESS));
460 }
461 }
435 } 462 }
436 463
437 464
438 void LayerWidget::Start() 465 void LayerWidget::Start()
439 { 466 {