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

vb_headinfo_join

PURPOSE ^

join plural Headinfo to single head file serially-concatenated

SYNOPSIS ^

function vb_headinfo_join(info_list, joined_file, verbose_swt)

DESCRIPTION ^

 join plural Headinfo to single head file serially-concatenated
 [usage]
   vb_headinfo_join(info_list, joined_file, verbose_swt)
 [input]
     info_list : <required> array of plural Headinfo <<struct>>
               :  [N x 1] or [1 x N]

   joined_file : <optional> stored file path which has joined data
               :  ['./joined_head.head.mat']

   verbose_swt : <optional> switch to output verbose messages
               :  [true] or false
 [output]
   void

 [note]
   stored data are as follow:
     ((multi-layer head-mat file))
        XXhead : [Npoint x 3]
         Vhead : [NPoint x 3]
         Fhead : [NPatch x 3] 
       Nvertex : [NL x 2]  : start and end index
        Npatch : [NL x 2]  : start and end index
      Layer%ag : {NL} names of each layer

   <<prior conditions>>
     Each Headinfo has the complete fields set and is the same struct

   @see vb_headinfo_make.m
   @see vb_headinfo_save.m

 [history]
   2007-04-10 (Sako) initial version
   2007-06-15 (Sako) removed some fields from multi-layer head-mat file
   2010-10-25 (Sako) modified how to get length of vhead

 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 vb_headinfo_join(info_list, joined_file, verbose_swt)
