Home > vbmeg > external > iso2mesh > readasc.m

readasc

PURPOSE ^

SYNOPSIS ^

function [node,elem]=readasc(fname)

DESCRIPTION ^

 [node,elem]=readasc(fname)

 read FreeSurfer ASC mesh format

 author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>
 date: 2009/04/02
 
 input:
      fname: name of the asc file

 output:
      node: node positions of the mesh
      elem: element list of the mesh

 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [node,elem]=readasc(fname)
0002 %
0003 % [node,elem]=readasc(fname)
0004 %
0005 % read FreeSurfer ASC mesh format
0006 %
0007 % author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>
0008 % date: 2009/04/02
0009 %
0010 % input:
0011 %      fname: name of the asc file
0012 %
0013 % output:
0014 %      node: node positions of the mesh
0015 %      elem: element list of the mesh
0016 %
0017 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0018 %
0019 
0020 node=[];
0021 elem=[];
0022 fid=fopen(fname,'rt');
0023 if(fid==-1)
0024         error(['can not read file ' fname]);
0025 end
0026 
0027 line=fgetl(fid); % the first line is #!ascii ....
0028 dim=fscanf(fid,'%d',2);
0029 node=fscanf(fid,'%f',[4,dim(1)])';
0030 elem=fscanf(fid,'%f',inf);
0031 fclose(fid);
0032 
0033 if(length(elem)==4*dim(2))
0034     elem=reshape(elem,[4,dim(2)])';
0035 elseif(length(elem)==8*dim(2))
0036     elem=reshape(elem,[8,dim(2)])';
0037 end
0038 
0039 if(~any(node(:,end)))
0040     node=node(:,1:end-1);
0041 end
0042 if(~any(elem(:,end))) 
0043         elem=elem(:,1:end-1);
0044 end
0045 
0046 elem=elem+1;

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