% Description:
%
%       GaussianTable.m computes a specialized Gaussian lookup table.
%       This table was created in an attempt to speed up the algorithm,
%       which is why it may not make a lot of sense at first.
%       
% Input:
%
%       d - side of a block
%       sigma - width of the Gaussian
%       nr - number of blocks that span the rows
%       nc - number of blocks that span the columns
%
% Output:
%
%       table - the specialized Gaussian table
%

function [table] = GaussianTable(d,sigma,nr,nc)

table = zeros(d*nr,d*nc);

% Block (1,1)
for x = 1:1:d/2,
    for y = x:1:d/2,
        value = Gaussian(d,1,1,x,y,sigma);
        table(x,y) = value;
        table(y,x) = value;
        table((d-x+1),y) = value;
        table(y,(d-x+1)) = value;
        table(x,(d-y+1)) = value;
        table((d-y+1),x) = value;
        table((d-x+1),(d-y+1)) = value;
        table((d-y+1),(d-x+1)) = value;
    end
end

% Diagonal Blocks (Assume nr < nc)
for j = 2:1:nr,
    k = j; 
    
    for x = 1:1:d,
        for y = x:1:d,
            value = Gaussian(d,j,k,x,y,sigma);
            table((d*(j-1)+x),(d*(k-1)+y)) = value;
            table((d*(k-1)+y),(d*(j-1)+x)) = value;
        end
    end
    
end

% Fill in the Square
for j = 1:1:nr-1,
    for k = j+1:1:nr,
        
        for x = 1:1:d,
            for y = 1:1:d,
                value = Gaussian(d,j,k,x,y,sigma);
                table((d*(j-1)+x),(d*(k-1)+y)) = value;
                table((d*(k-1)+y),(d*(j-1)+x)) = value;
            end
        end
        
    end
end

% Fill in the Right
for j = 1:1:nr,
    for k = nr+1:1:nc,
        
        for x = 1:1:d,
            for y = 1:1:d,
                value = Gaussian(d,j,k,x,y,sigma);
                table((d*(j-1)+x),(d*(k-1)+y)) = value;
            end
        end
        
    end
end
        
                
                
    