-
Notifications
You must be signed in to change notification settings - Fork 2
/
dosia.py
163 lines (131 loc) · 5.29 KB
/
dosia.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
#!/usr/bin/python3
import medimage as image, dicom, gpumcd, numpy as np
from gui import *
from PyQt5.QtGui import QIcon
# todo: load this from an ini? gui setting?
sett = gpumcd.Settings("d:\\postdoc\\gpumcd_data")
class FourPanel(QWidget):
def __init__(self, tl, tr, bl, br, *args,**kwargs):
super().__init__(*args,**kwargs)
mainLayout = QGridLayout()
mainLayout.addWidget(tl, 0, 0)
mainLayout.addWidget(tr, 0, 1)
mainLayout.addWidget(bl, 1, 0)
mainLayout.addWidget(br, 1, 1)
# make all panels take up same space (quadrants)
mainLayout.setRowStretch(0, 1)
mainLayout.setRowStretch(1, 1)
mainLayout.setColumnStretch(0, 1)
mainLayout.setColumnStretch(1, 1)
self.setLayout(mainLayout)
class DosiaMain(QMainWindow):
def __init__(self, *args,**kwargs):
super().__init__(*args,**kwargs)
self.setWindowTitle("Dosia")
self.resize(800, 800)
self.move(300, 300)
self.setWindowIcon(QIcon('gui/audio-card.svg'))
# Menu bar
menu_load_file = QAction('&File(s) (RTPlan, Dose, CT)', self)
menu_load_file.triggered.connect(self.loadfiles)
menu_load_dir = QAction('&Directory (CT)', self)
menu_load_dir.triggered.connect(self.loaddir)
# menu_open_linaclog = QAction('&Linac Log', self)
# menu_open_linaclog.triggered.connect(self.loadlinaclog)
# menu_open_linaclog.setDisabled(True) #TODO: enable if rtplan loaded
self.menu_gpumcd_calculate = QAction('&Calculate Dose', self)
self.menu_gpumcd_calculate.triggered.connect(self.calcgpumcd)
self.menu_gpumcd_calculate.setDisabled(True) #TODO: enable if rtplan and ct loaded
self.menu_gpumcd_save = QAction('&Save Dose', self)
self.menu_gpumcd_save.triggered.connect(self.savegpumcd)
self.menu_gpumcd_save.setDisabled(True) #TODO: enable if gpumcd dose calculated.
menu_bar = self.menuBar()
menu_open = menu_bar.addMenu('&Load')
menu_open.addAction(menu_load_file)
menu_open.addAction(menu_load_dir)
menu_gpumcd = menu_bar.addMenu('&GPUMCD')
menu_gpumcd.addAction(self.menu_gpumcd_calculate)
menu_gpumcd.addAction(self.menu_gpumcd_save)
# Quadrants
self.planpane = QWidget()
self.plandosepane = QWidget()
self.ctpane = QWidget()
self.gpumcdpane = QWidget()
self.resetpanes()
# statusbar
self.statusBar().showMessage('Ready')
# done!
self.show()
def resetpanes(self):
try:
if self.planpane.ready and self.plandosepane.ready and self.ctpane.ready:
self.menu_gpumcd_calculate.setDisabled(False)
except:
pass #first launch
self.setCentralWidget(FourPanel(self.planpane,self.plandosepane,self.ctpane,self.gpumcdpane))
#TODO: error handling in loading files
def loadfiles(self):
files=QFileDialog.getOpenFileNames(self, 'Load Dicom file(s) (RTPlan, Dose, CT)')[0]
# try:
for fname in files:
opendicomobject = dicom.pydicom_object(fname)
if opendicomobject.modality == "RTPLAN":
self.planpane = PlanPane(fname,sett)
if opendicomobject.modality == "CT":
self.ctpane = ImagePane(fname)
if opendicomobject.modality == "RTDOSE":
self.plandosepane = ImagePane(fname)
# except Exception as e:
# self.popup(f"That was not a valid DICOM file.\n{str(e)}")
# return
self.resetpanes()
def loaddir(self):
fname = str(QFileDialog.getExistingDirectory(self, 'Open Dicom CT (slices) directory'))
try:
opendicomobject = dicom.pydicom_object(fname)
assert opendicomobject.modality == "CT", "That directory did not contain a valid set of DICOM CT slices."
self.ctpane = ImagePane(fname)
except Exception as e:
self.popup(f"That was not a valid DICOM file.\n{str(e)}")
return
self.resetpanes()
def loadcase(self):
# TODO: open dir and search for rtplan,ct,dose and set panes accordingly.
# multiple rtplan selector?
pass
def loadlinaclog(self):
# fname = str(QFileDialog.getOpenFileName(self, 'Open Dicom Dose')[0])
# self.topleft = QWidget()#somewidget(fname)
self.resetpanes()
def calcgpumcd(self):
dosia = gpumcd.Dosia(sett,self.ctpane.image,self.planpane.plan,self.plandosepane.image)
self.gpumcdpane = ImagePane(dosia.gpumcd_dose)
self.menu_gpumcd_save.setDisabled(False)
self.resetpanes()
def savegpumcd(self):
fname = str(QFileDialog.getSaveFileName(self, 'Save GPUMCD Dose')[0])
self.gpumcdpane.image.saveas(fname)
# self.topleft = QWidget()#somewidget(fname)
# self.setCentralWidget(FourPanel(self.topleft,self.topright,self.bottomleft,self.bottomright))
def popup(self,message):
a = QMessageBox()
a.setText(message)
a.exec()
print(str(message))
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
#### TEST PLAN VIEWER
# fname="D:/postdoc/analyses/gpumcd_python/dicom/20181101 CTRT KNO-hals/1. UPI263538/2.25.1025001435024675917588954042793107482"
# fname="D:/postdoc/analyses/correcteddicom/F180220C/1.3.46.670589.13.586672257.20190716134201.81016_0001_000000_156328075700a1.dcm"
# fname="D:/postdoc/analyses/correcteddicom/MonacoPhantom/2.16.840.1.113669.2.931128.223131424.20180410170709.445490_0001_000000_1533630935003e.dcm"
# p=PlanPane(fname)
# p.show()
#### TEST IMAGE VIEWER
# fname = "D:/postdoc/analyses/gpumcd_python/dicom/20181101 CTRT KNO-hals/2. HalsSupracl + C 3.0 B40s PLAN"
# fname = "D:/postdoc/analyses/gpumcd_python/dicom/20181101 CTRT KNO-hals/1. UPI263538/2.25.117736802457958133832899838499337503296"
# p=ImagePane(fname)
# p.show()
#### TEST MAIN
Main = DosiaMain()
sys.exit(app.exec())