0001 function mesh_write_fs_overlay(p)
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
0028
0029 fprintf('\nMESH_WRITE_FS_OVERLAY...\n');
0030
0031 if ~exist('p','var'),
0032 error('...no input p struct.\n');
0033 elseif isempty(p),
0034 error('...input p struct is empty.\n');
0035 elseif isempty(p.mesh.data),
0036 error('...input p struct has no mesh data.\n');
0037 end
0038
0039 [path,name,ext] = fileparts(strcat(p.mesh.path,filesep,p.mesh.file));
0040 file = fullfile(path,[name ext]);
0041
0042 fprintf('...writing FreeSurfer overlays to:\n\t%s\n',path);
0043
0044 tic;
0045
0046 Meshes = p.mesh.data.meshtype;
0047
0048 [path,name,ext] = fileparts(file);
0049
0050 for i=1:size(Meshes,2),
0051
0052 if Meshes{i},
0053
0054
0055 if size(p.mesh.data.Cdata,2) >= i,
0056 if ~isempty(p.mesh.data.Cdata{i}),
0057 if size(p.mesh.data.Cdata{i},2) > 1,
0058
0059 w = p.mesh.data.Cdata{i}(:,p.mesh.samplePoint);
0060 else
0061 w = p.mesh.data.Cdata{i};
0062 end
0063
0064 outputExt = [ext, '.w'];
0065 outputName = strcat(name,'.',Meshes{i});
0066 outputFile = fullfile(path,[outputName outputExt]);
0067
0068 fprintf('...writing overlay: %s\n',[outputName outputExt]);
0069 fs_write_wfile(outputFile,w);
0070 else
0071 msg = sprintf('\np.mesh.data.Cdata{%d} is empty\n',i);
0072 warning(msg);
0073 end
0074 else
0075 msg = sprintf('\nno p.mesh.data.Cdata{%d}\n',i);
0076 warning(msg);
0077 end
0078 end
0079 end
0080
0081 t=toc; fprintf('...done (%5.2f sec).\n\n',t);
0082
0083 return