Home > bioelectromagnetism > mesh_freesurferTRI2matlab.m

mesh_freesurferTRI2matlab

PURPOSE ^

mesh_freesurferTRI2matlab - Read FreeSurfer tesselation (.tri)

SYNOPSIS ^

function [vertices,faces] = mesh_freesurferTRI2matlab(file)

DESCRIPTION ^

 mesh_freesurferTRI2matlab - Read FreeSurfer tesselation (.tri)
 
 USEAGE: [vertices,faces] = mesh_freesurferTRI2matlab(file)
 
 This function will load an ascii file that contains a one
 line specification of the number of vertices followed 
 by rows of vertex points.  It then reads a one line
 specification of the number of faces followed by rows
 of face indices into the vertex rows.  Each vertex row 
 contains a vertex index number and 3 x,y,z coordinates. 
 Each face row contains a face index and three vertex 
 indices.  Vertices in the .tri file are indexed from one
 and those returned are indexed from one.
 
 See also the mesh_freesurfer2matlab function to load
 the tesselations that are created by the mris_convert
 function of freesurfer, which have a different text format
 from those of the BEM .tri files.

 The freesurfer tesselations may contain too many faces
 for efficient computations.  If so, try 'reducepatch'.

 The returned matrices can be input to the patch command, like so:

    Hpatch = patch('Vertices',vertices,'Faces',faces,...
                   'EdgeColor',[.8 .8 .8],'FaceColor',[0.9 0.9 0.9]);

 This will plot the mesh as a patch object.  See the patch command
 and matlab help for more information on coloring this object.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [vertices,faces] = mesh_freesurferTRI2matlab(file)
0002 
0003 % mesh_freesurferTRI2matlab - Read FreeSurfer tesselation (.tri)
0004 %
0005 % USEAGE: [vertices,faces] = mesh_freesurferTRI2matlab(file)
0006 %
0007 % This function will load an ascii file that contains a one
0008 % line specification of the number of vertices followed
0009 % by rows of vertex points.  It then reads a one line
0010 % specification of the number of faces followed by rows
0011 % of face indices into the vertex rows.  Each vertex row
0012 % contains a vertex index number and 3 x,y,z coordinates.
0013 % Each face row contains a face index and three vertex
0014 % indices.  Vertices in the .tri file are indexed from one
0015 % and those returned are indexed from one.
0016 %
0017 % See also the mesh_freesurfer2matlab function to load
0018 % the tesselations that are created by the mris_convert
0019 % function of freesurfer, which have a different text format
0020 % from those of the BEM .tri files.
0021 %
0022 % The freesurfer tesselations may contain too many faces
0023 % for efficient computations.  If so, try 'reducepatch'.
0024 %
0025 % The returned matrices can be input to the patch command, like so:
0026 %
0027 %    Hpatch = patch('Vertices',vertices,'Faces',faces,...
0028 %                   'EdgeColor',[.8 .8 .8],'FaceColor',[0.9 0.9 0.9]);
0029 %
0030 % This will plot the mesh as a patch object.  See the patch command
0031 % and matlab help for more information on coloring this object.
0032 %
0033 
0034 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $
0035 
0036 % Licence:  GNU GPL, no implied or express warranties
0037 % History:  03/02 Darren.Weber_at_radiology.ucsf.edu
0038 %
0039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0040 
0041 fid = fopen(file,'r');
0042 
0043 if isequal(fid,-1),
0044     S=sprintf('Could not open file: "%s"',file);
0045     error(S);
0046 else
0047     
0048     fprintf('...Reading FreeSurfer Tesselation (.tri)\n');
0049     
0050     tic;
0051     
0052     % Check for comment on first line of file
0053     frewind(fid); temp = fscanf(fid,'%s',1); frewind(fid);
0054     if findstr(temp,'#'), temp = fgetl(fid); end
0055     
0056     % Read vertices
0057     Nvertices = fscanf(fid,'%d',1);
0058     fprintf('...Reading %d Vertices\n',Nvertices);
0059     vertices = fscanf(fid,'%f',[4,Nvertices]);
0060     % remove first row (index) and translate
0061     vertices = vertices(2:4,:)';
0062     
0063     % Read faces
0064     Nfaces    = fscanf(fid,'%d',1);
0065     fprintf('...Reading %d Faces\n',Nfaces);
0066     faces = fscanf(fid,'%d',[4,Nfaces]);
0067     % remove first row (index) & translate
0068     faces = faces(2:4,:)';
0069     
0070     fclose(fid);
0071     
0072     t = toc;
0073     fprintf('...done (%6.2f sec).\n',t);
0074     
0075 end
0076 
0077 return

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