Package SlicerVMTKLevelSet :: Module SlicerVMTKEvolutionCurvesGUI
[hide private]
[frames] | no frames]

Source Code for Module SlicerVMTKLevelSet.SlicerVMTKEvolutionCurvesGUI

  1  from SlicerVMTKAdvancedPageSkeleton import SlicerVMTKAdvancedPageSkeleton 
  2  from Slicer import slicer 
  3   
  4  vtkKWPushButton_InvokedEvent = 10000 
  5   
  6  ### 
  7  ### curves evolution (derived from skeleton) 
  8  ### 
9 -class SlicerVMTKEvolutionCurvesGUI(SlicerVMTKAdvancedPageSkeleton):
10
11 - def __init__(self,parentFrame,parentClass):
12 SlicerVMTKAdvancedPageSkeleton.__init__(self,parentFrame,parentClass) 13 14 self._iterationsThumbwheel = slicer.vtkKWThumbWheel() 15 self._weightsFrame = slicer.vtkKWFrameWithLabel() 16 self._propagationScalingSpinBox = slicer.vtkKWSpinBoxWithLabel() 17 self._curvatureScalingSpinBox = slicer.vtkKWSpinBoxWithLabel() 18 self._advectionScalingSpinBox = slicer.vtkKWSpinBoxWithLabel() 19 self._startButton = slicer.vtkKWPushButton() 20 self._resetButton = slicer.vtkKWPushButton()
21
22 - def Destructor(self):
23 SlicerVMTKAdvancedPageSkeleton.Destructor(self) 24 25 self._iterationsThumbwheel.SetParent(None) 26 self._iterationsThumbwheel = None 27 self._weightsFrame.SetParent(None) 28 self._weightsFrame = None 29 self._propagationScalingSpinBox.SetParent(None) 30 self._propagationScalingSpinBox = None 31 self._curvatureScalingSpinBox.SetParent(None) 32 self._curvatureScalingSpinBox = None 33 self._advectionScalingSpinBox.SetParent(None) 34 self._advectionScalingSpinBox = None 35 self._startButton.SetParent(None) 36 self._startButton = None 37 self._resetButton.SetParent(None) 38 self._resetButton = None
39
40 - def AddGUIObservers(self):
41 self._startButtonTag = self._parentClass.AddObserverByNumber(self._startButton,vtkKWPushButton_InvokedEvent) 42 43 self._resetButtonTag = self._parentClass.AddObserverByNumber(self._resetButton,vtkKWPushButton_InvokedEvent)
44 45
46 - def RemoveGUIObservers(self):
47 48 self._parentClass.RemoveObserver(self._startButtonTag) 49 self._parentClass.RemoveObserver(self._resetButtonTag)
50
51 - def ProcessGUIEvents(self,caller,event):
52 if caller == self._startButton and event == vtkKWPushButton_InvokedEvent: 53 self.Execute() 54 self._parentClass.UpdateMRML() 55 elif caller == self._resetButton and event == vtkKWPushButton_InvokedEvent: 56 self.Reset() 57 self._parentClass.UpdateMRML()
58
59 - def UpdateMRML(self):
60 node = self._parentClass.GetScriptedModuleNode() 61 62 if node: 63 64 node.SetParameter('CURVES_iterations',self._iterationsThumbwheel.GetValue()) 65 node.SetParameter('CURVES_propagationScaling',self._propagationScalingSpinBox.GetWidget().GetValue()) 66 node.SetParameter('CURVES_curvatureScaling',self._curvatureScalingSpinBox.GetWidget().GetValue()) 67 node.SetParameter('CURVES_advectionScaling',self._advectionScaling.GetWidget().GetValue())
68
69 - def UpdateGUI(self):
70 71 node = self._parentClass.GetScriptedModuleNode() 72 73 if node: 74 75 if node.GetParameter('CURVES_iterations'): 76 self._iterationsThumbwheel.SetValue(node.GetParameter('CURVES_iterations')) 77 78 if node.GetParameter('CURVES_propagationScaling'): 79 self._propagationScalingSpinBox.GetWidget().SetValue(node.GetParameter('CURVES_propagationScaling')) 80 81 if node.GetParameter('CURVES_curvatureScaling'): 82 self._curvatureScalingSpinBox.GetWidget().SetValue(node.GetParameter('CURVES_curvatureScaling')) 83 84 if node.GetParameter('CURVES_advectionScaling'): 85 self._advectionScalingSpinBox.GetWidget().SetValue(node.GetParameter('CURVES_advectionScaling'))
86
87 - def BuildGUI(self):
88 SlicerVMTKAdvancedPageSkeleton.BuildGUI(self) 89 90 self._iterationsThumbwheel.SetParent(self._parentFrame) 91 self._iterationsThumbwheel.Create() 92 self._iterationsThumbwheel.SetRange(0.0,2000.0) 93 self._iterationsThumbwheel.ClampMinimumValueOn() 94 self._iterationsThumbwheel.ClampMaximumValueOn() 95 self._iterationsThumbwheel.ClampResolutionOn() 96 self._iterationsThumbwheel.SetThumbWheelHeight(10) 97 self._iterationsThumbwheel.SetResolution(1.0) 98 self._iterationsThumbwheel.SetLength(150) 99 self._iterationsThumbwheel.DisplayEntryOn() 100 self._iterationsThumbwheel.DisplayLabelOn() 101 #self._iterationsThumbwheel.DisplayEntryAndLabelOnTopOff() 102 self._iterationsThumbwheel.GetLabel().SetText("Number of iterations") 103 104 slicer.TkCall("pack %s -side top -expand y -padx 2 -pady 10" % self._iterationsThumbwheel.GetWidgetName()) 105 106 self._weightsFrame.SetParent(self._parentFrame) 107 self._weightsFrame.Create() 108 self._weightsFrame.AllowFrameToCollapseOff() 109 self._weightsFrame.SetLabelText("Scaling weights:") 110 self._weightsFrame.SetReliefToSunken() 111 112 slicer.TkCall("pack %s -side top -expand y -padx 2 -pady 10 -in %s" % (self._weightsFrame.GetWidgetName(), self._parentFrame.GetWidgetName())) 113 114 self._propagationScalingSpinBox.SetParent(self._weightsFrame.GetFrame()) 115 self._propagationScalingSpinBox.Create() 116 self._propagationScalingSpinBox.GetWidget().SetRange(0.0,10.0) 117 self._propagationScalingSpinBox.GetWidget().SetIncrement(0.1) 118 self._propagationScalingSpinBox.GetWidget().SetWidth(5) 119 self._propagationScalingSpinBox.GetWidget().SetValueFormat("%.1f") 120 self._propagationScalingSpinBox.SetLabelText("Propagation scaling:") 121 self._propagationScalingSpinBox.SetBalloonHelpString("Propagation scaling is the weight you assign to model inflation.") 122 123 slicer.TkCall("pack %s -side top -anchor e -expand y -padx 2 -pady 2" % self._propagationScalingSpinBox.GetWidgetName()) 124 125 self._curvatureScalingSpinBox.SetParent(self._weightsFrame.GetFrame()) 126 self._curvatureScalingSpinBox.Create() 127 self._curvatureScalingSpinBox.GetWidget().SetRange(0.0,10.0) 128 self._curvatureScalingSpinBox.GetWidget().SetIncrement(0.1) 129 self._curvatureScalingSpinBox.GetWidget().SetWidth(5) 130 self._curvatureScalingSpinBox.GetWidget().SetValueFormat("%.1f") 131 self._curvatureScalingSpinBox.SetLabelText("Curvature scaling:") 132 self._curvatureScalingSpinBox.SetBalloonHelpString("Curvature scaling is the weight you assign to model surface regularization (this will eventually make the model collapse and vanish if it's too strong)") 133 134 slicer.TkCall("pack %s -side top -anchor e -expand y -padx 2 -pady 2" % self._curvatureScalingSpinBox.GetWidgetName()) 135 136 self._advectionScalingSpinBox.SetParent(self._weightsFrame.GetFrame()) 137 self._advectionScalingSpinBox.Create() 138 self._advectionScalingSpinBox.GetWidget().SetRange(0.0,10.0) 139 self._advectionScalingSpinBox.GetWidget().SetIncrement(0.1) 140 self._advectionScalingSpinBox.GetWidget().SetWidth(5) 141 self._advectionScalingSpinBox.GetWidget().SetValueFormat("%.1f") 142 self._advectionScalingSpinBox.SetLabelText("Advection scaling:") 143 self._advectionScalingSpinBox.SetBalloonHelpString("Advection scaling is the most important weight. It regulates the attraction of the surface of the image gradient modulus ridges, which is ultimately what you want.") 144 145 slicer.TkCall("pack %s -side top -anchor e -expand y -padx 2 -pady 2" % self._advectionScalingSpinBox.GetWidgetName()) 146 147 self._startButton.SetParent(self._parentFrame) 148 self._startButton.Create() 149 self._startButton.SetEnabled(1) 150 self._startButton.SetActiveBackgroundColor(0.9,0.9,0.9) 151 self._startButton.SetReliefToRaised() 152 self._startButton.SetBackgroundColor(0.9,0.9,0.9) 153 self._startButton.SetText("Start!") 154 self._startButton.SetWidth(8) 155 self._startButton.SetHeight(2) 156 self._startButton.SetBalloonHelpString("Click to start") 157 158 self._resetButton.SetParent(self._parentFrame) 159 self._resetButton.Create() 160 self._resetButton.SetEnabled(1) 161 self._resetButton.SetActiveBackgroundColor(0.9,0.9,0.9) 162 self._resetButton.SetReliefToRaised() 163 self._resetButton.SetBackgroundColor(0.9,0.9,0.9) 164 self._resetButton.SetText("Cancel") 165 self._resetButton.SetWidth(8) 166 self._resetButton.SetHeight(2) 167 self._resetButton.SetBalloonHelpString("Click to reset") 168 169 170 slicer.TkCall("pack %s -side right -expand n -padx 2 -pady 5 -in %s" % (self._startButton.GetWidgetName(), self._parentFrame.GetWidgetName())) 171 slicer.TkCall("pack %s -side right -expand n -padx 2 -pady 5 -in %s" % (self._resetButton.GetWidgetName(), self._parentFrame.GetWidgetName())) 172 173 self.Reset()
174
175 - def Execute(self):
176 177 scene = self._parentClass.GetLogic().GetMRMLScene() 178 179 origInVolumeNode = self._parentClass._inVolumeSelector.GetSelected() 180 inVolumeNode = self._parentClass._outInitVolume 181 numberOfIterations = int(self._iterationsThumbwheel.GetValue()) 182 propagationScaling = float(self._propagationScalingSpinBox.GetWidget().GetValue()) 183 curvatureScaling = float(self._curvatureScalingSpinBox.GetWidget().GetValue()) 184 advectionScaling = float(self._advectionScalingSpinBox.GetWidget().GetValue()) 185 186 self._parentClass.SetUpdatingOn() 187 188 myLogic = self._parentClass.GetMyLogic() 189 resultContainer = myLogic.ExecuteCurves(origInVolumeNode,inVolumeNode,numberOfIterations,propagationScaling,curvatureScaling,advectionScaling) 190 resultContainer = self._parentClass.GetHelper().SetAndMergeEvolVolume(resultContainer) 191 self._parentClass.GetHelper().GenerateEvolutionModel(resultContainer) 192 193 self._parentClass.SetUpdatingOff() 194 195 self._parentClass._state = 4 196 self._parentClass.UpdateGUIByState() 197 self._parentClass.UpdateMRML() # save the results
198
199 - def Reset(self):
200 201 self._iterationsThumbwheel.SetValue(300) 202 self._propagationScalingSpinBox.GetWidget().SetValue(0.0) 203 self._curvatureScalingSpinBox.GetWidget().SetValue(0.0) 204 self._advectionScalingSpinBox.GetWidget().SetValue(1.0)
205