matRad_computeSSD

Purpose ^

matRad SSD calculation

Synopsis ^

function stf = matRad_computeSSD(stf,ct,mode)

Description ^

 matRad SSD calculation
 
 call
   stf = matRad_computeSSD(stf,ct)
   stf = matRad_computeSSD(stf,ct,mode)

 input
   ct:     ct cube
   stf:    matRad steering information struct
   mode:   optional parameter specifying how to handle multiple
           cubes to compute one SSD
 output
   stf:    matRad steering information struct

 References
   -

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Copyright 2017 the matRad development team. 
 
 This file is part of the matRad project. It is subject to the license 
 terms in the LICENSE file found in the top-level directory of this 
 distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part 
 of the matRad project, including this file, may be copied, modified, 
 propagated, or distributed except according to the terms contained in the 
 LICENSE file.

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Cross-reference information ^

This function calls: This function is called by:

Subfunctions ^

Source code ^

0001 function stf = matRad_computeSSD(stf,ct,mode)
0002 % matRad SSD calculation
0003 %
0004 % call
0005 %   stf = matRad_computeSSD(stf,ct)
0006 %   stf = matRad_computeSSD(stf,ct,mode)
0007 %
0008 % input
0009 %   ct:     ct cube
0010 %   stf:    matRad steering information struct
0011 %   mode:   optional parameter specifying how to handle multiple
0012 %           cubes to compute one SSD
0013 % output
0014 %   stf:    matRad steering information struct
0015 %
0016 % References
0017 %   -
0018 %
0019 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0020 %
0021 % Copyright 2017 the matRad development team.
0022 %
0023 % This file is part of the matRad project. It is subject to the license
0024 % terms in the LICENSE file found in the top-level directory of this
0025 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0026 % of the matRad project, including this file, may be copied, modified,
0027 % propagated, or distributed except according to the terms contained in the
0028 % LICENSE file.
0029 %
0030 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0031 
0032 
0033 matRad_cfg = MatRad_Config.instance();
0034 
0035 if nargin < 3
0036     mode = 'first';
0037 end
0038 
0039 % booleon to show warnings only once in the console
0040 boolShowWarning = true;
0041 
0042 % set density threshold for SSD computation
0043 densityThreshold = matRad_cfg.propDoseCalc.defaultSsdDensityThreshold;
0044 
0045 if strcmp(mode,'first')
0046     
0047     for i = 1:size(stf,2)
0048         SSD = cell(1,stf(i).numOfRays);
0049         for j = 1:stf(i).numOfRays
0050             [alpha,~,rho,~,~] = matRad_siddonRayTracer(stf(i).isoCenter, ...
0051                                  ct.resolution, ...
0052                                  stf(i).sourcePoint, ...
0053                                  stf(i).ray(j).targetPoint, ...
0054                                  {ct.cube{1}});
0055             ixSSD = find(rho{1} > densityThreshold,1,'first');
0056 
0057             if boolShowWarning
0058                 if isempty(ixSSD)
0059                     matRad_cfg.dispWarning('ray does not hit patient. Trying to fix afterwards...');
0060                     boolShowWarning = false;
0061                 elseif ixSSD(1) == 1
0062                     matRad_cfg.dispWarning('Surface for SSD calculation starts directly in first voxel of CT!');
0063                     boolShowWarning = false;
0064                 end
0065             end
0066             
0067             % calculate SSD
0068             SSD{j} = double(2 * stf(i).SAD * alpha(ixSSD));
0069             stf(i).ray(j).SSD = SSD{j};            
0070         end
0071         
0072         % try to fix SSD by using SSD of closest neighbouring ray
0073         SSDnotSet = find(cellfun('isempty',SSD));
0074         if ~isempty(SSDnotSet)
0075             rayPos_bev = reshape([stf(i).ray(:).rayPos_bev]',[3 stf(i).numOfRays])';
0076             for j = SSDnotSet
0077                 stf(i).ray(j).SSD =  matRad_closestNeighbourSSD(rayPos_bev, SSD, rayPos_bev(j,:));
0078             end
0079         end
0080     end
0081 else
0082     matRad_cfg.dispError('mode not defined for SSD calculation');
0083 end
0084 
0085 end
0086 
0087 % default setting only use first cube
0088 function bestSSD = matRad_closestNeighbourSSD(rayPos, SSD, currPos)
0089     vDistances = sum((rayPos - repmat(currPos,size(rayPos,1),1)).^2,2);
0090     [~, vIdx]   = sort(vDistances);
0091     for ix = vIdx'
0092         bestSSD = SSD{ix};
0093         % if SSD has been found, bestSSD is not empty
0094         if ~any(isempty(bestSSD))
0095             break
0096         end
0097     end
0098     if any(isempty(bestSSD))
0099         matRad_cfg = MatRad_Config.instance();
0100         matRad_cfg.dispError('Could not fix SSD calculation.');
0101     end
0102 end
0103

| Generated by m2html © 2005