% sessionTag: 1:session A, 2:session B
function [ output_args ] = plot_SAP(ddd,algo,sessionTag)
figure;
temp = squeeze(mean(ddd,3));
temp = temp(:,any(temp));
data(:,1) = mean(temp,2);
rscale = [ 4.2 10.5 17.5];
session_A_index = [1 2 5 6 9  10 13 14 17 18 21 22 27 28 31 32 35 36 39];
session_B_index = [3 4 7 8 11 12 15 16 19 20 23 24 25 26 29 30 33 34 37 38];
session_A_s_index = [1 5 9  13 17 21 27 31 35 39];
session_B_s_index = [3 7 11 15 19 23 25 29 33 37];

if(isempty(data))
    colorScaled = rand(1,20);
else
    if sessionTag==1
        [a,b] = max(data(session_A_s_index,1));
        [c,d] = min(data(session_A_s_index,1));
        colorScaled(session_A_s_index) = (data(session_A_s_index,1)-c)/(a-c);
        colorScaled(session_B_s_index) = 1;
    elseif sessionTag == 2
        [a,b] = max(data(session_B_s_index,1));
        [c,d] = min(data(session_B_s_index,1));
        colorScaled(session_B_s_index) = (data(session_B_s_index,1)-c)/(a-c);
        colorScaled(session_A_s_index) = 1;
    elseif sessionTag ==3
    %%
        [a,b] = max(data);
        [c,d] = min(data);
        colorScaled = (data-c)/(a-c);
    %         colorScaled = data/a(1);
    %     meanFeatures = mean(temp,1);
    %     stdFeatures = std(temp,1);
    %     colorScaled = mean((temp-repmat(meanFeatures,size(temp,1),1))./(repmat(stdFeatures,size(temp,1),1)),2);
    %     [a,b] = max(colorScaled);
    %     [c,d] = min(colorScaled);
    %     colorScaled = (colorScaled-c)/(a-c);
    elseif sessionTag ==4 %standard SAP
        a = 40;
        c = 0;
        colorScaled = (data-c)/(a-c);
    %%
end
if(size(data,1)==39)
    colorIndex = [1:2:39];
    %     colorIndex = [2:2:38 39];
else
    colorIndex = [1:20];
