0001 function [V,F,xx,BV_index,Vinfo] = vb_make_brain_data(brain_parm);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 error('This function is a canditate to be removed, but invoked.');
0077
0078 global vbmeg_inst;
0079 define = vbmeg_inst.const;
0080
0081
0082 TRANS_COORDINATE = 0;
0083 TRANS_NORMAL = 1;
0084
0085
0086
0087
0088 tic;
0089 if isfield(brain_parm,'BV_left_file') & ...
0090 ~isempty(brain_parm.BV_left_file),
0091
0092
0093
0094
0095
0096
0097
0098 fprintf('\n--- Make brain model using BrainVoyager SRF files ');
0099 filetype = 'BrainVoyager';
0100
0101 Srf = vb_ScriptLoadSRF(brain_parm.BV_left_file);
0102 V0L = [Srf.VertexX, Srf.VertexY, Srf.VertexZ];
0103 n0L = [Srf.NormalX, Srf.NormalY, Srf.NormalZ];
0104 F0L = Srf.Triangles+1;
0105
0106 Srf = vb_ScriptLoadSRF(brain_parm.BV_right_file);
0107 V0R = [Srf.VertexX, Srf.VertexY, Srf.VertexZ];
0108 n0R = [Srf.NormalX, Srf.NormalY, Srf.NormalZ];
0109 F0R = Srf.Triangles+1;
0110 elseif isfield(brain_parm,'FS_left_file') & ...
0111 ~isempty(brain_parm.FS_left_file),
0112 fprintf('\n--- Make brain model using FreeSurfer .asc files ');
0113 filetype = 'FreeSurfer';
0114
0115 [V0L,F0L] = vb_fs_load_surface(brain_parm.FS_left_file,...
0116 brain_parm.FS_xfm_file,1.0);
0117 [V0R,F0R] = vb_fs_load_surface(brain_parm.FS_right_file,...
0118 brain_parm.FS_xfm_file,1.0);
0119
0120 [tmp1,tmp2,n0L] = vb_out_normal(F0L,V0L);
0121 [tmp3,tmp4,n0R] = vb_out_normal(F0R,V0R);
0122 n0L = -1*n0L;
0123 n0R = -1*n0R;
0124
0125 if size(tmp1,1)~=size(F0L,1) | size(tmp2,1)~=size(V0L,1) | ...
0126 size(tmp3,1)~=size(F0R,1) | size(tmp4,1)~=size(V0R,1),
0127 error(['There are some isolated pathces in the FreeSurfer ' ...
0128 'cortical model.']);
0129 end
0130 end
0131 fprintf('%f[sec]\n',toc);
0132
0133 switch filetype
0134 case 'BrainVoyager',
0135
0136
0137
0138
0139
0140
0141
0142
0143 tic;
0144 fprintf('--- Coordinate transformation (BV to VOX) ');
0145
0146 [Vdim, Vsize] = analyze_hdr_read(brain_parm.analyze_file);
0147
0148 V2L = vb_bvoyger_to_vox(V0L,Vdim,Vsize,TRANS_COORDINATE);
0149 V2R = vb_bvoyger_to_vox(V0R,Vdim,Vsize,TRANS_COORDINATE);
0150
0151 n2L = vb_bvoyger_to_vox(n0L,Vdim,Vsize,TRANS_NORMAL);
0152 n2R = vb_bvoyger_to_vox(n0R,Vdim,Vsize,TRANS_NORMAL);
0153
0154 fprintf('%f[sec]\n',toc);
0155 case 'FreeSurfer'
0156 V2L = V0L;
0157 V2R = V0R;
0158 n2L = n0L;
0159 n2R = n0R;
0160 end
0161
0162
0163
0164
0165 tic;
0166 fprintf('--- Reduce cortical vertices ');
0167
0168 [F3L,V3L] = vb_reducepatch( F0L, V2L, brain_parm.reduce_ratio );
0169 [F3R,V3R] = vb_reducepatch( F0R, V2R, brain_parm.reduce_ratio );
0170
0171 fprintf('%f[sec]\n',toc);
0172
0173
0174
0175
0176 tic;
0177 fprintf('--- Find original point corresponding to reduced model ');
0178
0179 IndxL = vb_find_match_point( V2L, V3L, brain_parm.N_step );
0180 IndxR = vb_find_match_point( V2R, V3R, brain_parm.N_step );
0181
0182 fprintf('%f[sec]\n',toc);
0183
0184
0185 n3L = n2L(IndxL,:);
0186 n3R = n2R(IndxR,:);
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196 switch filetype,
0197 case 'BrainVoyager',
0198 tic;
0199 fprintf('--- Coordinate transformation (VOX to SPM-ANALYZE) ');
0200 V3L = vb_vox_to_spm_right(V3L,Vdim,Vsize,TRANS_COORDINATE);
0201 V3R = vb_vox_to_spm_right(V3R,Vdim,Vsize,TRANS_COORDINATE);
0202
0203 n3L = vb_vox_to_spm_right(n3L,Vdim,Vsize,TRANS_NORMAL);
0204 n3R = vb_vox_to_spm_right(n3R,Vdim,Vsize,TRANS_NORMAL);
0205
0206 fprintf('%f[sec]\n',toc);
0207 case 'FreeSurfer',
0208 end
0209
0210
0211 NdipoleL = size(V3L,1);
0212 NdipoleR = size(V3R,1);
0213 Ndipole = NdipoleL + NdipoleR;
0214
0215 F3R = F3R + NdipoleL;
0216 F3 = [F3L ; F3R];
0217 n3 = [n3L ; n3R];
0218
0219 NdipoleL0 = size(V0L,1);
0220 clear V0L V0R V2L V2R F0L F0R n0L n0R n2L n2R Srf
0221
0222
0223
0224
0225 tic;
0226 fprintf('--- Change coordinate to [m] ');
0227 V = [V3L ; V3R]./1000;
0228
0229
0230 nn = sqrt(sum(n3.^2 ,2));
0231 ix = find(nn<eps);
0232 if ~isempty(ix),
0233 fprintf('!! There are abnormal normal vector \n');
0234 nn(ix) = 1;
0235 end
0236 xx = -n3./repmat(nn ,[1 3]);
0237
0238
0239
0240 Npatch = size(F3,1);
0241 F.F3 = F3;
0242 F.F3R = F3R;
0243 F.F3L = F3L;
0244 F.NdipoleL = NdipoleL;
0245
0246
0247 BV_index.Left = IndxL;
0248 BV_index.Right = IndxR+NdipoleL0;
0249
0250
0251 Vinfo.Ndipole = Ndipole;
0252 Vinfo.NdipoleL = NdipoleL;
0253 Vinfo.Npatch = Npatch;
0254 Vinfo.NdipoleL0 = NdipoleL0;
0255 Vinfo.Coord = 'SPM_Right_m';
0256
0257 clear V3L V3R n3L n3R
0258
0259 fprintf('%f[sec]\n',toc);
0260