From 8817de457e49c8ae342373a248afa629729b51eb Mon Sep 17 00:00:00 2001 From: chriscyyeung Date: Tue, 14 Sep 2021 17:13:34 -0400 Subject: [PATCH] Re #1: Add auto-update function --- MarkupToModel/MarkupToModel.py | 20 +++++++++++++++- MarkupToModel/Resources/UI/MarkupToModel.ui | 22 ++++++++++++++---- .../__pycache__/MarkupToModel.cpython-36.pyc | Bin 12092 -> 12713 bytes 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/MarkupToModel/MarkupToModel.py b/MarkupToModel/MarkupToModel.py index 74b8e61..1ed8150 100644 --- a/MarkupToModel/MarkupToModel.py +++ b/MarkupToModel/MarkupToModel.py @@ -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) @@ -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. diff --git a/MarkupToModel/Resources/UI/MarkupToModel.ui b/MarkupToModel/Resources/UI/MarkupToModel.ui index 91a3c6b..6488039 100644 --- a/MarkupToModel/Resources/UI/MarkupToModel.ui +++ b/MarkupToModel/Resources/UI/MarkupToModel.ui @@ -6,8 +6,8 @@ 0 0 - 270 - 159 + 274 + 191 @@ -67,14 +67,14 @@ - + Opacity: - + 0.010000000000000 @@ -90,6 +90,20 @@ + + + + Enable auto-udpate + + + + + + + + + + diff --git a/MarkupToModel/__pycache__/MarkupToModel.cpython-36.pyc b/MarkupToModel/__pycache__/MarkupToModel.cpython-36.pyc index d740ba3fd2501645c39dcedde394ef0edd163ae4..bda12e3bb706f1b3215a2c24ccad2819cda132f6 100644 GIT binary patch delta 1470 zcmah|O>7%Q6yCS?+M9J8JL{j=&Y#`<5UV5+Ed?YLsFS8@OYQtLO_6C59M3kf<9MU- zCTf#N6-o{u5IIaGBsjHdD4g2Lih4nUQ!fZ4E*usKkdOcg2@scFIPl&kO$9x$tNG@e z@4b05``+8nWFKERH!R@R0}khQZ8RGOK5K}vVoA(7HU^>NKF!>?kt@$O0H-jwEI z4#qd7azi;$4l@N=>y`|XqqL#oLDqhtbZki=F*nBZuFr@!J0s$}?~HiQpH1b~{g%0~ zP%&8FylGa_>;7V;R9t$zOn26Q^Y_D;ZqC;XzGkp&fiJDDTQ{qt)xvzm$Q;^4OJJ@ui8+$onp=lPXi^&8suG1LuJDyT z;1N54ui%E53BK!o4IRZ$u*ItwRmBlmS~4L@j{~HIk@R=qC5OE z+GaK*qw2pTU{OTdCK6Y1$A9~Qj#5Cp)i$iixm;Qofq}@dmmHrX$PtVY zTqJmf;3NTcEvIrj9mR)ZZRHl;DyF=QG+O_&=P!Vw`01H< z;I>%qdl44vyM5sHZKJjH08`4}5ci+m0ZU~1O=TC=s@Ur{eYYvl#{|0+?bt1(m#GRW z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