Home > vbmeg > external > mne > mne_write_surface.m

mne_write_surface

PURPOSE ^

SYNOPSIS ^

function mne_write_surface(fname,verts,faces,comment)

DESCRIPTION ^

 mne_write_surface(fname,verts,faces)

 Writes a FreeSurfer surface file

 fname       - The file to write
 verts       - Vertex coordinates in meters
 faces       - The triangle descriptions
 comment     - Optional comment to include

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mne_write_surface(fname,verts,faces,comment)
0002 %
0003 % mne_write_surface(fname,verts,faces)
0004 %
0005 % Writes a FreeSurfer surface file
0006 %
0007 % fname       - The file to write
0008 % verts       - Vertex coordinates in meters
0009 % faces       - The triangle descriptions
0010 % comment     - Optional comment to include
0011 %
0012 
0013 %
0014 %   Author : Matti Hamalainen, MGH Martinos Center
0015 %   License : BSD 3-clause
0016 %
0017 %
0018 %   Revision 1.1  2009/01/28 19:27:59  msh
0019 %   Added mne_write_surface
0020 %
0021 
0022 me='MNE:mne_write_surface';
0023 
0024 if nargin < 4
0025     comment = 'Triangle file written with MNE Matlab tools';
0026 end
0027 %
0028 %   The input file will be big endian
0029 %
0030 fid = fopen(fname,'wb','ieee-be');
0031 
0032 if (fid < 0)
0033     error(me,'Cannot open file %s', fname);
0034 end
0035 %
0036 %   Magic number to identify a TRIANGLE file
0037 %
0038 %
0039 TRIANGLE_FILE_MAGIC_NUMBER =  16777214 ;
0040 
0041 mne_fwrite3(fid,TRIANGLE_FILE_MAGIC_NUMBER) ;
0042 fprintf(fid,'%s\n\n',comment);
0043 fwrite(fid, size(verts,1), 'int32') ;
0044 fwrite(fid, size(faces,1), 'int32') ;
0045 fwrite(fid, 1000.0*reshape(verts',1,numel(verts)), 'float32') ;
0046 fwrite(fid, reshape(faces',1,numel(faces)) - 1, 'int32') ;
0047 fclose(fid) ;
0048 fprintf(1,'\tWrote the surface file %s with %d vertices and %d triangles\n',fname,size(verts,1),size(faces,1));
0049 
0050 return;

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005