-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctf_read_headshape.m
104 lines (84 loc) · 3 KB
/
ctf_read_headshape.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function HeadShape = ctf_read_headshape(file)
% ctf_read_headshape - read a CTF .shape file
%
% HeadShape = ctf_read_headshape(fileName)
%
% The *.shape file is an ascii text file in the following format:
%
% Number of Points
% x1 y1 z1
% x2 y2 z2
% .
% .
% .
% xn yn zn
%
%
% These vertex coordinates are returned into HeadShape (Nx3). The
% coordinate values are in centimeters in either the voxel MRI
% coordinate system or the MEG Head Coordinate System (see
% ctf_read_mri for more about the coordinate system).
%
% $Revision: 1.1 $ $Date: 2009-01-30 03:49:27 $
% Copyright (C) 2004 Darren L. Weber
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
% History: 02/2004, Darren.Weber_at_radiology.ucsf.edu
% - adapted from an appendex to CTF document
% MRIViewer.pdf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ver = '[$Revision: 1.1 $]';
fprintf('CTF_READ_HEADSHAPE [v%s]\n',ver(12:16)); tic;
fprintf('...checking file input parameter\n');
if ~exist('file','var'),
[fileName, filePath, filterIndex] = uigetfile('*.shape', 'Locate CTF .shape file');
file = fullfile(filePath, fileName);
elseif isempty(file),
fprintf('...file is empty\n');
[fileName, filePath, filterIndex] = uigetfile('*.shape', 'Locate CTF .shape file');
file = fullfile(filePath, fileName);
end
if ~exist(file,'file'),
fprintf('...file does not exist\n');
[fileName, filePath, filterIndex] = uigetfile('*.shape', 'Locate CTF .shape file');
file = fullfile(filePath, fileName);
end
fid = fopen(file,'r');
if isequal(fid,-1),
S=sprintf('Could not open file: "%s"',file);
error(S);
else
fprintf('...reading CTF head shape file (.shape)\n');
tic;
% Check for comment on first line of file
frewind(fid); temp = fscanf(fid,'%s',1); frewind(fid);
if findstr(temp,'#'), temp = fgetl(fid); end
% Read vertices
Nvertices = fscanf(fid,'%d',1);
fprintf('...reading %d vertices\n',Nvertices);
vertices = fscanf(fid,'%f',[3,Nvertices]);
% translate
HeadShape = vertices';
% Read faces
%Nfaces = fscanf(fid,'%d',1);
%fprintf('...Reading %d Faces\n',Nfaces);
%faces = fscanf(fid,'%d',[4,Nfaces]);
% remove first row (index) & translate
%faces = faces(2:4,:)';
fclose(fid);
t = toc;
fprintf('...done (%6.2f sec).\n\n',t);
end
return