Skip to content

Commit

Permalink
Re #1: Add auto-update function
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscyyeung committed Sep 14, 2021
1 parent d510366 commit 8817de4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
20 changes: 19 additions & 1 deletion MarkupToModel/MarkupToModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def setup(self):
self.ui.outputSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.updateParameterNodeFromGUI)
self.ui.opacitySlider.connect("valueChanged(double)", self.updateParameterNodeFromGUI)

self.observedMarkupNode = None
self.markupsObserverTag = None
self.ui.autoUpdateCheckBox.connect("toggled(bool)", self.onEnableAutoUpdate)

# Buttons
self.ui.applyButton.connect('clicked(bool)', self.onApplyButton)

Expand Down Expand Up @@ -236,10 +240,24 @@ def updateParameterNodeFromGUI(self, caller=None, event=None):

self._parameterNode.SetNodeReferenceID("InputVolume", self.ui.inputSelector.currentNodeID)
self._parameterNode.SetNodeReferenceID("OutputVolume", self.ui.outputSelector.currentNodeID)
self.ui.outputSelector.currentNode().GetDisplayNode().SetOpacity(self.ui.opacitySlider.value) #TODO: bugged
self.ui.outputSelector.currentNode().GetDisplayNode().SetOpacity(self.ui.opacitySlider.value)

self._parameterNode.EndModify(wasModified)

def onEnableAutoUpdate(self, autoUpdate):
if self.markupsObserverTag:
self.observedMarkupNode.RemoveObserver(self.markupsObserverTag)
self.observedMarkupNode = None
self.markupsObserverTag = None
if autoUpdate and self.ui.inputSelector.currentNode:
self.observedMarkupNode = self.ui.inputSelector.currentNode()
self.markupsObserverTag = self.observedMarkupNode.AddObserver(
slicer.vtkMRMLMarkupsNode.PointModifiedEvent, self.onMarkupsUpdated
)

def onMarkupsUpdated(self, caller=None, event=None):
self.onApplyButton()

def onApplyButton(self):
"""
Run processing when user clicks "Apply" button.
Expand Down
22 changes: 18 additions & 4 deletions MarkupToModel/Resources/UI/MarkupToModel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>270</width>
<height>159</height>
<width>274</width>
<height>191</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -67,14 +67,14 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Opacity:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="qMRMLSliderWidget" name="opacitySlider">
<property name="singleStep">
<double>0.010000000000000</double>
Expand All @@ -90,6 +90,20 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Enable auto-udpate</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="autoUpdateCheckBox">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Binary file modified MarkupToModel/__pycache__/MarkupToModel.cpython-36.pyc
Binary file not shown.

0 comments on commit 8817de4

Please sign in to comment.