join plural "single layer" head files and make single head file serially-concatenated [usage] vb_util_join_head_files(head_files, file_root, joined_file, ... layer_tag, calc_mode) [input] head_files : <required> cell array of plural "single layer" head files : [1 x N] file_root : <optional> root directory for 'head_files' ['.'] joined_file : <optional> output file path : ['(file_root)/joined_head.head.mat'] layer_tag : <optional> names of each layer [('CSF', 'Skull', 'Scalp')] calc_mode : <optional> calculation method of radius : [1] or 2 or 3 : 1 : mean distance of each head : 2 : minimum distance of each head : 3 : maximum distance of each head [output] idx : index list which is sorted by radius of each layer r_list : radius list which is sorted by their sizes [note] stored data are as follows: 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_tag : {NL} label of each layer !!!NOTICE!!! This function will be removed in a future release. Instead, you can use vb_head_join_files.m [history] 2006-12-04 (Sako) initial version 2007-06-14 (Sako) removed unnecessary parameters from head file 2010-10-25 (Sako) supported the case that XXhead is empty Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [idx, r_list] = vb_util_join_head_files(head_files, file_root, ... 0002 joined_file, layer_tag, calc_mode) 0003 % join plural "single layer" head files and make single head file 0004 % serially-concatenated 0005 % [usage] 0006 % vb_util_join_head_files(head_files, file_root, joined_file, ... 0007 % layer_tag, calc_mode) 0008 % [input] 0009 % head_files : <required> cell array of plural "single layer" head files 0010 % : [1 x N] 0011 % file_root : <optional> root directory for 'head_files' ['.'] 0012 % joined_file : <optional> output file path 0013 % : ['(file_root)/joined_head.head.mat'] 0014 % layer_tag : <optional> names of each layer [('CSF', 'Skull', 'Scalp')] 0015 % calc_mode : <optional> calculation method of radius 0016 % : [1] or 2 or 3 0017 % : 1 : mean distance of each head 0018 % : 2 : minimum distance of each head 0019 % : 3 : maximum distance of each head 0020 % [output] 0021 % idx : index list which is sorted by radius of each layer 0022 % r_list : radius list which is sorted by their sizes 0023 % [note] 0024 % stored data are as follows: 0025 % XXhead : [Npoint x 3] 0026 % Vhead : [NPoint x 3] 0027 % Fhead : [NPatch x 3] 0028 % Nvertex : [NL x 2] : start and end index 0029 % Npatch : [NL x 2] : start and end index 0030 % layer_tag : {NL} label of each layer 0031 % 0032 % !!!NOTICE!!! 0033 % This function will be removed in a future release. 0034 % Instead, you can use vb_head_join_files.m 0035 % 0036 % [history] 0037 % 2006-12-04 (Sako) initial version 0038 % 2007-06-14 (Sako) removed unnecessary parameters from head file 0039 % 2010-10-25 (Sako) supported the case that XXhead is empty 0040 % 0041 % Copyright (C) 2011, ATR All Rights Reserved. 0042 % License : New BSD License(see VBMEG_LICENSE.txt) 0043 0044 try 0045 % --- CHECK ARGUMENTS --- % 0046 if ~exist('head_files', 'var'), head_files = []; end 0047 if ~exist('file_root', 'var'), file_root = []; end 0048 if ~exist('joined_file', 'var'), joined_file = []; end 0049 if ~exist('layer_tag', 'var'), layer_tag = []; end 0050 if ~exist('calc_mode', 'var'), calc_mode = []; end 0051 [head_files, file_root, joined_file, layer_tag, calc_mode] = ... 0052 inner_check_arguments(head_files, file_root, joined_file, ... 0053 layer_tag, calc_mode); 0054 0055 % --- MAIN PROCEDURE ------------------------------------------------------- % 0056 % 0057 if ~iscell(head_files) 0058 % require no action 0059 warning('%s is not cell so it is not required to join', head_files); 0060 return; 0061 end 0062 0063 XXhead = []; 0064 Vhead = []; 0065 Fhead = []; 0066 Nvertex = []; 0067 Npatch = []; 0068 0069 % check number of layer 0070 NL = size(head_files, 2); 0071 NT = size(layer_tag, 2); 0072 0073 if ~isequal(NT, NL) 0074 error('head_files is %d, layer tag is %d.', NL, NT); 0075 end 0076 0077 % sort by average radius 0078 RR = []; 0079 for n = 1:NL 0080 load([file_root filesep head_files{n}], 'Vhead'); 0081 RR = [RR vb_util_distance_of_points(Vhead, calc_mode)]; 0082 end 0083 0084 % sort lists 0085 [r_list idx] = sort(RR); 0086 LayerTag = layer_tag(:,idx); 0087 head_files = head_files(:,idx); 0088 0089 % re-initialize Vhead 0090 Vhead = []; 0091 0092 begin_v = 1; 0093 begin_p = 1; 0094 Npoint = 0; 0095 for n = 1:size(head_files, 2) 0096 data = load([file_root filesep head_files{n}]); 0097 0098 % --- 2010-10-25 --> 0099 % len_v = size(data.XXhead,1); 0100 % len_p = size(data.Fhead,1); 0101 % 0102 % end_v = begin_v + len_v -1; 0103 % end_p = begin_p + len_p -1; 0104 % Nvertex = [Nvertex; begin_v end_v]; 0105 % Npatch = [Npatch; begin_p end_p]; 0106 % begin_v = end_v + 1; 0107 % begin_p = end_p + 1; 0108 % 0109 % XXhead = [XXhead; data.XXhead]; 0110 % Vhead = [ Vhead; data.Vhead]; 0111 % Fhead = [ Fhead; data.Fhead + Npoint]; 0112 0113 % len_v = size(data.XXhead,1); 0114 % len_p = size(data.Fhead,1); 0115 0116 len_v = size(vb_headinfo_get_vhead(data),1); 0117 len_p = size(vb_headinfo_get_fhead(data),1); 0118 0119 end_v = begin_v + len_v -1; 0120 end_p = begin_p + len_p -1; 0121 Nvertex = [Nvertex; begin_v end_v]; 0122 Npatch = [Npatch; begin_p end_p]; 0123 begin_v = end_v + 1; 0124 begin_p = end_p + 1; 0125 0126 % XXhead = [XXhead; data.XXhead]; 0127 % Vhead = [ Vhead; data.Vhead]; 0128 % Fhead = [ Fhead; data.Fhead + Npoint]; 0129 Vhead = [ Vhead; vb_headinfo_get_vhead(data)]; 0130 Fhead = [ Fhead; vb_headinfo_get_fhead(data) + Npoint]; 0131 0132 % support empty XXhead 0133 if isempty(data.XXhead) 0134 if ~isempty(data.Vhead) && ~isempty(data.Fhead) 0135 [new_f, new_v, data.XXhead] = vb_out_normal(data.Fhead, data.Vhead); 0136 else 0137 if isempty(data.Vhead), warning('Vhead is empty'); end 0138 if isempty(data.Fhead), warning('Fhead is empty'); end 0139 warning('XXhead is empty'); 0140 end 0141 end 0142 XXhead = [XXhead; vb_headinfo_get_xxhead(data)]; 0143 % <-- 2010-10-25 --- 0144 0145 Npoint = Npoint + len_v; 0146 end 0147 % vb_save(joined_file, 'XXhead', 'Vhead', 'Fhead', 'Nvertex', 'Npatch', 'R', 'Rmethod', 'Sigma', 'LayerTag'); 0148 vb_save(joined_file, ... 0149 'XXhead', 'Vhead', 'Fhead', 'Nvertex', 'Npatch', 'LayerTag'); 0150 % 0151 % --- END OF MAIN PROCEDURE ------------------------------------------------ % 0152 0153 catch 0154 rethrow(lasterror); 0155 end 0156 0157 % --- INNER FUNCTIONS ------------------------------------------------------ % 0158 % 0159 % --- inner_check_arguments() 0160 % 0161 function [head_files, file_root, joined_file, layer_tag, calc_mode] = ... 0162 inner_check_arguments(head_files, file_root, joined_file, ... 0163 layer_tag, calc_mode) 0164 0165 func_ = 'vb_util_join_head_files'; 0166 0167 if isempty(head_files) 0168 error('(%s)head_files is a required parameter', func_); 0169 end 0170 0171 if isempty(file_root) 0172 file_root = '.'; 0173 end 0174 0175 if isempty(joined_file) 0176 joined_file = [file_root filesep 'joined_head.head.mat']; 0177 end 0178 0179 if isempty(layer_tag) 0180 layer_tag = {'CSF' 'Skull' 'Scalp'}; 0181 end 0182 0183 if isempty(calc_mode) 0184 calc_mode = 1; % mean 0185 end 0186 return; 0187 % 0188 % --- end of inner_check_arguments() 0189 % 0190 % --- INNER FUNCTIONS ------------------------------------------------------ % 0191 0192 %%% END OF FILE %%%