0001 function apertureInfo = matRad_sequencing2ApertureInfo(Sequencing,stf)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 bixelWidth = stf(1).bixelWidth;
0033 numOfMLCLeafPairs = 80;
0034
0035
0036
0037 centralLeafPair = ceil(numOfMLCLeafPairs/2);
0038
0039
0040 bixelIndOffset = 0;
0041 totalNumOfBixels = sum([stf(:).totalNumOfBixels]);
0042 totalNumOfShapes = sum([Sequencing.beam.numOfShapes]);
0043 vectorOffset = totalNumOfShapes + 1;
0044
0045
0046 for i=1:size(stf,2)
0047
0048
0049
0050
0051 rayPos_bev = reshape([stf(i).ray.rayPos_bev],3,[]);
0052 X = rayPos_bev(1,:)';
0053 Z = rayPos_bev(3,:)';
0054
0055
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
0065 xPos = (X-minX)/stf(i).bixelWidth + 1;
0066 zPos = (Z-minZ)/stf(i).bixelWidth + 1;
0067
0068
0069 indInRay = zPos + (xPos-1)*dimZ;
0070
0071
0072 rayMap(indInRay) = 1;
0073
0074
0075 bixelIndMap = NaN * ones(dimZ,dimX);
0076 bixelIndMap(indInRay) = [1:stf(i).numOfRays] + bixelIndOffset;
0077 bixelIndOffset = bixelIndOffset + stf(i).numOfRays;
0078
0079
0080 posOfCornerBixel = [minX 0 minZ];
0081
0082
0083 lim_l = NaN * ones(dimZ,1);
0084 lim_r = NaN * ones(dimZ,1);
0085
0086 for l = 1:dimZ
0087 lim_lInd = find(rayMap(l,:),1,'first');
0088 lim_rInd = find(rayMap(l,:),1,'last');
0089
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
0095
0096 for m = 1:Sequencing.beam(i).numOfShapes
0097
0098
0099 shapeMap = Sequencing.beam(i).shapes(:,:,m);
0100
0101
0102 leftLeafPos = NaN * ones(dimZ,1);
0103 rightLeafPos = NaN * ones(dimZ,1);
0104
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)
0110 leftLeafPos(l) = (lim_l(l)+lim_r(l))/2;
0111 rightLeafPos(l) = leftLeafPos(l);
0112 else
0113
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
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
0130 vectorOffset = vectorOffset + dimZ;
0131
0132 end
0133
0134
0135
0136 leafPairPos = unique(Z);
0137
0138
0139 topLeafPairPos = maxZ;
0140 bottomLeafPairPos = minZ;
0141
0142 topLeafPair = centralLeafPair - topLeafPairPos/bixelWidth;
0143 bottomLeafPair = centralLeafPair - bottomLeafPairPos/bixelWidth;
0144
0145
0146 isActiveLeafPair = zeros(numOfMLCLeafPairs,1);
0147 isActiveLeafPair(topLeafPair:bottomLeafPair) = 1;
0148
0149
0150
0151
0152 MLCWindow = [minX-bixelWidth/2 maxX+bixelWidth/2 ...
0153 minZ-bixelWidth/2 maxZ+bixelWidth/2];
0154
0155
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
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
0177 [apertureInfo.apertureVector, apertureInfo.mappingMx, apertureInfo.limMx] = matRad_OptimizationProblemDAO.matRad_daoApertureInfo2Vec(apertureInfo);
0178
0179 end