tomoBeamOnOffSinogram.asv 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. function RtomoAll = tomoBeamOnOffSinogram(GeomROI,xpmin,xpmax,Mxp,Nphi,Nrot)
  2. % Figures out which beams should be on or off for tomotherapy treatment.
  3. ptv = [];
  4. ptv.x_count = GeomROI.dim(1);
  5. ptv.y_count = GeomROI.dim(2);
  6. ptv.z_count = GeomROI.dim(3);
  7. ptv.non_zero_indices = GeomROI.ind;
  8. ptv.non_zero_values = single(GeomROI);
  9. ptvFull = full3D(ptv);
  10. tumorMask = [];
  11. tumorMask.start = GeomROI.start;
  12. tumorMask.voxel_size = GeomROI.pixdim;
  13. tumorMask.data = ptvFull;
  14. [M,N,Q] = size(tumorMask.data);
  15. % create axes
  16. x = [0:M-1]*tumorMask.voxel_size(1) + tumorMask.start(1);
  17. y = [0:N-1]*tumorMask.voxel_size(2) + tumorMask.start(2);
  18. z = [0:Q-1]*tumorMask.voxel_size(3) + tumorMask.start(3);
  19. % Calculate the maximum tumor cross section
  20. bigSlice = double(~~sum(tumorMask.data,3));
  21. % grow the tumor by 5 voxels
  22. BW = bwdist(bigSlice);
  23. bigSlice(BW < 5) = 1;
  24. bigSlice = rot90(bigSlice);
  25. % Specify beam parameters: must match those in helicalDosecalcSetup.m
  26. % exactly!
  27. % xpmin = -20;
  28. % xpmax = 20;
  29. % Mxp = 64;
  30. xpTomo = [-(Mxp-1)/2:(Mxp-1)/2]*(xpmax - xpmin)/Mxp;
  31. % Nphi = 51;
  32. phiTomo = [0:Nphi-1]*360/Nphi;
  33. phi = [0:359];
  34. % calculate the radon transform of the mask
  35. [R,xp] = radon(bigSlice,phi);
  36. xp = xp*tumorMask.voxel_size(1);
  37. % create downsampling matrices
  38. [PHI,XP] = meshgrid(phi,xp);
  39. [PHITOMO,XPTOMO] = meshgrid(phiTomo,xpTomo);
  40. % resample the sinogram
  41. Rinterp = interp2(PHI,XP,R,PHITOMO,XPTOMO);
  42. Rtomo = ~~interp2(PHI,XP,R,PHITOMO,XPTOMO);
  43. % make copies of sinogram for 3D dose calculation
  44. RtomoDouble = double(Rtomo);
  45. % convert 2D sinograms to 3D for dose calc
  46. RtomoDouble = reshape(RtomoDouble,Mxp*Nrot,1);
  47. rowVector = ones(1,Nrot);
  48. RtomoAll = RtomoDouble*rowVector;
  49. RtomoAll = reshape(RtomoAll,Mxp,Nphi*Nrot);
  50. fprintf('Unused beams turned off.\n')