function v=lookup(d,phi,thd,table,dsz)
% Lookup values from an edge pair geometry table
%
% Parameters:
%
%   d       Distance
%   phi     Direction
%   thd     Orientation difference
%   table   Edge pair geometry table
%   dsz     Size of a distance bin table
%
% Return:
%
%   v       The value
%
% Copyright (C) 2001-2009 Center for Perceptual Systems

% Get table dimensions
dbins=size(table,1);
phibins=size(table,2);
thdbins=size(table,3);

% Determine radians per bin
phisz=2*pi/phibins;
thdsz=2*pi/thdbins;

% Get bin numbers
[dbin,phibin,thdbin]=getbins(d,phi,thd,dsz,phisz,thdsz);

% Get a linear index
ind=getindex(dbin,phibin,thdbin,dbins,phibins);

% Get the value
v=table(ind);