end
t=0:0.001:1;
%inner ring
s1=rscale(1)*sin(2*pi/4*t);
c1=rscale(1)*cos(2*pi/4*t);
s2=rscale(1)*sin(2*pi/4*(t+1));
c2=rscale(1)*cos(2*pi/4*(t+1));
s3=rscale(1)*sin(2*pi/4*(t+2));
c3=rscale(1)*cos(2*pi/4*(t+2));
s4=rscale(1)*sin(2*pi/4*(t+3));
c4=rscale(1)*cos(2*pi/4*(t+3));
%middle ring
s5=rscale(2)*sin(2*pi/8*t);
c5=rscale(2)*cos(2*pi/8*t);
s6=rscale(2)*sin(2*pi/8*(t+1));
c6=rscale(2)*cos(2*pi/8*(t+1));
s7=rscale(2)*sin(2*pi/8*(t+2));
c7=rscale(2)*cos(2*pi/8*(t+2));
s8=rscale(2)*sin(2*pi/8*(t+3));
c8=rscale(2)*cos(2*pi/8*(t+3));
s9=rscale(2)*sin(2*pi/8*(t+4));
c9=rscale(2)*cos(2*pi/8*(t+4));
s10=rscale(2)*sin(2*pi/8*(t+5));
c10=rscale(2)*cos(2*pi/8*(t+5));
s11=rscale(2)*sin(2*pi/8*(t+6));
c11=rscale(2)*cos(2*pi/8*(t+6));
s12=rscale(2)*sin(2*pi/8*(t+7));
c12=rscale(2)*cos(2*pi/8*(t+7));
%outter ring
s13=rscale(3)*sin(2*pi/8*t);
c13=rscale(3)*cos(2*pi/8*t);
s14=rscale(3)*sin(2*pi/8*(t+1));
c14=rscale(3)*cos(2*pi/8*(t+1));
s15=rscale(3)*sin(2*pi/8*(t+2));
c15=rscale(3)*cos(2*pi/8*(t+2));
s16=rscale(3)*sin(2*pi/8*(t+3));
c16=rscale(3)*cos(2*pi/8*(t+3));
s17=rscale(3)*sin(2*pi/8*(t+4));
c17=rscale(3)*cos(2*pi/8*(t+4));
s18=rscale(3)*sin(2*pi/8*(t+5));
c18=rscale(3)*cos(2*pi/8*(t+5));
s19=rscale(3)*sin(2*pi/8*(t+6));
c19=rscale(3)*cos(2*pi/8*(t+6));
s20=rscale(3)*sin(2*pi/8*(t+7));
c20=rscale(3)*cos(2*pi/8*(t+7));
%outter ring
patch([0,s13],[0,c13],[1 1 1]*colorScaled(colorIndex(13)),'linestyle','none');
patch([0,s14],[0,c14],[1 1 1]*colorScaled(colorIndex(14)),'linestyle','none');
patch([0,s15],[0,c15],[1 1 1]*colorScaled(colorIndex(15)),'linestyle','none');
patch([0,s16],[0,c16],[1 1 1]*colorScaled(colorIndex(16)),'linestyle','none');
patch([0,s17],[0,c17],[1 1 1]*colorScaled(colorIndex(17)),'linestyle','none');
patch([0,s18],[0,c18],[1 1 1]*colorScaled(colorIndex(18)),'linestyle','none');
patch([0,s19],[0,c19],[1 1 1]*colorScaled(colorIndex(19)),'linestyle','none');
patch([0,s20],[0,c20],[1 1 1]*colorScaled(colorIndex(20)),'linestyle','none');
%middle ring
patch([0,s5],[0,c5],[1 1 1]*colorScaled(colorIndex(5)),'linestyle','none');
patch([0,s6],[0,c6],[1 1 1]*colorScaled(colorIndex(6)),'linestyle','none');
patch([0,s7],[0,c7],[1 1 1]*colorScaled(colorIndex(7)),'linestyle','none');
patch([0,s8],[0,c8],[1 1 1]*colorScaled(colorIndex(8)),'linestyle','none');
patch([0,s9],[0,c9],[1 1 1]*colorScaled(colorIndex(9)),'linestyle','none');
patch([0,s10],[0,c10],[1 1 1]*colorScaled(colorIndex(10)),'linestyle','none');
patch([0,s11],[0,c11],[1 1 1]*colorScaled(colorIndex(11)),'linestyle','none');
patch([0,s12],[0,c12],[1 1 1]*colorScaled(colorIndex(12)),'linestyle','none');
%inner ring
patch([0,s1],[0,c1],[1 1 1]*colorScaled(colorIndex(1)),'linestyle','none');
patch([0,s2],[0,c2],[1 1 1]*colorScaled(colorIndex(2)),'linestyle','none');
patch([0,s3],[0,c3],[1 1 1]*colorScaled(colorIndex(3)),'linestyle','none');
patch([0,s4],[0,c4],[1 1 1]*colorScaled(colorIndex(4)),'linestyle','none');
hold on;
%lines
rs1=rscale(1)*sin(2*pi*t);
rc1=rscale(1)*cos(2*pi*t);
rs2=rscale(2)*sin(2*pi*t);
rc2=rscale(2)*cos(2*pi*t);
rs3=rscale(2)*sin(2*pi*t);
rc3=rscale(2)*cos(2*pi*t);
plot(rs1,rc1,'k',rs2,rc2,'k',rs3,rc3,'k');
gca;
plot([-rscale(3) rscale(3)],[0 0],'k');
plot([0 0],[-rscale(3) rscale(3)],'k');
xlim([-20 20]);
ylim([-20 20]);
set(gca,'linewidth',2)
set(gca,'XTick',[-20:5:20]);
% set(gca,'XTickLabelRotation',45);
box off;
ylabel('degree');
xlabel('degree');
set(gca,'fontsize',20)
axis equal;
title(algo);
colorbar;
colormap('gray');
end

