function plotgeometry(d,phi,thd,w,len,symm)
% Plot edge pair geometry
%
% Parameters:
%
%   d       Distance
%   phi     Direction
%   thd     Orientation difference
%   w       Weight
%   len     Length in pixels of an edge element
%   symm    Orientation symmetry flag
%
% Notes:
%
%   The weight is a value from 0.0 to 1.0 that is used as a
%   lookup in the colormap.
%
%   When the orientation symmetry flag is set, edge elements
%   are plotted such that their orientations are
%   rotationally symmetric.
%
% Copyright (C) 2001-2009 Center for Perceptual Systems

% First sort by weight so that edges with lower weights are
% plotted first.
tmp=sortrows([w(:)';d(:)';phi(:)';thd(:)']');
w=tmp(:,1);
d=tmp(:,2);
phi=tmp(:,3);
thd=tmp(:,4);

% Get coordinates
[x,y]=pol2cart(phi(:),d(:));
[u,v]=pol2cart(thd(:),len);
% Draw lines
if symm==true
    h=line([(x-u)';(x+u)'],[(y-v)';(y+v)']);
else
    h=line([x';(x+u)'],[y';(y+v)']);
end

% Use a modified hsv colormap
map=hsv(340); map=map(256:-1:1,:);

% Set the color according to w
for j=1:length(w)
    set(h(j),'color',map(round(w(j)*255+1),:));
end

% Set aspect ratio
daspect([1 1 1])
