0001 function matRad_visSpotWeights(stf,weights)
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 numOfBeams = size(stf,2);
0032
0033
0034 counter = 0;
0035 for i = 1:numOfBeams
0036 for j = 1:stf(i).numOfRays
0037 for k = 1:stf(i).numOfBixelsPerRay(j)
0038 counter = counter + 1;
0039 bixelLut.beamNum(counter) = i;
0040 bixelLut.rayNum(counter) = j;
0041 bixelLut.bixelNum(counter) = k;
0042 bixelLut.energy(counter) = stf(i).ray(j).energy(k);
0043 end
0044 end
0045 end
0046
0047 if strcmp(stf(1).radiationMode, 'photons')
0048
0049
0050 figure;
0051 rowNum = floor(sqrt(numOfBeams));
0052 colNum = ceil(numOfBeams/rowNum);
0053
0054 w_max = max(weights);
0055
0056 for i=1:numOfBeams
0057
0058
0059 rayPos_mat = vertcat(stf(i).ray(:).rayPos_bev);
0060 x_min = min(rayPos_mat(:, 1));
0061 z_min = min(rayPos_mat(:, 3));
0062 x_max = max(rayPos_mat(:, 1));
0063 z_max = max(rayPos_mat(:, 3));
0064
0065
0066 weight_matrix{i} = zeros((x_max-x_min)/stf(i).bixelWidth,(z_max-z_min)/stf(i).bixelWidth);
0067
0068 for j=1:stf(i).numOfRays
0069
0070
0071 weight_ix = and((bixelLut.beamNum==i), (bixelLut.rayNum==j));
0072
0073 w_norm = weights(weight_ix)/w_max;
0074
0075 xpos = (stf(i).ray(j).rayPos_bev(1) + abs(x_min))/stf(i).bixelWidth +1;
0076 zpos = (stf(i).ray(j).rayPos_bev(3) + abs(z_min))/stf(i).bixelWidth +1;
0077 weight_matrix{i}(xpos,zpos) = w_norm;
0078 end
0079
0080
0081 ax = subplot(rowNum,colNum, i);
0082 hold on;
0083 imagesc( [x_min x_max], [z_min z_max], weight_matrix{i});
0084 axis image;
0085 title(sprintf(['spotweights in beam ' num2str(i)]));
0086 xlabel('x [mm]');
0087 ylabel('z [mm]');
0088 cmap = colormap(ax, 'jet');
0089 cb = colorbar;
0090 ylabel(cb, 'normalized weight');
0091 hold off;
0092 end
0093
0094 elseif ( strcmp(stf(1).radiationMode, 'protons') || strcmp(stf(1).radiationMode, 'carbon') )
0095
0096
0097
0098 w_max = max(weights);
0099
0100 for i=1:numOfBeams
0101 fprintf(['Calculate weights for Beam ' num2str(i) '...\n']);
0102
0103
0104 rayPos_mat = vertcat(stf(i).ray(:).rayPos_bev);
0105 x_min = min(rayPos_mat(:, 1));
0106 z_min = min(rayPos_mat(:, 3));
0107 x_max = max(rayPos_mat(:, 1));
0108 z_max = max(rayPos_mat(:, 3));
0109
0110
0111 all_energies{i} = unique(cat(2, stf(i).ray(:).energy));
0112 numOfEnergies(i) = length(all_energies{i});
0113
0114
0115 weight_matrix{i} = zeros((x_max-x_min)/stf(i).bixelWidth,(z_max-z_min)/stf(i).bixelWidth, numOfEnergies(i));
0116
0117
0118 beam_ix = (bixelLut.beamNum == i);
0119
0120 for j=1:numOfEnergies(i)
0121
0122 energy_ix = and((bixelLut.energy == all_energies{i}(j)),beam_ix) ;
0123
0124 for k=1:stf(i).numOfRays
0125
0126 weight_ix = and((bixelLut.rayNum==k),energy_ix);
0127
0128
0129 w_norm = weights(weight_ix)/w_max;
0130 if isempty(w_norm)
0131 w_norm = 0;
0132 end
0133
0134
0135 xpos = (stf(i).ray(k).rayPos_bev(1) + abs(x_min))/stf(i).bixelWidth +1;
0136 zpos = (stf(i).ray(k).rayPos_bev(3) + abs(z_min))/stf(i).bixelWidth +1;
0137 weight_matrix{i}(xpos,zpos, j) = w_norm;
0138 end
0139
0140 end
0141
0142
0143 figure('Name', sprintf(['Beam ' num2str(i)]), 'WindowScrollWheelFcn', @figScroll);
0144 ax = axes;
0145
0146 curr_ix_energy(i) = 1;
0147
0148
0149 img = imagesc( [x_min x_max], [z_min z_max], weight_matrix{i}(:,:,curr_ix_energy(i)));
0150 axis image;
0151 title(sprintf(['spotweights in beam ' num2str(i) ', energy: ' num2str(all_energies{i}(curr_ix_energy(i)))] ));
0152 xlabel('x [mm]');
0153 ylabel('z [mm]');
0154 cmap = colormap(ax, 'jet');
0155 caxis(ax, [0 1]);
0156 colormap(ax, cmap);
0157 cb = colorbar;
0158 ylabel(cb, 'normalized weight');
0159 hold off;
0160
0161 end
0162
0163 end
0164
0165
0166 function figScroll(src,callbackdata)
0167
0168
0169
0170 curr_fig = gcf;
0171 curr_ax = gca(curr_fig);
0172 childrenOfAx = get(curr_ax,'Children');
0173
0174
0175 fig_name = get(curr_fig,'Name');
0176 curr_beam = str2double(fig_name(end));
0177
0178
0179 curr_ix_energy(curr_beam) = curr_ix_energy(curr_beam) - callbackdata.VerticalScrollCount;
0180
0181
0182 curr_ix_energy(curr_beam) = min(curr_ix_energy(curr_beam), numOfEnergies(curr_beam));
0183 curr_ix_energy(curr_beam) = max(curr_ix_energy(curr_beam), 1);
0184
0185
0186 set(childrenOfAx,'CData',weight_matrix{curr_beam}(:,:,curr_ix_energy(curr_beam)));
0187 title(sprintf(['spotweights in beam ' num2str(curr_beam) ', energy: ' num2str(all_energies{curr_beam}(curr_ix_energy(curr_beam)))]));
0188 drawnow;
0189
0190 end
0191 end