
close all

pat_path='C:\010-work\003_localGit\WiscPlan_v2\data\PatientData';

% geometry
load([pat_path '\matlab_files\Geometry.mat'])
load([pat_path '\matlab_files\optResults.mat'])


CTin=Geometry.data;
dose_01 = optResults.dose{end};
% colorwash(CTin, dose_01, [-500, 500], [0,60])




%% Get the original image DVH
roi_idx = 1;
color_01 = [0.9,0.1,0.1];


ROI_01 = logical(zeros(size(CTin)));
ROI_01(Geometry.ROIS{1, roi_idx}.ind) = 1;
%     orthoslice(ROI, [0,1])

%% get the DVH for a shifted image (but no corrections)
% Shift up
color_10 = [0.9,0.1,0.9];
for plotIdx =1:8;
    
    shiftAngleList= [0, pi/2, pi, 1.5*pi];
    shiftAngle = shiftAngleList(1);
    
    shiftmag = 0.25 *plotIdx;

    shift = shiftmag * [cos(shiftAngle), sin(shiftAngle)];

    dose_s1 = imtranslate(dose_01, shift, 'FillValues', 0);
    [dvh_10{plotIdx}, dosebins_10{plotIdx}] = dvhist(dose_s1, ROI_01);

end
% colorwash(CTin, dose_s1, [-500, 500], [0,60])


color_11 = [0.5,0.2,0.3];
for plotIdx=1:10;
    shiftmag = 1;
    shiftAngle= 2*pi*rand();

    shift = shiftmag*rand() * [cos(shiftAngle), sin(shiftAngle)];
    
    dose_s1 = imtranslate(dose_01, shift, 'FillValues', 0);
    [dvh_11{plotIdx}, dosebins_11{plotIdx}] = dvhist(dose_s1, ROI_01);
end

%% get DVH for shifted CT images
color_20 = [0.5,0.2,0.8];
load('dosePert_01.mat')
[dvh_20{1}, dosebins_20{1}] = dvhist(D, ROI_01);
load('dosePert_02.mat')
[dvh_20{2}, dosebins_20{2}] = dvhist(D, ROI_01);
load('dosePert_03.mat')
[dvh_20{3}, dosebins_20{3}] = dvhist(D, ROI_01);
load('dosePert_04.mat')
[dvh_20{4}, dosebins_20{4}] = dvhist(D, ROI_01);

%% get DVH for shifted CT images
color_30 = [0.2,0.9,0.2];
load('dosePert_11.mat')
[dvh_30{1}, dosebins_30{1}] = dvhist(D, ROI_01);
load('dosePert_12.mat')
[dvh_30{2}, dosebins_30{2}] = dvhist(D, ROI_01);
load('dosePert_13.mat')
[dvh_30{3}, dosebins_30{3}] = dvhist(D, ROI_01);
load('dosePert_14.mat')
[dvh_30{4}, dosebins_30{4}] = dvhist(D, ROI_01);
load('dosePert_15.mat')
[dvh_30{5}, dosebins_30{5}] = dvhist(D, ROI_01);
load('dosePert_16.mat')
[dvh_30{6}, dosebins_30{6}] = dvhist(D, ROI_01);

%%      Plot stuff
% colorwash(CTin, D, [-500, 500], [0,60])

%       original image
[dvh_01, dosebins_01] = dvhist(dose_01, ROI_01);
figure
hold on
% %    ---- shifted dose
for i=1:size(dosebins_10,2)
plot(dosebins_10{i}, dvh_10{i}, 'Color', color_10 , 'LineStyle', '--', 'DisplayName', 'test');
end

for i=1:size(dosebins_11,2)
plot(dosebins_11{i}, dvh_11{i}, 'Color', color_11 , 'LineStyle', '--', 'DisplayName', 'test');
end

for i=1:4
plot(dosebins_20{i}, dvh_20{i}, 'Color', color_20 , 'LineStyle', '--', 'DisplayName', 'test');
end
% 
% for i=1:6
% plot(dosebins_30{i}, dvh_30{i}, 'Color', color_30 , 'LineStyle', '--', 'DisplayName', 'test');
% end

plot(dosebins_01, dvh_01, 'Color', color_01 , 'LineStyle', '-', 'DisplayName', 'test');
hold off

xlabel('Dose (Gy)')
ylabel('Volume (%)')

