% Plot reconstructed conductivity with or without numbers
%
% Inputs:
% n            size of the grid is nxn
% condmatH     conductivity values between horizontal neighbors, nx(n-1) matrix
% condmatV     conductivity values between vertical neighbors, (n-1)x n matrix
% fignum       figure window number
% scaleMIN     maximum cond value for setting the colorscale
% scaleMAX     maximum cond value for setting the colorscale
%
% Samuli Siltanen May 2025

function EIT_FD_demo2D_recon_colors_plot(n,condmatH,condmatV,fignum,scaleMIN,scaleMAX)

% Record and check the size of the conductivity matrices
[cHrow,cHcol] = size(condmatH);
if ~(cHrow==(cHcol+1))
    error('Conductivity matrix condmatH should be nx(n-1) size')
end
if ~(cHrow==n)
    error('Conductivity matrix condmatH has wrong size')
end
[cVrow,cVcol] = size(condmatV);
if ~(cVrow==(cVcol-1))
    error('Conductivity matrix condmatV should be (n-1)x n size')
end
if ~(cVcol==n)
    error('Conductivity matrix condmatV has wrong size')
end


% Set display parameters
geometry_set;

% Create plot window
figure(fignum)
clf

% Left (Western) boundary has conductivity = 1
for rrr=1:n
    curr_cond_color = colorscale_cond_scaled(1,scaleMIN,scaleMAX);
    p = patch([0 Dx/2 0],(n-rrr)+[0 Dx/2 Dx],curr_cond_color);
    set(p,'edgecolor',curr_cond_color)
    hold on
end
% Right (Eastern) boundary has conductivity = 1
for rrr=1:n
    curr_cond_color = colorscale_cond_scaled(1,scaleMIN,scaleMAX);
    p = patch(n*Dx-[0 Dx/2 0],(n-rrr)+[0 Dx/2 Dx],curr_cond_color);
    set(p,'edgecolor',curr_cond_color)
    hold on
end
% Top (northern) boundary has conductivity = 1
for ccc=1:n
    curr_cond_color = colorscale_cond_scaled(1,scaleMIN,scaleMAX);
    p = patch((ccc-1)*Dx+[0 Dx/2 Dx],n*Dx-[0 Dx/2 0],curr_cond_color);
    set(p,'edgecolor',curr_cond_color)
    hold on
end
% Bottom (Southern) boundary has conductivity = 1
for ccc=1:n
    curr_cond_color = colorscale_cond_scaled(1,scaleMIN,scaleMAX);
    p = patch((ccc-1)*Dx+[0 Dx/2 Dx],[0 Dx/2 0],curr_cond_color);
    set(p,'edgecolor',curr_cond_color)
    hold on
end

% Conductivities inside the grid (not at the boundary
star_x = [-Dx/2 0    Dx/2  0   ];
star_y = [ 0    Dx/2 0    -Dx/2];
% First: conductivities between horizontal neighbors
for rrr = 1:n
    for ccc = 1:(n-1)
        curr_cond_color = colorscale_cond_scaled(condmatH(rrr,ccc),scaleMIN,scaleMAX);
        pc = patch(ccc*Dx+star_x,(n-rrr+.5)*Dx+star_y,curr_cond_color);
        set(pc,'edgecolor',curr_cond_color);
    end
end
% Then: conductivities between vertical neighbors
for rrr = 1:(n-1)
    for ccc = 1:n
        curr_cond_color = colorscale_cond_scaled(condmatV(rrr,ccc),scaleMIN,scaleMAX);
        pc = patch((ccc-.5)*Dx+star_x,(n-rrr)*Dx+star_y,curr_cond_color);
        set(pc,'edgecolor',curr_cond_color);
    end
end



% Axis settings
axis([-3*Dx (n+3)*Dx -3*Dx (n+3)*Dx])
axis equal
axis off



