ROI_goals_prep.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. function ROI_goals_prep
  2. % this function creates and saves dose painting plans based on Geometry
  3. % and beamlets created in WiscPlan. Manually change hardcode of whatever
  4. % you want the plan to be!
  5. %% ---=== INPUT PARAMS ===---
  6. patient = 'avastin_009';
  7. outName = 'ROI_goals_DP';
  8. switch patient
  9. case 'avastin_009'
  10. paths.in = '\\Mpufs5\data_wnx1\_Data\Avastin\AV009\PF_RODP_analysis';
  11. paths.CT_in = ['AV009b_1ct_resized'];
  12. paths.target_bin_in = ['\RODP_files\AV009b_flt_seg_thr2_imclose_binPTV'];
  13. paths.target_fzy_in = ['\RODP_files\AV009b_flt_seg_thr2_imclose_fuzzyCTV'];
  14. paths.body_bin_in = ['\RODP_files\AV009b_seg_head_crop_bin'];
  15. paths.wiscplan = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatData_Avastin009';
  16. case 'avastin_009_dumb'
  17. paths.in = '\\Mpufs5\data_wnx1\_Data\Avastin\AV009\PF_RODP_analysis';
  18. paths.CT_in = ['AV009b_1ct_resized'];
  19. paths.target_bin_in = ['\RODP_files\AV009b_flt_seg_thr2_imclose_binPTV'];
  20. paths.target_fzy_in = ['\RODP_files\AV009b_flt_seg_thr2_imclose_fuzzyCTV'];
  21. paths.body_bin_in = ['\RODP_files\AV009b_seg_head_crop_bin'];
  22. paths.wiscplan = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatData_Avastin009';
  23. case 'avastin_009_DP'
  24. paths.in = '\\Mpufs5\data_wnx1\_Data\Avastin\AV009\PF_RODP_analysis';
  25. paths.CT_in = ['AV009b_1ct_resized'];
  26. paths.target_bin_in = ['\RODP_files\AV009b_flt_seg_thr2_imclose_binPTV'];
  27. paths.target_fzy_in = ['\RODP_files\AV009b_flt_seg_thr2_imclose_fuzzyCTV'];
  28. paths.body_bin_in = ['\RODP_files\AV009b_seg_head_crop_bin'];
  29. paths.wiscplan = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatData_Avastin009';
  30. case 'gbm_005'
  31. paths.in = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL005\B1\Processed';
  32. paths.CT_in = ['FET_FGL005_B1_CT2FET'];
  33. paths.target_bin_in = ['\RODP_files\FET_FGL005_B1_thr2_binPTV'];
  34. paths.target_fzy_in = ['\RODP_files\FET_FGL005_B1_thr2_fuzzyCTV'];
  35. paths.body_bin_in = ['\RODP_files\FET_FGL005_B1_head_crop_bin'];
  36. paths.wiscplan = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatData_ausGli_005_16beam';
  37. case 'gbm_005_dumb'
  38. paths.in = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL005\B1\Processed';
  39. paths.CT_in = ['FET_FGL005_B1_CT2FET'];
  40. paths.target_bin_in = ['\RODP_files\FET_FGL005_B1_thr2_binPTV'];
  41. paths.target_fzy_in = ['\RODP_files\FET_FGL005_B1_thr2_fuzzyCTV'];
  42. paths.body_bin_in = ['\RODP_files\FET_FGL005_B1_head_crop_bin'];
  43. paths.wiscplan = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatData_ausGli_005_16beam_2';
  44. case 'gbm_005_DP'
  45. paths.in = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL005\B1\Processed';
  46. paths.CT_in = ['FET_FGL005_B1_CT2FET'];
  47. paths.target_bin_in = ['\RODP_files\FET_FGL005_B1_thr2_binPTV'];
  48. paths.target_fzy_in = ['\RODP_files\FET_FGL005_B1_thr2_fuzzyCTV'];
  49. paths.body_bin_in = ['\RODP_files\FET_FGL005_B1_head_crop_bin'];
  50. paths.wiscplan = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatData_ausGli_005_16beam';
  51. case 'gbm_015'
  52. paths.in = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL015\B1\Processed';
  53. paths.CT_in = ['FET_FGL015_B1_CT2FET'];
  54. paths.target_bin_in = ['\RODP_files\FET_FGL015_B1_thr2_binPTV'];
  55. paths.target_fzy_in = ['\RODP_files\FET_FGL015_B1_thr2_fuzzyCTV'];
  56. paths.body_bin_in = ['\RODP_files\FET_FGL015_B1_head_crop_bin'];
  57. paths.wiscplan = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatData_ausGli_015_64beam';
  58. case 'gbm_022'
  59. patname = 'FET_FGL022';
  60. paths.in = ['\\Mpufs5\data_wnx1\_Data\Glioma_aus\' patname '\B1\Processed'];
  61. paths.CT_in = [patname '_B1_CT2FET'];
  62. paths.target_bin_in = ['\RODP_files\' patname '_B1_thr2_binPTV'];
  63. paths.target_fzy_in = ['\RODP_files\' patname '_B1_thr2_fuzzyCTV'];
  64. paths.body_bin_in = ['\RODP_files\' patname '_B1_head_crop_bin'];
  65. paths.wiscplan = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatData_ausGli_022';
  66. otherwise
  67. error('invalid case')
  68. end
  69. %% ---=== LOAD DATA ===---
  70. % load Geometry
  71. load([paths.wiscplan '\matlab_files\Geometry.mat']);
  72. fprintf('Loaded geometry ')
  73. % load beamlets
  74. [beamlets, beamlets_joined, numBeamlet, numBeam, beam_i_list] = get_beam_lets(Geometry, paths.wiscplan);
  75. fprintf('and beamlets.\n')
  76. %% ---=== GET OPTGOAL ===---
  77. switch patient
  78. case 'avastin_009'
  79. ROI_goals.optGoal = make_ROI_goals_avastin_009(Geometry, beamlets);
  80. ROI_goals.optGoal_beam = make_ROI_goals_avastin_009(Geometry, beamlets_joined);
  81. ROI_goals.optGoal_idx=[1,3]; % indeces of volumes you want on histogram
  82. ROI_goals.targetMinMax_idx=[1,2]; % indeces of limits for min/max target volume
  83. case 'avastin_009_dumb'
  84. ROI_goals.optGoal = make_ROI_goals_avastin_009_dumb(Geometry, beamlets);
  85. ROI_goals.optGoal_beam = make_ROI_goals_avastin_009_dumb(Geometry, beamlets_joined);
  86. ROI_goals.optGoal_idx=[1,3]; % indeces of volumes you want on histogram
  87. ROI_goals.targetMinMax_idx=[1,2]; % indeces of limits for min/max target volume
  88. case 'avastin_009_DP'
  89. ROI_goals.optGoal = make_ROI_goals_avastin_009(Geometry, beamlets);
  90. ROI_goals.optGoal_beam = make_ROI_goals_avastin_009(Geometry, beamlets_joined);
  91. ROI_goals.optGoal_idx=[1,3]; % indeces of volumes you want on histogram
  92. ROI_goals.targetMinMax_idx=[1,2]; % indeces of limits for min/max target volume
  93. case 'gbm_005'
  94. ROI_goals.optGoal = make_ROI_goals_gbm_005(Geometry, beamlets);
  95. ROI_goals.optGoal_beam = make_ROI_goals_gbm_005(Geometry, beamlets_joined);
  96. ROI_goals.optGoal_idx=[1,3]; % indeces of volumes you want on histogram
  97. ROI_goals.targetMinMax_idx=[1,2]; % indeces of limits for min/max target volume
  98. case 'gbm_005_dumb'
  99. ROI_goals.optGoal = make_ROI_goals_gbm_005_dumb(Geometry, beamlets);
  100. ROI_goals.optGoal_beam = make_ROI_goals_gbm_005_dumb(Geometry, beamlets_joined);
  101. ROI_goals.optGoal_idx=[1,3]; % indeces of volumes you want on histogram
  102. ROI_goals.targetMinMax_idx=[1,2]; % indeces of limits for min/max target volume
  103. case 'gbm_005_DP'
  104. ROI_goals.optGoal = make_ROI_goals_gbm_005_DP(Geometry, beamlets);
  105. ROI_goals.optGoal_beam = make_ROI_goals_gbm_005_DP(Geometry, beamlets_joined);
  106. ROI_goals.optGoal_idx=[1,3]; % indeces of volumes you want on histogram
  107. ROI_goals.targetMinMax_idx=[1,2]; % indeces of limits for min/max target volume
  108. case 'gbm_015'
  109. ROI_goals.optGoal = make_ROI_goals_gbm_015(Geometry, beamlets);
  110. ROI_goals.optGoal_beam = make_ROI_goals_gbm_015(Geometry, beamlets_joined);
  111. ROI_goals.optGoal_idx=[1,3]; % indeces of volumes you want on histogram
  112. ROI_goals.targetMinMax_idx=[1,2]; % indeces of limits for min/max target volume
  113. case 'gbm_022'
  114. ROI_goals.optGoal = make_ROI_goals_gbm_022(Geometry, beamlets);
  115. ROI_goals.optGoal_beam = make_ROI_goals_gbm_022(Geometry, beamlets_joined);
  116. ROI_goals.optGoal_idx=[1,3]; % indeces of volumes you want on histogram
  117. ROI_goals.targetMinMax_idx=[1,2]; % indeces of limits for min/max target volume
  118. otherwise
  119. error('invalid case')
  120. end
  121. %% ---=== SAVE OPTGOAL ===---
  122. fprintf('Writing ROI_goals...')
  123. save([paths.in '\RODP_files\' outName '.mat'], 'ROI_goals')
  124. fprintf(' done!\n')
  125. end
  126. function optGoal = make_ROI_goals_avastin_009_DP(Geometry, beamlets, minDose, maxDose)
  127. optGoal={};
  128. DP_dir = '\\Mpufs5\data_wnx1\_Data\Avastin\AV009\PF_RODP_analysis';
  129. [minDose, minDose_meta] = nrrdread([DP_dir '\RODP_files\AV009b_flt_seg_thr3_imclose_DP_maxDose.nrrd']);
  130. [maxDose, maxDose_meta] = nrrdread([DP_dir '\RODP_files\AV009b_flt_seg_thr3_imclose_DP_minDose.nrrd']);
  131. minDose = double(minDose);
  132. maxDose = double(maxDose);
  133. % -- START DEFINITION OF GOAL --
  134. goal_1.name = 'CTV_min';
  135. goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
  136. ROI_idx = Geometry.ROIS{1, 1}.ind;
  137. goal_1.ROI_idx = ROI_idx;
  138. goal_1.imgDim = size(Geometry.data);
  139. goal_1.D_final = minDose(ROI_idx);
  140. goal_1.function = 'min_sq';
  141. goal_1.beamlets_pruned = beamlets(ROI_idx, :);
  142. goal_1.target_alpha = 1;
  143. goal_1.target = minDose(ROI_idx); % minDose(ROI_idx);
  144. goal_1.opt_weight = 70 / numel(ROI_idx); % normalize to volume of target area
  145. goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  146. % assign target
  147. optGoal{end+1}=goal_1;
  148. % -- END DEFINITION OF GOAL --
  149. % -- START DEFINITION OF GOAL --
  150. goal_2.name = 'CTV_max';
  151. goal_2.ROI_name = Geometry.ROIS{1, 1}.name;
  152. ROI_idx = Geometry.ROIS{1, 1}.ind;
  153. goal_2.ROI_idx = ROI_idx;
  154. goal_2.imgDim = size(Geometry.data);
  155. goal_2.D_final = maxDose(ROI_idx);
  156. goal_2.function = 'max_sq';
  157. goal_2.beamlets_pruned = beamlets(ROI_idx, :);
  158. goal_2.target_alpha = 1;
  159. goal_2.target = maxDose(ROI_idx); % maxDose(ROI_idx);
  160. goal_2.opt_weight = 1 / numel(ROI_idx); % normalize to volume of target area
  161. goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  162. % assign target
  163. optGoal{end+1}=goal_2;
  164. % -- END DEFINITION OF GOAL --
  165. % -- START DEFINITION OF GOAL --
  166. goal_3.name = 'head_max';
  167. goal_3.ROI_name = Geometry.ROIS{1, 2}.name;
  168. ROI_idx = Geometry.ROIS{1, 2}.ind;
  169. goal_3.ROI_idx = ROI_idx;
  170. goal_3.imgDim = size(Geometry.data);
  171. goal_3.D_final = 20;
  172. goal_3.function = 'max_sq';
  173. goal_3.beamlets_pruned = beamlets(ROI_idx, :);
  174. goal_3.target_alpha = 1;
  175. goal_3.target = ones(numel(ROI_idx), 1) * goal_3.D_final;
  176. goal_3.opt_weight = 5 / numel(ROI_idx); % normalize to volume of target area
  177. goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
  178. % assign target
  179. optGoal{end+1}=goal_3;
  180. % -- END DEFINITION OF GOAL --
  181. end
  182. function optGoal = make_ROI_goals_avastin_009_dumb(Geometry, beamlets, minDose, maxDose)
  183. optGoal={};
  184. DP_dir = '\\Mpufs5\data_wnx1\_Data\Avastin\AV009\PF_RODP_analysis';
  185. [minDose, minDose_meta] = nrrdread([DP_dir '\RODP_files\AV009b_flt_seg_thr3_imclose_DP_maxDose.nrrd']);
  186. [maxDose, maxDose_meta] = nrrdread([DP_dir '\RODP_files\AV009b_flt_seg_thr3_imclose_DP_minDose.nrrd']);
  187. minDose = double(minDose);
  188. maxDose = double(maxDose);
  189. % -- START DEFINITION OF GOAL --
  190. goal_1.name = 'CTV_min';
  191. goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
  192. ROI_idx = Geometry.ROIS{1, 1}.ind;
  193. goal_1.ROI_idx = ROI_idx;
  194. goal_1.imgDim = size(Geometry.data);
  195. goal_1.D_final = 60;
  196. goal_1.function = 'min_sq';
  197. goal_1.beamlets_pruned = beamlets(ROI_idx, :);
  198. % goal_1.target_alpha = 1;
  199. goal_1.target = ones(numel(ROI_idx), 1) * 60; % minDose(ROI_idx);
  200. goal_1.opt_weight = 70 / numel(ROI_idx); % normalize to volume of target area
  201. goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  202. % assign target
  203. optGoal{end+1}=goal_1;
  204. % -- END DEFINITION OF GOAL --
  205. % -- START DEFINITION OF GOAL --
  206. goal_2.name = 'CTV_max';
  207. goal_2.ROI_name = Geometry.ROIS{1, 1}.name;
  208. ROI_idx = Geometry.ROIS{1, 1}.ind;
  209. goal_2.ROI_idx = ROI_idx;
  210. goal_2.imgDim = size(Geometry.data);
  211. goal_2.D_final = 63;
  212. goal_2.function = 'max_sq';
  213. goal_2.beamlets_pruned = beamlets(ROI_idx, :);
  214. % goal_2.target_alpha = 1;
  215. goal_2.target = ones(numel(ROI_idx), 1) * 63; % maxDose(ROI_idx);
  216. goal_2.opt_weight = 1 / numel(ROI_idx); % normalize to volume of target area
  217. goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  218. % assign target
  219. optGoal{end+1}=goal_2;
  220. % -- END DEFINITION OF GOAL --
  221. % -- START DEFINITION OF GOAL --
  222. goal_3.name = 'head_max';
  223. goal_3.ROI_name = Geometry.ROIS{1, 2}.name;
  224. ROI_idx = Geometry.ROIS{1, 2}.ind;
  225. goal_3.ROI_idx = ROI_idx;
  226. goal_3.imgDim = size(Geometry.data);
  227. goal_3.D_final = 20;
  228. goal_3.function = 'max';
  229. goal_3.beamlets_pruned = beamlets(ROI_idx, :);
  230. goal_3.target_alpha = 1;
  231. goal_3.target = ones(numel(ROI_idx), 1) * goal_3.D_final;
  232. goal_3.opt_weight = 5 / numel(ROI_idx); % normalize to volume of target area
  233. goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
  234. % assign target
  235. optGoal{end+1}=goal_3;
  236. % -- END DEFINITION OF GOAL --
  237. end
  238. function optGoal = make_ROI_goals_avastin_009(Geometry, beamlets, minDose, maxDose)
  239. optGoal={};
  240. DP_dir = '\\Mpufs5\data_wnx1\_Data\Avastin\AV009\PF_RODP_analysis';
  241. [minDose, minDose_meta] = nrrdread([DP_dir '\RODP_files\AV009b_flt_seg_thr3_imclose_DP_maxDose.nrrd']);
  242. [maxDose, maxDose_meta] = nrrdread([DP_dir '\RODP_files\AV009b_flt_seg_thr3_imclose_DP_minDose.nrrd']);
  243. minDose = double(minDose);
  244. maxDose = double(maxDose);
  245. % -- START DEFINITION OF GOAL --
  246. goal_1.name = 'CTV_min';
  247. goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
  248. ROI_idx = Geometry.ROIS{1, 1}.ind;
  249. goal_1.ROI_idx = ROI_idx;
  250. goal_1.imgDim = size(Geometry.data);
  251. goal_1.D_final = minDose(ROI_idx);
  252. goal_1.function = 'min_sq';
  253. goal_1.beamlets_pruned = beamlets(ROI_idx, :);
  254. goal_1.target_alpha = 1;
  255. goal_1.target = minDose(ROI_idx); % minDose(ROI_idx);
  256. goal_1.opt_weight = 70 / numel(ROI_idx); % normalize to volume of target area
  257. goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  258. % assign target
  259. optGoal{end+1}=goal_1;
  260. % -- END DEFINITION OF GOAL --
  261. % -- START DEFINITION OF GOAL --
  262. goal_2.name = 'CTV_max';
  263. goal_2.ROI_name = Geometry.ROIS{1, 1}.name;
  264. ROI_idx = Geometry.ROIS{1, 1}.ind;
  265. goal_2.ROI_idx = ROI_idx;
  266. goal_2.imgDim = size(Geometry.data);
  267. goal_2.D_final = maxDose(ROI_idx);
  268. goal_2.function = 'max_sq';
  269. goal_2.beamlets_pruned = beamlets(ROI_idx, :);
  270. goal_2.target_alpha = 1;
  271. goal_2.target = maxDose(ROI_idx); % maxDose(ROI_idx);
  272. goal_2.opt_weight = 1 / numel(ROI_idx); % normalize to volume of target area
  273. goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  274. % assign target
  275. optGoal{end+1}=goal_2;
  276. % -- END DEFINITION OF GOAL --
  277. % -- START DEFINITION OF GOAL --
  278. goal_3.name = 'head_max';
  279. goal_3.ROI_name = Geometry.ROIS{1, 2}.name;
  280. ROI_idx = Geometry.ROIS{1, 2}.ind;
  281. goal_3.ROI_idx = ROI_idx;
  282. goal_3.imgDim = size(Geometry.data);
  283. goal_3.D_final = 20;
  284. goal_3.function = 'max_sq';
  285. goal_3.beamlets_pruned = beamlets(ROI_idx, :);
  286. goal_3.target_alpha = 1;
  287. goal_3.target = ones(numel(ROI_idx), 1) * goal_3.D_final;
  288. goal_3.opt_weight = 5 / numel(ROI_idx); % normalize to volume of target area
  289. goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
  290. % assign target
  291. optGoal{end+1}=goal_3;
  292. % -- END DEFINITION OF GOAL --
  293. end
  294. function optGoal = make_ROI_goals_gbm_005(Geometry, beamlets, minDose, maxDose)
  295. optGoal={};
  296. DP_dir = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL005\B1\Processed';
  297. [minDose, minDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL005_B1_seg_thr2.0_DP_minDose.nrrd']);
  298. [maxDose, maxDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL005_B1_seg_thr2.0_DP_maxDose.nrrd']);
  299. minDose = double(minDose);
  300. maxDose = double(maxDose);
  301. % -- START DEFINITION OF GOAL --
  302. goal_1.name = 'CTV_min';
  303. goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
  304. ROI_idx = Geometry.ROIS{1, 1}.ind;
  305. goal_1.ROI_idx = ROI_idx;
  306. goal_1.imgDim = size(Geometry.data);
  307. goal_1.D_final = minDose(ROI_idx);
  308. goal_1.function = 'min_sq';
  309. goal_1.beamlets_pruned = beamlets(ROI_idx, :);
  310. goal_1.target_alpha = 1;
  311. goal_1.target = minDose(ROI_idx); % minDose(ROI_idx);
  312. goal_1.opt_weight = 70 / numel(ROI_idx); % normalize to volume of target area
  313. goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  314. % assign target
  315. optGoal{end+1}=goal_1;
  316. % -- END DEFINITION OF GOAL --
  317. % -- START DEFINITION OF GOAL --
  318. goal_2.name = 'CTV_max';
  319. goal_2.ROI_name = Geometry.ROIS{1, 1}.name;
  320. ROI_idx = Geometry.ROIS{1, 1}.ind;
  321. goal_2.ROI_idx = ROI_idx;
  322. goal_2.imgDim = size(Geometry.data);
  323. goal_2.D_final = maxDose(ROI_idx);
  324. goal_2.function = 'max_sq';
  325. goal_2.beamlets_pruned = beamlets(ROI_idx, :);
  326. goal_2.target_alpha = 1;
  327. goal_2.target = maxDose(ROI_idx); % maxDose(ROI_idx);
  328. goal_2.opt_weight = 1 / numel(ROI_idx); % normalize to volume of target area
  329. goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  330. % assign target
  331. optGoal{end+1}=goal_2;
  332. % -- END DEFINITION OF GOAL --
  333. % -- START DEFINITION OF GOAL --
  334. goal_3.name = 'head_max';
  335. goal_3.ROI_name = Geometry.ROIS{1, 2}.name;
  336. ROI_idx = Geometry.ROIS{1, 2}.ind;
  337. goal_3.ROI_idx = ROI_idx;
  338. goal_3.imgDim = size(Geometry.data);
  339. goal_3.D_final = 20;
  340. goal_3.function = 'max';
  341. goal_3.beamlets_pruned = beamlets(ROI_idx, :);
  342. goal_3.target_alpha = 1;
  343. goal_3.target = ones(numel(ROI_idx), 1) * goal_3.D_final;
  344. goal_3.opt_weight = 5 / numel(ROI_idx); % normalize to volume of target area
  345. goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
  346. % assign target
  347. optGoal{end+1}=goal_3;
  348. % -- END DEFINITION OF GOAL --
  349. end
  350. function optGoal = make_ROI_goals_gbm_005_dumb(Geometry, beamlets, minDose, maxDose)
  351. optGoal={};
  352. DP_dir = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL005\B1\Processed';
  353. % [minDose, minDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL005_B1_seg_thr2.0_DP_minDose.nrrd']);
  354. % [maxDose, maxDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL005_B1_seg_thr2.0_DP_maxDose.nrrd']);
  355. % minDose = double(minDose);
  356. % maxDose = double(maxDose);
  357. % -- START DEFINITION OF GOAL --
  358. goal_1.name = 'PTV_min';
  359. goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
  360. ROI_idx = Geometry.ROIS{1, 1}.ind;
  361. goal_1.ROI_idx = ROI_idx;
  362. goal_1.imgDim = size(Geometry.data);
  363. goal_1.D_final = 60;
  364. goal_1.function = 'min_sq';
  365. goal_1.beamlets_pruned = beamlets(ROI_idx, :);
  366. goal_1.target = ones(numel(ROI_idx), 1) * 60;
  367. % goal_1.target = minDose(ROI_idx);
  368. goal_1.opt_weight = 77 / numel(ROI_idx); % normalize to volume of target area
  369. goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  370. % assign target
  371. optGoal{end+1}=goal_1;
  372. % -- END DEFINITION OF GOAL --
  373. % -- START DEFINITION OF GOAL --
  374. goal_2.name = 'PTV_max';
  375. goal_2.ROI_name = Geometry.ROIS{1, 1}.name;
  376. ROI_idx = Geometry.ROIS{1, 1}.ind;
  377. goal_2.ROI_idx = ROI_idx;
  378. goal_2.imgDim = size(Geometry.data);
  379. goal_2.D_final = 63;
  380. goal_2.function = 'max_sq';
  381. goal_2.beamlets_pruned = beamlets(ROI_idx, :);
  382. goal_2.target = ones(numel(ROI_idx), 1) * 63;
  383. % goal_2.target = maxDose(ROI_idx);
  384. goal_2.opt_weight = 1 / numel(ROI_idx); % normalize to volume of target area
  385. goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  386. % assign target
  387. optGoal{end+1}=goal_2;
  388. % -- END DEFINITION OF GOAL --
  389. % -- START DEFINITION OF GOAL --
  390. goal_3.name = 'head_max';
  391. goal_3.ROI_name = Geometry.ROIS{1, 2}.name;
  392. ROI_idx = Geometry.ROIS{1, 2}.ind;
  393. goal_3.ROI_idx = ROI_idx;
  394. goal_3.imgDim = size(Geometry.data);
  395. goal_3.D_final = 20;
  396. goal_3.function = 'max';
  397. goal_3.beamlets_pruned = beamlets(ROI_idx, :);
  398. goal_3.target = ones(numel(ROI_idx), 1) * 20;
  399. goal_3.opt_weight = 5 / numel(ROI_idx); % normalize to volume of target area
  400. goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
  401. % assign target
  402. optGoal{end+1}=goal_3;
  403. % -- END DEFINITION OF GOAL --
  404. end
  405. function optGoal = make_ROI_goals_gbm_005_DP(Geometry, beamlets, minDose, maxDose)
  406. optGoal={};
  407. DP_dir = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL005\B1\Processed';
  408. [minDose, minDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL005_B1_seg_thr2.0_DP_minDose.nrrd']);
  409. [maxDose, maxDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL005_B1_seg_thr2.0_DP_maxDose.nrrd']);
  410. minDose = double(minDose);
  411. maxDose = double(maxDose);
  412. % -- START DEFINITION OF GOAL --
  413. goal_1.name = 'CTV_min';
  414. goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
  415. ROI_idx = Geometry.ROIS{1, 1}.ind;
  416. goal_1.ROI_idx = ROI_idx;
  417. goal_1.imgDim = size(Geometry.data);
  418. goal_1.D_final = minDose(ROI_idx);
  419. goal_1.function = 'min_sq';
  420. goal_1.beamlets_pruned = beamlets(ROI_idx, :);
  421. goal_1.target_alpha = 1;
  422. goal_1.target = minDose(ROI_idx); % minDose(ROI_idx);
  423. goal_1.opt_weight = 70 / numel(ROI_idx); % normalize to volume of target area
  424. goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  425. % assign target
  426. optGoal{end+1}=goal_1;
  427. % -- END DEFINITION OF GOAL --
  428. % -- START DEFINITION OF GOAL --
  429. goal_2.name = 'CTV_max';
  430. goal_2.ROI_name = Geometry.ROIS{1, 1}.name;
  431. ROI_idx = Geometry.ROIS{1, 1}.ind;
  432. goal_2.ROI_idx = ROI_idx;
  433. goal_2.imgDim = size(Geometry.data);
  434. goal_2.D_final = maxDose(ROI_idx);
  435. goal_2.function = 'max_sq';
  436. goal_2.beamlets_pruned = beamlets(ROI_idx, :);
  437. goal_2.target_alpha = 1;
  438. goal_2.target = maxDose(ROI_idx); % maxDose(ROI_idx);
  439. goal_2.opt_weight = 1 / numel(ROI_idx); % normalize to volume of target area
  440. goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  441. % assign target
  442. optGoal{end+1}=goal_2;
  443. % -- END DEFINITION OF GOAL --
  444. % -- START DEFINITION OF GOAL --
  445. goal_3.name = 'head_max';
  446. goal_3.ROI_name = Geometry.ROIS{1, 2}.name;
  447. ROI_idx = Geometry.ROIS{1, 2}.ind;
  448. goal_3.ROI_idx = ROI_idx;
  449. goal_3.imgDim = size(Geometry.data);
  450. goal_3.D_final = 20;
  451. goal_3.function = 'max';
  452. goal_3.beamlets_pruned = beamlets(ROI_idx, :);
  453. goal_3.target_alpha = 1;
  454. goal_2.target = maxDose(ROI_idx); % maxDose(ROI_idx);
  455. % goal_3.target = ones(numel(ROI_idx), 1) * goal_3.D_final;
  456. goal_3.opt_weight = 5 / numel(ROI_idx); % normalize to volume of target area
  457. goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
  458. % assign target
  459. optGoal{end+1}=goal_3;
  460. % -- END DEFINITION OF GOAL --
  461. end
  462. function optGoal = make_ROI_goals_gbm_015(Geometry, beamlets, minDose, maxDose)
  463. optGoal={};
  464. DP_dir = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL015\B1\Processed';
  465. [minDose, minDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL015_B1_thr2_DP_minDose.nrrd']);
  466. [maxDose, maxDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL015_B1_thr2_DP_maxDose.nrrd']);
  467. minDose = double(minDose);
  468. maxDose = double(maxDose);
  469. % -- START DEFINITION OF GOAL --
  470. goal_1.name = 'CTV_min';
  471. goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
  472. ROI_idx = Geometry.ROIS{1, 1}.ind;
  473. goal_1.ROI_idx = ROI_idx;
  474. goal_1.imgDim = size(Geometry.data);
  475. goal_1.D_final = minDose(ROI_idx);
  476. goal_1.function = 'min';
  477. goal_1.beamlets_pruned = beamlets(ROI_idx, :);
  478. goal_1.target = minDose(ROI_idx); % minDose(ROI_idx);
  479. goal_1.opt_weight = 40 / numel(ROI_idx); % normalize to volume of target area
  480. goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  481. % assign target
  482. optGoal{end+1}=goal_1;
  483. % -- END DEFINITION OF GOAL --
  484. % -- START DEFINITION OF GOAL --
  485. goal_2.name = 'CTV_max';
  486. goal_2.ROI_name = Geometry.ROIS{1, 1}.name;
  487. ROI_idx = Geometry.ROIS{1, 1}.ind;
  488. goal_2.ROI_idx = ROI_idx;
  489. goal_2.imgDim = size(Geometry.data);
  490. goal_2.D_final = maxDose(ROI_idx);
  491. goal_2.function = 'max_sq';
  492. goal_2.beamlets_pruned = beamlets(ROI_idx, :);
  493. goal_2.target = maxDose(ROI_idx); % maxDose(ROI_idx);
  494. goal_2.opt_weight = 2 / numel(ROI_idx); % normalize to volume of target area
  495. goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  496. % assign target
  497. optGoal{end+1}=goal_2;
  498. % -- END DEFINITION OF GOAL --
  499. % -- START DEFINITION OF GOAL --
  500. goal_3.name = 'head_max';
  501. goal_3.ROI_name = Geometry.ROIS{1, 2}.name;
  502. ROI_idx = Geometry.ROIS{1, 2}.ind;
  503. goal_3.ROI_idx = ROI_idx;
  504. goal_3.imgDim = size(Geometry.data);
  505. goal_3.D_final = 20;
  506. goal_3.function = 'max';
  507. goal_3.beamlets_pruned = beamlets(ROI_idx, :);
  508. goal_3.target = ones(numel(ROI_idx), 1) * goal_3.D_final;
  509. goal_3.opt_weight = 7 / numel(ROI_idx); % normalize to volume of target area
  510. goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
  511. % assign target
  512. optGoal{end+1}=goal_3;
  513. % -- END DEFINITION OF GOAL --
  514. end
  515. function optGoal = make_ROI_goals_gbm_022(Geometry, beamlets, minDose, maxDose)
  516. optGoal={};
  517. DP_dir = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL022\B1\Processed';
  518. [minDose, minDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL022_B1_thr2_DP_minDose.nrrd']);
  519. [maxDose, maxDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL022_B1_thr2_DP_maxDose.nrrd']);
  520. minDose = double(minDose);
  521. maxDose = double(maxDose);
  522. % -- START DEFINITION OF GOAL --
  523. goal_1.name = 'CTV_min';
  524. goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
  525. ROI_idx = Geometry.ROIS{1, 1}.ind;
  526. goal_1.ROI_idx = ROI_idx;
  527. goal_1.imgDim = size(Geometry.data);
  528. goal_1.D_final = minDose(ROI_idx);
  529. goal_1.function = 'min';
  530. goal_1.beamlets_pruned = beamlets(ROI_idx, :);
  531. goal_1.target = minDose(ROI_idx); % minDose(ROI_idx);
  532. goal_1.opt_weight = 40 / numel(ROI_idx); % normalize to volume of target area
  533. goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  534. % assign target
  535. optGoal{end+1}=goal_1;
  536. % -- END DEFINITION OF GOAL --
  537. % -- START DEFINITION OF GOAL --
  538. goal_2.name = 'CTV_max';
  539. goal_2.ROI_name = Geometry.ROIS{1, 1}.name;
  540. ROI_idx = Geometry.ROIS{1, 1}.ind;
  541. goal_2.ROI_idx = ROI_idx;
  542. goal_2.imgDim = size(Geometry.data);
  543. goal_2.D_final = maxDose(ROI_idx);
  544. goal_2.function = 'max_sq';
  545. goal_2.beamlets_pruned = beamlets(ROI_idx, :);
  546. goal_2.target = maxDose(ROI_idx); % maxDose(ROI_idx);
  547. goal_2.opt_weight = 2 / numel(ROI_idx); % normalize to volume of target area
  548. goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  549. % assign target
  550. optGoal{end+1}=goal_2;
  551. % -- END DEFINITION OF GOAL --
  552. % -- START DEFINITION OF GOAL --
  553. goal_3.name = 'head_max';
  554. goal_3.ROI_name = Geometry.ROIS{1, 2}.name;
  555. ROI_idx = Geometry.ROIS{1, 2}.ind;
  556. goal_3.ROI_idx = ROI_idx;
  557. goal_3.imgDim = size(Geometry.data);
  558. goal_3.D_final = 20;
  559. goal_3.function = 'max';
  560. goal_3.beamlets_pruned = beamlets(ROI_idx, :);
  561. goal_3.target = ones(numel(ROI_idx), 1) * goal_3.D_final;
  562. goal_3.opt_weight = 7 / numel(ROI_idx); % normalize to volume of target area
  563. goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
  564. % assign target
  565. optGoal{end+1}=goal_3;
  566. % -- END DEFINITION OF GOAL --
  567. end
  568. function beamlets = get_beamlets(beamlet_cell_array, numVox);
  569. wbar1 = waitbar(0, 'Creating beamlet array');
  570. numBeam = size(beamlet_cell_array,2);
  571. batchSize=100;
  572. beamlets = sparse(0, 0);
  573. for beam_i=1:numBeam
  574. % for each beam define how much dose it delivers on each voxel
  575. idx=beamlet_cell_array{1, beam_i}.non_zero_indices;
  576. % break the beamlets into multiple batches
  577. if rem(beam_i, batchSize)==1;
  578. beamlet_batch = sparse(numVox, batchSize);
  579. beam_i_temp=1;
  580. end
  581. beamlet_batch(idx, beam_i_temp) = 1000*beamlet_cell_array{1, beam_i}.non_zero_values;
  582. waitbar(beam_i/numBeam, wbar1, ['Adding beamlet array: #', num2str(beam_i)])
  583. % add the batch to full set when filled
  584. if rem(beam_i, batchSize)==0;
  585. beamlets =[beamlets, beamlet_batch];
  586. end
  587. % crop and add the batch to full set when completed
  588. if beam_i==numBeam;
  589. beamlet_batch=beamlet_batch(:, 1:beam_i_temp);
  590. beamlets =[beamlets, beamlet_batch];
  591. end
  592. beam_i_temp=beam_i_temp+1;
  593. end
  594. close(wbar1)
  595. end