Page MenuHomePhabricator

[Segmentation] Monitoring of segmentation nodes in views is error prone/ not safe.
Open, NormalPublic

Description

In QmitkMultiLabelSegmentationView::CreateQtPartControl(QWidget *parent) and QmitSegmentationView::CreateQtPartControl(QWidget *parent) one can find a proplematic code:

// set callback function for already existing segmentation nodes
mitk::DataStorage::SetOfObjects::ConstPointer allSegmentations = GetDataStorage()->GetSubset(m_SegmentationPredicate);
for (mitk::DataStorage::SetOfObjects::const_iterator iter = allSegmentations->begin(); iter != allSegmentations->end(); ++iter)
{
  mitk::DataNode* node = *iter;
  auto command = itk::SimpleMemberCommand<QmitkMultiLabelSegmentationView>::New();
  command->SetCallbackFunction(this, &QmitkMultiLabelSegmentationView::ValidateSelectionInput);
  m_WorkingDataObserverTags.insert(std::pair<mitk::DataNode *, unsigned long>(
    node, node->GetProperty("visible")->AddObserver(itk::ModifiedEvent(), command)));
}

Problem: code assumes that property "visible" does always exist. If this is not the case, code crashes (that was the problem reported by T28886) when trying to call AddObserver. In some situations (e.g. custom written scene files) this could happen.

The problem could be prevented with a check for existance, but I want to discuss if this kind of observer pattern still make sense here. If I see the code in ValidateSelectionInput() correctly, which is called by the observer, it does the following:

  1. checks if the geometry of reference and working image fits
  2. checks if they are visible
  3. acts accordingly

To attach an observer on each segmentation node seems over bloated. I think just monitor the visiblity states of the current working image and reference image, would be sufficient.

ToDo: Discuss and conclude how to handle.

Event Timeline

floca triaged this task as Normal priority.Dec 6 2021, 9:02 PM
floca created this task.
floca moved this task from Backlog to MITK Meeting on the Request for Discussion board.

Maybe I can clarify something:

This change was introduced with D533, while I was refactoring both the segmentation- and the multilabelsegmentation plugin view to be in line. This was a preliminary step for the related tasks.
The observer pattern was already included in the original QmitkSegmentationView (see line 824 of https://phabricator.mitk.org/differential/changeset/?ref=47452). (Btw.: This was slightly changed and moved to line 448 of the new file (right side of the diff)).

The logic is basically the same as in NodeAdded(const mitk::DataNode* node) (in both plugin views).

The reason why this was added to the Multilabel segmentation view was the following:
The observer pattern helps to correctly validate if a segmentation node can be used for a segmentation. This is mainly to enable / disable the segmentation tools / controls and to write warning messages conc. hidden segmentation nodes / non-matching geometry.

However, I agree that it should be enough to only care for the validation of the currently selected input nodes (working node / reference node).
I can propose a change and we can test if this is the desired behavior.

To reproduce the issue:

  • open MITK 2021.02 workbench
  • open the ML view, add a n image and create a segmentation
  • close the view and open it again
  • change the visibility of the image and / or segmentation node
  • see how the view controls stay activated and no warning message appears
  • compare this to the segmentation view in this MITK version
  • compare this to the ML view in MITK 2021.10 and / or the develop

However, I agree that it should be enough to only care for the validation of the currently selected input nodes (working node / reference node).
I can propose a change and we can test if this is the desired behavior.

That would be nice. Thanks.

Suggestion: Open another task for ensuring at least default properties like "visible" that we can then kind of rely on.