1
0

ROI_goals_prep.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. %% ---=== LOAD DATA ===---
  6. patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatData_ausGli_005';
  7. % load Geometry
  8. load([patient_dir '\matlab_files\Geometry.mat']);
  9. fprintf('Loaded geometry ')
  10. % load beamlets
  11. [beamlets, beamlets_joined, numBeamlet, numBeam, beam_i_list] = get_beam_lets(Geometry, patient_dir);
  12. fprintf('and beamlets.\n')
  13. %% ---=== GET OPTGOAL ===---
  14. ROI_goals.optGoal = make_ROI_goals_gbm_005(Geometry, beamlets);
  15. ROI_goals.optGoal_beam = make_ROI_goals_gbm_005(Geometry, beamlets_joined);
  16. ROI_goals.optGoal_idx=[1,3]; % indeces of volumes you want on histogram
  17. ROI_goals.targetMinMax_idx=[1,2]; % indeces of limits for min/max target volume
  18. %% ---=== SAVE OPTGOAL ===---
  19. fprintf('Writing ROI_goals...')
  20. DP_dir = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL005\B1\Processed';
  21. save([DP_dir '\RODP_files\ROI_goals.mat'], 'ROI_goals')
  22. fprintf(' done!\n')
  23. end
  24. function optGoal = make_ROI_goals_gbm_005(Geometry, beamlets, minDose, maxDose)
  25. optGoal={};
  26. DP_dir = '\\Mpufs5\data_wnx1\_Data\Glioma_aus\FET_FGL005\B1\Processed';
  27. [minDose, minDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL005_B1_DP_minDose.nrrd']);
  28. [maxDose, maxDose_meta] = nrrdread([DP_dir '\RODP_files\FET_FGL005_B1_DP_maxDose.nrrd']);
  29. minDose = double(minDose);
  30. maxDose = double(maxDose);
  31. % -- START DEFINITION OF GOAL --
  32. goal_1.name = 'CTV_min';
  33. goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
  34. ROI_idx = Geometry.ROIS{1, 1}.ind;
  35. goal_1.ROI_idx = ROI_idx;
  36. goal_1.imgDim = size(Geometry.data);
  37. goal_1.D_final = minDose(ROI_idx);
  38. goal_1.function = 'min';
  39. goal_1.beamlets_pruned = beamlets(ROI_idx, :);
  40. goal_1.target = minDose(ROI_idx); % minDose(ROI_idx);
  41. goal_1.opt_weight = 40 / numel(ROI_idx); % normalize to volume of target area
  42. goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  43. % assign target
  44. optGoal{end+1}=goal_1;
  45. % -- END DEFINITION OF GOAL --
  46. % -- START DEFINITION OF GOAL --
  47. goal_2.name = 'CTV_max';
  48. goal_2.ROI_name = Geometry.ROIS{1, 1}.name;
  49. ROI_idx = Geometry.ROIS{1, 1}.ind;
  50. goal_2.ROI_idx = ROI_idx;
  51. goal_2.imgDim = size(Geometry.data);
  52. goal_2.D_final = maxDose(ROI_idx);
  53. goal_2.function = 'max_sq';
  54. goal_2.beamlets_pruned = beamlets(ROI_idx, :);
  55. goal_2.target = maxDose(ROI_idx); % maxDose(ROI_idx);
  56. goal_2.opt_weight = 2 / numel(ROI_idx); % normalize to volume of target area
  57. goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  58. % assign target
  59. optGoal{end+1}=goal_2;
  60. % -- END DEFINITION OF GOAL --
  61. % -- START DEFINITION OF GOAL --
  62. goal_3.name = 'head_max';
  63. goal_3.ROI_name = Geometry.ROIS{1, 2}.name;
  64. ROI_idx = Geometry.ROIS{1, 2}.ind;
  65. goal_3.ROI_idx = ROI_idx;
  66. goal_3.imgDim = size(Geometry.data);
  67. goal_3.D_final = 20;
  68. goal_3.function = 'max_sq';
  69. goal_3.beamlets_pruned = beamlets(ROI_idx, :);
  70. goal_3.target = ones(numel(ROI_idx), 1) * goal_3.D_final;
  71. goal_3.opt_weight = 7 / numel(ROI_idx); % normalize to volume of target area
  72. goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
  73. % assign target
  74. optGoal{end+1}=goal_3;
  75. % -- END DEFINITION OF GOAL --
  76. end
  77. function beamlets = get_beamlets(beamlet_cell_array, numVox);
  78. wbar1 = waitbar(0, 'Creating beamlet array');
  79. numBeam = size(beamlet_cell_array,2);
  80. batchSize=100;
  81. beamlets = sparse(0, 0);
  82. for beam_i=1:numBeam
  83. % for each beam define how much dose it delivers on each voxel
  84. idx=beamlet_cell_array{1, beam_i}.non_zero_indices;
  85. % break the beamlets into multiple batches
  86. if rem(beam_i, batchSize)==1;
  87. beamlet_batch = sparse(numVox, batchSize);
  88. beam_i_temp=1;
  89. end
  90. beamlet_batch(idx, beam_i_temp) = 1000*beamlet_cell_array{1, beam_i}.non_zero_values;
  91. waitbar(beam_i/numBeam, wbar1, ['Adding beamlet array: #', num2str(beam_i)])
  92. % add the batch to full set when filled
  93. if rem(beam_i, batchSize)==0;
  94. beamlets =[beamlets, beamlet_batch];
  95. end
  96. % crop and add the batch to full set when completed
  97. if beam_i==numBeam;
  98. beamlet_batch=beamlet_batch(:, 1:beam_i_temp);
  99. beamlets =[beamlets, beamlet_batch];
  100. end
  101. beam_i_temp=beam_i_temp+1;
  102. end
  103. close(wbar1)
  104. end