Skip to content

Commit

Permalink
PERF: Improve performance when removing segmentation from SH tree
Browse files Browse the repository at this point in the history
When removing a vtkMRMLSegmentationNode using the SubjectHierarchy tree, all of the virtual children would be removing before the segmentation. This caused a large number of updates in various segmentation widgets as all of the widgets were regenerated when each of the segments were removed from the segmentation node.

This commit improves performance by blocking modification events on the segmentation node (or any other node with virtual children), until all of the children have been removed. Rendering is also blocked during the item removal to prevent unnecessary updates of the views.
  • Loading branch information
Sunderlandkyl committed Sep 29, 2023
1 parent 5b0bcad commit 0c47b18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Libs/MRML/Core/vtkMRMLSubjectHierarchyNode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,9 @@ bool vtkSubjectHierarchyItem::RemoveChild(vtkSubjectHierarchyItem* item)
// as they represent the item's data node's content), then remove virtual branch
if (removedItem->IsVirtualBranchParent())
{
// If the item has many virtual children, then it may invoke a large number of events.
// To avoid this, block modified events on the data node until all of the children are removed.
MRMLNodeModifyBlocker blocker(removedItem->DataNode);
removedItem->RemoveAllChildren();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ void qSlicerSubjectHierarchyPluginLogic::onNodeAboutToBeRemoved(vtkObject* scene
vtkIdType itemID = shNode->GetItemByDataNode(dataNode);
if (itemID)
{
// Block render to avoid unnecessary view updates.
SlicerRenderBlocker renderBlocker;
shNode->RemoveItem(itemID, false, false);
}
}
Expand Down

0 comments on commit 0c47b18

Please sign in to comment.