Calculate leadfield matrix and create leadfiled file (.basis.mat). (VBMEG public function) This function can calculate leadfield matrix for using the following numerical methods: MEG Sphere model (Sarvas equation) MEG 1-shell BEM (boundary element method) MEG Spherical harmonics expansion EEG 3-shell Sphere model EEG 3-shell BEM [syntax] vb_job_leadfield(basis_parm) vb_job_leadfield(proj_root, basis_parm) [old style] [input] proj_root : <<string>> VBMEG project root directory. basis_parm: <<struct>> Parameters for leadfield calculation. --- fields of basis_parm brain_file : <<string>> Cortical surface model file (.brain.mat). area_file : <<string>> Cortical area file (.area.mat). meg_file : <<string>> MEG-MAT or EEG-MAT file (.meg.mat). basis_file : <<string>> Leadfield file (.basis.mat). bem_mode : <<int>> Specify numerical method for calculating leadfield. =0: MEG Sphere model (Sarvas equation). =1: MEG 1-shell BEM (boundary element method). =2: MEG Spherical harmonics expansion. =3: EEG 3-shell Sphere model. =4: EEG 3-shell BEM. head_file : <optional><<string>> Head model file (.head.mat). This parameter is referred if the lead field is calculated by BEM or spherical harmonics expansion (see 'bem_mode'). expansion Basis_mode : <<int>> Degree of freedom of current direction. Not only the DOF, but also the direction of current dipoles at each vertex is also specified by this parameter. Currently VBMEG supports Basis_mode=1 (1st June, 2010). =1: Single dipole perpendicular to the cortical surface. =2: Double dipoles tangental to the cortical surface. =3: Triple dipoles parallel to three axes (x, y, z). Vcenter : <<vector>> Coordinate value of the head center (1x3 on SPM_Right_m). func_order : <<int?>> Order of spherical harmonics function. This parameter is effective when employing spherical harmonics expansion (see 'bem_mode'). sigma : <<vector>> Conductivity from innermost to outermost. radius : <<vector>> Relative radius of sphere from innermost to outermost. area_key : <optional><<string>> normal_mode: <optional><int> Recalc : <optional> --- [output] Leadfield file (.basis.mat) is created with filename specified by 'basis_file' field. If BEM is used, head model file (.head.mat) is updated with a matrix, which depends only on the head model, not on the cortical surface model. So, if size of .head.mat file become large, it is not an error. [note] This function call the following sub-functions in accordance with basis_parm.bem_mode: vb_job_leadfield_meg_sphere vb_job_leadfield_meg_bem vb_job_leadfield_meg_harmonics vb_job_leadfield_eeg_sphere vb_job_leadfield_eeg_bem 'vbmeg_inst' structure have constants for specifying the numerical method and model related to leadfield calculation. Those constants are recommended to specify parameters for readability of your program. --- Constants for 'basis_parm.bem_mode' vbmeg_inst.const.BASIS_MEG_SPHERE = 0 vbmeg_inst.const.BASIS_MEG_BEM = 1 vbmeg_inst.const.BASIS_MEG_HARMONICS = 2 vbmeg_inst.const.BASIS_MEG_SPHERE = 3 vbmeg_inst.const.BASIS_MEG_BEM = 4 --- Constants for 'basis_parm.Basis_mode' vbmeg_inst.const.CURRENT_NORMAL = 1 vbmeg_inst.const.CURRENT_TANGENT = 2 vbmeg_inst.const.CURRENT_3D = 3 --- Constants for 'basis_parm.normal_mode vbmeg_inst.const.NORMAL_ADJACENT_MEAN = 0 vbmeg_inst.const.NORMAL_NEIGHBOR_MEAN = 1 --- [history] 2007-01-26 (Sako) reworked the architecture 2008-10-15 Taku Yoshioka Support '.sensortype' parameter (argument check) 2010-05-?? Taku Yoshioka Minor change (verbose level support) Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function vb_job_leadfield(varargin) 0002 % Calculate leadfield matrix and create leadfiled file (.basis.mat). 0003 % (VBMEG public function) 0004 % 0005 % This function can calculate leadfield matrix for using the following 0006 % numerical methods: 0007 % MEG Sphere model (Sarvas equation) 0008 % MEG 1-shell BEM (boundary element method) 0009 % MEG Spherical harmonics expansion 0010 % EEG 3-shell Sphere model 0011 % EEG 3-shell BEM 0012 % 0013 % [syntax] 0014 % vb_job_leadfield(basis_parm) 0015 % vb_job_leadfield(proj_root, basis_parm) [old style] 0016 % 0017 % [input] 0018 % proj_root : <<string>> VBMEG project root directory. 0019 % basis_parm: <<struct>> Parameters for leadfield calculation. 0020 % --- fields of basis_parm 0021 % brain_file : <<string>> Cortical surface model file (.brain.mat). 0022 % area_file : <<string>> Cortical area file (.area.mat). 0023 % meg_file : <<string>> MEG-MAT or EEG-MAT file (.meg.mat). 0024 % basis_file : <<string>> Leadfield file (.basis.mat). 0025 % bem_mode : <<int>> Specify numerical method for calculating 0026 % leadfield. 0027 % =0: MEG Sphere model (Sarvas equation). 0028 % =1: MEG 1-shell BEM (boundary element method). 0029 % =2: MEG Spherical harmonics expansion. 0030 % =3: EEG 3-shell Sphere model. 0031 % =4: EEG 3-shell BEM. 0032 % head_file : <optional><<string>> Head model file (.head.mat). This 0033 % parameter is referred if the lead field is calculated by 0034 % BEM or spherical harmonics expansion (see 'bem_mode'). 0035 % expansion 0036 % Basis_mode : <<int>> Degree of freedom of current direction. Not only 0037 % the DOF, but also the direction of current dipoles at each 0038 % vertex is also specified by this parameter. Currently 0039 % VBMEG supports Basis_mode=1 (1st June, 2010). 0040 % =1: Single dipole perpendicular to the cortical surface. 0041 % =2: Double dipoles tangental to the cortical surface. 0042 % =3: Triple dipoles parallel to three axes (x, y, z). 0043 % Vcenter : <<vector>> Coordinate value of the head center (1x3 on 0044 % SPM_Right_m). 0045 % func_order : <<int?>> Order of spherical harmonics function. This 0046 % parameter is effective when employing spherical harmonics 0047 % expansion (see 'bem_mode'). 0048 % sigma : <<vector>> Conductivity from innermost to outermost. 0049 % radius : <<vector>> Relative radius of sphere from innermost to 0050 % outermost. 0051 % area_key : <optional><<string>> 0052 % normal_mode: <optional><int> 0053 % Recalc : <optional> 0054 % --- 0055 % 0056 % [output] 0057 % Leadfield file (.basis.mat) is created with filename specified by 0058 % 'basis_file' field. If BEM is used, head model file (.head.mat) is 0059 % updated with a matrix, which depends only on the head model, not on the 0060 % cortical surface model. So, if size of .head.mat file become large, it 0061 % is not an error. 0062 % 0063 % [note] 0064 % This function call the following sub-functions in accordance with 0065 % basis_parm.bem_mode: 0066 % vb_job_leadfield_meg_sphere 0067 % vb_job_leadfield_meg_bem 0068 % vb_job_leadfield_meg_harmonics 0069 % vb_job_leadfield_eeg_sphere 0070 % vb_job_leadfield_eeg_bem 0071 % 0072 % 'vbmeg_inst' structure have constants for specifying the numerical 0073 % method and model related to leadfield calculation. Those constants are 0074 % recommended to specify parameters for readability of your program. 0075 % --- Constants for 'basis_parm.bem_mode' 0076 % vbmeg_inst.const.BASIS_MEG_SPHERE = 0 0077 % vbmeg_inst.const.BASIS_MEG_BEM = 1 0078 % vbmeg_inst.const.BASIS_MEG_HARMONICS = 2 0079 % vbmeg_inst.const.BASIS_MEG_SPHERE = 3 0080 % vbmeg_inst.const.BASIS_MEG_BEM = 4 0081 % --- Constants for 'basis_parm.Basis_mode' 0082 % vbmeg_inst.const.CURRENT_NORMAL = 1 0083 % vbmeg_inst.const.CURRENT_TANGENT = 2 0084 % vbmeg_inst.const.CURRENT_3D = 3 0085 % --- Constants for 'basis_parm.normal_mode 0086 % vbmeg_inst.const.NORMAL_ADJACENT_MEAN = 0 0087 % vbmeg_inst.const.NORMAL_NEIGHBOR_MEAN = 1 0088 % --- 0089 % 0090 % [history] 0091 % 2007-01-26 (Sako) reworked the architecture 0092 % 2008-10-15 Taku Yoshioka 0093 % Support '.sensortype' parameter (argument check) 0094 % 2010-05-?? Taku Yoshioka 0095 % Minor change (verbose level support) 0096 % 0097 % Copyright (C) 2011, ATR All Rights Reserved. 0098 % License : New BSD License(see VBMEG_LICENSE.txt) 0099 0100 global vbmeg_inst; 0101 const = vbmeg_inst.const; 0102 0103 if length(varargin) == 1 0104 proj_root = []; 0105 basis_parm = varargin{1}; 0106 elseif length(varargin) == 2 0107 proj_root = varargin{1}; 0108 basis_parm = varargin{2}; 0109 end 0110 0111 % --- CHECK ARGUMENTS --- % 0112 if ~exist('proj_root', 'var'), proj_root = []; end 0113 if ~exist('basis_parm', 'var'), basis_parm = []; end 0114 [proj_root, basis_parm] = inner_check_arguments(const, proj_root, basis_parm); 0115 0116 % --- MAIN PROCEDURE --------------------------------------------------------- % 0117 % 0118 switch basis_parm.bem_mode 0119 case const.BASIS_MEG_SPHERE, 0120 [basis, basis_parm] = vb_job_leadfield_meg_sphere(proj_root, basis_parm); 0121 0122 case const.BASIS_MEG_BEM, 0123 [basis, basis_parm] = vb_job_leadfield_meg_bem(proj_root, basis_parm); 0124 0125 case const.BASIS_MEG_HARMONICS, 0126 [basis, basis_parm] = vb_job_leadfield_meg_harmonics(proj_root, basis_parm); 0127 0128 case const.BASIS_EEG_SPHERE, 0129 [basis, basis_parm] = vb_job_leadfield_eeg_sphere(proj_root, basis_parm); 0130 0131 case const.BASIS_EEG_BEM, 0132 [basis, basis_parm] = vb_job_leadfield_eeg_bem(proj_root, basis_parm); 0133 end 0134 0135 inner_terminate(const, proj_root, basis_parm, basis); 0136 % 0137 % --- MAIN PROCEDURE --------------------------------------------------------- % 0138 0139 0140 % --- INNER FUNCTIONS -------------------------------------------------------- % 0141 % 0142 % --- inner_terminate() 0143 % 0144 function inner_terminate(const, proj_root, basis_parm, basis) 0145 0146 % const.BASIS_MEG_SPHERE; % MEG Sphere model (Sarvas) 0147 % const.BASIS_MEG_BEM; % MEG BEM 0148 % const.BASIS_MEG_HARMONICS;% MEG Spherical harmonics expansion 0149 % const.BASIS_EEG_SPHERE; % EEG 3-shell Sphere model 0150 % const.BASIS_EEG_BEM; % EEG 3-shell BEM 0151 0152 bem_name = { ... 0153 'MEG spherical model (Sarvas)'; ... 0154 'MEG BEM 1 shell model'; ... 0155 'MEG spherical harmonics expansion'; ... 0156 'EEG spherical 3 shell model'; ... 0157 'EEG BEM 3 shell model'; ... 0158 }; 0159 0160 switch basis_parm.bem_mode 0161 case const.BASIS_MEG_SPHERE 0162 calc_type = bem_name{1}; 0163 0164 case const.BASIS_MEG_BEM 0165 calc_type = bem_name{2}; 0166 0167 case const.BASIS_MEG_HARMONICS 0168 calc_type = bem_name{3}; 0169 0170 case const.BASIS_EEG_SPHERE 0171 calc_type = bem_name{4}; 0172 0173 case const.BASIS_EEG_BEM 0174 calc_type = bem_name{5}; 0175 0176 otherwise 0177 calc_type = 'unknown calculation type'; 0178 end 0179 0180 vb_disp(sprintf('Leadfield calculation : %s', calc_type)); 0181 vb_disp(sprintf('Current direction = %d',basis_parm.Basis_mode)); 0182 0183 if isfield(basis_parm, 'normal_mode') ... 0184 & basis_parm.normal_mode == const.NORMAL_NEIGHBOR_MEAN, 0185 vb_disp('Normal vector is averaged over neighborhood'); 0186 end 0187 0188 % Output file path 0189 basis_file = fullfile(proj_root, basis_parm.basis_file); 0190 vb_disp(sprintf('Save basis file [%s]', basis_file)); 0191 vb_save(basis_file,'basis','basis_parm'); 0192 0193 % project_file save 0194 proj_file = get_project_filename; 0195 if isempty(proj_file) 0196 return; 0197 end 0198 0199 project_file_mgr('load', proj_file); 0200 project_file_mgr('add', 'basis_parm', basis_parm); 0201 % 0202 % --- end of inner_terminate() 0203 0204 0205 % --- inner_check_arguments() 0206 % 0207 function [proj_root, basis_parm] = ... 0208 inner_check_arguments(const, proj_root, basis_parm) 0209 0210 if isempty(basis_parm), error('basis_parm is a required parameter'); end; 0211 0212 proj_root = vb_rm_trailing_slash(proj_root); 0213 0214 % check common fields of basis_parm 0215 if ~isfield(basis_parm, 'normal_mode') 0216 basis_parm.normal_mode = const.NORMAL_ADJACENT_MEAN; 0217 end 0218 0219 if ~isfield(basis_parm,'Recalc'), 0220 % Recalculation force flag 0221 basis_parm.Recalc = OFF; 0222 end 0223 0224 if ~isfield(basis_parm,'DEBUG'), 0225 basis_parm.DEBUG = OFF; 0226 end 0227 0228 if ~isfield(basis_parm,'sensortype'), 0229 basis_parm.sensortype = []; 0230 end 0231 0232 % if you want to check other points, you can do that here 0233 % ... 0234 0235 % 0236 % --- end of inner_check_arguments() 0237 % 0238 % --- END OF INNER FUNCTIONS ------------------------------------------------- % 0239 0240 %%% END OF FILE %%%