Prepare leadfieled calculation [V, xx, pick, Qpick, Wsensor, BEM, Vhead, Fhead, Omega, Sout, SPHinfo] = ... vb_prepare_lead_field(basis_parm) --- Input basis_parm.brain_file : brain file (.brain.mat) basis_parm.area_file : area file (.area.mat) basis_parm.meg_file : MEG data file (.meg.mat) basis_parm.Basis_mode : number of independent curent direction = 1 : current vextor = xx(n,:) = 2 : current vextor = orthogonal vectors to V(n,:) = 3 : current vextor = xx(n,:) & orthogonal vectors to xx(n,:) basis_parm.bem_mode : Leadfield calculation method MEG 0 : MEG spherical model (Sarvas) 1 : MEG BEM 1 shell model 2 : MEG spherical harmonics expansion EEG 3 : EEG spherical 3 shell model 4 : EEG BEM 3 shell model --- Optional Input basis_parm.normal_mode : = 0 : normal vector at the vertex (Defualt) = 1 : average normal vector in the neighbor of BV original brain basis_parm.head_file : Head surface file (.head.mat) basis_parm.area_key : Area key to specify possible current region basis_parm.func_order : Order of spherical harmonics function basis_parm.Recalc : Recalculation force flag basis_parm.sigma : Conductivity of each region basis_parm.radius : Relative radius of sphere basis_parm.radius_method : priority of radius. mainly for 3-shell model. : 'basis_parm' or 'head_mean' or 'head_max' : 'basis_parm' : basis_parm.radius : 'head_mean' : mean distance of each head : 'head_max' : maximum distance of each head --- Output V(n,:) : dipole position (3-D coordinate) at n-th vertex xx(n,:) : dipole current direction (unit vector) at n-th vertex pick(k, 1:3) : sensor coil coordinate Qpick(k, 1:3) : sensor coil direction Wsensor(m,n) = n-th coil weight for m-th sensor channel basis(channel,dipole) = Wsensor * basis(coil,dipole) BEM : BEM parameters Vhead : Head surface coordinate Fhead : Head surface patch index Sout : Head surface normal direction Omega : Solid angle matrix SPHinfo : Parameters for Spherical Harmonics new version 2005-8-10 M. Sato 2006-7-23 M. Sato basis_parm.normal_mode is added for soft normal constraint modified by Sako 2006-07-28 modified by M. Sato 2006-08-24 modified by Sako 2006-12-04 : for EEG 3-shell head model Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [V, xx, pick, Qpick, Wsensor, BEM, Vhead, Fhead, ... 0002 Omega, Sout, SPHinfo] = vb_prepare_lead_field(basis_parm) 0003 % Prepare leadfieled calculation 0004 % [V, xx, pick, Qpick, Wsensor, BEM, Vhead, Fhead, Omega, Sout, SPHinfo] = ... 0005 % vb_prepare_lead_field(basis_parm) 0006 % --- Input 0007 % basis_parm.brain_file : brain file (.brain.mat) 0008 % basis_parm.area_file : area file (.area.mat) 0009 % basis_parm.meg_file : MEG data file (.meg.mat) 0010 % basis_parm.Basis_mode : number of independent curent direction 0011 % = 1 : current vextor = xx(n,:) 0012 % = 2 : current vextor = orthogonal vectors to V(n,:) 0013 % = 3 : current vextor = xx(n,:) & orthogonal vectors to xx(n,:) 0014 % basis_parm.bem_mode : Leadfield calculation method 0015 % MEG 0016 % 0 : MEG spherical model (Sarvas) 0017 % 1 : MEG BEM 1 shell model 0018 % 2 : MEG spherical harmonics expansion 0019 % EEG 0020 % 3 : EEG spherical 3 shell model 0021 % 4 : EEG BEM 3 shell model 0022 % 0023 % --- Optional Input 0024 % basis_parm.normal_mode : 0025 % = 0 : normal vector at the vertex (Defualt) 0026 % = 1 : average normal vector in the neighbor of BV original brain 0027 % 0028 % basis_parm.head_file : Head surface file (.head.mat) 0029 % basis_parm.area_key : Area key to specify possible current region 0030 % basis_parm.func_order : Order of spherical harmonics function 0031 % basis_parm.Recalc : Recalculation force flag 0032 % basis_parm.sigma : Conductivity of each region 0033 % basis_parm.radius : Relative radius of sphere 0034 % basis_parm.radius_method : priority of radius. mainly for 3-shell model. 0035 % : 'basis_parm' or 'head_mean' or 'head_max' 0036 % : 'basis_parm' : basis_parm.radius 0037 % : 'head_mean' : mean distance of each head 0038 % : 'head_max' : maximum distance of each head 0039 % --- Output 0040 % V(n,:) : dipole position (3-D coordinate) at n-th vertex 0041 % xx(n,:) : dipole current direction (unit vector) at n-th vertex 0042 % pick(k, 1:3) : sensor coil coordinate 0043 % Qpick(k, 1:3) : sensor coil direction 0044 % 0045 % Wsensor(m,n) = n-th coil weight for m-th sensor channel 0046 % basis(channel,dipole) = Wsensor * basis(coil,dipole) 0047 % 0048 % BEM : BEM parameters 0049 % Vhead : Head surface coordinate 0050 % Fhead : Head surface patch index 0051 % Sout : Head surface normal direction 0052 % Omega : Solid angle matrix 0053 % SPHinfo : Parameters for Spherical Harmonics 0054 % 0055 % new version 2005-8-10 M. Sato 0056 % 2006-7-23 M. Sato 0057 % basis_parm.normal_mode is added for soft normal constraint 0058 % modified by Sako 2006-07-28 0059 % modified by M. Sato 2006-08-24 0060 % modified by Sako 2006-12-04 : for EEG 3-shell head model 0061 % 0062 % Copyright (C) 2011, ATR All Rights Reserved. 0063 % License : New BSD License(see VBMEG_LICENSE.txt) 0064 0065 % Set parameters 0066 vb_struct2vars(basis_parm,{'bem_mode','Basis_mode','area_key','proj_root'}); 0067 0068 % Basis mode definition 0069 global vbmeg_inst; 0070 const = vbmeg_inst.const; 0071 % const.BASIS_MEG_SPHERE; % MEG Sphere model (Sarvas) 0072 % const.BASIS_MEG_BEM; % MEG BEM 0073 % const.BASIS_MEG_HARMONICS;% MEG Spherical harmonics expansion 0074 % const.BASIS_EEG_SPHERE; % EEG 3-shell Sphere model 0075 % const.BASIS_EEG_BEM; % EEG 3-shell BEM 0076 0077 % Check optional parameter 0078 if isfield(basis_parm,'normal_mode') 0079 normal_mode = basis_parm.normal_mode; 0080 else 0081 normal_mode = const.NORMAL_ADJACENT_MEAN; 0082 end 0083 0084 if ~isfield(basis_parm,'Recalc'), 0085 % Recalculation force flag 0086 basis_parm.Recalc = OFF; 0087 end 0088 0089 if ~isfield(basis_parm, 'func_order'), 0090 % Order of spherical harmonics function 0091 basis_parm.func_order = 35; 0092 end 0093 0094 if ~isfield(basis_parm,'DEBUG'), 0095 basis_parm.DEBUG = OFF; 0096 end 0097 0098 brain_file = [proj_root filesep basis_parm.brain_file]; 0099 area_file = [proj_root filesep basis_parm.area_file ]; 0100 meg_file = [proj_root filesep basis_parm.meg_file]; 0101 0102 % Load sensor info 0103 [pick,Qpick,Wsensor,V0] = vb_load_sensor(meg_file); 0104 0105 % Load cortical vertex coordinate and normal vector 0106 [V ,xx] = vb_load_cortex_area(brain_file,area_file,area_key,normal_mode); 0107 0108 switch bem_mode 0109 case {const.BASIS_MEG_SPHERE} 0110 % case {const.BASIS_MEG_SPHERE, const.BASIS_EEG_SPHERE} 0111 % Change center of coordinate 0112 pick = [pick(:,1)-V0(1), pick(:,2)-V0(2), pick(:,3)-V0(3)]; 0113 V = [ V(:,1)-V0(1), V(:,2)-V0(2), V(:,3)-V0(3)]; 0114 0115 case const.BASIS_MEG_HARMONICS, 0116 % Load head file 0117 head_file = [proj_root filesep basis_parm.head_file]; 0118 load([head_file], 'Vhead'); 0119 0120 % Center of Head 0121 if basis_parm.DEBUG == ON, 0122 % Setting for DEBUG to check Leadfield calculation 0123 Hcenter = [0 0 0]; 0124 else 0125 Hcenter = mean(Vhead); 0126 end 0127 0128 % Change center of coordinate 0129 Vhead = [Vhead(:,1)-Hcenter(1), ... 0130 Vhead(:,2)-Hcenter(2), Vhead(:,3)-Hcenter(3)]; 0131 V = [ V(:,1)-Hcenter(1), ... 0132 V(:,2)-Hcenter(2), V(:,3)-Hcenter(3)]; 0133 pick = [ pick(:,1)-Hcenter(1), ... 0134 pick(:,2)-Hcenter(2), pick(:,3)-Hcenter(3)]; 0135 0136 case const.BASIS_EEG_SPHERE 0137 pick = [pick(:,1)-V0(1), pick(:,2)-V0(2), pick(:,3)-V0(3)]; 0138 V = [ V(:,1)-V0(1), V(:,2)-V0(2), V(:,3)-V0(3)]; 0139 basis_parm = vb_util_check_head_shell_info(basis_parm); 0140 0141 case const.BASIS_EEG_BEM 0142 basis_parm = vb_util_check_head_shell_info(basis_parm); 0143 end 0144 0145 % Calculate current direction according to 'Basis_mode' 0146 [V,xx] = vb_current_vector(V, xx, Basis_mode); 0147 0148 % Prepare BEM parameter and calculate solid angle matrix 0149 [BEM, Vhead, Fhead, Omega, Sout, SPHinfo] = vb_prepare_bem(basis_parm); 0150