1 from SlicerVMTKAdvancedPageSkeleton import SlicerVMTKAdvancedPageSkeleton
2 from Slicer import slicer
3
4 vtkKWPushButton_InvokedEvent = 10000
5 vtkKWExtent_EndChangeEvent = 10002
6
7
8
9
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
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
66
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
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
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
123
124 if self._state == 0:
125
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
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
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
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
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
243
244
245
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
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
268 scene.RemoveNode(self._targetFiducialList)
269 self._targetFiducialList = None
270
271
272
297
299
300 scene = self._parentClass.GetLogic().GetMRMLScene()
301
302 if self._sourceFiducialList == None:
303
304
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
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
342
344 scene = self._parentClass.GetLogic().GetMRMLScene()
345
346 if self._targetFiducialList == None:
347
348
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
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
387
388
389
390
391
392
425
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
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()
488
489
490
499