function disc = makeDisc(Nx, Nz, cx, cz, radius, plot_disc)
%MAKEDISC   Create a binary map of a filled disc within a 2D grid.
%
% DESCRIPTION:
%       makeDisc creates a binary map of a filled disc within a
%       two-dimensional grid (the disc position is denoted by 1's in the
%       matrix with 0's elsewhere). A single pixel is taken as the disc
%       centre thus the total diameter of the disc will always be an odd
%       number of pixels. As the returned disc has a constant pixel radius,
%       if used within a k-space grid where dx ~= dz, the disc will appear
%       oval shaped. If part of the disc overlaps the grid edge, the rest
%       of the disc will wrap to the grid edge on the opposite side. 
%
% USAGE:
%       disc = makeDisc(Nx, Nz, cx, cz, radius)
%       disc = makeDisc(Nx, Nz, cx, cz, radius, plot_disc)
%
% INPUTS:
%       Nx, Nz          - size of the 2D grid [number of pixels]
%       cx, cz          - centre of the disc [pixel coordinates]
%       radius          - disc radius [number of pixels]
%
% OPTIONAL INPUTS:
%       plot_disc       - Boolean controlling whether the disc is plotted
%                         using imagesc (default = false)
%
% OUTPUTS:
%       disc            - 2D binary map of a filled disc
%
% ABOUT:
%       author          - Bradley Treeby
%       date            - 9th June 2009
%       last update     - 17th July 2009
%       
% This function is part of the k-Wave Toolbox (http://www.k-wave.org)
% Copyright (C) 2009, 2010, 2011 Bradley Treeby and Ben Cox
%
% See also makeCircle, makeBall 

% This file is part of k-Wave. k-Wave is free software: you can
% redistribute it and/or modify it under the terms of the GNU Lesser
% General Public License as published by the Free Software Foundation,
% either version 3 of the License, or (at your option) any later version.
% 
% k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY
% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
% FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
% more details. 
% 
% You should have received a copy of the GNU Lesser General Public License
% along with k-Wave. If not, see <http://www.gnu.org/licenses/>.

% check for plot_disc input
if nargin < 6
    plot_disc = false;
end

% check for zero values
if cx == 0
    cx = floor(Nx/2) + 1;
end
if cz == 0
    cz = floor(Nz/2) + 1;
end

% check the inputs
if cx < 1 || cx > Nx || cz < 1 || cz > Nz
    error('Disc center must be within grid');
end

% define literals
MAGNITUDE = 1;

% create empty matrix
disc = zeros(Nz, Nx);

% define pixel map
r = makePixelMap(Nx, Nz, 'Shift', [0 0]);

% create disc
disc(r < radius) = MAGNITUDE;

% shift centre
cx = round(cx) - ceil(Nx/2);
cz = round(cz) - ceil(Nz/2);
disc = circshift(disc, [cz cx]);

% create the figure
if plot_disc
    figure;
    imagesc(disc, [-1 1]);
    colormap(getColorMap);
    axis image;
    xlabel('x-position [pixels]');
    ylabel('z-position [pixels]');
end