0002 % join plural Headinfo to single head file serially-concatenated
0003 % [usage]
0004 %   vb_headinfo_join(info_list, joined_file, verbose_swt)
0005 % [input]
0006 %     info_list : <required> array of plural Headinfo <<struct>>
0007 %               :  [N x 1] or [1 x N]
0008 %
0009 %   joined_file : <optional> stored file path which has joined data
0010 %               :  ['./joined_head.head.mat']
0011 %
0012 %   verbose_swt : <optional> switch to output verbose messages
0013 %               :  [true] or false
0014 % [output]
0015 %   void
0016 %
0017 % [note]
0018 %   stored data are as follow:
0019 %     ((multi-layer head-mat file))
0020 %        XXhead : [Npoint x 3]
0021 %         Vhead : [NPoint x 3]
0022 %         Fhead : [NPatch x 3]
0023 %       Nvertex : [NL x 2]  : start and end index
0024 %        Npatch : [NL x 2]  : start and end index
0025 %      Layer%ag : {NL} names of each layer
0026 %
0027 %   <<prior conditions>>
0028 %     Each Headinfo has the complete fields set and is the same struct
0029 %
0030 %   @see vb_headinfo_make.m
0031 %   @see vb_headinfo_save.m
0032 %
0033 % [history]
0034 %   2007-04-10 (Sako) initial version
0035 %   2007-06-15 (Sako) removed some fields from multi-layer head-mat file
0036 %   2010-10-25 (Sako) modified how to get length of vhead
0037 %
0038 % Copyright (C) 2011, ATR All Rights Reserved.
0039 % License : New BSD License(see VBMEG_LICENSE.txt)
0040 
0041 try
0042   % --- CHECK ARGUMENTS --- %
0043   if ~exist('info_list', 'var'),   info_list = []; end;
0044   if ~exist('joined_file', 'var'), joined_file = []; end;
0045   if ~exist('verbose_swt', 'var'), verbose_swt = []; end;
0046   
0047   [info_list, joined_file, VERBOSE] = ...
0048     inner_check_arguments(info_list, joined_file, verbose_swt);
0049 
0050   % --- check info_list
0051   if size(info_list,2) <= 1
0052     vb_headinfo_save(info_list(1), joined_file);
0053     return;
0054   end
0055 
0056   % --- MAIN PROCEDURE ------------------------------------------------------- %
0057   %
0058 
0059   % Rmethod
0060   %  --- All of the 'Rmethod' is expected to be the same
0061   Rmethod = vb_headinfo_get_rmethod(info_list(1));
0062 
0063   % get calculation mode by Rmethod
0064   if isempty(Rmethod)
0065     calc_mode = 1;
0066   else
0067     calc_mode = vb_util_convert_rmethod2calcmode(Rmethod);
0068   end
0069   
0070   % sort by average radius
0071   RR = [];
0072   N_info = size(info_list, 2);
0073 
0074   XXhead = [];
0075   Vhead = [];
0076   Fhead = [];
0077   Nvertex = [];
0078   Npatch = [];
0079   R = [];
0080   Sigma = zeros(1, N_info);
0081   LayerTag = cell(1, N_info);
0082 
0083   for ni = 1:N_info
0084     Vhead = vb_headinfo_get_vhead(info_list(ni));
0085     RR = [RR vb_util_distance_of_points(Vhead, calc_mode)];
0086   end
0087   
0088   [R idx] = sort(RR);
0089   
0090   InfoList = info_list(idx);
0091 
0092   % re-initialize Vhead
0093   Vhead = [];
0094   
0095   begin_v = 1;
0096   begin_p = 1;
0097   Npoint  = 0;
0098 
0099   for ni = 1:N_info
0100     cur_info = InfoList(ni);
0101   
0102     len_v = size(vb_headinfo_get_vhead(cur_info),1);
0103     len_p = size(vb_headinfo_get_fhead(cur_info),1);
0104 
0105     end_v = begin_v + len_v -1;
0106     end_p = begin_p + len_p -1;
0107     Nvertex = [Nvertex; begin_v end_v];
0108     Npatch  = [Npatch;  begin_p end_p];
0109     begin_v = end_v + 1;
0110     begin_p = end_p + 1;
0111   
0112     XXhead = [XXhead; vb_headinfo_get_xxhead(cur_info)];
0113     Vhead  = [ Vhead; vb_headinfo_get_vhead(cur_info)];
0114     Fhead  = [ Fhead; vb_headinfo_get_fhead(cur_info) + Npoint];
0115     
0116 %     Sigma(ni)    = vb_headinfo_get_sigma(cur_info);
0117     sigma = vb_headinfo_get_sigma(cur_info);
0118     if isempty(sigma)
0119       sigma = NaN;
0120     end
0121     Sigma(ni) = sigma;
0122     LayerTag{ni} = vb_headinfo_get_layertag(cur_info);
0123     
0124     Npoint = Npoint + len_v;
0125   end
0126 
0127   % make Headinfo
0128   Headinfo = vb_headinfo_make([], Vhead, Fhead, XXhead, LayerTag, Sigma, ...
0129     Rmethod, R, Npatch, Nvertex);
0130 
0131   % save Headinfo
0132   vb_headinfo_save(Headinfo, joined_file);
0133 
0134   if VERBOSE
0135     fprintf('--- saved as current joined file : %s\n', joined_file);
0136   end
0137 
0138 catch
0139   rethrow(lasterror);
0140 end
0141 
0142 % --- INNER FUNCTIONS -------------------------------------------------------- %
0143 %
0144 % --- inner_check_arguments()
0145 %
0146 function [info_list, joined_file, VERBOSE] = ...
0147   inner_check_arguments(info_list, joined_file, verbose_swt)
0148 
0149 % required parameters
0150 if isempty(info_list)
0151   error('info_list is a required parameter');  
0152 end
0153 
0154 % optional parameters
0155 if isempty(joined_file)
0156   joined_file = ['.' filesep 'joined_head.head.mat'];
0157 end
0158 
0159 if isempty(verbose_swt)
0160   VERBOSE = true;
0161 else
0162   VERBOSE = verbose_swt;
0163 end
0164 
0165 % arrange arrays to [1 x N]
0166 info_list = vb_util_arrange_list(info_list, 1);
0167 %
0168 % --- end of inner_check_arguments()
0169 
0170 %
0171 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0172 %%% END OF FILE %%%

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