forked from fangq/iso2mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readasc.m
46 lines (41 loc) · 901 Bytes
/
readasc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function [node,elem]=readasc(fname)
%
% [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)
%
node=[];
elem=[];
fid=fopen(fname,'rt');
if(fid==-1)
error(['can not read file ' fname]);
end
line=fgetl(fid); % the first line is #!ascii ....
dim=fscanf(fid,'%d',2);
node=fscanf(fid,'%f',[4,dim(1)])';
elem=fscanf(fid,'%f',inf);
fclose(fid);
if(length(elem)==4*dim(2))
elem=reshape(elem,[4,dim(2)])';
elseif(length(elem)==8*dim(2))
elem=reshape(elem,[8,dim(2)])';
end
if(~any(node(:,end)))
node=node(:,1:end-1);
end
if(~any(elem(:,end)))
elem=elem(:,1:end-1);
end
elem=elem+1;