function [ DMAP, MAP, MLINE, ROIMAP ] = otl2dmap(X, Y, SZ, NFILL)
% [ DMAP, MAP, MLINE, ROIMAP ] = otl2dmap(X, Y, SZ, NFILL)
%
% Create a distance-map for use in shape-based interpolation.
% (Raya and Udupa, IEEE Trans. on Medical Imaging, 9(1):32-42, 1990).
%
% First, X and Y are converted into a MAP and ROIMAP using otl2map.
%
% Next, we compute the distance from each point in ROIMAP to the nearest
% boundary point.  That distance is written into the distance map DMAP.
%
% Points which are inside the boundary have positive distances, and points
% which are outside the boundary have negative distances.
%
% Thus we create a sort of "image" whose intensities get monotonically larger
% as you get closer to the "center" of any region of interest.
%

% Create a map and ROIMAP
[ MAP, MLINE, ROIMAP ] = otl2map(X, Y, SZ, NFILL);

% If X is zero-length, return an all-zero DMAP!!
if length(X)==0, 
  DMAP = zeros(SZ);
  return;
end;

% Get the list of all pixels on the outline
[ yOTL, xOTL ] = find(ROIMAP);

% Find the DMAP
DMAP = mkdmap( xOTL, yOTL, MAP );
