0001 function rr = vb_util_calc_head_radius(proj_root, head_file, calc_mode)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
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
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
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