function C = gcrf(varargin)
% GCRF  Grid CRF constructor
%
% C = GCRF(L,M,N,D,I,S) where L is the number of labels, M is the number
% of node features, and N is the number of edge features. D
% indicates whether default edge features (node features paired with
% neighboring labels) are used. I is to indicate (an)isotropy on edges. S is
% to indicate label symmetry on edges.

% C = GCRF Creates an empty/default object
% C = GCRF(A) where A is a gcrf object will return a copy of A
  
% Fields:
%   numLabels
%   weights
%   defEdge
%   isotropic
%   symmetric

    
% Jerod Weinman
% jerod@acm.org
    
% $Id: gcrf.m 1 2009-05-07 13:41:00Z weinman $
 
% 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/>.

  if nargin == 0
	
	% Set fields
	C.numLabels = 0;
	C.weights = [];
	C.defEdge = false;
	C.isotropic = 0;
	C.symmetric = 0;
	
	C = class(C,'gcrf');
  elseif nargin == 1 & isa(varargin{1},'gcrf')
	
	C = varargin{1};
	
  else

	L = varargin{1};
	M = varargin{2};
	N = varargin{3};
	
	if nargin<4
	  D = 1;
	else
	  D = varargin{4};
	end;
	
	if nargin<5
	  I = 0;
	else
	  I = varargin{5};
	end;
	
	if nargin<6
	  S = 0;
	else
	  S = varargin{6};
	end;
	
	W = struct('node',{zeros(M+1,L)}, ...
			   'hEdge',{zeros(L,L,N+1)}, ...
			   'vEdge',{zeros(L,L,N+1)}, ...
			   'dhEdge',{zeros(L,L,M,2)},...
			   'dvEdge',{zeros(L,L,M,2)} );

	% Set fields
	C.numLabels = L;
	C.weights = W;
	C.defEdge = D;
	C.isotropic = I;
	C.symmetric = S;
	
	C = class(C,'gcrf');
  end;
  
