matRad_sequencing2ApertureInfo

Purpose ^

matRad function to generate a shape info struct

Synopsis ^

function apertureInfo = matRad_sequencing2ApertureInfo(Sequencing,stf)

Description ^

 matRad function to generate a shape info struct 
 based on the result of multileaf collimator sequencing

 call
   apertureInfo = matRad_sequencing2ApertureInfo(Sequencing,stf)

 input
   Sequencing: matRad sequencing result struct
   stf:        matRad steering information struct

 output
   apertureInfo: matRad aperture weight and shape info struct

 References
   
   -
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Copyright 2015 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:

Source code ^

0001 function apertureInfo = matRad_sequencing2ApertureInfo(Sequencing,stf)
0002 % matRad function to generate a shape info struct
0003 % based on the result of multileaf collimator sequencing
0004 %
0005 % call
0006 %   apertureInfo = matRad_sequencing2ApertureInfo(Sequencing,stf)
0007 %
0008 % input
0009 %   Sequencing: matRad sequencing result struct
0010 %   stf:        matRad steering information struct
0011 %
0012 % output
0013 %   apertureInfo: matRad aperture weight and shape info struct
0014 %
0015 % References
0016 %
0017 %   -
0018 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 %
0020 % Copyright 2015 the matRad development team.
0021 %
0022 % This file is part of the matRad project. It is subject to the license
0023 % terms in the LICENSE file found in the top-level directory of this
0024 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0025 % of the matRad project, including this file, may be copied, modified,
0026 % propagated, or distributed except according to the terms contained in the
0027 % LICENSE file.
0028 %
0029 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0030 
0031 % MLC parameters:
0032 bixelWidth = stf(1).bixelWidth; % [mm]
0033 numOfMLCLeafPairs = 80;
0034 %     define central leaf pair (here we want the 0mm position to be in the
0035 %     center of a leaf pair (e.g. leaf 41 stretches from -2.5mm to 2.5mm
0036 %     for a bixel/leafWidth of 5mm and 81 leaf pairs)
0037 centralLeafPair = ceil(numOfMLCLeafPairs/2);
0038 
0039 % initializing variables
0040 bixelIndOffset = 0; % used for creation of bixel index maps
0041 totalNumOfBixels = sum([stf(:).totalNumOfBixels]);
0042 totalNumOfShapes = sum([Sequencing.beam.numOfShapes]);
0043 vectorOffset = totalNumOfShapes + 1; % used for bookkeeping in the vector for optimization
0044 
0045 % loop over all beams
0046 for i=1:size(stf,2)
0047     
0048     %% 1. read stf and create maps (Ray & Bixelindex)
0049     
0050     % get x- and z-coordinates of bixels
0051     rayPos_bev = reshape([stf(i).ray.rayPos_bev],3,[]);
0052     X = rayPos_bev(1,:)';
0053     Z = rayPos_bev(3,:)';
0054     
0055     % create ray-map
0056     maxX = max(X); minX = min(X);    
0057     maxZ = max(Z); minZ = min(Z);
0058     
0059     dimX = (maxX-minX)/stf(i).bixelWidth + 1;
0060     dimZ = (maxZ-minZ)/stf(i).bixelWidth + 1;
0061 
0062     rayMap = zeros(dimZ,dimX);
0063     
0064     % get indices for x and z positions
0065     xPos = (X-minX)/stf(i).bixelWidth + 1;
0066     zPos = (Z-minZ)/stf(i).bixelWidth + 1;
0067     
0068     % get indices in the ray-map
0069     indInRay = zPos + (xPos-1)*dimZ;
0070 
0071     % fill ray-map
0072     rayMap(indInRay) = 1;
0073     
0074     % create map of bixel indices
0075     bixelIndMap = NaN * ones(dimZ,dimX);
0076     bixelIndMap(indInRay) = [1:stf(i).numOfRays] + bixelIndOffset;
0077     bixelIndOffset = bixelIndOffset + stf(i).numOfRays;
0078     
0079     % store physical position of first entry in bixelIndMap
0080     posOfCornerBixel = [minX 0 minZ];
0081     
0082     % get leaf limits from the leaf map
0083     lim_l = NaN * ones(dimZ,1);
0084     lim_r = NaN * ones(dimZ,1);
0085     % looping oder leaf pairs
0086     for l = 1:dimZ
0087         lim_lInd = find(rayMap(l,:),1,'first');
0088         lim_rInd = find(rayMap(l,:),1,'last');
0089         % the physical position [mm] can be calculated from the indices
0090         lim_l(l) = (lim_lInd-1)*bixelWidth + minX - 1/2*bixelWidth;
0091         lim_r(l) = (lim_rInd-1)*bixelWidth + minX + 1/2*bixelWidth;
0092     end
0093         
0094     % get leaf positions for all shapes
0095     % leaf positions can be extracted from the shapes created in Sequencing
0096     for m = 1:Sequencing.beam(i).numOfShapes
0097         
0098         % loading shape from Sequencing result
0099         shapeMap = Sequencing.beam(i).shapes(:,:,m);
0100         % get left and right leaf indices from shapemap
0101         % initializing limits
0102         leftLeafPos = NaN * ones(dimZ,1);
0103         rightLeafPos = NaN * ones(dimZ,1);
0104         % looping over leaf pairs
0105         for l = 1:dimZ
0106             leftLeafPosInd  = find(shapeMap(l,:),1,'first');
0107             rightLeafPosInd = find(shapeMap(l,:),1,'last');
0108             
0109             if isempty(leftLeafPosInd) && isempty(rightLeafPosInd) % if no bixel is open, use limits from Ray positions
0110                 leftLeafPos(l) = (lim_l(l)+lim_r(l))/2;
0111                 rightLeafPos(l) = leftLeafPos(l);
0112             else
0113             % the physical position [mm] can be calculated from the indices
0114                 leftLeafPos(l) = (leftLeafPosInd-1)*bixelWidth...
0115                                     + minX - 1/2*bixelWidth;
0116                 rightLeafPos(l) = (rightLeafPosInd-1)*bixelWidth...
0117                                     + minX + 1/2*bixelWidth;
0118                               
0119             end
0120         end
0121         
0122         % save data for each shape of this beam
0123         apertureInfo.beam(i).shape(m).leftLeafPos = leftLeafPos;
0124         apertureInfo.beam(i).shape(m).rightLeafPos = rightLeafPos;
0125         apertureInfo.beam(i).shape(m).weight = Sequencing.beam(i).shapesWeight(m);
0126         apertureInfo.beam(i).shape(m).shapeMap = shapeMap;
0127         apertureInfo.beam(i).shape(m).vectorOffset = vectorOffset;
0128         
0129         % update index for bookkeeping
0130         vectorOffset = vectorOffset + dimZ;
0131            
0132     end
0133         
0134     % z-coordinates of active leaf pairs
0135     % get z-coordinates from bixel positions
0136     leafPairPos = unique(Z);
0137         
0138     % find upmost and downmost leaf pair
0139     topLeafPairPos = maxZ;
0140     bottomLeafPairPos = minZ;
0141     
0142     topLeafPair = centralLeafPair - topLeafPairPos/bixelWidth;
0143     bottomLeafPair = centralLeafPair - bottomLeafPairPos/bixelWidth;
0144         
0145     % create bool map of active leaf pairs
0146     isActiveLeafPair = zeros(numOfMLCLeafPairs,1);
0147     isActiveLeafPair(topLeafPair:bottomLeafPair) = 1;
0148         
0149     % create MLC window
0150     % getting the dimensions of the MLC in order to be able to plot the
0151     % shapes using physical coordinates
0152     MLCWindow = [minX-bixelWidth/2 maxX+bixelWidth/2 ...
0153                     minZ-bixelWidth/2 maxZ+bixelWidth/2];
0154     
0155     % save data for each beam
0156     apertureInfo.beam(i).numOfShapes = Sequencing.beam(i).numOfShapes;
0157     apertureInfo.beam(i).numOfActiveLeafPairs = dimZ;
0158     apertureInfo.beam(i).leafPairPos = leafPairPos;
0159     apertureInfo.beam(i).isActiveLeafPair = isActiveLeafPair;
0160     apertureInfo.beam(i).centralLeafPair = centralLeafPair;
0161     apertureInfo.beam(i).lim_l = lim_l;
0162     apertureInfo.beam(i).lim_r = lim_r;
0163     apertureInfo.beam(i).bixelIndMap = bixelIndMap;
0164     apertureInfo.beam(i).posOfCornerBixel = posOfCornerBixel;
0165     apertureInfo.beam(i).MLCWindow = MLCWindow;
0166     
0167 end
0168 
0169 % save global data
0170 apertureInfo.bixelWidth = bixelWidth;
0171 apertureInfo.numOfMLCLeafPairs = numOfMLCLeafPairs;
0172 apertureInfo.totalNumOfBixels = totalNumOfBixels;
0173 apertureInfo.totalNumOfShapes = sum([apertureInfo.beam.numOfShapes]);
0174 apertureInfo.totalNumOfLeafPairs = sum([apertureInfo.beam.numOfShapes]*[apertureInfo.beam.numOfActiveLeafPairs]');
0175 
0176 % create vectors for optimization
0177 [apertureInfo.apertureVector, apertureInfo.mappingMx, apertureInfo.limMx] = matRad_OptimizationProblemDAO.matRad_daoApertureInfo2Vec(apertureInfo);
0178 
0179 end

| Generated by m2html © 2005