% --- Parameters & main variables in Leadfield calculation

% --- 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
% 
% --- OUTPUT
% basis( L * Nvertex , Npick) 
%   : Magnetic field for MEG case
%   : Electric potential for EEG case
% basis( n, k )
%  : k-th sensor magnetic field for dipole current at n
%  : k-th sensor electric potential for dipole current at n

% Basis mode definition
% global vbmeg_inst;
% const = vbmeg_inst.const;
% const.BASIS_MEG_SPHERE;   %  MEG Sphere model (Sarvas)
% const.BASIS_MEG_BEM;      %  MEG BEM
% const.BASIS_MEG_HARMONICS;%  MEG Spherical harmonics expansion
% const.BASIS_EEG_SPHERE;   %  EEG 3-shell Sphere model
% const.BASIS_EEG_BEM;      %  EEG 3-shell BEM

% BEM MEG function (./bem)
bem_meg.m
LF行列を計算するプログラム

bem_inverse_meg.m
ポテンシャル定数近似用逆行列計算プログラム

bem_meg_linear_grk.m
Galerkin法で計算したポテンシャル(1次近似)から磁場を計算する

solid_angle_grk.m
solid_auto_grk.m
Galerkin法(ポテンシャル1次近似)に必要な重み付き立体角計算

cross2.m
外積計算

