-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
327 lines (251 loc) · 14 KB
/
main.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
from PyQt5.uic import loadUiType
from PyQt5.QtWidgets import *
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QFile
from PlaneViewClass import *
from PyQt5 import QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import vtk
import sys
import os
ui,_ = loadUiType(os.path.join(os.path.dirname(__file__),'MPR_UI2.ui'))
class MainWindow(QtWidgets.QMainWindow, ui):
def __init__(self, parent = None):
super().__init__()
QtWidgets.QMainWindow.__init__(self, parent)
self.setupUi(self)
super().__init__()
QtWidgets.QMainWindow.__init__(self, parent)
self.setupUi(self)
# Load and apply the darkeum style sheet
style_sheet_file = QFile("darkeum_stylesheet.qss")
style_sheet_file.open(QFile.ReadOnly | QFile.Text)
style_sheet = style_sheet_file.readAll().data().decode()
self.setStyleSheet(style_sheet)
self.uiElementBlocks = {'Top Left': {'Slider': self.topLeftView_verticalSlider,
#'Play Button': self.topLeftView_playButton,
'Pause Button': self.topLeftView_pauseButton,
'Stop Button': self.topLeftView_stopButton,
'Orientation Combobox': self.topLeftView_comboBox},
'Top Right': {'Slider': self.topRightView_verticalSlider,
#'Play Button': self.topRightView_playButton,
'Pause Button': self.topRightView_pauseButton,
'Stop Button': self.topRightView_stopButton,
'Orientation Combobox': self.topRightView_comboBox},
'Bottom Left': {'Slider': self.bottomLeftView_verticalSlider,
#'Play Button': self.bottomLeftView_playButton,
'Pause Button': self.bottomLeftView_pauseButton,
'Stop Button': self.bottomLeftView_stopButton,
'Orientation Combobox': self.bottomLeftView_comboBox},
'Bottom Right': {'Slider': self.bottomRightView_verticalSlider,
#'Play Button': self.bottomRightView_playButton,
'Pause Button': self.bottomRightView_pauseButton,
'Stop Button': self.bottomRightView_stopButton,
'Orientation Combobox': self.bottomRightView_comboBox} }
# Hide the UI components initially
self.topLeftView_comboBox.setVisible(False)
self.topRightView_comboBox.setVisible(False)
self.bottomLeftView_comboBox.setVisible(False)
self.bottomRightView_comboBox.setVisible(False)
self.topLeftView_verticalSlider.setVisible(False)
#self.topLeftView_playButton.setVisible(False)
self.topLeftView_pauseButton.setVisible(False)
self.topLeftView_stopButton.setVisible(False)
self.topleft_maximizebutton.setVisible(False)
self.topRightView_verticalSlider.setVisible(False)
#self.topRightView_playButton.setVisible(False)
self.topRightView_pauseButton.setVisible(False)
self.topRightView_stopButton.setVisible(False)
self.topright_maximizebutton.setVisible(False)
self.bottomLeftView_verticalSlider.setVisible(False)
# self.bottomLeftView_playButton.setVisible(False)
self.bottomLeftView_pauseButton.setVisible(False)
self.bottomLeftView_stopButton.setVisible(False)
self.bottomleft_maximizebutton.setVisible(False)
self.bottomRightView_verticalSlider.setVisible(False)
# self.bottomRightView_playButton.setVisible(False)
self.bottomRightView_pauseButton.setVisible(False)
self.bottomRightView_stopButton.setVisible(False)
self.buttomright_maximizebutton.setVisible(False)
self.top_left_minimize_button.setVisible(False)
self.top_right_minimize_button.setVisible(False)
self.bottom_left_minimize_button.setVisible(False)
self.bottom_right_minimize_button.setVisible(False)
self.actionOpen.triggered.connect(self.OpenFile)
self.topleft_maximizebutton.clicked.connect(self.maximize_topleft)
self.topright_maximizebutton.clicked.connect(self.maximize_topright)
self.bottomleft_maximizebutton.clicked.connect(self.maximize_bottomleft)
self.buttomright_maximizebutton.clicked.connect(self.maximize_buttomright)
self.top_left_minimize_button.clicked.connect(self.minimize_topleft)
self.top_right_minimize_button.clicked.connect(self.minimize_topright)
self.bottom_left_minimize_button.clicked.connect(self.minimize_bottomleft)
self.bottom_right_minimize_button.clicked.connect(self.minimize_bottomright)
# self.minimize_button.clicked.connect(self.Minimize)
def OpenFile(self):
file_name, _ = QFileDialog.getOpenFileName(self, "Open Image", os.path.dirname(__file__) + "/Dataset", "Case Files (*.mhd)")
if file_name == "": return
self.ReadData()
print(self.imageMapToColors)
self.axialViewer = PlaneViewer(self, self.topLeftView_gridLayout, 'Axial', self.imageMapToColors, 'Top Left')
self.coronalViewer = PlaneViewer(self, self.topRightView_gridLayout, 'Coronal', self.imageMapToColors, 'Top Right')
self.sagittalViewer = PlaneViewer(self, self.bottomRightView_gridLayout, 'Sagittal', self.imageMapToColors, 'Bottom Right')
self.ConnectAllSliders()
self.Initial_nofiletext.setVisible(False)
self.topLeftView_comboBox.setVisible(True)
self.topRightView_comboBox.setVisible(True)
self.bottomLeftView_comboBox.setVisible(True)
self.bottomRightView_comboBox.setVisible(True)
self.topLeftView_verticalSlider.setVisible(True)
#self.topLeftView_playButton.setVisible(True)
self.topLeftView_pauseButton.setVisible(True)
self.topLeftView_stopButton.setVisible(True)
self.topleft_maximizebutton.setVisible(True)
self.topRightView_verticalSlider.setVisible(True)
#self.topRightView_playButton.setVisible(True)
self.topRightView_pauseButton.setVisible(True)
self.topRightView_stopButton.setVisible(True)
self.topright_maximizebutton.setVisible(True)
self.bottomLeftView_verticalSlider.setVisible(True)
#self.bottomLeftView_playButton.setVisible(True)
self.bottomLeftView_pauseButton.setVisible(True)
self.bottomLeftView_stopButton.setVisible(True)
self.bottomleft_maximizebutton.setVisible(True)
self.bottomRightView_verticalSlider.setVisible(True)
# self.bottomRightView_playButton.setVisible(True)
self.bottomRightView_pauseButton.setVisible(True)
self.bottomRightView_stopButton.setVisible(True)
self.buttomright_maximizebutton.setVisible(True)
self.show()
self.axialViewer.RenderViewer()
self.axialViewer.RunViewer()
self.coronalViewer.RenderViewer()
self.coronalViewer.RunViewer()
self.sagittalViewer.RenderViewer()
self.sagittalViewer.RunViewer()
self.HandleEmptyViewer()
def ConnectAllSliders(self):
for viewer in [self.axialViewer, self.coronalViewer, self.sagittalViewer]:
viewer.ConnectSliderToIndicators(self)
viewer.slider.valueChanged.connect(lambda value, viewer=viewer: viewer.SliderScroll(value))
viewer.slider.setValue(0)
def DisconnectAllSliders(self):
for viewer in [self.axialViewer, self.coronalViewer, self.sagittalViewer]:
viewer.slider.valueChanged.disconnect()
def SwapViewers(self, planeViewer):
viewers = [self.axialViewer, self.coronalViewer, self.sagittalViewer]
for viewer in viewers:
if (viewer.orientation == planeViewer.orientation) and (viewer.uiLocation != planeViewer.uiLocation): viewerToSwapWith = viewer
viewerToSwapWith.SetViewerOrientation(self, planeViewer.pastOrientation)
def ReadData(self):
imageReader = vtk.vtkMetaImageReader()
imageReader.SetFileName("Dataset/out.mhd")
imageReader.UpdateWholeExtent()
print(imageReader.GetAnatomicalOrientation())
range = imageReader.GetOutput().GetScalarRange()
imageShiftScale = vtk.vtkImageShiftScale()
imageShiftScale.SetInputConnection(imageReader.GetOutputPort())
imageShiftScale.SetOutputScalarTypeToUnsignedChar()
imageShiftScale.SetShift(range[0])
imageShiftScale.SetScale(255.0/(range[1]-range[0]))
imageShiftScale.UpdateWholeExtent()
imageWindowLevel = vtk.vtkImageMapToWindowLevelColors()
imageWindowLevel.SetInputConnection(imageShiftScale.GetOutputPort())
imageWindowLevel.SetWindow(100.0)
imageWindowLevel.SetLevel(50.0)
imageWindowLevel.UpdateWholeExtent()
self.imageMapToColors = vtk.vtkImageMapToColors()
self.imageMapToColors.SetOutputFormatToRGBA()
self.imageMapToColors.SetInputConnection(imageWindowLevel.GetOutputPort())
grayscaleLut = vtk.vtkLookupTable()
grayscaleLut.SetNumberOfTableValues(256)
grayscaleLut.SetTableRange(0, 255)
grayscaleLut.SetRampToLinear()
grayscaleLut.SetHueRange(0, 0)
grayscaleLut.SetSaturationRange(0, 0)
grayscaleLut.SetValueRange(0, 1)
grayscaleLut.SetAlphaRange(1, 1)
grayscaleLut.Build()
self.imageMapToColors.SetLookupTable(grayscaleLut)
self.imageMapToColors.UpdateWholeExtent()
def HandleEmptyViewer(self):
self.bottomLeftView_renderer = vtk.vtkRenderer()
self.bottomLeftView_renderWindowInteractor = QVTKRenderWindowInteractor(self)
self.bottomLeftView_renderWindowInteractor.GetRenderWindow().AddRenderer(self.bottomLeftView_renderer)
bottomLeftView_interactorStyle = vtk.vtkInteractorStyleImage()
self.bottomLeftView_renderWindowInteractor.SetInteractorStyle(bottomLeftView_interactorStyle)
self.bottomLeftView_iren = self.bottomLeftView_renderWindowInteractor.GetRenderWindow().GetInteractor()
self.bottomLeftView_gridLayout.insertWidget(0, self.bottomLeftView_renderWindowInteractor)
self.bottomLeftView_renderWindowInteractor.GetRenderWindow().Render()
self.bottomLeftView_iren.Initialize()
def closeEvent(self, QCloseEvent):
super().closeEvent(QCloseEvent)
self.axialViewer.CloseViewer()
self.coronalViewer.CloseViewer()
self.sagittalViewer.CloseViewer()
self.axialViewer.timer.stop()
self.coronalViewer.timer.stop()
self.sagittalViewer.timer.stop()
# Empty 4th viewer
self.bottomLeftView_renderWindowInteractor.close()
def maximize_topleft(self):
self.top_left_widget.showMaximized()
self.top_right_widget.hide()
self.bottom_left_widget.hide()
self.bottom_right_widget.hide()
self.top_left_minimize_button.setVisible(True)
self.topleft_maximizebutton.setVisible(False)
def maximize_topright(self):
self.top_right_widget.showMaximized()
self.top_left_widget.hide()
self.bottom_left_widget.hide()
self.bottom_right_widget.hide()
self.top_right_minimize_button.setVisible(True)
self.topright_maximizebutton.setVisible(False)
def maximize_bottomleft(self):
self.bottom_left_widget.showMaximized()
self.top_left_widget.hide()
self.top_right_widget.hide()
self.bottom_right_widget.hide()
self.bottom_left_minimize_button.setVisible(True)
self.bottomleft_maximizebutton.setVisible(False)
def maximize_buttomright(self):
self.bottom_right_widget.showMaximized()
self.top_left_widget.hide()
self.top_right_widget.hide()
self.bottom_left_widget.hide()
self.bottom_right_minimize_button.setVisible(True)
self.buttomright_maximizebutton.setVisible(False)
def minimize_topleft(self):
self.top_left_widget.showMinimized()
self.top_right_widget.show()
self.bottom_left_widget.show()
self.bottom_right_widget.show()
self.top_left_minimize_button.setVisible(False)
self.topleft_maximizebutton.setVisible(True)
def minimize_topright(self):
self.top_right_widget.showMinimized()
self.top_left_widget.show()
self.bottom_left_widget.show()
self.bottom_right_widget.show()
self.top_right_minimize_button.setVisible(False)
self.topright_maximizebutton.setVisible(True)
def minimize_bottomleft(self):
self.bottom_left_widget.showMinimized()
self.top_left_widget.show()
self.top_right_widget.show()
self.bottom_right_widget.show()
self.bottom_left_minimize_button.setVisible(False)
self.bottomleft_maximizebutton.setVisible(True)
def minimize_bottomright(self):
self.bottom_right_widget.showMinimized()
self.top_left_widget.show()
self.top_right_widget.show()
self.bottom_left_widget.show()
self.bottom_right_minimize_button.setVisible(False)
self.buttomright_maximizebutton.setVisible(True)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())