-
Notifications
You must be signed in to change notification settings - Fork 1
/
guillotine_for_fading.py
220 lines (188 loc) · 6.35 KB
/
guillotine_for_fading.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import numpy as np
from fos import Window, Scene
#from fos.actor.slicer import Slicer
from slicer_for_fading import Slicer
from pyglet.gl import *
from PySide.QtCore import Qt
class Guillotine(Slicer):
""" Head slicer actor
Notes
------
Coordinate Systems
http://www.grahamwideman.com/gw/brain/orientation/orientterms.htm
http://www.slicer.org/slicerWiki/index.php/Coordinate_systems
http://eeg.sourceforge.net/mri_orientation_notes.html
"""
step = 1
def draw(self):
#i slice
if self.show_i:
glPushMatrix()
glRotatef(90, 0., 1., 0)
glRotatef(90, 0., 0., 1.)
self.tex.update_quad(self.texcoords_i, self.vertcoords_i)
self.tex.set_state()
self.tex.draw()
self.tex.unset_state()
glPopMatrix()
#j slice
if self.show_j:
glPushMatrix()
glRotatef(180, 0., 1., 0) # added for fsl convention
glRotatef(90, 0., 0., 1.)
self.tex.update_quad(self.texcoords_j, self.vertcoords_j)
self.tex.set_state()
self.tex.draw()
self.tex.unset_state()
glPopMatrix()
#k slice
if self.show_k:
glPushMatrix()
glRotatef(90, 1., 0, 0.)
glRotatef(90, 0., 0., 1)
glRotatef(180, 1., 0., 0.) # added for fsl
self.tex.update_quad(self.texcoords_k, self.vertcoords_k)
self.tex.set_state()
self.tex.draw()
self.tex.unset_state()
glPopMatrix()
def right2left(self, step):
if self.i + step < self.I:
self.slice_i(self.i + step)
else:
self.slice_i(self.I - 1)
def left2right(self, step):
if self.i - step >= 0:
self.slice_i(self.i - step)
else:
self.slice_i(0)
def inferior2superior(self, step):
if self.k + step < self.K:
self.slice_k(self.k + step)
else:
self.slice_k(self.K - 1)
def superior2inferior(self, step):
if self.k - step >= 0:
self.slice_k(self.k - step)
else:
self.slice_k(0)
def anterior2posterior(self, step):
if self.j + step < self.J:
self.slice_j(self.j + step)
else:
self.slice_j(self.J - 1)
def posterior2anterior(self, step):
if self.j - step >= 0:
self.slice_j(self.j - step)
else:
self.slice_j(0)
def reset_slices(self):
self.slice_i(self.I / 2)
self.slice_j(self.J / 2)
self.slice_k(self.K / 2)
def slices_ijk(self, i, j, k):
self.slice_i(i)
self.slice_j(j)
self.slice_k(k)
def show_coronal(self, bool=True):
self.show_k = bool
def show_axial(self, bool=True):
self.show_i = bool
def show_saggital(self, bool=True):
self.show_j = bool
def show_all(self, bool=True):
self.show_i = bool
self.show_j = bool
self.show_k = bool
def process_messages(self,messages):
msg=messages['key_pressed']
#print 'Processing messages in actor', self.name,
# #' key_press message ', msg
if msg!=None:
self.process_keys(msg,None)
# msg=messages['mouse_position']
# #print 'Processing messages in actor', self.name,
# #' mouse_pos message ', msg
# if msg!=None:
# self.process_mouse_position(*msg)
pass
def process_keys(self,symbol,modifiers):
#NEEDS to change
#if modifiers & Qt.Key_Shift:
# print 'Shift'
#print("Increase step.")
# self.step=5
if symbol == Qt.Key_Up:
print 'Up'
self.inferior2superior(self.step)
self.step=1
if symbol == Qt.Key_Down:
print 'Down'
self.superior2inferior(self.step)
self.step=1
if symbol == Qt.Key_Left:
print 'Left'
self.left2right(self.step)
self.step=1
if symbol == Qt.Key_Right:
print 'Right'
self.right2left(self.step)
self.step=1
if symbol == Qt.Key_PageUp:
print 'PgUp'
self.posterior2anterior(self.step)
self.step=1
if symbol == Qt.Key_PageDown:
print 'PgDown'
self.anterior2posterior(self.step)
self.step=1
#HIDE SLICES
if symbol == Qt.Key_0:
print('0 - Show/Hide all')
if self.show_i==True | self.show_j==True | self.show_k==True :
self.show_i = False
self.show_j = False
self.show_k = False
else:
self.show_i = True
self.show_j = True
self.show_k = True
if symbol == Qt.Key_1:
print('1')
self.show_axial(not self.show_i)
if symbol == Qt.Key_2:
print('2')
self.show_saggital(not self.show_j)
if symbol == Qt.Key_3:
print('3')
self.show_coronal(not self.show_k)
if symbol == Qt.Key_Home:
print('Home')
self.reset_slices()
# if symbol == Qt.Key_End:
# print('End')
# if self.alpha>0:
# self.alpha-=1
# self.sli=self.update_slice(0,self.vxi)
# self.slj=self.update_slice(1,self.vxj)
# self.slk=self.update_slice(2,self.vxk)
if __name__ == '__main__':
import nibabel as nib
dname = '/usr/share/fsl/data/standard/'
fname = dname + 'FMRIB58_FA_1mm.nii.gz'
fname = '/home/eg309/Data/trento_processed/subj_01/MPRAGE_32/rawbet.nii.gz'
img=nib.load(fname)
data = img.get_data()
data = np.interp(data, [data.min(), data.max()], [0, 255])
from fos import Init, Run
Init()
window = Window(caption="[F]OS", bgcolor=(0.4, 0.4, 0.9))
scene = Scene(activate_aabb=False)
guil = Guillotine('VolumeSlicer', data)
scene.add_actor(guil)
window.add_scene(scene)
window.refocus_camera()
#window = Window()
window.show()
#print get_ipython()
Run()