% --- Executes on button press in pot_plot.
function pot_plot_Callback(hObject, eventdata, handles)
global analyse_press pot_press field_press force_press
load analys_var POT
if analyse_press==1
    cla
    axis square
    pot_press=1;
    field_press=0;
    force_press=0;
    axes(handles.grid)
    pcolor(POT)
    shading flat
    shading interp
    colorbar 
    pot_overlay()
    
%     figure(1)
%     [m,n,p] = size(G.cdata);
%     mask = ones(m,n);
%     i = find(G.cdata(:,:,3)==0);
%     mask(i) = 0; %levels of transparency
%     B=imresize(G.cdata,[60 60]);
%     set(gca,'XLim',[1 613],'YLim',[1 497])    
%     MASK=imresize(mask,[60 60]);
%     %overlay images with transparency
%     h = imshow(G.cdata);
%     set(h,'AlphaData',mask)
%     colormap(G.colormap)
    
elseif analyse_press==0
    msgbox('Press analyse first')
end

function pot_overlay()
global shape invisible

[disc,page]=size(shape);
seq1=zeros(page,1);
for i=1:page
    seq1(i)=shape(i).seq;
end

[disc,pagei]=size(invisible);
seq2=zeros(pagei,1);
connect=zeros(pagei,1);
for i=1:pagei
    seq2(i)=invisible(i).seq;
    connect(i)=invisible(i).shape;
    id2=invisible(i).id;
    limcai=invisible(i).position;
    for k=1:page
        if shape(k).seq==connect(i)
            id1=shape(k).id;
            limcao=shape(k).position;
        end            
    end 
    
    if (id1==0)&&(id2==0)
        fill_ell_ell(limcao,limcai)
    elseif (id1==0)&&(id2==1)
        fill_ell_rect(limcao,limcai)
    elseif (id1==1)&&(id2==0)
        fill_rect_ell(limcao,limcai)
    elseif (id1==1)&&(id2==1)
        fill_rect_rect(limcao,limcai)
    end   
end

seq=vertcat(seq1,seq2);
rectangles=setdiff(seq,connect);
[m,n]=size(rectangles);
for i=1:m
    post=rectangles(i);
    for j=1:page
        if shape(j).seq==post
            limca=shape(j).position;
            if shape(j).id==1
                rectangle('Position',limca,'FaceColor','w','EdgeColor','w')
            elseif shape(j).id==0
                rectangle('Position',limca,'Curvature',[1 1],'FaceColor','w','EdgeColor','w')
            end
        end
    end
end
return

