matRad_visSpotWeights

Purpose ^

visualise spot weights per energy slice (or fluence map for photons resp.)

Synopsis ^

function matRad_visSpotWeights(stf,weights)

Description ^

 visualise spot weights per energy slice (or fluence map for photons resp.)
 for single beams
 
 call
    matRad_visSpotWeights(stf,weights)

 input
   stf:              matRad stf struct
   weights:          spot weights for bixels (resultGUI.w)

Cross-reference information ^

This function calls: This function is called by:

Subfunctions ^

Source code ^

0001 function matRad_visSpotWeights(stf,weights)
0002 % visualise spot weights per energy slice (or fluence map for photons resp.)
0003 % for single beams
0004 %
0005 % call
0006 %    matRad_visSpotWeights(stf,weights)
0007 %
0008 % input
0009 %   stf:              matRad stf struct
0010 %   weights:          spot weights for bixels (resultGUI.w)
0011 
0012 % output
0013 %      plots for all beams - for particles: scroll mousewheel to access different energies
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 numOfBeams = size(stf,2);
0032 
0033 % construct look up table weight --> bixel
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         % plot weights for all beams in one figure
0050         figure;
0051         rowNum = floor(sqrt(numOfBeams)); % number of rows in subplot
0052         colNum = ceil(numOfBeams/rowNum); % numberof columns in subplot
0053         % maximum weight
0054         w_max = max(weights);
0055         
0056         for i=1:numOfBeams
0057            
0058            % find range of ray positions within beam
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            % initialise weight matrix
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                % find weight for this ray
0071                weight_ix = and((bixelLut.beamNum==i), (bixelLut.rayNum==j));
0072                % normalize weight
0073                w_norm = weights(weight_ix)/w_max;
0074                % find position in matrix corresponding to ray
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            % plot weight matrix
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         % for protons and carbon Ions consider different energies as well
0097         % maximum weight
0098         w_max = max(weights);
0099         
0100         for i=1:numOfBeams
0101            fprintf(['Calculate weights for Beam ' num2str(i) '...\n']);
0102            
0103            % find range of ray positions within beam
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            % find all energies used
0111            all_energies{i} = unique(cat(2, stf(i).ray(:).energy));
0112            numOfEnergies(i) = length(all_energies{i});
0113            
0114            % initialise weight matrix
0115            weight_matrix{i} = zeros((x_max-x_min)/stf(i).bixelWidth,(z_max-z_min)/stf(i).bixelWidth, numOfEnergies(i));
0116            
0117            % find all bixel in this beam
0118            beam_ix = (bixelLut.beamNum == i);
0119            
0120            for j=1:numOfEnergies(i)
0121                % find all bixel with this energy
0122                energy_ix = and((bixelLut.energy == all_energies{i}(j)),beam_ix) ;
0123                
0124                for k=1:stf(i).numOfRays
0125                    % find weights for this ray
0126                    weight_ix = and((bixelLut.rayNum==k),energy_ix);
0127 
0128                    % normalize weight
0129                    w_norm = weights(weight_ix)/w_max;
0130                    if isempty(w_norm)
0131                        w_norm = 0;
0132                    end
0133                    
0134                    % find position in matrix corresponding to ray
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            % new figure for each beam
0143            figure('Name', sprintf(['Beam ' num2str(i)]), 'WindowScrollWheelFcn', @figScroll);
0144            ax = axes;
0145            
0146            curr_ix_energy(i) = 1; % current energy slice index
0147            
0148            % plot spot weights
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       % function to enable scrolling through energy slices
0168         
0169       % get handles for current figure and object
0170       curr_fig = gcf;
0171       curr_ax = gca(curr_fig);
0172       childrenOfAx = get(curr_ax,'Children');
0173       
0174       % get current beam number
0175       fig_name = get(curr_fig,'Name');
0176       curr_beam = str2double(fig_name(end));
0177       
0178       % set new energy slice
0179       curr_ix_energy(curr_beam) = curr_ix_energy(curr_beam) - callbackdata.VerticalScrollCount;
0180       
0181       % project to allowed range
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       % change Data in plot
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

| Generated by m2html © 2005