0001 function [HeadInfo] = vb_head_get_specified_headinfo(headfile, layer)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 if ~exist('headfile', 'var'), headfile = []; end;
0032 if ~exist('layer', 'var'), layer = []; end;
0033
0034 [layer_number, head_info] = inner_check_arguments(headfile, layer);
0035
0036
0037
0038
0039
0040
0041
0042 if layer_number == 0
0043 HeadInfo = head_info;
0044 return;
0045 end
0046
0047
0048
0049 IDX_BEGIN = 1;
0050 IDX_END = 2;
0051 Vhead_begin = head_info.Nvertex(layer_number, IDX_BEGIN);
0052 Vhead_end = head_info.Nvertex(layer_number, IDX_END);
0053
0054 Fhead_begin = head_info.Npatch(layer_number, IDX_BEGIN);
0055 Fhead_end = head_info.Npatch(layer_number, IDX_END);
0056
0057
0058
0059 vhead = vb_headinfo_get_vhead(head_info);
0060 xxhead = vb_headinfo_get_xxhead(head_info);
0061 fhead = vb_headinfo_get_fhead(head_info);
0062
0063 HeadInfo = [];
0064
0065 if ~isempty(vhead)
0066 cur_vhead = vhead(Vhead_begin:Vhead_end, :);
0067 else
0068 cur_vhead = [];
0069 end
0070 HeadInfo = vb_headinfo_set_vhead(HeadInfo, cur_vhead);
0071
0072 if ~isempty(xxhead)
0073 cur_xxhead = xxhead(Vhead_begin:Vhead_end, :);
0074 else
0075 cur_xxhead = [];
0076 end
0077 HeadInfo = vb_headinfo_set_xxhead(HeadInfo, cur_xxhead);
0078
0079 if ~isempty(fhead)
0080 tmpFhead = fhead (Fhead_begin:Fhead_end, :);
0081
0082 cur_fhead = tmpFhead-(Vhead_begin-1);
0083 else
0084 cur_fhead = [];
0085 end
0086 HeadInfo = vb_headinfo_set_fhead(HeadInfo, cur_fhead);
0087
0088
0089 sigma = vb_headinfo_get_sigma(head_info);
0090 if ~isempty(sigma)
0091 HeadInfo = vb_headinfo_set_sigma(HeadInfo, sigma(layer_number));
0092 else
0093 HeadInfo = vb_headinfo_set_sigma(HeadInfo, []);
0094 end
0095
0096
0097 layer_tag = vb_headinfo_get_layertag(head_info);
0098 if ~isempty(layer_tag)
0099 HeadInfo = vb_headinfo_set_layertag(HeadInfo, layer_tag{layer_number});
0100 else
0101 HeadInfo = vb_headinfo_set_layertag(HeadInfo, []);
0102 end
0103
0104
0105 thisRadius = vb_headinfo_get_radius(head_info);
0106 if ~isempty(thisRadius)
0107 HeadInfo = vb_headinfo_set_radius(HeadInfo, thisRadius(layer_number));
0108 else
0109 HeadInfo = vb_headinfo_set_radius(HeadInfo, []);
0110 end
0111 return;
0112
0113
0114
0115
0116
0117 function [layer_number, head_info] = inner_check_arguments(headfile, layer)
0118 layer_number = 0;
0119
0120 if isempty(headfile), error('headfile is a required parameter'); end;
0121
0122 if exist(headfile, 'file') ~= 2
0123 error('cannot read headfile : %s', headfile); end;
0124
0125 if isempty(layer)
0126 error('neither layer_number nor layer_tag are NOT specified'); end;
0127
0128
0129
0130 head_info = load(headfile);
0131
0132
0133 if ~isfield(head_info, 'Nvertex')
0134 if isfield(head_info, 'Vhead') ...
0135 && isfield(head_info, 'Fhead') ...
0136 && isfield(head_info, 'XXhead')
0137
0138 layer_number = 0;
0139 return;
0140 else
0141 error('incomplete headfile : %s', headfile);
0142 end
0143 elseif isempty(head_info.Nvertex)
0144 layer_number = 0;
0145 return;
0146 end
0147
0148
0149
0150 Nlayer = vb_headinfo_get_layer_num(head_info);
0151
0152 if isnumeric(layer)
0153 layer_number = layer;
0154 if layer_number > Nlayer
0155 error('specified layer is over : %d', layer_number);
0156 end
0157 return;
0158 else
0159 if isfield(head_info, 'LayerTag')
0160 specified_tag = upper(layer);
0161
0162
0163 for nl = 1:Nlayer
0164
0165 my_tag = upper(deblank(head_info.LayerTag(:,nl)));
0166 if strcmp(specified_tag, my_tag)
0167 layer_number = nl;
0168 break;
0169 end
0170 end
0171 if layer_number == 0
0172 head_info = [];
0173 end
0174 else
0175 error('There is not LayerTag field in this head model : %s', headfile);
0176 end
0177 end
0178
0179
0180
0181
0182