0001 function [Vnew,Fnew,xxnew,Indx,Vinfo] = vb_smooth_cortex_LR(V, F, Para)
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 if ~exist('Para','var'), Para = []; end
0053
0054 if ~isfield(Para,'Dim') | isempty(Para.Dim)
0055 error('Size of mask image is not specified');
0056 else
0057 Dim = Para.Dim;
0058 end
0059
0060
0061 if ~isfield(Para,'vstep'),
0062 error('Step size of mask image is not specified');
0063 else
0064 step = Para.vstep;
0065 end;
0066
0067
0068 if ~isfield(Para,'Nvertex'),
0069 Nvertex = 3000;
0070 else
0071 Nvertex = Para.Nvertex;
0072 end;
0073
0074
0075
0076 if ~isfield(Para,'R_fill'),
0077 R_fill = [4];
0078 else
0079 R_fill = Para.R_fill;
0080 end;
0081
0082 if ~isfield(Para,'R_cut'),
0083 R_cut = [ 6 6 -6 -6 -6 -4];
0084 else
0085 R_cut = Para.R_cut;
0086 end;
0087 if ~isfield(Para,'R_smooth'),
0088 R_smooth = [ 6 6 -6 -6];
0089 else
0090 R_smooth = Para.R_smooth;
0091 end;
0092
0093 if ~isfield(Para,'Nloop'), Para.Nloop = 200; end
0094 if ~isfield(Para,'Nlast'), Para.Nlast = 0; end
0095 if ~isfield(Para,'tangent_rate'), Para.tangent_rate = 0.3; end
0096 if ~isfield(Para,'mask_ratio'), Para.mask_ratio = 0.5; end
0097 if ~isfield(Para,'mask_threshold'), Para.mask_threshold = 0.3; end
0098
0099 if ~isfield(Para,'plot_mode'),
0100 plot_mode = 0;
0101 else
0102 plot_mode = Para.plot_mode;
0103 end;
0104
0105
0106
0107
0108
0109
0110 [BB] = vb_cortex_fill(V, F, step, R_fill, 'LR', Dim);
0111
0112 if plot_mode > 0,
0113
0114 Nfig = [3, 3];
0115
0116 zindx = [10:10:Dim(3)];
0117 fclr = [0.8 0.7 0.6];
0118 eclr = 'w';
0119 light_mode=1;
0120 end
0121
0122 BB = vb_morphology_operation(BB, R_cut, step);
0123
0124 if plot_mode > 1,
0125 vb_plot_slice( BB, [], zindx, 1, Nfig);
0126 end
0127
0128
0129
0130
0131 B = vb_cortex_fill(V, F, step, R_fill, 'L', Dim);
0132 B = vb_morphology_operation(B, R_smooth, step);
0133
0134 if plot_mode > 1,
0135 vb_plot_slice( B, [], zindx, 1, Nfig);
0136 end
0137
0138
0139
0140
0141 NL = F.NdipoleL;
0142 [VL,FL,xxL] = vb_make_inner_sphere(V(1:NL,:), Nvertex);
0143 [VL,FL,xxL] = vb_surf_smooth_fit(VL,FL,xxL, B, Para);
0144
0145
0146
0147
0148 B = vb_cortex_fill(V, F, step, R_fill, 'R', Dim);
0149 B = vb_morphology_operation(B, R_smooth, step);
0150
0151 if plot_mode > 1,
0152 vb_plot_slice( B, [], zindx, 1, Nfig);
0153 end
0154
0155
0156
0157
0158 [VR,FR,xxR] = vb_make_inner_sphere(V((NL+1):end,:), Nvertex, 1);
0159 [VR,FR,xxR] = vb_surf_smooth_fit(VR,FR,xxR, B, Para);
0160
0161 fprintf('# of left cortex = %d\n',size(VL,1))
0162 fprintf('# of right cortex = %d\n',size(VR,1))
0163
0164 if Para.Nlast > 0,
0165
0166 fprintf('Surface smooth by spring model\n')
0167 tic
0168 Para.Nloop = Para.Nlast;
0169 [VL, FL, xxL] = vb_surf_smooth(VL,FL,xxL,Para);
0170 [VR, FR, xxR] = vb_surf_smooth(VR,FR,xxR,Para);
0171 vb_ptime(toc)
0172 end
0173
0174
0175 fprintf('Remove central region from left cortex\n')
0176
0177 VL_indx = vb_remove_vertex_by_mask(VL,BB,step);
0178 [VL, FL] = vb_trans_index( VL, FL, VL_indx);
0179
0180 fprintf('Remove central region from right cortex\n')
0181 VR_indx = vb_remove_vertex_by_mask(VR,BB,step);
0182 [VR, FR] = vb_trans_index( VR, FR, VR_indx);
0183
0184 fprintf('# of left cortex = %d\n',size(VL,1))
0185 fprintf('# of right cortex = %d\n',size(VR,1))
0186
0187
0188 [FL, VL, xxL] = vb_out_normal( FL ,VL);
0189 omega = vb_solid_angle_check(VL,FL);
0190 fprintf('Closed surface index (=1) for left cortex: %f\n', omega)
0191
0192 [FR, VR, xxR] = vb_out_normal( FR ,VR);
0193 omega = vb_solid_angle_check(VR,FR);
0194 fprintf('Closed surface index (=1) for right cortex: %f\n', omega)
0195
0196 NdipoleL = size(VL,1);
0197
0198 Vnew = [VL ; VR];
0199 xxnew = [xxL; xxR];
0200
0201 Fnew.F3L = FL;
0202 Fnew.F3R = FR + NdipoleL;
0203 Fnew.F3 = [FL ; FR + NdipoleL];
0204
0205 Fnew.NdipoleL = NdipoleL;
0206
0207 Ndipole = size(Vnew,1);
0208 Npatch = size(Fnew.F3,1);
0209
0210
0211 Vinfo.Ndipole = Ndipole;
0212 Vinfo.NdipoleL = NdipoleL;
0213 Vinfo.Npatch = Npatch;
0214 Vinfo.Coord = 'Analyze_Right_mm';
0215
0216
0217 fprintf('# of vertex = %d\n', Ndipole)
0218
0219
0220
0221
0222 Zstep = 100;
0223 Rmax = 10;
0224
0225
0226 tic
0227 fprintf('Find original vertex corresponding to the smoothed surface\n')
0228 [Indx ,ddmin] = vb_find_nearest_point(V, Vnew, Rmax, Zstep);
0229
0230 fprintf('Max distance between new and old vertex = %f\n',max(ddmin))
0231 vb_ptime(toc)
0232
0233 if Para.plot_mode > 0
0234 dmax = 10;
0235 X0 = mean(Vnew);
0236 F3 = Fnew.F3;
0237 vb_plot_slice_surf( B, Vnew/step, F3, round(X0(1)/step), 'x',[1 1],'r-',dmax);
0238 vb_plot_slice_surf( B, Vnew/step, F3, round(X0(2)/step), 'y',[1 1],'r-',dmax);
0239 vb_plot_slice_surf( B, Vnew/step, F3, round(X0(3)/step), 'z',[1 1],'r-',dmax);
0240 end