0001 function [stcs] = mne_morph_data(from,to,stcs,grade)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 if nargin < 5
0028 grade = 5;
0029 end
0030
0031 sphere_from = [getenv('SUBJECTS_DIR'),'/',from,'/surf/lh.sphere.reg'];
0032 [tmp, tris{1}] = mne_read_surface(sphere_from);
0033 sphere_from = [getenv('SUBJECTS_DIR'),'/',from,'/surf/rh.sphere.reg'];
0034 [tmp, tris{2}] = mne_read_surface(sphere_from);
0035
0036 [map{1}, map{2}] = mne_read_morph_map(from,to);
0037
0038 for hemi = 1:2
0039 e = mne_mesh_edges(tris{hemi});
0040 e = e==2;
0041 n_vertices = length(e);
0042 e = e + speye(n_vertices, n_vertices);
0043 idx_use = stcs{hemi}.vertices + 1;
0044 n_iter = 100;
0045 for k = 1:n_iter
0046 data1 = e(:,idx_use) * ones(length(idx_use),1);
0047 stcs{hemi}.data = e(:,idx_use)*stcs{hemi}.data;
0048 idx_use = find(data1);
0049 fprintf(1,'%d/%d ',k,length(idx_use));
0050 if ( k == n_iter ) || ( length(idx_use) >= n_vertices )
0051 stcs{hemi}.data(idx_use,:) = bsxfun(@rdivide, stcs{hemi}.data(idx_use,:), data1(idx_use));
0052 break;
0053 else
0054 stcs{hemi}.data = bsxfun(@rdivide, stcs{hemi}.data(idx_use,:), data1(idx_use));
0055 end
0056 end
0057 fprintf(1,'\n');
0058 stcs{hemi}.data = map{hemi}*stcs{hemi}.data;
0059 end
0060
0061 ico_file_name = [getenv('MNE_ROOT'),'/share/mne/icos.fif'];
0062
0063 s = mne_read_bem_surfaces(ico_file_name);
0064
0065 for k = 1:length(s)
0066 if (s(k).id == 9000 + grade)
0067 ico = s(k);
0068 break;
0069 end
0070 end
0071
0072 sphere = [getenv('SUBJECTS_DIR'),'/',to,'/surf/lh.sphere.reg'];
0073 lhs = mne_read_surface(sphere);
0074 sphere = [getenv('SUBJECTS_DIR'),'/',to,'/surf/rh.sphere.reg'];
0075 rhs = mne_read_surface(sphere);
0076
0077 nearest{1} = zeros(ico.np, 1);
0078 nearest{2} = zeros(ico.np, 1);
0079
0080 lhs = bsxfun(@rdivide, lhs, sqrt(sum(lhs.^2, 2)));
0081 rhs = bsxfun(@rdivide, rhs, sqrt(sum(rhs.^2, 2)));
0082
0083 for k = 1:size(ico.rr,1)
0084 dots = ico.rr(k,:)*lhs';
0085 [tmp, nearest{1}(k)] = max(dots);
0086 dots = ico.rr(k,:)*rhs';
0087 [tmp, nearest{2}(k)] = max(dots);
0088 end
0089
0090 stcs{1}.data = stcs{1}.data(nearest{1},:);
0091 stcs{2}.data = stcs{2}.data(nearest{2},:);
0092 stcs{1}.vertices = nearest{1}-1;
0093 stcs{2}.vertices = nearest{2}-1;
0094
0095 fprintf(1, '\n');