-
Notifications
You must be signed in to change notification settings - Fork 2
/
4_markups to models.py
155 lines (120 loc) · 6.7 KB
/
4_markups to models.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#MARKUPS TO MODELS
# 1 TYMPANIC MEMBRANE AND EXTRACOLUMELLA
#markups fiducial node
inputMarkups = getNode(ID+'ECandTMmrk_outline')
#create model node
ECTMModel = slicer.mrmlScene.AddNode(slicer.vtkMRMLModelNode())#adding a node to scene
ECTMModel.SetName(ID+'EC_TM_mod')
ECTMModel.CreateDefaultDisplayNodes()
ECTMModel.GetDisplayNode().SetSliceIntersectionVisibility(True)
#ECTMModel.GetDisplayNode().SetColor(0,1,0)
#
##create markups to model node
markupsToModel = slicer.mrmlScene.AddNode(slicer.vtkMRMLMarkupsToModelNode())
markupsToModel.SetAutoUpdateOutput(True)
markupsToModel.SetAndObserveMarkupsNodeID(inputMarkups.GetID())#set input node
markupsToModel.SetAndObserveModelNodeID(ECTMModel.GetID())#set model node (only needed for the first one)
markupsToModel.SetModelType(0)#closed surface
#####check the coverage of the model in 4d view
# CONVERT TO segmentation
modeloutlinenode = slicer.util.getNode(ID+'EC_TM_mod')#create model node from the just created model
slicer.modules.segmentations.logic().ImportModelToSegmentationNode(modeloutlinenode,segmentationNode,"tosegment")
#remove visibility of 'EC_TM_mod' model and
modeloutlinenode.SetDisplayVisibility(0)
#now run the thresholding on the EC_TM_mod area
#create maxent segment, isodata segment, and subtract the two
thresh_EC_TMseg = segmentationNode.GetSegmentation().AddEmptySegment(ID+" ECplusTM")#create new segmentation ID
segmentationNode.GetSegmentation().GetSegment(ID+" ECplusTM").SetColor(1,0,0)
#momentsISODATA-MAXENT THRESHOLD FOR UMBO
segmentEditorNode.SetOverwriteMode(slicer.vtkMRMLSegmentEditorNode.OverwriteNone)
segmentEditorNode.SetMaskMode(slicer.vtkMRMLSegmentEditorNode.PaintAllowedInsideSingleSegment)
segmentEditorNode.SetSelectedSegmentID(ID+" ECplusTM")#
#segmentEditorNode.SetSelectedSegmentID(EC_TM_modthresh)#
segmentEditorNode.SetMaskSegmentID(ID+'EC_TM_mod')
segmentEditorWidget.setActiveEffectByName("Threshold")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("MinimumThreshold", str(ISOval))#str(ISOval)
effect.setParameter("MaximumThreshold",str(Maxentval))
effect.self().onApply()#apply separate
#set mod region segment visibility off
#segmentationDisplayNode.SetSegmentVisibility(ID+'EC_TM_mod',0)
#
# ###########2 RW curve markup to model
#name markups fiducial node
RWmarkup = getNode(ID+" RW")
#create model node
RWmodeloutlinenode = slicer.mrmlScene.AddNode(slicer.vtkMRMLModelNode())#adding a node to scene
RWmodeloutlinenode.SetName(ID+'RW_mod')
RWmodeloutlinenode.CreateDefaultDisplayNodes()
RWmodeloutlinenode.GetDisplayNode().SetSliceIntersectionVisibility(True)
RWmodeloutlinenode.GetDisplayNode().SetColor(1,0,0)
#new markups to model node
markupsToModel2 = slicer.mrmlScene.AddNode(slicer.vtkMRMLMarkupsToModelNode())
markupsToModel2.SetAutoUpdateOutput(True)
markupsToModel2.SetAndObserveMarkupsNodeID(RWmarkup.GetID())#set input node
markupsToModel2.SetAndObserveModelNodeID(RWmodeloutlinenode.GetID())#set model node (only needed for the first one)
markupsToModel2.SetModelType(1)#curve
markupsToModel2.SetTubeRadius(0.2)
markupsToModel2.SetTubeLoop(1)#1 = curve is a loop
markupsToModel2.SetCurveType(2)#polynomial least squares
#markupsToModel.SetAndObserveModelNodeID(outputMode2.GetID())#set model node
#CONVERT RW MODEL TO SEGMENTATION
RWmodeloutlinenode = slicer.util.getNode(ID+'RW_mod')#create model node from the just created model
slicer.modules.segmentations.logic().ImportModelToSegmentationNode(RWmodeloutlinenode,segmentationNode,"tosegment")
#remove visibility of 'RW' model and
RWmodeloutlinenode.SetDisplayVisibility(0)
#MAX ENTROPY THRESHOLD OF RW
RW_modthreshseg = segmentationNode.GetSegmentation().AddEmptySegment(ID+" RW_modthresh")#create new segmentation ID
segmentationNode.GetSegmentation().GetSegment(ID+" RW_modthresh").SetColor(1,1,1)
segmentEditorNode.SetOverwriteMode(slicer.vtkMRMLSegmentEditorNode.OverwriteNone)
segmentEditorNode.SetMaskMode(slicer.vtkMRMLSegmentEditorNode.PaintAllowedInsideSingleSegment)
segmentEditorNode.SetSelectedSegmentID(ID+" RW_modthresh")
segmentEditorNode.SetMaskSegmentID(ID+'RW_mod')
segmentEditorWidget.setActiveEffectByName("Threshold")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("MinimumThreshold", str(Maxentval))
effect.setParameter("MaximumThreshold",str(volumeScalarRange[1]))
effect.self().onApply()#apply separate
############MAKE CA curve markup to model
CAmarkup = getNode(ID+" CA")
#create model node
CAmodeloutlinenode = slicer.mrmlScene.AddNode(slicer.vtkMRMLModelNode())#adding a node to scene
CAmodeloutlinenode.SetName(ID+'CA_mod')
CAmodeloutlinenode.CreateDefaultDisplayNodes()
CAmodeloutlinenode.GetDisplayNode().SetSliceIntersectionVisibility(True)
CAmodeloutlinenode.GetDisplayNode().SetColor(1,0,0)
#new markups to model node
markupsToModel2 = slicer.mrmlScene.AddNode(slicer.vtkMRMLMarkupsToModelNode())
markupsToModel2.SetAutoUpdateOutput(True)
markupsToModel2.SetAndObserveMarkupsNodeID(CAmarkup.GetID())#set input node
markupsToModel2.SetAndObserveModelNodeID(CAmodeloutlinenode.GetID())#set model node (only needed for the first one)
markupsToModel2.SetModelType(1)#curve
markupsToModel2.SetTubeRadius(0.2)
markupsToModel2.SetTubeLoop(1)#1 = curve is a loop
markupsToModel2.SetCurveType(2)#polynomial least squares
############# CA ################3# Then need to import as a segmentation
CAmodeloutlinenode = slicer.util.getNode(ID+'CA_mod')#create model node from the just created model
slicer.modules.segmentations.logic().ImportModelToSegmentationNode(CAmodeloutlinenode,segmentationNode,"tosegment")
#remove visibility of model
CAmodeloutlinenode.SetDisplayVisibility(0)
#MAX ENTROPY THRESHOLD OF ECD
CA_modthreshseg = segmentationNode.GetSegmentation().AddEmptySegment(ID+" CA_modthresh")#create new segmentation ID
segmentationNode.GetSegmentation().GetSegment(ID+" CA_modthresh").SetColor(1,1,1)
#
segmentEditorNode.SetOverwriteMode(slicer.vtkMRMLSegmentEditorNode.OverwriteNone)
segmentEditorNode.SetMaskMode(slicer.vtkMRMLSegmentEditorNode.PaintAllowedInsideSingleSegment)
segmentEditorNode.SetSelectedSegmentID(ID+" CA_modthresh")
segmentEditorNode.SetMaskSegmentID(ID+'CA_mod')
segmentEditorWidget.setActiveEffectByName("Threshold")
effect = segmentEditorWidget.activeEffect()
#effect.setParameter("AutoThresholdMode",'SET_MIN_UPPER')
#effect.setParameter("AutoThresholdMethod","MAXIMUM_ENTROPY")#maximum entropy algorithm
effect.setParameter("MinimumThreshold", str(Maxentval))
effect.setParameter("MaximumThreshold",str(volumeScalarRange[1]))
effect.self().onApply()#apply separate
#set mod region segment visibility off
segmentationDisplayNode.SetSegmentVisibility(ID+"CA_mod",0)
segmentationDisplayNode.SetSegmentVisibility(ID+"EC_TM_mod",0)
#set mod region segment visibility off
segmentationDisplayNode.SetSegmentVisibility(ID+"RW_mod",0)
##################