function plot_mesh_norms(vertex,face,norms,options)

% plot_mesh - plot a 3D mesh.
%
%   plot_mesh(vertex,face, options);
%
%   'options' is a structure that may contains:
%       - 'normal' : a (nvertx x 3) array specifying the normals at each vertex.
%       - 'edge_color' : a float specifying the color of the edges.
%       - 'face_color' : a float specifying the color of the faces.
%       - 'face_vertex_color' : a color per vertex or face.
%       - 'vertex'
%
%   See also: mesh_previewer.
%
%   Copyright (c) 2004 Gabriel Peyr?

if nargin<4,
    options.style = ['-'];
    options.line_width = 1;
    options.cstyle=['bgrcmyk'];
    options.len=1;
end
if isfield(options,'style')==0,
    options.style = ['-'];
end
if isfield(options,'line_width')==0,
    options.line_width = 1;
end
if isfield(options,'len')==0,
    options.len=1;
 end
 options.len=0.5;
if isfield(options,'cstyle')==0,
    options.cstyle=['bgrcmyk'];
end
% can flip to accept data in correct ordering
if (size(vertex,1)==3 | size(vertex,1)==2) & size(vertex,2)~=3
    vertex = vertex';
end
if size(face,1)==3 & size(face,2)~=3
    face = face';
end

if size(face,2)~=3 | (size(vertex,2)~=3 & size(vertex,2)~=2)
    error('face or vertex does not have correct format.');
end
%axis ij;
hold on;
for i=1:size(face,1),
   xx=[vertex(face(i,1),:); vertex(face(i,2),:); vertex(face(i,3),:)];
   xx=mean(xx);
   xx=[xx;xx+norms(i,:)*options.len];
   crstyle=[sprintf('%c%s',options.cstyle(mod(i-1,length(options.cstyle))+1),options.style)];
    
   if size(xx,2)==2,
        hh=plot(xx(:,1), xx(:,2),crstyle);
    else
        hh=plot3(xx(:,1), xx(:,2), xx(:,3),crstyle);
    end
    set(hh,'LineWidth',options.line_width);
end

return
