0001 function normal_stat = vb_original_normal_statics(proj_root,brain_parm,BV_index)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 if isempty(proj_root)
0022 brain_file = [brain_parm.brain_file];
0023 else
0024 brain_file = [proj_root filesep brain_parm.brain_file];
0025 end
0026
0027
0028 if isfield(brain_parm,'R_normal')
0029 Rmax = brain_parm.R_normal;
0030 else
0031 Rmax = 0.003;
0032 end
0033
0034 EPS = 1e-10;
0035
0036
0037
0038 vb_disp('Calculate original normal statics')
0039 vb_disp('Load original brain')
0040 [V0L,F0L,n0L,V0R,F0R,n0R] = vb_load_orig_brain_surf(brain_parm);
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 vb_disp('Change coordinate to [m] ');
0053
0054 V0L = V0L/1000;
0055 V0R = V0R/1000;
0056
0057 NV0L = size(V0L,1);
0058 NV0R = size(V0R,1);
0059 NV0 = NV0L + NV0R;
0060
0061
0062
0063
0064 vb_disp('check normal direction outward: ')
0065
0066
0067
0068
0069 omega = vb_solid_angle_check(V0L,F0L);
0070 vb_disp(sprintf('Left solid_angle/(2*pi) = %5.3f',omega));
0071 if abs(omega - 1) > EPS,
0072 vb_disp('Surface is not closed ');
0073 end
0074 omega = vb_solid_angle_check(V0R,F0R);
0075 vb_disp(sprintf('Right solid_angle/(2*pi) = %5.3f',omega));
0076 if abs(omega - 1) > EPS,
0077 vb_disp('Surface is not closed ');
0078 end
0079
0080
0081
0082
0083 NLxx = sum( (sum(n0L.^2,2) - 1) < EPS );
0084 if NLxx ~= NV0L,
0085 vb_disp(sprintf('# of left abnormal normal vector (%d)',NV0L - NLxx));
0086 end
0087 NRxx = sum( (sum(n0R.^2,2) - 1) < EPS );
0088 if NRxx ~= NV0R,
0089 vb_disp(sprintf('\n# of right abnormal normal vector (%d)',NV0R - NRxx));
0090 end
0091
0092
0093
0094
0095 indxL = BV_index.Left;
0096 indxR = BV_index.Right;
0097
0098 NL = length(indxL);
0099 NR = length(indxR);
0100
0101 if min(indxR) > NV0L,
0102 indxR = indxR - NV0L;
0103 end
0104
0105
0106
0107
0108
0109
0110 neighbor = cell(NL+NR,1);
0111 neighbor_dd = zeros(NL+NR,1);
0112 neighbor_area = zeros(NL+NR,1);
0113
0114
0115
0116
0117 tic
0118 vb_disp_nonl('Find neighbor index (Left): ')
0119 [xxDL,xxFL, xxTL] = vb_next_distance( F0L, V0L );
0120 vb_disp(sprintf('%f[sec]',toc));
0121
0122
0123 [xxAL] = vb_calc_patch_area(V0L, F0L, xxTL);
0124 vb_disp(':Done')
0125
0126 vb_disp_nonl('Make neighbor list of original brain (Left): ')
0127 tic
0128
0129 prg_all = NL;
0130 prg = 0;
0131 Ndisp = fix(prg_all/20);
0132
0133
0134 for n=1:NL
0135 [Vindx, dd] = vb_find_neighbor(Rmax, indxL(n), xxFL, xxDL );
0136 neighbor{n} = Vindx;
0137
0138
0139 neighbor_dd(n) = mean(dd);
0140
0141 neighbor_area(n) = sum(xxAL(Vindx));
0142
0143 if mod(n,Ndisp)==0,
0144 for ii=1:15; vb_disp_nonl(sprintf('\b')); end
0145 vb_disp_nonl(sprintf('%3d %% processed',ceil(100*(prg/prg_all))));
0146 end
0147 prg = prg+1;
0148 end
0149 vb_disp_nonl(sprintf(' %f[sec]\n',toc));
0150
0151
0152
0153
0154 tic
0155 vb_disp_nonl('Find neighbor index (Right): ')
0156 [xxDR,xxFR,xxTR] = vb_next_distance( F0R, V0R );
0157 vb_disp(sprintf('%f[sec]',toc));
0158
0159
0160 [xxAR] = vb_calc_patch_area(V0R, F0R, xxTR);
0161 vb_disp(':Done')
0162
0163 vb_disp_nonl('Make neighbor list of original brain (Right): ')
0164 tic
0165
0166 prg_all = NR;
0167 prg = 0;
0168 Ndisp = fix(prg_all/20);
0169
0170
0171 for n=1:NR
0172 [Vindx, dd] = vb_find_neighbor(Rmax, indxR(n), xxFR, xxDR );
0173 neighbor{n + NL} = Vindx + NV0L;
0174
0175
0176 neighbor_dd(n + NL) = mean(dd);
0177
0178 neighbor_area(n + NL) = sum(xxAR(Vindx));
0179
0180 if mod(n,Ndisp)==0,
0181 for ii=1:15; vb_disp_nonl(sprintf('\b')); end
0182 vb_disp_nonl(sprintf('%3d %% processed',ceil(100*(prg/prg_all))));
0183 end
0184 prg = prg+1;
0185 end
0186 vb_disp_nonl(sprintf(' %f[sec]\n',toc));
0187
0188
0189 normal_stat.neighbor_org = neighbor;
0190 normal_stat.neighbor_dd = neighbor_dd;
0191 normal_stat.neighbor_area = neighbor_area;
0192
0193
0194 normal_stat.normal_org = [n0L; n0R];
0195
0196
0197
0198
0199
0200
0201
0202 normal_stat.Nvertex = NL+NR;
0203 normal_stat.NvertexL = NL;
0204 normal_stat.NvertexR = NR;
0205 normal_stat.Nvertex0 = NV0;
0206 normal_stat.NvertexL0 = NV0L;
0207 normal_stat.NvertexR0 = NV0R;
0208
0209 return