function I = edgeind(N,R,C,D)
% EDGEIND Index of edge(s) originating at node(s)
%
% I = EDGEIND(N,R,C,D) where N are the node numbers, R and C are
% the grid size and D==1 indicates horizontal, or D==0 vertical
% edges

    
% Jerod Weinman
% jerod@acm.org
    
% $Id%
 
% Jerod Weinman
% jerod@acm.org
% Copyright 2004, 2008, 2009
 
%    This file is part of Matlab GridCRF.
%
%    Matlab GridCRF is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    Matlab GridCRF 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 General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with Matlab GridCRF.  If not, see <http://www.gnu.org/licenses/>.

  [Kr,Kc] = nodesub(R,C);
  
  if D
    I = sub2ind([R C-1],Kr(N),Kc(N));
  else
    I = sub2ind([R-1 C],Kr(N),Kc(N));
  end;
