Home > bioelectromagnetism > freesurfer_plot_surf.m

freesurfer_plot_surf

PURPOSE ^

freesurfer_plot_surf

SYNOPSIS ^

function [Hf,Hp] = freesurfer_plot_surf(Hf,surf,normals,orientOnly)

DESCRIPTION ^

 freesurfer_plot_surf

 [Hf,Hp] = freesurfer_plot_surf(Hf,surf,normals,orientOnly)

 Hf is a figure handle to plot into, using hold on; if empty, a new figure
 is created.

 surf is a struct, returned by freesurfer_read_surf, with fields:

    surf.faces     - Tx3 triangles of the surface
    surf.vertices  - Vx3 vertex coordinates

 normals is 0 or 1; if 1, plot the surface normal vectors; see
 freesurfer_read_surf for notes about the order of vertices in the face
 matrix to obtain outward normals. For outward normals, prior to input to
 this function, use:

    surf.faces = surf.faces(:,[1 3 2]);

 orientOnly is 0 or 1; if 1, and normals = 1, the normals are converted to
 unit normals, so they only indicate orientation.  This vector field has a
 more uniform appearance.

 Hf is a handle to the figure
 Hp is a handle to the patch object

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Hf,Hp] = freesurfer_plot_surf(Hf,surf,normals,orientOnly)
0002 
0003 % freesurfer_plot_surf
0004 %
0005 % [Hf,Hp] = freesurfer_plot_surf(Hf,surf,normals,orientOnly)
0006 %
0007 % Hf is a figure handle to plot into, using hold on; if empty, a new figure
0008 % is created.
0009 %
0010 % surf is a struct, returned by freesurfer_read_surf, with fields:
0011 %
0012 %    surf.faces     - Tx3 triangles of the surface
0013 %    surf.vertices  - Vx3 vertex coordinates
0014 %
0015 % normals is 0 or 1; if 1, plot the surface normal vectors; see
0016 % freesurfer_read_surf for notes about the order of vertices in the face
0017 % matrix to obtain outward normals. For outward normals, prior to input to
0018 % this function, use:
0019 %
0020 %    surf.faces = surf.faces(:,[1 3 2]);
0021 %
0022 % orientOnly is 0 or 1; if 1, and normals = 1, the normals are converted to
0023 % unit normals, so they only indicate orientation.  This vector field has a
0024 % more uniform appearance.
0025 %
0026 % Hf is a handle to the figure
0027 % Hp is a handle to the patch object
0028 %
0029 
0030 % $Revision: 1.4 $ $Date: 2005/08/14 21:22:42 $
0031 
0032 % Copyright (C) 2000  Darren L. Weber
0033 %
0034 % This program is free software; you can redistribute it and/or
0035 % modify it under the terms of the GNU General Public License
0036 % as published by the Free Software Foundation; either version 2
0037 % of the License, or (at your option) any later version.
0038 %
0039 % This program is distributed in the hope that it will be useful,
0040 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0041 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0042 % GNU General Public License for more details.
0043 %
0044 % You should have received a copy of the GNU General Public License
0045 % along with this program; if not, write to the Free Software
0046 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
0047 % USA.
0048 
0049 % History:  04/2005, Darren.Weber_at_radiology.ucsf.edu
0050 %           06/2005, Darren.Weber_at_radiology.ucsf.edu
0051 %                    added options to plot surface normals
0052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0053 
0054 ver = '$Revision: 1.4 $ $Date: 2005/08/14 21:22:42 $';
0055 fprintf('FREESURFER_PLOT_SURF [v %s]\n\n',ver(11:15));
0056 
0057 if ~exist('normals','var'), normals = 0; end
0058 if isempty(normals), normals = 0; end
0059 if ~exist('orientOnly','var'), orientOnly = 0; end
0060 if isempty(orientOnly), orientOnly = 0; end
0061 
0062 if normals,
0063     facecolor = [0.75 0.1 0.1];
0064 else
0065     facecolor = [0.65 0.6 0.6];
0066 end
0067 
0068 if ~exist('Hf','var'),
0069     Hf = figure; hold on
0070 end
0071 if isempty(Hf),
0072     Hf = figure; hold on
0073 end
0074 
0075 Hp = patch('vertices',surf.vertices,'faces',surf.faces,...
0076     'facecolor',facecolor,'edgecolor','none',...
0077     'FaceLighting','phong');
0078 
0079 if normals,
0080     x = surf.vertices(:,1);
0081     y = surf.vertices(:,2);
0082     z = surf.vertices(:,3);
0083     normals = get(Hp,'VertexNormals');
0084     if orientOnly,
0085         [nrm,normals] = colnorm(normals');
0086         normals = normals';
0087     end
0088     u = normals(:,1);
0089     v = normals(:,2);
0090     w = normals(:,3);
0091     quiver3(x,y,z,u,v,w,0) % do not scale the normals
0092 end
0093 
0094 daspect([1,1,1])
0095 camlight
0096 camproj('perspective')
0097 
0098 material dull
0099 lighting phong
0100 
0101 axis off
0102 rotate3d
0103 hold off
0104 
0105 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003