Skip to content

Commit

Permalink
removed DoseSummationType handling, because I do not understand what …
Browse files Browse the repository at this point in the history
…it means exactly. See comments. Cleanup up filestruc a bit, and allow gui to run without tpsdose
  • Loading branch information
brenthuisman committed Feb 12, 2020
1 parent eb11967 commit 307e81b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__pycache__
GPUMonteCarloDoseLibrary.dll
dll/*.dll
.vscode
*.lnk
*.lnk
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ Files in the root are executable scripts, subdirectories are libraries. The `dat

`dicom` contains a small helper class to quickly get relevant data from a dicom file, and a function that helps you loop the dose engine over large quantities of treatments.

`dll` contains some dlls required to run GPUMCD, including the wrapper dll that I provide to you without source code, because at this time I am not 100% sure I can license it the same as this repo. All files here are provided as a courtesy and are excluded from the license of this repo.
`dll` is empty, and needs to be populated with some dlls by you. See `dll/placeholder.txt`. I do not redistribute them because I am not sure that I can.

Installation
------------

Right now, you must install the dependencies yourself.

$ pip(3) install medimage pyqt5
$ pip3 install medimage pyqt5

Then, populated the `dll` directory to wherever pip installed the package, or, if checkout the git repo, in that directory. Alternatively, copy `dosia.ini`,`data` and `dll` from here, put it somewhere, and make sure you instantiate the Settings-object with this directory.

This repo does NOT include GPUMCD, as this is not freely available software. You need to obtain GPUMCD from Elekta, in the form of a file called `GPUMonteCarloDoseLibrary.dll`, which could be provided to you as part of the Monaco treatment planning software, typically installed to `C:\Program Files\CMS\Monaco`. Right now, this file must be copied and placed in the `dll` subdir of this project.

Expand Down
2 changes: 1 addition & 1 deletion dicom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self,fname):
print(self.DoseSummationType)
assert self.DoseUnits == "GY", "This dose image is not in GY units."
assert self.DoseType == "PHYSICAL", "This dose image is not physical dose."
assert self.DoseSummationType in ["PLAN","FRACTION"], "This dose image is not per plan or fraction."
# assert self.DoseSummationType in ["PLAN","FRACTION"], "This dose image is not per plan or fraction."
elif self.modality == "RTPLAN":
self.sopid = str(self.data.SOPInstanceUID)
self.PatientPosition = str(self.data.PatientSetupSequence[0].PatientPosition)
Expand Down
8 changes: 8 additions & 0 deletions dll/placeholder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The files that you should copy here are:

* cudart64_80.dll
* curand64_80.dll
* msvcp120.dll (possibly)
* msvcr120.dll (possibly)
* libgpumcd.dll
* GPUMonteCarloDoseLibrary.dll
32 changes: 16 additions & 16 deletions gpumcd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ def __init__(self,sett,ct,plan,plandose):
eng.get_dose(self.gpumcd_dose[-1])

for d in self.gpumcd_dose:
# If I look at dicompyler code, at no point do I see conditionals for multiplying with NumberOfFractionsPlanned. Therefore, below logic is commented out for now.
d.mul(plan.NumberOfFractionsPlanned)

#If I look at dicompyler code, at no point do I see conditionals for multiplying with NumberOfFractionsPlanned.
if gpumcd_factor:
d.mul(plan.NumberOfFractionsPlanned)
else:
# From what I've seen, dosemaps are exported per plan REGARDLESS of value of DoseSummationType. we try anyway.
# https://dicom.innolitics.com/ciods/rt-dose/rt-dose/3004000a
if str(plandose.DoseSummationType).upper() == 'PLAN':
print("Dose was computed for whole PLAN, multiplying GPUMCD dose with number of fractions.")
d.mul(plan.NumberOfFractionsPlanned)
elif str(plandose.DoseSummationType).upper() == 'FRACTION':
#Editors note: 'FRACTION' here refers to fraction-GROUP-SEQUENCE! There may be multiple in a plan (and thus in a dose), altough I've never seen it. I could not find a defintion of 'fraction-group'. However, it does not correspond to what we call a fraction at the AvL: that's a session in DICOM parlance.
print("Dose was computed for FRACTION (-group!), multiplying GPUMCD dose with number of fractions.")
d.mul(plan.NumberOfFractionsPlanned)
elif str(plandose.DoseSummationType).upper() == 'BEAM':
else:
assert plandose.DoseSummationType == 'FRACTION'
# if gpumcd_factor:
# d.mul(plan.NumberOfFractionsPlanned)
# else:
# # From what I've seen, dosemaps are exported per plan REGARDLESS of value of DoseSummationType. we try anyway.
# # https://dicom.innolitics.com/ciods/rt-dose/rt-dose/3004000a
# if str(plandose.DoseSummationType).upper() == 'PLAN':
# print("Dose was computed for whole PLAN, multiplying GPUMCD dose with number of fractions.")
# d.mul(plan.NumberOfFractionsPlanned)
# elif str(plandose.DoseSummationType).upper() == 'FRACTION':
# #Editors note: 'FRACTION' here refers to fraction-GROUP-SEQUENCE! There may be multiple in a plan (and thus in a dose), altough I've never seen it. I could not find a defintion of 'fraction-group'. However, it does not correspond to what we call a fraction at the AvL: that's a session in DICOM parlance.
# print("Dose was computed for FRACTION (-group!), multiplying GPUMCD dose with number of fractions.")
# d.mul(plan.NumberOfFractionsPlanned)
# elif str(plandose.DoseSummationType).upper() == 'BEAM':
# else:
# assert plandose.DoseSummationType == 'FRACTION'

# self.gpumcd_dose = ct_obj.dosemap
4 changes: 2 additions & 2 deletions gpumcd/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self,dosia_ini_dir=None):
defkwargs = {
'directories':{ # relative to dosia.ini or absolute
'material_data': path.join(dosia_ini_dir,'data/materials_clin'),
'gpumcd_dll': path.join(dosia_ini_dir,'data/dll'),
'gpumcd_dll': path.join(dosia_ini_dir,'dll'),
'hounsfield_conversion': path.join(dosia_ini_dir,'data/hounsfield')
},
'gpumcd_machines':{
Expand Down Expand Up @@ -77,7 +77,7 @@ def __init__(self,dosia_ini_dir=None):
if path.isdir("C:/Program Files/CMS/Monaco"):
self.directories['gpumcd_dll'] = "C:/Program Files/CMS/Monaco"
from shutil import copyfile
copyfile(path.join(dosia_ini_dir,'data/dll/libgpumcd.dll'),self.directories['gpumcd_dll'])
copyfile(path.join(dosia_ini_dir,'dll/libgpumcd.dll'),self.directories['gpumcd_dll'])
else:
self.directories['gpumcd_dll'] = cfg.get('directories','gpumcd_dll').replace('\\','/')
assert(path.isdir(self.directories['gpumcd_dll']))
Expand Down
11 changes: 9 additions & 2 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, *args,**kwargs):

def resetpanes(self):
try:
if self.planpane.ready and self.plandosepane.ready and self.ctpane.ready:
if self.planpane.ready and self.ctpane.ready: #no plandoseready
self.menu_gpumcd_calculate.setDisabled(False)
# self.menu_gpumcd_setmachfile.setDisabled(False)
except:
Expand Down Expand Up @@ -166,7 +166,14 @@ def setmachfilegpumcd(self):
self.planpane.plan.accelerator.setmachfile(machfile)

def calcgpumcd(self):
dosia = gpumcd.Dosia(self.sett,self.ctpane.image[0],self.planpane.plan,self.plandosepane.image[0])
try:
self.plandosepane.ready
dosia = gpumcd.Dosia(self.sett,self.ctpane.image[0],self.planpane.plan,self.plandosepane.image[0])
except:
c = self.ctpane.image[0].copy()
c.resample([3,3,3])
c.zero_out()
dosia = gpumcd.Dosia(self.sett,self.ctpane.image[0],self.planpane.plan,c)

self.gpumcdpane = ImagePane(dosia.gpumcd_dose) #FIXME: prepare for sum_beams = False
self.menu_gpumcd_save.setDisabled(False)
Expand Down

0 comments on commit 307e81b

Please sign in to comment.