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

vb_head_get_specified_headinfo

PURPOSE ^

return HeadInfo (its fields are Vhead, Fhead, XXhead) of specified layer

SYNOPSIS ^

function [HeadInfo] = vb_head_get_specified_headinfo(headfile, layer)

DESCRIPTION ^

 return HeadInfo (its fields are Vhead, Fhead, XXhead) of specified layer
 [usage]
   [HeadInfo] = vb_head_get_specified_headinfo(headfile, layer)
 [input]
   headfile : <required> headfile (.head.mat)
      layer : <required> number of layer or layer tag that you'd like to get
 [output]
   HeadInfo : <struct> its fields are ...
            :  Vhead
            :  Fhead
            :  XXhead
            :  sigma (if it exists)
 [note]
   layer is acceptable 'number' and 'string'.
   if number is given, this function recognizes as number of layer, and
   if string is given, recognizes as layer tag (e.g. 'Skull')
   for layer tag, not case-sensitive

   if specified headfile has valid 'sigma' data, you can get relevant sigma

 [history]
   2007-02-14 (Sako) initial version
   2007-04-10 (Sako) modified Fhead value and added returning sigma
   2010-10-25 (Sako) supported the case that a head data is empty

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [HeadInfo] = vb_head_get_specified_headinfo(headfile, layer)
0002 % return HeadInfo (its fields are Vhead, Fhead, XXhead) of specified layer
0003 % [usage]
0004 %   [HeadInfo] = vb_head_get_specified_headinfo(headfile, layer)
0005 % [input]
0006 %   headfile : <required> headfile (.head.mat)
0007 %      layer : <required> number of layer or layer tag that you'd like to get
0008 % [output]
0009 %   HeadInfo : <struct> its fields are ...
0010 %            :  Vhead
0011 %            :  Fhead
0012 %            :  XXhead
0013 %            :  sigma (if it exists)
0014 % [note]
0015 %   layer is acceptable 'number' and 'string'.
0016 %   if number is given, this function recognizes as number of layer, and
0017 %   if string is given, recognizes as layer tag (e.g. 'Skull')
0018 %   for layer tag, not case-sensitive
0019 %
0020 %   if specified headfile has valid 'sigma' data, you can get relevant sigma
0021 %
0022 % [history]
0023 %   2007-02-14 (Sako) initial version
0024 %   2007-04-10 (Sako) modified Fhead value and added returning sigma
0025 %   2010-10-25 (Sako) supported the case that a head data is empty
0026 %
0027 % Copyright (C) 2011, ATR All Rights Reserved.
0028 % License : New BSD License(see VBMEG_LICENSE.txt)
0029 
0030 % --- CHECK ARGUMENTS --- %
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 % --- MAIN PROCEDURE --------------------------------------------------------- %
0037 %
0038 
0039 % --- single layer model
0040 %
0041 % if layer_number == 0 || layer_number == 1
0042 if layer_number == 0
0043   HeadInfo = head_info;
0044   return;
0045 end
0046 
0047 % --- plural layers model
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 % HeadInfo.Vhead  = head_info.Vhead ([Vhead_begin:Vhead_end], :);
0058 % HeadInfo.XXhead = head_info.XXhead([Vhead_begin:Vhead_end], :);
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   % HeadInfo.Fhead  = tmpFhead - (Vhead_begin-1);
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 % sigma
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 % layer_tag
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 % Radius
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 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0114 
0115 % --- INNER FUNCTIONS -------------------------------------------------------- %
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 % --- load
0130 head_info = load(headfile);
0131 
0132 % --- check whether be plural layer model or not
0133 if ~isfield(head_info, 'Nvertex')
0134   if isfield(head_info, 'Vhead') ...
0135       && isfield(head_info, 'Fhead') ...
0136       && isfield(head_info, 'XXhead')
0137       % single layer model
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 % plural layers
0149 % Nlayer = size(head_info.Nvertex, 1);
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     % matching
0163     for nl = 1:Nlayer
0164 %       my_tag = upper(deblank(head_info.LayerTag(nl,:)));
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 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0180 
0181 
0182 %%% END OF FILE %%%

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