tomoBeamOnOffSinogram.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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(ones(length(GeomROI.ind),1));
  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. xpTomo = [-(Mxp-1)/2:(Mxp-1)/2]*(xpmax - xpmin)/Mxp;
  26. NphiTomo = 51;
  27. phiTomo = [0:NphiTomo-1]*360/NphiTomo;
  28. phi = [0:359];
  29. % calculate the radon transform of the mask
  30. [R,xp] = radon(bigSlice,phi);
  31. xp = xp*tumorMask.voxel_size(1);
  32. % create downsampling matrices
  33. [PHI,XP] = meshgrid(phi,xp);
  34. [PHITOMO,XPTOMO] = meshgrid(phiTomo,xpTomo);
  35. % resample the sinogram
  36. Rinterp = interp2(PHI,XP,R,PHITOMO,XPTOMO);
  37. Rinterp(isnan(Rinterp) == 1) = 0;
  38. Rtomo = ~~Rinterp;
  39. % make copies of sinogram for 3D dose calculation
  40. RtomoDouble = double(Rtomo);
  41. % convert 2D sinograms to 3D for dose calc
  42. RtomoDouble = reshape(RtomoDouble,Mxp*NphiTomo,1);
  43. rowVector = ones(1,Nrot);
  44. RtomoAll = RtomoDouble*rowVector;
  45. RtomoAll = reshape(RtomoAll,Mxp,NphiTomo*Nrot);
  46. fprintf('Unused beams turned off.\n')