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

Source Code for Module SlicerVMTKLevelSet.SlicerVMTKInitializationCollidingFrontsGUI

  1  from SlicerVMTKAdvancedPageSkeleton import SlicerVMTKAdvancedPageSkeleton 
  2  from Slicer import slicer 
  3   
  4  vtkKWPushButton_InvokedEvent = 10000 
  5  vtkKWExtent_EndChangeEvent = 10002 
  6   
  7  ### 
  8  ### colliding fronts page (derived from skeleton) 
  9  ### 
10 -class SlicerVMTKInitializationCollidingFrontsGUI(SlicerVMTKAdvancedPageSkeleton):
11
12 - def __init__(self,parentFrame,parentClass):
13 SlicerVMTKAdvancedPageSkeleton.__init__(self,parentFrame,parentClass) 14 15 self._firstRowFrame = slicer.vtkKWFrame() 16 self._addSourcePointButton = slicer.vtkKWPushButton() 17 self._addTargetPointButton = slicer.vtkKWPushButton() 18 self._secondRowFrame = slicer.vtkKWFrame() 19 self._thresholdFrame = slicer.vtkKWFrameWithLabel() 20 self._thresholdSlider = slicer.vtkKWExtent() 21 self._startButton = slicer.vtkKWPushButton() 22 self._resetButton = slicer.vtkKWPushButton() 23 24 self._sourceFiducialList = None 25 self._targetFiducialList = None 26 27 28 self._state = 0
29
30 - def Destructor(self):
31 SlicerVMTKAdvancedPageSkeleton.Destructor(self) 32 33 self._firstRowFrame.SetParent(None) 34 self._firstRowFrame = None 35 self._addSourcePointButton.SetParent(None) 36 self._addSourcePointButton = None 37 self._addTargetPointButton.SetParent(None) 38 self._addTargetPointButton = None 39 self._secondRowFrame.SetParent(None) 40 self._secondRowFrame = None 41 self._thresholdFrame.SetParent(None) 42 self._thresholdFrame = None 43 self._thresholdSlider.SetParent(None) 44 self._thresholdSlider = None 45 self._startButton.SetParent(None) 46 self._startButton = None 47 self._resetButton.SetParent(None) 48 self._resetButton = None 49 50 self._sourceFiducialList = None 51 self._targetFiducialList = None 52 self._state = None
53
54 - def AddGUIObservers(self):
55 SlicerVMTKAdvancedPageSkeleton.AddGUIObservers(self) 56 57 self._addSourcePointButtonTag = self._parentClass.AddObserverByNumber(self._addSourcePointButton,vtkKWPushButton_InvokedEvent) 58 59 self._addTargetPointButtonTag = self._parentClass.AddObserverByNumber(self._addTargetPointButton,vtkKWPushButton_InvokedEvent) 60 61 self._thresholdSliderTag = self._parentClass.AddObserverByNumber(self._thresholdSlider, vtkKWExtent_EndChangeEvent) 62 63 self._startButtonTag = self._parentClass.AddObserverByNumber(self._startButton,vtkKWPushButton_InvokedEvent) 64 65 self._resetButtonTag = self._parentClass.AddObserverByNumber(self._resetButton,vtkKWPushButton_InvokedEvent)
66
67 - def RemoveGUIObservers(self):
68 SlicerVMTKAdvancedPageSkeleton.RemoveGUIObservers(self) 69 70 self._parentClass.RemoveObserver(self._addSourcePointButtonTag) 71 72 self._parentClass.RemoveObserver(self._addTargetPointButtonTag) 73 74 self._parentClass.RemoveObserver(self._thresholdSliderTag) 75 76 self._parentClass.RemoveObserver(self._startButtonTag) 77 self._parentClass.RemoveObserver(self._resetButtonTag)
78 79
80 - def UpdateMRML(self):
81 SlicerVMTKAdvancedPageSkeleton.UpdateMRML(self) 82 83 node = self._parentClass.GetScriptedModuleNode() 84 85 if self._sourceFiducialList != None: 86 node.SetParameter('CF_sourceFiducialList',self._sourceFiducialList.GetID()) 87 else: 88 node.SetParameter('CF_sourceFiducialList',"None") 89 90 if self._targetFiducialList != None: 91 node.SetParameter('CF_targetFiducialList',self._targetFiducialList.GetID()) 92 else: 93 node.SetParameter('CF_targetFiducialList',"None") 94 95 extentValues = self._thresholdSlider.GetExtent() 96 node.SetParameter('CF_lowerThreshold', extentValues[0]) 97 node.SetParameter('CF_higherThreshold', extentValues[1]) 98 node.SetParameter('CF_state', self._state)
99
100 - def UpdateGUI(self):
101 SlicerVMTKAdvancedPageSkeleton.UpdateGUI(self) 102 103 node = self._parentClass.GetScriptedModuleNode() 104 105 self._sourceFiducialList = None 106 self._targetFiducialList = None 107 108 if (node.GetParameter("CF_sourceFiducialList")!="None" and node.GetParameter("CF_sourceFiducialList")): 109 self._sourceFiducialList = self._parentClass.GetLogic().GetMRMLScene().GetNodeByID(node.GetParameter("CF_sourceFiducialList")) 110 111 if (node.GetParameter("CF_targetFiducialList")!="None" and node.GetParameter("CF_targetFiducialList")): 112 self._targetFiducialList = self._parentClass.GetLogic().GetMRMLScene().GetNodeByID(node.GetParameter("CF_targetFiducialList")) 113 114 self._state = node.GetParameter('CF_state') 115 self.UpdateGUIByState() 116 117 self._parentClass.SetUpdatingOn() 118 self._thresholdSlider.SetExtent(node.GetParameter("CF_lowerThreshold"),node.GetParameter("CF_higherThreshold"),0,100,0,100) 119 self._parentClass.SetUpdatingOff()
120 121 # belongs to UpdateGUI
122 - def UpdateGUIByState(self):
123 124 if self._state == 0: 125 # initial state, no button pressed, everything removed 126 127 self._addSourcePointButton.SetActiveBackgroundColor(0.9,0.9,0.9) 128 self._addSourcePointButton.SetReliefToRaised() 129 self._addSourcePointButton.SetBackgroundColor(0.9,0.9,0.9) 130 self._addSourcePointButton.SetForegroundColor(0.2,0.6,0.2) 131 self._addSourcePointButton.SetText("1. Add Source Point") 132 self._addSourcePointButton.SetWidth(15) 133 self._addSourcePointButton.SetEnabled(1) 134 self._addSourcePointButton.SetBalloonHelpString("Click to add new source point") 135 136 self._addTargetPointButton.SetActiveBackgroundColor(0.9,0.9,0.9) 137 self._addTargetPointButton.SetReliefToRaised() 138 self._addTargetPointButton.SetBackgroundColor(0.9,0.9,0.9) 139 self._addTargetPointButton.SetForegroundColor(0.2,0.2,0.6) 140 self._addTargetPointButton.SetText("2. Add Target Point") 141 self._addTargetPointButton.SetWidth(15) 142 self._addTargetPointButton.SetBalloonHelpString("Click to add new target point") 143 self._addTargetPointButton.SetEnabled(0) 144 145 self._parentClass.SetUpdatingOn() 146 self._thresholdFrame.AllowFrameToCollapseOff() 147 self._thresholdFrame.SetLabelText("Threshold of Gray Values") 148 self._thresholdFrame.SetReliefToSunken() 149 150 inVolumeNode = self._parentClass._inVolumeSelector.GetSelected() 151 152 if inVolumeNode: 153 154 # update min and max 155 imageMaxValue = round(inVolumeNode.GetImageData().ToArray().max(),0) 156 imageMinValue = round(inVolumeNode.GetImageData().ToArray().min(),0) 157 self._parentClass.SetUpdatingOn() 158 self._thresholdSlider.SetExtentRange(imageMinValue, imageMaxValue, 0, 100, 0, 100) 159 self._thresholdSlider.SetExtent(imageMinValue, imageMaxValue, 0, 100, 0, 100) 160 self._parentClass.SetUpdatingOff() 161 162 else: 163 164 self._parentClass.SetUpdatingOn() 165 self._thresholdSlider.SetExtentRange(0, 100, 0, 100, 0, 100) 166 self._thresholdSlider.SetExtent(0, 100, 0, 100, 0, 100) 167 self._parentClass.SetUpdatingOff() 168 169 self._thresholdSlider.SetReliefToSunken() 170 self._thresholdSlider.ZExtentVisibilityOff() 171 self._thresholdSlider.YExtentVisibilityOff() 172 self._thresholdSlider.SetEnabled(1) 173 self._thresholdSlider.GetXRange().SetLabelText("Gray Values of Vessels") 174 #self._thresholdSlider.SetEndCommand(self._parentClass.vtkScriptedModuleGUI, "Invoke CF_ExtentUpdate") 175 self._parentClass.SetUpdatingOff() 176 177 self._startButton.SetEnabled(0) 178 self._startButton.SetActiveBackgroundColor(0.9,0.9,0.9) 179 self._startButton.SetReliefToRaised() 180 self._startButton.SetBackgroundColor(0.9,0.9,0.9) 181 self._startButton.SetText("Start!") 182 self._startButton.SetWidth(8) 183 self._startButton.SetHeight(2) 184 self._startButton.SetBalloonHelpString("Click to start") 185 186 self._resetButton.SetEnabled(1) 187 self._resetButton.SetActiveBackgroundColor(0.9,0.9,0.9) 188 self._resetButton.SetReliefToRaised() 189 self._resetButton.SetBackgroundColor(0.9,0.9,0.9) 190 self._resetButton.SetText("Cancel") 191 self._resetButton.SetWidth(8) 192 self._resetButton.SetHeight(2) 193 self._resetButton.SetBalloonHelpString("Click to reset") 194 195 196 elif self._state == 1: 197 198 self._state = 0 199 self.UpdateGUIByState() 200 self._state = 1 201 202 # source button pressed before 203 self._addSourcePointButton.SetActiveBackgroundColor(0.9,0.9,0.9) 204 self._addSourcePointButton.SetReliefToRaised() 205 self._addSourcePointButton.SetBackgroundColor(0.9,0.9,0.9) 206 self._addSourcePointButton.SetForegroundColor(0.2,0.6,0.2) 207 self._addSourcePointButton.SetText("Source point added!") 208 self._addSourcePointButton.SetWidth(15) 209 self._addSourcePointButton.SetBalloonHelpString("No other source point needed") 210 self._addSourcePointButton.SetEnabled(0) 211 self._addTargetPointButton.SetEnabled(1) 212 self._startButton.SetEnabled(0) 213 self._resetButton.SetEnabled(1) 214 self._parentClass.SetUpdatingOn() 215 self._thresholdSlider.SetEnabled(1) 216 self._parentClass.SetUpdatingOff() 217 218 elif self._state == 2: 219 220 self._state = 1 221 self.UpdateGUIByState() 222 self._state = 2 223 224 # target button pressed before 225 self._addTargetPointButton.SetActiveBackgroundColor(0.9,0.9,0.9) 226 self._addTargetPointButton.SetReliefToRaised() 227 self._addTargetPointButton.SetBackgroundColor(0.9,0.9,0.9) 228 self._addTargetPointButton.SetForegroundColor(0.2,0.2,0.6) 229 self._addTargetPointButton.SetActiveForegroundColor(0.1,0.1,0.1) 230 self._addTargetPointButton.SetText("Target point added!") 231 self._addTargetPointButton.SetWidth(15) 232 self._addTargetPointButton.SetBalloonHelpString("No other target point needed") 233 self._addTargetPointButton.SetEnabled(0) 234 self._addSourcePointButton.SetEnabled(0) 235 self._startButton.SetEnabled(1) 236 self._resetButton.SetEnabled(1) 237 self._parentClass.SetUpdatingOn() 238 self._thresholdSlider.SetEnabled(1) 239 self._parentClass.SetUpdatingOff()
240 241 # 242 # if which == 1, delete only source 243 # if which == 2, delete only target 244 # else delete both 245 #
246 - def DeleteFiducialListsFromScene(self,which):
247 SlicerVMTKAdvancedPageSkeleton.DeleteFiducialListsFromScene(self,which) 248 249 node = self._parentClass.GetScriptedModuleNode() 250 251 if node: 252 253 scene = self._parentClass.GetLogic().GetMRMLScene() 254 255 if (which!=2): 256 257 if self._sourceFiducialList!=None: 258 if scene.IsNodePresent(self._sourceFiducialList): 259 # node is in scene, now delete 260 scene.RemoveNode(self._sourceFiducialList) 261 self._sourceFiducialList = None 262 263 if (which!=1): 264 265 if self._targetFiducialList!=None: 266 if scene.IsNodePresent(self._targetFiducialList): 267 # node is in scene, now delete 268 scene.RemoveNode(self._targetFiducialList) 269 self._targetFiducialList = None
270 271 272
273 - def ProcessGUIEvents(self,caller,event):
274 SlicerVMTKAdvancedPageSkeleton.ProcessGUIEvents(self,caller,event) 275 276 if caller == self._addSourcePointButton and event == vtkKWPushButton_InvokedEvent: 277 if self._parentClass.GetHelper().GetIsInteractiveMode() == 0: 278 self.InitAddSourcePoint() 279 elif self._parentClass.GetHelper().GetIsInteractiveMode() == 1: 280 self.TeardownAddSourcePoint() 281 282 elif caller == self._addTargetPointButton and event == vtkKWPushButton_InvokedEvent: 283 if self._parentClass.GetHelper().GetIsInteractiveMode() == 0: 284 self.InitAddTargetPoint() 285 elif self._parentClass.GetHelper().GetIsInteractiveMode() == 1: 286 self.TeardownAddTargetPoint() 287 288 elif caller == self._startButton and event == vtkKWPushButton_InvokedEvent: 289 self.Execute() 290 self._parentClass.UpdateMRML() 291 elif caller == self._resetButton and event == vtkKWPushButton_InvokedEvent: 292 self.DeleteFiducialListsFromScene(0) 293 self.Reset() 294 self._parentClass.UpdateMRML() 295 elif caller == self._thresholdSlider and event == vtkKWExtent_EndChangeEvent: 296 self._parentClass.UpdateMRML()
297
298 - def InitAddSourcePoint(self):
299 300 scene = self._parentClass.GetLogic().GetMRMLScene() 301 302 if self._sourceFiducialList == None: 303 304 # no list created yet 305 self._sourceFiducialList = slicer.vtkMRMLFiducialListNode() 306 self._sourceFiducialList.SetName("VMTK Colliding Fronts Source Points") 307 self._sourceFiducialList.SetScene(scene) 308 self._sourceFiducialList.SetColor(0.2,0.6,0.2) 309 self._sourceFiducialList.SetGlyphTypeFromString("Circle2D") 310 self._sourceFiducialList.SetLocked(1) 311 scene.AddNode(self._sourceFiducialList) 312 313 #change the button appeareance 314 self._addSourcePointButton.SetActiveBackgroundColor(0.2,0.6,0.2) 315 self._addSourcePointButton.SetReliefToSunken() 316 self._addSourcePointButton.SetBackgroundColor(0.2,0.6,0.2) 317 self._addSourcePointButton.SetForegroundColor(0.2,0.2,0.2) 318 self._addSourcePointButton.SetText("Click into slice") 319 self._addSourcePointButton.SetWidth(15) 320 321 self._parentClass.UnLockInitInterface(0) 322 self._addTargetPointButton.SetEnabled(0) 323 self._thresholdSlider.SetEnabled(0) 324 self._startButton.SetEnabled(0) 325 self._resetButton.SetEnabled(0) 326 327 self._currentFiducialList = self._sourceFiducialList 328 self._currentFiducialListLabel = "SP" 329 self._parentClass.GetHelper().SetIsInteractiveMode(1,self)
330
331 - def TeardownAddSourcePoint(self):
332 333 self._currentFiducialList = None 334 self._currentFiducialListLabel = None 335 self._parentClass.GetHelper().SetIsInteractiveMode(0,None) 336 337 self.DeleteFiducialListsFromScene(1) 338 339 self._parentClass.UnLockInitInterface(1) 340 self._state = 0 341 self.UpdateGUIByState()
342
343 - def InitAddTargetPoint(self):
344 scene = self._parentClass.GetLogic().GetMRMLScene() 345 346 if self._targetFiducialList == None: 347 348 # no list created yet 349 self._targetFiducialList = slicer.vtkMRMLFiducialListNode() 350 self._targetFiducialList.SetName("VMTK Colliding Fronts Target Points") 351 self._targetFiducialList.SetScene(scene) 352 self._targetFiducialList.SetColor(0.2,0.2,0.6) 353 self._targetFiducialList.SetGlyphTypeFromString("Circle2D") 354 self._targetFiducialList.SetLocked(1) 355 scene.AddNode(self._targetFiducialList) 356 357 #change the button appeareance 358 self._addTargetPointButton.SetActiveBackgroundColor(0.2,0.2,0.6) 359 self._addTargetPointButton.SetReliefToSunken() 360 self._addTargetPointButton.SetBackgroundColor(0.2,0.2,0.6) 361 self._addTargetPointButton.SetForegroundColor(0.7,0.7,0.7) 362 self._addTargetPointButton.SetActiveForegroundColor(0.7,0.7,0.7) 363 self._addTargetPointButton.SetText("Click into slice") 364 self._addTargetPointButton.SetWidth(15) 365 366 self._parentClass.UnLockInitInterface(0) 367 self._addSourcePointButton.SetEnabled(0) 368 self._thresholdSlider.SetEnabled(0) 369 self._startButton.SetEnabled(0) 370 self._resetButton.SetEnabled(0) 371 372 self._currentFiducialList = self._targetFiducialList 373 self._currentFiducialListLabel = "TP" 374 self._parentClass.GetHelper().SetIsInteractiveMode(1,self)
375
376 - def TeardownAddTargetPoint(self):
377 378 self._currentFiducialList = None 379 self._currentFiducialListLabel = None 380 self._parentClass.GetHelper().SetIsInteractiveMode(0,None) 381 382 self.DeleteFiducialListsFromScene(2) 383 384 self._parentClass.UnLockInitInterface(1) 385 self._state = 1 386 self.UpdateGUIByState()
387 388 389 # 390 # x,y 391 # which is the Name of the SliceWindow (Red,Yellow,Green) 392 #
393 - def HandleClickInSliceWindowWithCoordinates(self, which, coordinates):
394 SlicerVMTKAdvancedPageSkeleton.HandleClickInSliceWindowWithCoordinates(self, which, coordinates) 395 396 coordinatesRAS = self._parentClass.GetHelper().ConvertCoordinates2RAS(which,coordinates) 397 fiducial = self._currentFiducialList.AddFiducialWithXYZ(coordinatesRAS[0], coordinatesRAS[1], coordinatesRAS[2],0) 398 399 self._currentFiducialList.SetNthFiducialLabelText(fiducial, self._currentFiducialListLabel+str(fiducial)) 400 self._parentClass.GetHelper().debug("Fiducial Added! Only one needed!") 401 402 self._parentClass.GetHelper().SetIsInteractiveMode(0,None) 403 404 if self._currentFiducialListLabel == "SP": 405 406 # one fiducial added to source points 407 # disable source point button 408 409 #re-change the button appeareance 410 self._state = 1 411 self.UpdateGUIByState() 412 413 self._parentClass.UpdateMRML() 414 415 elif self._currentFiducialListLabel == "TP": 416 417 # one fiducial added to target points 418 # disable target point button 419 420 #re-change the button appeareance 421 self._state = 2 422 self.UpdateGUIByState() 423 424 self._parentClass.UpdateMRML()
425
426 - def BuildGUI(self):
427 SlicerVMTKAdvancedPageSkeleton.BuildGUI(self) 428 429 self._firstRowFrame.SetParent(self._parentFrame) 430 self._firstRowFrame.Create() 431 432 self._addSourcePointButton.SetParent(self._firstRowFrame) 433 self._addSourcePointButton.Create() 434 435 self._addTargetPointButton.SetParent(self._firstRowFrame) 436 self._addTargetPointButton.Create() 437 438 self._secondRowFrame.SetParent(self._parentFrame) 439 self._secondRowFrame.Create() 440 441 self._thresholdFrame.SetParent(self._parentFrame) 442 self._thresholdFrame.Create() 443 444 self._thresholdSlider.SetParent(self._thresholdFrame.GetFrame()) 445 self._thresholdSlider.Create() 446 447 self._startButton.SetParent(self._parentFrame) 448 self._startButton.Create() 449 450 self._resetButton.SetParent(self._parentFrame) 451 self._resetButton.Create() 452 453 self.UpdateGUIByState() 454 455 456 slicer.TkCall("pack %s -side top -expand y -padx 2 -pady 2 -in %s" % (self._firstRowFrame.GetWidgetName(), self._parentFrame.GetWidgetName())) 457 slicer.TkCall("pack %s -side top -expand y -padx 2 -pady 2 -in %s" % (self._secondRowFrame.GetWidgetName(), self._parentFrame.GetWidgetName())) 458 459 slicer.TkCall("pack %s -side top -expand n -padx 2 -pady 2" % (self._addSourcePointButton.GetWidgetName())) 460 slicer.TkCall("pack %s -side top -expand n -padx 2 -pady 2" % (self._addTargetPointButton.GetWidgetName())) 461 slicer.TkCall("pack %s -side left -expand y -padx 2 -pady 2 -in %s" % (self._thresholdFrame.GetWidgetName(), self._secondRowFrame.GetWidgetName())) 462 slicer.TkCall("pack %s -side top -expand n -padx 2 -pady 2" % (self._thresholdSlider.GetWidgetName())) 463 464 slicer.TkCall("pack %s -side right -expand n -padx 2 -pady 2 -in %s" % (self._startButton.GetWidgetName(), self._parentFrame.GetWidgetName())) 465 slicer.TkCall("pack %s -side right -expand n -padx 2 -pady 2 -in %s" % (self._resetButton.GetWidgetName(), self._parentFrame.GetWidgetName()))
466 467
468 - def Execute(self):
469 470 self._parentClass.SetUpdatingOn() 471 472 extentValues = self._thresholdSlider.GetExtent() 473 inVolumeNode = self._parentClass._inVolumeSelector.GetSelected() 474 lowerThreshold = extentValues[0] 475 higherThreshold = extentValues[1] 476 sourceSeedsNode = self._sourceFiducialList 477 targetSeedsNode = self._targetFiducialList 478 479 myLogic = self._parentClass.GetMyLogic() 480 resultContainer = myLogic.ExecuteCollidingFronts(inVolumeNode,lowerThreshold,higherThreshold,sourceSeedsNode,targetSeedsNode) 481 resultContainer = self._parentClass.GetHelper().SetAndMergeInitVolume(resultContainer) 482 self._parentClass.GetHelper().GenerateInitializationModel(resultContainer) 483 484 self._parentClass.SetUpdatingOff() 485 self._parentClass._state = 1 486 self._parentClass.UpdateGUIByState() 487 self._parentClass.UpdateMRML() # save the results
488 489 490
491 - def Reset(self):
492 SlicerVMTKAdvancedPageSkeleton.Reset(self) 493 494 self._sourceFiducialList = None 495 self._targetFiducialList = None 496 497 self._state = 0 498 self.UpdateGUIByState()
499