MCPcopy Create free account
hub / github.com/MITK/MITK / DoUpdatePreview

Method DoUpdatePreview

Modules/PythonSegmentation/src/mitknnInteractiveTool.cpp:530–648  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

528}
529
530void mitk::nnInteractiveTool::DoUpdatePreview(const Image* inputAtTimeStep, const Image* /*oldSegAtTimeStep*/, MultiLabelSegmentation* previewImage, TimeStepType timeStep)
531{
532 // This method assumes it is only called when an interaction has occurred or
533 // when a session should be (re)initialized with a label mask. Otherwise,
534 // calling this method will reset any existing preview content.
535
536 if (previewImage == nullptr || m_Impl->GetPythonContext() == nullptr)
537 return;
538
539 // Color the preview with the selected target label's color (falling back to
540 // the special preview color) so it matches the label being segmented.
541 auto previewColor = this->GetSpecialPreviewColor();
542
543 if (const auto* segmentation = this->GetTargetSegmentation(); segmentation != nullptr)
544 {
545 if (const auto* activeLabel = segmentation->GetActiveLabel(); activeLabel != nullptr)
546 previewColor = activeLabel->GetColor();
547 }
548
549 this->SetPreviewLabel(1, previewColor);
550
551 // An undo restored the target buffer in place; just repaint the preview from
552 // it. This must run before the interactor branch (an interactor is typically
553 // still enabled while undoing) and must not emit PreviewUpdatedEvent, so it
554 // does not trigger the GUI's auto-confirm.
555 if (m_Impl->UndoRefreshPending)
556 {
557 m_Impl->UndoRefreshPending = false;
558 previewImage->UpdateGroupImage(previewImage->GetActiveLayer(), m_Impl->TargetBuffer, timeStep, 0);
559 return;
560 }
561
562 const auto* interactor = m_Impl->GetEnabledInteractor();
563
564 try
565 {
566 if (interactor != nullptr)
567 {
568 switch (interactor->GetType())
569 {
570 case InteractionType::Point:
571 {
572 auto point = static_cast<const PointInteractor*>(interactor)->GetLastPoint();
573 m_Impl->AddPointInteraction(point.value(), inputAtTimeStep);
574 break;
575 }
576 case InteractionType::Box:
577 {
578 auto box = static_cast<const BoxInteractor*>(interactor)->GetLastBox();
579 m_Impl->AddBoxInteraction(box, inputAtTimeStep);
580 break;
581 }
582 case InteractionType::Scribble:
583 {
584 auto scribbleInteractor = static_cast<const ScribbleInteractor*>(interactor);
585 auto mask = scribbleInteractor->GetLastScribbleMask();
586 if (mask.IsNull())
587 {

Callers

nothing calls this directly

Calls 15

SetPreviewLabelMethod · 0.95
HandleSessionErrorMethod · 0.95
DescriptionFunction · 0.85
GetTargetSegmentationMethod · 0.80
GetActiveLabelMethod · 0.80
UpdateGroupImageMethod · 0.80
GetActiveLayerMethod · 0.80
GetEnabledInteractorMethod · 0.80
GetLastPointMethod · 0.80
GetLastBoxMethod · 0.80
AddBoxInteractionMethod · 0.80

Tested by

no test coverage detected