mesh_emse2brainstorm - Convert EMSE meshes (.wfr) to brainstorm format USEAGE: [Comment,Faces,Vertices] = mesh_emse2brainstorm(fileprefix,meshes) This routine calls the mesh_emse_wfr2matlab routine for each layer of the subject tesselation required in brainstorm (ie, cortex, inner skull, scalp). It returns the variables required by BrainStorm for source modelling. The EMSE coordinate framework is different from that of Neuroscan and Brainstorm, so all vertices and faces are rearranged to suit. fileprefix should be a string containing the path and subject code for the emse meshes to load and convert. For example: 'c:\data\c01_'. If the cell array 'meshes' is given, it should contain the names of the meshes to load. Only those meshes will be loaded. For example: meshes = {'cortex','innerskull','scalp'} is the default. This routine then loads the following EMSE meshes: c:\data\c01_cortex.wfr c:\data\c01_innerskull.wfr c:\data\c01_scalp.wfr The workspace variables created are saved, in the brainstorm file format, into the file called 'c:\data\c01_subjecttess.mat'. The variables from this file can be loaded using the matlab 'load' command. To plot the default cortex, skull & scalp BrainStorm data: Hpatch1 = patch('Vertices',Vertices{1}','Faces',Faces{1},... 'EdgeColor',[.6 .6 .6],'FaceColor',[0.9 0.9 0.9]); Hpatch2 = patch('Vertices',Vertices{2}','Faces',Faces{2},... 'EdgeColor',[.6 .6 .6],'FaceColor',[0.9 0.9 0.9]); Hpatch3 = patch('Vertices',Vertices{3}','Faces',Faces{3},... 'EdgeColor',[.6 .6 .6],'FaceColor',[0.9 0.9 0.9]); See the BrainStorm website at http://neuroimage.usc.edu/brainstorm/ for more information about the BrainStorm toolbox and the format and content of the subjecttess variables. Also, see the EMSE/MRVU website at http://www.sourcesignal.com.
0001 function [Comment,Faces,Vertices] = mesh_emse2brainstorm(file,meshes) 0002 0003 % mesh_emse2brainstorm - Convert EMSE meshes (.wfr) to brainstorm format 0004 % 0005 % USEAGE: [Comment,Faces,Vertices] = mesh_emse2brainstorm(fileprefix,meshes) 0006 % 0007 % This routine calls the mesh_emse_wfr2matlab routine for 0008 % each layer of the subject tesselation required in brainstorm 0009 % (ie, cortex, inner skull, scalp). It returns the variables 0010 % required by BrainStorm for source modelling. The EMSE coordinate 0011 % framework is different from that of Neuroscan and Brainstorm, so 0012 % all vertices and faces are rearranged to suit. 0013 % 0014 % fileprefix should be a string containing the path and subject 0015 % code for the emse meshes to load and convert. For example: 0016 % 'c:\data\c01_'. If the cell array 'meshes' is given, it should 0017 % contain the names of the meshes to load. Only those meshes will 0018 % be loaded. For example: meshes = {'cortex','innerskull','scalp'} 0019 % is the default. This routine then loads the following EMSE meshes: 0020 % 0021 % c:\data\c01_cortex.wfr 0022 % c:\data\c01_innerskull.wfr 0023 % c:\data\c01_scalp.wfr 0024 % 0025 % The workspace variables created are saved, in the brainstorm 0026 % file format, into the file called 'c:\data\c01_subjecttess.mat'. 0027 % The variables from this file can be loaded using the matlab 'load' 0028 % command. To plot the default cortex, skull & scalp BrainStorm data: 0029 % 0030 % Hpatch1 = patch('Vertices',Vertices{1}','Faces',Faces{1},... 0031 % 'EdgeColor',[.6 .6 .6],'FaceColor',[0.9 0.9 0.9]); 0032 % Hpatch2 = patch('Vertices',Vertices{2}','Faces',Faces{2},... 0033 % 'EdgeColor',[.6 .6 .6],'FaceColor',[0.9 0.9 0.9]); 0034 % Hpatch3 = patch('Vertices',Vertices{3}','Faces',Faces{3},... 0035 % 'EdgeColor',[.6 .6 .6],'FaceColor',[0.9 0.9 0.9]); 0036 % 0037 % See the BrainStorm website at http://neuroimage.usc.edu/brainstorm/ 0038 % for more information about the BrainStorm toolbox and the format 0039 % and content of the subjecttess variables. Also, see the EMSE/MRVU 0040 % website at http://www.sourcesignal.com. 0041 % 0042 0043 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $ 0044 0045 % Licence: GNU GPL, no implied or express warranties 0046 % History: 01/02 Darren.Weber_at_radiology.ucsf.edu 0047 % 0048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0049 0050 % Check for existence of saved file 0051 brainstormfile = strcat(file,'subjecttess'); 0052 0053 fid = fopen(strcat(brainstormfile,'.mat'),'r'); 0054 0055 if (fid ~= -1), 0056 fclose(fid); 0057 fprintf('\nLoading BrainStorm data from %s',brainstormfile); 0058 fprintf('\nTo reload data from EMSE, first delete/rename BrainStorm data.\n\n'); 0059 load(brainstormfile); 0060 return; 0061 else 0062 0063 if ~exist('meshes','var'), 0064 meshes = {'cortex','innerskull','scalp'}; 0065 end 0066 0067 Comment = meshes; 0068 Faces = cell(size(meshes)); 0069 Vertices = cell(size(meshes)); 0070 0071 % Load EMSE data 0072 options = {'vertex','patch'}; % only load vertex & patch data 0073 for i = 1:max(size(meshes)), 0074 fprintf('\nLoading EMSE mesh: %s\n',meshes{i}); 0075 inputfile = strcat(file,meshes{i},'.wfr'); 0076 [vertices,patches] = mesh_emse2matlab(inputfile,options); 0077 % EMSE vertices are rearranged here, swapping x & y to 0078 % match the coordinate frame of the NeuroScan 3Dspace electrodes. 0079 Vertices{i} = [ vertices.y; vertices.x; vertices.z ]; % 3 x n 0080 % The faces remain the same order as they refer only to the 0081 % vertices as a set of 3D coordinates. 0082 Faces{i} = [ patches.vertex1; patches.vertex2; patches.vertex3 ]'; % m x 3 0083 end 0084 0085 fprintf('\nSaving BrainStorm data to %s',brainstormfile); 0086 save(brainstormfile, 'Comment', 'Faces', 'Vertices'); 0087 end