/
iGynePy.py
129 lines (106 loc) · 4.88 KB
/
iGynePy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from __main__ import vtk, qt, ctk, slicer
import os.path,time
import iGyneWizard
class iGynePy:
def __init__( self, parent ):
parent.title = "iGyne"
parent.categories = ["Wizards"]
parent.contributors = ["Guillaume Pernelle", "Xiaojun Chen", "Yi Gao", "Tina Kapur", "Jan Egger", "Carolina Vale"]
parent.helpText = "https://github.com/gpernelle/iGyne/wiki";
parent.acknowledgementText = " Version : " + "iGyne v2.0."
self.parent = parent
class iGynePyWidget:
def __init__( self, parent=None ):
if not parent:
self.parent = slicer.qMRMLWidget()
self.parent.setLayout( qt.QVBoxLayout() )
self.parent.setMRMLScene( slicer.mrmlScene )
else:
self.parent = parent
self.layout = self.parent.layout()
# this flag is 1 if there is an update in progress
self.__updating = 1
# the pointer to the logic and the mrmlManager
self.__mrmlManager = None
self.__logic = None
if not parent:
self.setup()
# after setup, be ready for events
self.__updating = 0
self.parent.show()
if slicer.mrmlScene.GetTagByClassName( "vtkMRMLScriptedModuleNode" ) != 'ScriptedModule':
slicer.mrmlScene.RegisterNodeClass(vtkMRMLScriptedModuleNode())
def setup( self ):
'''
Create and start the iGyne workflow.
'''
self.workflow = ctk.ctkWorkflow()
workflowWidget = ctk.ctkWorkflowStackedWidget()
workflowWidget.setWorkflow( self.workflow )
# create all wizard steps
selectProcedureStep = iGyneWizard.iGyneSelectProcedureStep( 'SelectProcedure' )
selectApplicatorStep = iGyneWizard.iGyneSelectApplicatorStep( 'SelectApplicator' )
loadModelStep = iGyneWizard.iGyneLoadModelStep( 'LoadModel' )
firstRegistrationStep = iGyneWizard.iGyneFirstRegistrationStep( 'FirstRegistration' )
secondRegistrationStep = iGyneWizard.iGyneSecondRegistrationStep( 'SecondRegistration' )
needlePlanningStep = iGyneWizard.iGyneNeedlePlanningStep( 'NeedlePlanning' )
needleSegmentationStep = iGyneWizard.iGyneNeedleSegmentationStep( 'NeedleSegmentation' )
# add the wizard steps to an array for convenience
allSteps = []
allSteps.append( selectProcedureStep )
allSteps.append( selectApplicatorStep )
allSteps.append( loadModelStep )
allSteps.append( firstRegistrationStep )
allSteps.append( secondRegistrationStep )
allSteps.append( needlePlanningStep )
allSteps.append( needleSegmentationStep )
self.workflow.addTransition( selectProcedureStep, selectApplicatorStep )
self.workflow.addTransition( selectApplicatorStep, loadModelStep )
self.workflow.addTransition( loadModelStep, firstRegistrationStep )
self.workflow.addTransition( firstRegistrationStep, secondRegistrationStep )
self.workflow.addTransition( secondRegistrationStep, needlePlanningStep )
self.workflow.addTransition( needlePlanningStep, needleSegmentationStep )
self.workflow.addTransition(selectProcedureStep,needleSegmentationStep)
nNodes = slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLScriptedModuleNode')
self.parameterNode = None
for n in xrange(nNodes):
compNode = slicer.mrmlScene.GetNthNodeByClass(n, 'vtkMRMLScriptedModuleNode')
nodeid = None
if compNode.GetModuleName() == 'iGynePy':
self.parameterNode = compNode
print 'Found existing iGyne parameter node'
break
if self.parameterNode == None:
self.parameterNode = slicer.mrmlScene.CreateNodeByClass('vtkMRMLScriptedModuleNode')
self.parameterNode.SetModuleName('iGynePy')
slicer.mrmlScene.AddNode(self.parameterNode)
# Propagate the workflow, the logic and the MRML Manager to the steps
for s in allSteps:
s.setWorkflow( self.workflow )
s.setParameterNode (self.parameterNode)
# restore workflow step
currentStep = self.parameterNode.GetParameter('currentStep')
if currentStep != '':
print 'Restoring workflow step to ', currentStep
if currentStep == 'SelectProcedure':
self.workflow.setInitialStep(selectProcedureStep)
if currentStep == 'SelectApplicator':
self.workflow.setInitialStep(selectApplicatorStep)
if currentStep == 'LoadModel':
self.workflow.setInitialStep(loadModelStep)
if currentStep == 'FirstRegistration':
self.workflow.setInitialStep(firstRegistrationStep)
if currentStep == 'SecondRegistration':
self.workflow.setInitialStep(secondRegistrationStep)
if currentStep == 'NeedlePlanning':
self.workflow.setInitialStep(needlePlanningStep)
if currentStep == 'NeedleSegmentation':
self.workflow.setInitialStep(needleSegmentationStep)
else:
print 'currentStep in parameter node is empty!'
# start the workflow and show the widget
self.workflow.start()
workflowWidget.visible = True
self.layout.addWidget( workflowWidget )
def enter(self):
print "iGyne: enter() called"