From 379c96b59c8eeb73de783ea821b829173310254f Mon Sep 17 00:00:00 2001 From: James Butler Date: Thu, 26 May 2022 17:53:45 -0400 Subject: [PATCH] ENH: Optimize processing Segment Editor updates during Batch Processing For example when removing volume nodes, this can trigger a change of the current Source Volume node specification in the Segment Editor module if the current volume node is removed from the scene. When this happens over and over during batch processing there was frequent updating of the source volume node for SegmentEditor logic which can be an expensive operation, especially the sourceVolumeNodeChanged call for SegmentEditorThresholdEffect. --- .../Widgets/qMRMLSegmentEditorWidget.cxx | 33 ++++++++++++++++++- .../Widgets/qMRMLSegmentEditorWidget.h | 3 ++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentEditorWidget.cxx b/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentEditorWidget.cxx index 1a625c21e6d..8e3baec9e1c 100644 --- a/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentEditorWidget.cxx +++ b/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentEditorWidget.cxx @@ -1178,7 +1178,7 @@ void qMRMLSegmentEditorWidget::updateEffectList() void qMRMLSegmentEditorWidget::updateWidgetFromMRML() { Q_D(qMRMLSegmentEditorWidget); - if (!this->mrmlScene() || this->mrmlScene()->IsClosing()) + if (!this->mrmlScene() || this->mrmlScene()->IsClosing() || this->mrmlScene()->IsBatchProcessing()) { return; } @@ -1777,6 +1777,7 @@ void qMRMLSegmentEditorWidget::setMRMLScene(vtkMRMLScene* newScene) // observe close event so can re-add a parameters node if necessary this->qvtkConnect(this->mrmlScene(), vtkMRMLScene::EndCloseEvent, this, SLOT(onMRMLSceneEndCloseEvent())); + this->qvtkConnect(this->mrmlScene(), vtkMRMLScene::EndBatchProcessEvent, this, SLOT(onMRMLSceneEndBatchProcessEvent())); } //----------------------------------------------------------------------------- @@ -1786,6 +1787,28 @@ void qMRMLSegmentEditorWidget::onMRMLSceneEndCloseEvent() this->updateWidgetFromMRML(); } +//----------------------------------------------------------------------------- +void qMRMLSegmentEditorWidget::onMRMLSceneEndBatchProcessEvent() +{ + Q_D(qMRMLSegmentEditorWidget); + if (!this->mrmlScene()) + { + return; + } + if (d->ParameterSetNode->GetSegmentationNode() != d->SegmentationNodeComboBox->currentNode()) + { + this->setSegmentationNode(d->SegmentationNodeComboBox->currentNode()); + } + + if (d->ParameterSetNode->GetSourceVolumeNode() != d->SourceVolumeNodeComboBox->currentNode()) + { + this->setSourceVolumeNode(d->SourceVolumeNodeComboBox->currentNode()); + } + + // force update (clear GUI if no node is selected anymore) + this->updateWidgetFromMRML(); +} + //----------------------------------------------------------------------------- void qMRMLSegmentEditorWidget::onInteractionNodeModified() { @@ -2003,6 +2026,10 @@ QString qMRMLSegmentEditorWidget::sourceVolumeNodeID()const void qMRMLSegmentEditorWidget::onSegmentationNodeChanged(vtkMRMLNode* node) { Q_D(qMRMLSegmentEditorWidget); + if (!this->mrmlScene() || this->mrmlScene()->IsBatchProcessing()) + { + return; + } this->setSegmentationNode(node); } @@ -2066,6 +2093,10 @@ void qMRMLSegmentEditorWidget::setCurrentSegmentID(const QString segmentID) void qMRMLSegmentEditorWidget::onSourceVolumeNodeChanged(vtkMRMLNode* node) { Q_D(qMRMLSegmentEditorWidget); + if (!this->mrmlScene() || this->mrmlScene()->IsBatchProcessing()) + { + return; + } this->setSourceVolumeNode(node); } diff --git a/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentEditorWidget.h b/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentEditorWidget.h index 5e0d802eba5..7515d24e6e7 100644 --- a/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentEditorWidget.h +++ b/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentEditorWidget.h @@ -494,6 +494,9 @@ protected slots: /// Clean up when scene is closed void onMRMLSceneEndCloseEvent(); + /// Updates needed after batch processing is done + void onMRMLSceneEndBatchProcessEvent(); + /// Set default parameters in parameter set node (after setting or closing scene) void initializeParameterSetNode();