plot_DVH.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. % ---- DVH PLOT FUNCTION ----
  2. function plot_DVH(Geometry, dose)
  3. % this function plots the DVHs of the given dose
  4. nfrac=1;
  5. colorList = jet(numel(Geometry.ROIS));
  6. names = {};
  7. figure
  8. hold on
  9. for roi_idx= 1:numel(Geometry.ROIS);
  10. % plot the histogram
  11. [dvh dosebins] = get_dvh_data(dose, Geometry.ROIS{roi_idx}.ind, nfrac);
  12. plot(dosebins, dvh,'Color', colorList(roi_idx, :),'LineStyle', '-','DisplayName', Geometry.ROIS{roi_idx}.name);
  13. names{roi_idx} = Geometry.ROIS{roi_idx}.name;
  14. end
  15. hold off
  16. % get % of volume above/below threshold
  17. % num_vox = numel(optGoal{targetMinMax_idx(1)}.target);
  18. % perc_vox_min = 100* numel(find((dose(optGoal{targetMinMax_idx(1)}.ROI_idx) - optGoal{targetMinMax_idx(1)}.target*0.95) <0)) ...
  19. % / num_vox;
  20. % perc_vox_max = 100* numel(find((dose(optGoal{targetMinMax_idx(2)}.ROI_idx) - optGoal{targetMinMax_idx(2)}.target*1.07) >0)) ...
  21. % / num_vox;
  22. title(['NLP optimized DVH'])
  23. legend(names)
  24. axis([0 110 0 100])
  25. end
  26. function plot_DVH_robust(dose, optGoal, optGoal_idx)
  27. % this function plots the DVHs of the given dose
  28. nfrac=1;
  29. figure
  30. hold on
  31. for goal_i=optGoal_idx
  32. % for all the perturbations
  33. for nrs_i = 1:optGoal{1}.NbrRandScenarios
  34. for sss_i = 1:optGoal{1}.NbrSystSetUpScenarios % syst. setup scenarios = ss
  35. for rrs_i = 1:optGoal{1}.NbrRangeScenarios % range scenario = rs
  36. % plot the histogram
  37. ROI_idx = optGoal{goal_i}.nrs{nrs_i}.sss{sss_i}.rrs{rrs_i}.ROI_idx;
  38. [dvh dosebins] = get_dvh_data(dose,ROI_idx,nfrac);
  39. plot(dosebins, dvh,'Color', optGoal{goal_i}.dvh_col,'LineStyle', '-','DisplayName', optGoal{goal_i}.ROI_name);
  40. end
  41. end
  42. end
  43. end
  44. hold off
  45. end
  46. function [dvh dosebins] = get_dvh_data(dose,roi_idx,nfrac);
  47. % this function calculates the data for the DVH
  48. dosevec = dose(roi_idx);
  49. [pdf dosebins] = hist(dosevec, 999);
  50. % clip negative bins
  51. pdf = pdf(dosebins >= 0);
  52. dosebins = dosebins(dosebins >= 0);
  53. dvh = fliplr(cumsum(fliplr(pdf))) / numel(dosevec) * 100;
  54. % append the last bin
  55. dosebins = [dosebins dosebins(end)+0.1];
  56. dvh = [dvh 0];
  57. end