Home > vbmeg > functions > leadfield > head > vb_util_calc_head_radius.m

vb_util_calc_head_radius

PURPOSE ^

calculate radius of head from head file

SYNOPSIS ^

function rr = vb_util_calc_head_radius(proj_root, head_file, calc_mode)

DESCRIPTION ^

 calculate radius of head from head file
 [usage]
   rr = vb_util_calc_head_radius(proj_root, head_file)
 [input]
   proj_root : <required> project root directory
   head_file : <required> head file (cell array (plural shell model) or not cell)
   calc_mode : <optional> calculation mode (1 or 2 or 3 or 4) [1]
             :  =1 : <default> calculate average of distance
             :  =2 : apply minimum value of all distances
             :  =3 : apply maximum value of all distances
             :  =4 : apply user-specified radius
             :  =other : <warning> calculate average
 [output]
          rr : rate of radius
 [note]
   
 [history]
   2006-12-04 (Sako) initial version

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function rr = vb_util_calc_head_radius(proj_root, head_file, calc_mode)
0002 % calculate radius of head from head file
0003 % [usage]
0004 %   rr = vb_util_calc_head_radius(proj_root, head_file)
0005 % [input]
0006 %   proj_root : <required> project root directory
0007 %   head_file : <required> head file (cell array (plural shell model) or not cell)
0008 %   calc_mode : <optional> calculation mode (1 or 2 or 3 or 4) [1]
0009 %             :  =1 : <default> calculate average of distance
0010 %             :  =2 : apply minimum value of all distances
0011 %             :  =3 : apply maximum value of all distances
0012 %             :  =4 : apply user-specified radius
0013 %             :  =other : <warning> calculate average
0014 % [output]
0015 %          rr : rate of radius
0016 % [note]
0017 %
0018 % [history]
0019 %   2006-12-04 (Sako) initial version
0020 %
0021 % Copyright (C) 2011, ATR All Rights Reserved.
0022 % License : New BSD License(see VBMEG_LICENSE.txt)
0023 
0024 if ~exist('proj_root', 'var') 
0025   error('proj_root is a required parameter');
0026 end
0027 
0028 if ~exist('head_file', 'var') || isempty(head_file)
0029   error('head_file is a required parameter');
0030 end
0031 
0032 if ~exist('calc_mode', 'var') || isempty(calc_mode)
0033   calc_mode = 1;
0034 elseif isempty(find(calc_mode == [1 2 3 4]))
0035   error('undefined calc_mode : %d', calc_mode);
0036 end
0037 
0038 switch calc_mode
0039   case  1, this_calc_method = 'MEAN';
0040   case  2, this_calc_method = 'MIN';
0041   case  3, this_calc_method = 'MAX';
0042   case  4, this_calc_method = 'USER';
0043 end
0044 
0045 rr = [];
0046 
0047 if iscell(head_file)
0048   for i = 1:length(head_file)
0049     cur_head = fullfile(proj_root, head_file{i});
0050     if exist(cur_head, 'file') ~= 2
0051       error('cannot find head file : %s', cur_head);
0052     end
0053     load(cur_head, 'Vhead');
0054     rr = [rr vb_util_distance_of_points(Vhead, calc_mode)];
0055   end
0056   rr = rr ./ max(rr);
0057   
0058 else
0059   head_file_path = fullfile(proj_root, head_file);
0060   if exist(head_file_path, 'file') ~= 2
0061     error('invalid head_file : %s', head_file_path);
0062   end
0063   
0064   head = load(head_file_path);
0065   
0066   if ~isfield(head, 'Vhead')
0067     error('invalid head data - cannot find Vhead field');
0068   end
0069   
0070   % consistent check of calc_mode with Rmethod
0071   is_consistent_r_method = false;
0072   if isfield(head, 'Rmethod') && ~isempty(head.Rmethod)
0073     if strcmp(head.Rmethod, this_calc_method)
0074       is_consistent_r_method = true;
0075     end
0076   end
0077 
0078   if isfield(head, 'R') && ~isempty(head.R) && is_consistent_r_method
0079     rr = head.R;
0080     rr = rr ./ max(rr);
0081     return;
0082     
0083   elseif ~isfield(head, 'Nvertex')
0084     % maybe single shell model
0085     rr = vb_util_distance_of_points(head.Vhead, calc_mode);
0086     rr = rr ./ max(rr);
0087     
0088   else
0089     n_shell = size(head.Nvertex,1);
0090     
0091     for sh = 1:n_shell
0092       cur_vhead = head.Vhead(head.Nvertex(sh,1):head.Nvertex(sh,2),:);
0093       rr = [rr vb_util_distance_of_points(cur_vhead, calc_mode)];
0094     end
0095     rr = rr ./ max(rr);
0096   end
0097 end
0098 %%% END OF FILE %%%

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005