0001 function [V,F,xx,BV_index,Vinfo] = vb_make_brain_std(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 plot_mode = 1;
0061
0062 global vbmeg_inst;
0063 const = vb_define_verbose;
0064
0065
0066 Rmax = 4;
0067 EPS = 1e-10;
0068
0069
0070 vb_disp('Load original brain surface');
0071
0072 [V0L,F0L,n0L,V0R,F0R,n0R] = vb_load_orig_brain_surf(brain_parm);
0073
0074
0075
0076
0077
0078 vb_disp('Extract cortex area index');
0079
0080 [Vindex] = vb_extract_cortex(V0L,F0L,V0R,F0R,brain_parm,1);
0081
0082 vb_disp('Reduce cortex');
0083
0084
0085 VLref = V0L;
0086 VRref = V0R;
0087
0088 R = 1.0;
0089 if isfield(brain_parm, 'Nvertex') && ~isempty(brain_parm.Nvertex) &&...
0090 isnumeric(brain_parm.Nvertex)
0091
0092 N = brain_parm.Nvertex;
0093 if((size(V0L, 1) + size(V0R, 1)) < N)
0094 vb_disp(['brain_parm.Nvertex is larger than original model''s one.'...
0095 'No reduction is applied.'], const.VERBOSE_LEVEL_WARNING);
0096 else
0097 R = N;
0098 vb_disp(sprintf('Nvertex = %d is applied.', brain_parm.Nvertex));
0099 end
0100 elseif isfield(brain_parm, 'reduce_ratio') && ...
0101 isnumeric(brain_parm.reduce_ratio)
0102 R = brain_parm.reduce_ratio;
0103 vb_disp(sprintf('reduce_ratio = %.2f is applied.', ...
0104 brain_parm.reduce_ratio));
0105 end
0106
0107
0108
0109 [FL,VL] = vb_reducepatch( F0L, V0L, R );
0110 [FR,VR] = vb_reducepatch( F0R, V0R, R );
0111
0112 [FL, VL, xxL] = vb_out_normal_surf(FL,VL);
0113 [FR, VR, xxR] = vb_out_normal_surf(FR,VR);
0114
0115
0116
0117
0118 omega = vb_solid_angle_check(VL,FL);
0119 vb_disp(sprintf('Left solid_angle/(2*pi) = %5.3f',omega));
0120 if abs(omega - 1) > EPS,
0121 vb_disp('Surface is not closed ');
0122 end
0123 omega = vb_solid_angle_check(VR,FR);
0124 vb_disp(sprintf('Right solid_angle/(2*pi) = %5.3f',omega));
0125 if abs(omega - 1) > EPS,
0126 vb_disp('Surface is not closed ');
0127 end
0128
0129 NdipoleL = size(VL,1);
0130 NdipoleR = size(VR,1);
0131 Ndipole = NdipoleL + NdipoleR;
0132 FR = FR + NdipoleL;
0133
0134 F.F3 = [FL ; FR];
0135 F.F3R = FR;
0136 F.F3L = FL;
0137 F.NdipoleL = NdipoleL;
0138
0139
0140
0141
0142
0143
0144
0145 vb_disp('Find original point corresponding to reduced model');
0146
0147 tic;
0148 vb_disp_nonl('Left cortex: ');
0149 [IndxL, ddL] = vb_find_nearest_point(VLref, VL, Rmax, 100, 1, 1);
0150 vb_disp(sprintf('%f[sec]',toc));
0151
0152 tic;
0153 vb_disp_nonl('Right cortex: ');
0154 [IndxR, ddR] = vb_find_nearest_point(VRref, VR, Rmax, 100, 1, 1);
0155
0156 vb_disp(sprintf('%f[sec]',toc));
0157
0158 dd = [ddL; ddR];
0159 dmax = max(dd);
0160 fprintf('Max distance = %4.1f mm \n', dmax)
0161
0162
0163
0164
0165 V = [VL; VR]/1000;
0166
0167
0168 xx = [xxL ; xxR];
0169
0170
0171 NdipoleL0 = size(VLref,1);
0172 NdipoleR0 = size(VRref,1);
0173 Npatch = size(F.F3,1);
0174
0175
0176 BV_index.Left = IndxL;
0177 BV_index.Right = IndxR + NdipoleL0;
0178
0179
0180 BV_index.cortexL = Vindex.cortexL;
0181 BV_index.cortexR = Vindex.cortexR + NdipoleL0;
0182
0183
0184 Vinfo.Ndipole = Ndipole;
0185 Vinfo.NdipoleL = NdipoleL;
0186 Vinfo.NdipoleR = NdipoleR;
0187
0188 Vinfo.Ndipole0 = NdipoleL0 + NdipoleR0;
0189 Vinfo.NdipoleL0 = NdipoleL0;
0190 Vinfo.NdipoleR0 = NdipoleR0;
0191
0192 Vinfo.Npatch = Npatch;
0193 Vinfo.Coord = 'SPM_Right_m';
0194 Vinfo.dd_match = dd;
0195
0196
0197 flgL = zeros(NdipoleL0,1);
0198 flgR = zeros(NdipoleR0,1);
0199
0200
0201 flgL(Vindex.cortexL) = 1;
0202 flgR(Vindex.cortexR) = 1;
0203
0204
0205 tblL = zeros(NdipoleL0,1);
0206 tblR = zeros(NdipoleR0,1);
0207
0208 tblL(IndxL) = 1:NdipoleL;
0209 tblR(IndxR) = 1:NdipoleR;
0210
0211
0212 ixL = find( tblL .* flgL > 0);
0213 ixR = find( tblR .* flgR > 0);
0214
0215 Vinfo.cortexL = tblL(ixL);
0216 Vinfo.cortexR = tblR(ixR) + NdipoleL;
0217
0218 if plot_mode == 0, return; end;
0219
0220
0221 nonL = vb_setdiff2([1:NdipoleL], Vinfo.cortexL);
0222 nonR = vb_setdiff2([(NdipoleL+1):Ndipole], Vinfo.cortexR);
0223
0224 FLz = vb_patch_select(nonL, F.F3L, Ndipole);
0225 FRz = vb_patch_select(nonR, F.F3R, Ndipole);
0226
0227 figure;
0228 subplot(1,2,1)
0229 vb_plot_surf(V,F.F3L,'','b')
0230 hold on
0231 vb_plot_surf(V,FLz,'r','r')
0232
0233 subplot(1,2,2)
0234 vb_plot_surf(V,F.F3R,'','b')
0235 hold on
0236 vb_plot_surf(V,FRz,'r','r')
0237