get_beamlets.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. function [beamlets, numBeamlet] = get_beamlets(Geometry, patient_dir)
  2. % this function loads and returns beamlets and joined beams
  3. beamlet_batch_filename = [patient_dir '\' 'batch_dose.bin'];
  4. beamlet_cell_array = read_ryan_beamlets(beamlet_batch_filename, 'ryan');
  5. numVox = numel(Geometry.data);
  6. numBeamlet = size(beamlet_cell_array,2);
  7. if size(Geometry.data, 1)<129
  8. batchSize = 400;
  9. else
  10. batchSize = 200;
  11. end
  12. beamlets = get_beamlets2(beamlet_cell_array, numVox, batchSize);
  13. % --- join beamlets into beams
  14. % load([patient_dir '\all_beams.mat'])
  15. % beamletOrigin=[0 0 0];
  16. % beam_i=0;
  17. % beam_i_list=[];
  18. % for beamlet_i = 1:numel(all_beams)
  19. % newBeamletOrigin = all_beams{beamlet_i}.ip;
  20. % if any(newBeamletOrigin ~= beamletOrigin)
  21. % beam_i = beam_i+1;
  22. % beamletOrigin = newBeamletOrigin;
  23. % end
  24. % beam_i_list=[beam_i_list, beam_i];
  25. % end
  26. %
  27. %
  28. % wbar2 = waitbar(0, 'merging beamlets into beams');
  29. % numBeam=numel(unique(beam_i_list));
  30. % beamlets_joined=sparse(size(beamlets,1), numBeam);
  31. % for beam_i = 1:numel(unique(beam_i_list))
  32. % beam_full = sum(beamlets(:,beam_i_list == beam_i), 2);
  33. % beamlets_joined(:,beam_i) = beam_full;
  34. % waitbar(beam_i/numBeam, wbar2)
  35. % end
  36. %
  37. % close(wbar2)
  38. end
  39. % ---- GET BEAMLETS ----
  40. function beamlets = get_beamlets2(beamlet_cell_array, numVox, batchSize);
  41. wbar1 = waitbar(0, 'Creating beamlet array');
  42. numBeam = size(beamlet_cell_array,2);
  43. beamlets = sparse(0, 0);
  44. for beam_i=1:numBeam
  45. % for each beam define how much dose it delivers on each voxel
  46. idx=beamlet_cell_array{1, beam_i}.non_zero_indices;
  47. % break the beamlets into multiple batches
  48. if rem(beam_i, batchSize)==1;
  49. beamlet_batch = sparse(numVox, batchSize);
  50. beam_i_temp=1;
  51. end
  52. % beamlet_batch(idx, beam_i_temp) = 1000*beamlet_cell_array{1, beam_i}.non_zero_values;
  53. beamlet_batch(idx, beam_i_temp) = beamlet_cell_array{1, beam_i}.non_zero_values;
  54. waitbar(beam_i/numBeam, wbar1, ['Adding beamlet array: #', num2str(beam_i)])
  55. % add the batch to full set when filled
  56. if rem(beam_i, batchSize)==0;
  57. beamlets =[beamlets, beamlet_batch];
  58. end
  59. % crop and add the batch to full set when completed
  60. if beam_i==numBeam;
  61. beamlet_batch=beamlet_batch(:, 1:beam_i_temp);
  62. beamlets =[beamlets, beamlet_batch];
  63. end
  64. beam_i_temp=beam_i_temp+1;
  65. end
  66. close(wbar1)
  67. end
  68. function show_joint_beamlets(beamlets, IMGsize, Beam_list)
  69. % this function overlays and plots multiple beamlets. The goal is to
  70. % check whether some beamlets are part of the same beam manually.
  71. beam=sum(beamlets(:, Beam_list), 2);
  72. beamImg=reshape(full(beam), IMGsize);
  73. orthoslice(beamImg)
  74. end