0001 function [HeadInfo] = vb_util_get_specified_layer_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 if ~exist('headfile', 'var'), headfile = []; end;
0026 if ~exist('layer', 'var'), layer = []; end;
0027
0028 [layer_number, head_info] = inner_check_arguments(headfile, layer);
0029
0030
0031
0032
0033
0034
0035 if layer_number == 0
0036 HeadInfo = head_info;
0037 return;
0038 end
0039
0040
0041
0042 IDX_BEGIN = 1;
0043 IDX_END = 2;
0044 Vhead_begin = head_info.Nvertex(layer_number, IDX_BEGIN);
0045 Vhead_end = head_info.Nvertex(layer_number, IDX_END);
0046
0047 Fhead_begin = head_info.Npatch(layer_number, IDX_BEGIN);
0048 Fhead_end = head_info.Npatch(layer_number, IDX_END);
0049
0050 HeadInfo.Vhead = head_info.Vhead ([Vhead_begin:Vhead_end], :);
0051 HeadInfo.XXhead = head_info.XXhead([Vhead_begin:Vhead_end], :);
0052 HeadInfo.Fhead = head_info.Fhead ([Fhead_begin:Fhead_end], :);
0053 return;
0054
0055
0056
0057
0058
0059 function [layer_number, head_info] = inner_check_arguments(headfile, layer)
0060
0061 if isempty(headfile), error('headfile is a required parameter'); end;
0062
0063 if exist(headfile, 'file') ~= 2
0064 error('cannot read headfile : %s', headfile); end;
0065
0066 if isempty(layer)
0067 error('neither layer_number nor layer_tag are NOT specified'); end;
0068
0069
0070
0071 head_info = load(headfile);
0072
0073
0074 if ~isfield(head_info, 'Nvertex')
0075 if isfield(head_info, 'Vhead') ...
0076 && isfield(head_info, 'Fhead') ...
0077 && isfield(head_info, 'XXhead')
0078
0079 layer_number = 0;
0080 return;
0081 else
0082 error('incomplete headfile : %s', headfile);
0083 end
0084 end
0085
0086
0087 Nlayer = size(head_info.Nvertex, 1);
0088
0089 if isnumeric(layer)
0090 layer_number = layer;
0091 if layer_number > Nlayer
0092 error('specified layer is over : %d', layer_number);
0093 end
0094 return;
0095 else
0096 if isfield(head_info, 'LayerTag')
0097 specified_tag = upper(layer);
0098
0099
0100 for nl = 1:Nlayer
0101 my_tag = upper(deblank(head_info.LayerTag(nl,:)));
0102 if strcmp(specified_tag, my_tag)
0103 layer_number = nl;
0104 return;
0105 end
0106 end
0107 else
0108 error('There is not LayerTag field in this head model : %s', headfile);
0109 end
0110 end
0111
0112
0113
0114
0115