1
0

ROI_goals_prep.m 30 KB

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