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

vb_util_get_specified_layer_headinfo

PURPOSE ^

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

SYNOPSIS ^

function [HeadInfo] = vb_util_get_specified_layer_headinfo(headfile, layer)

DESCRIPTION ^

 return HeadInfo (its fields are Vhead, Fhead, XXhead) of specified layer
 [usage]
   [HeadInfo] = vb_util_get_specified_layer_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
 [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
 [history]
   2007-02-14 (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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [HeadInfo] = vb_util_get_specified_layer_headinfo(headfile, layer)
0002 % return HeadInfo (its fields are Vhead, Fhead, XXhead) of specified layer
0003 % [usage]
0004 %   [HeadInfo] = vb_util_get_specified_layer_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 % [note]
0014 %   layer is acceptable 'number' and 'string'.
0015 %   if number is given, this function recognizes as number of layer, and
0016 %   if string is given, recognizes as layer tag (e.g. 'Skull')
0017 %   for layer tag, not case-sensitive
0018 % [history]
0019 %   2007-02-14 (Sako) initial version
0020 %
0021 % Copyright (C) 2011, ATR All Rights Reserved.
0022 % License : New BSD License(see VBMEG_LICENSE.txt)
0023 
0024 % --- CHECK ARGUMENTS --- %
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 % --- MAIN PROCEDURE --------------------------------------------------------- %
0031 %
0032 
0033 % --- single layer model
0034 %
0035 if layer_number == 0
0036   HeadInfo = head_info;
0037   return;
0038 end
0039 
0040 % --- plural layers model
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 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0056 
0057 % --- INNER FUNCTIONS -------------------------------------------------------- %
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 % --- load
0071 head_info = load(headfile);
0072 
0073 % --- check whether be plural layer model or not
0074 if ~isfield(head_info, 'Nvertex')
0075   if isfield(head_info, 'Vhead') ...
0076       && isfield(head_info, 'Fhead') ...
0077       && isfield(head_info, 'XXhead')
0078       % single layer model
0079       layer_number = 0;
0080     return;
0081   else
0082     error('incomplete headfile : %s', headfile);
0083   end
0084 end
0085 
0086 % plural layers
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     % matching
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 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0113 
0114 
0115 %%% END OF FILE %%%

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