Skip to content

Commit

Permalink
BUG: Fix issue with scene loading in External Beam Planning
Browse files Browse the repository at this point in the history
Empty output total dose volume was created on setting the plan. This resulted in an invalid scene if was saved before dose calculation, which in turn resulted using a random volume node instead of the empty dose volume when calculating dose after loading that scene.
Now the output total dose can be set to None (the combobox will say 'Create new output dose volume') and the volume is only created when clicking the Calculate dose button.

Re #73
cpinter committed Jul 3, 2019
1 parent 7817d72 commit 7664806
Showing 2 changed files with 78 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -17,7 +17,16 @@
<property name="spacing">
<number>4</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
@@ -49,7 +58,16 @@
<string>Plan parameters</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<property name="spacing">
@@ -295,11 +313,17 @@
<property name="text">
<string>Output</string>
</property>
<property name="contentsFrameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<property name="spacing">
@@ -325,6 +349,12 @@
<property name="baseName">
<string>TotalDose</string>
</property>
<property name="noneEnabled">
<bool>true</bool>
</property>
<property name="noneDisplay">
<string>Create new output dose volume</string>
</property>
</widget>
</item>
<item row="1" column="0">
@@ -433,11 +463,17 @@
<property name="text">
<string>Beams</string>
</property>
<property name="contentsFrameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<property name="spacing">
42 changes: 32 additions & 10 deletions ExternalBeamPlanning/qSlicerExternalBeamPlanningModuleWidget.cxx
Original file line number Diff line number Diff line change
@@ -399,16 +399,6 @@ void qSlicerExternalBeamPlanningModuleWidget::setPlanNode(vtkMRMLNode* node)
}
}

// Create and select output dose volume if missing
if (!planNode->GetOutputTotalDoseVolumeNode())
{
vtkSmartPointer<vtkMRMLScalarVolumeNode> newDoseVolume = vtkSmartPointer<vtkMRMLScalarVolumeNode>::New();
std::string newDoseVolumeName = std::string(planNode->GetName()) + "_TotalDose";
newDoseVolume->SetName(newDoseVolumeName.c_str());
this->mrmlScene()->AddNode(newDoseVolume);
planNode->SetAndObserveOutputTotalDoseVolumeNode(newDoseVolume);
}

// Set dose engine from UI if not specified in plan
if (!planNode->GetDoseEngineName())
{
@@ -981,6 +971,12 @@ void qSlicerExternalBeamPlanningModuleWidget::calculateDoseClicked()
qCritical() << Q_FUNC_INFO << ": Invalid scene";
return;
}
vtkMRMLSubjectHierarchyNode* shNode = vtkMRMLSubjectHierarchyNode::GetSubjectHierarchyNode(this->mrmlScene());
if (!shNode)
{
qCritical() << Q_FUNC_INFO << ": Failed to access subject hierarchy node";
return;
}

vtkMRMLRTPlanNode* planNode = vtkMRMLRTPlanNode::SafeDownCast(d->MRMLNodeComboBox_RtPlan->currentNode());
if (!planNode)
@@ -991,6 +987,32 @@ void qSlicerExternalBeamPlanningModuleWidget::calculateDoseClicked()
return;
}

// Create and select output dose volume if missing
if (!planNode->GetOutputTotalDoseVolumeNode())
{
vtkIdType planShItemID = shNode->GetItemByDataNode(planNode);
if (!planShItemID)
{
qCritical() << Q_FUNC_INFO << ": Invalid subject hierarchy item for plan " << planNode->GetName();
return;
}
vtkSmartPointer<vtkMRMLScalarVolumeNode> newDoseVolume = vtkSmartPointer<vtkMRMLScalarVolumeNode>::New();
std::string newDoseVolumeName = std::string(planNode->GetName()) + "_TotalDose";
newDoseVolume->SetName(newDoseVolumeName.c_str());
this->mrmlScene()->AddNode(newDoseVolume);

// Move total dose volume under study (same branch as plan)
shNode->SetItemParent(shNode->GetItemByDataNode(newDoseVolume), shNode->GetItemParent(planShItemID));

// Set volume to plan
planNode->SetAndObserveOutputTotalDoseVolumeNode(newDoseVolume);

// Set also on UI
bool wasBlocked = d->MRMLNodeComboBox_DoseVolume->blockSignals(true);
d->MRMLNodeComboBox_DoseVolume->setCurrentNode(newDoseVolume);
d->MRMLNodeComboBox_DoseVolume->blockSignals(wasBlocked);
}

// Start timer
QTime time;
time.start();

0 comments on commit 7664806

Please sign in to comment.