0001 function [V, F, xxn] = vb_surf_smooth_out(V,F,xx,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 if ~exist('Para','var'), Para = []; end
0040 if ~isfield(Para,'Nloop'), Para.Nloop = 200; end
0041 if ~isfield(Para,'Ndisp'), Para.Ndisp = Para.Nloop+1; end
0042 if ~isfield(Para,'tangent_rate'), Para.tangent_rate = 0.3; end
0043 if ~isfield(Para,'out_ratio'), Para.out_ratio = 0.5; end
0044
0045 tangent_rate = Para.tangent_rate;
0046 out_rate = Para.out_ratio;
0047
0048 Nloop = Para.Nloop;
0049 Npoint = size(V,1);
0050 Npatch = size(F,1);
0051
0052
0053 Ndisp = Para.Ndisp;
0054 Nfig = fix(Nloop/Ndisp);
0055
0056 if Nfig < 2,
0057 NYfig = 1;
0058 else
0059 NYfig = 2;
0060 end
0061 NXfig = max(ceil(Nfig/NYfig), 1);
0062 nfig = NXfig*NYfig + 1;
0063
0064 fclr = [];
0065 eclr = [];
0066 light_mode = 1;
0067 vangle = [-70 20];
0068
0069
0070 xxf = zeros(Npatch,3);
0071
0072 nns = zeros(Npatch,1);
0073
0074 VV1 = zeros(Npatch,3);
0075 VV2 = zeros(Npatch,3);
0076 VV3 = zeros(Npatch,3);
0077
0078
0079 xxn = zeros(Npoint,3);
0080 xxs = zeros(Npoint,1);
0081
0082 fd = zeros(Npoint,3);
0083
0084 Nv = zeros(Npoint,1);
0085
0086 nnf = zeros(Npoint,1);
0087
0088
0089 F1 = F(:,1);
0090 F2 = F(:,2);
0091 F3 = F(:,3);
0092
0093
0094 xxf = vb_cross2( V(F2,:)-V(F1,:) , V(F3,:)-V(F1,:) );
0095
0096
0097 xxk = xx(F1,:)+xx(F2,:)+xx(F3,:);
0098
0099 xdot = sum( xxk .* xxf ,2);
0100 ix = find(sign(xdot) < 0 );
0101
0102
0103
0104 F(ix,2) = F3(ix);
0105 F(ix,3) = F2(ix);
0106
0107 F2 = F(:,2);
0108 F3 = F(:,3);
0109
0110
0111 for n=1:Npatch,
0112 inx = F(n,:)';
0113 Nv(inx) = Nv(inx) + 2;
0114 end;
0115
0116
0117
0118 for i=1:Nloop,
0119
0120
0121 V1=V(F1,:);
0122 V2=V(F2,:);
0123 V3=V(F3,:);
0124
0125
0126 xxf = vb_cross2( V2 - V1, V3 - V1 );
0127
0128
0129 nns = sqrt(sum(xxf.^2,2));
0130 xxf = xxf./nns(:,ones(1,3));
0131
0132
0133 VV1 = V2 + V3 - 2*V1;
0134 VV2 = V3 + V1 - 2*V2;
0135 VV3 = V1 + V2 - 2*V3;
0136
0137
0138 xxn = zeros(Npoint,3);
0139
0140 fd = zeros(Npoint,3);
0141
0142 for n=1:Npatch,
0143
0144 j1=F1(n);
0145 j2=F2(n);
0146 j3=F3(n);
0147
0148 xxn(j1,:) = xxn(j1,:) + xxf(n,:);
0149 xxn(j2,:) = xxn(j2,:) + xxf(n,:);
0150 xxn(j3,:) = xxn(j3,:) + xxf(n,:);
0151
0152
0153 fd(j1,:) = fd(j1,:) + VV1(n,:);
0154 fd(j2,:) = fd(j2,:) + VV2(n,:);
0155 fd(j3,:) = fd(j3,:) + VV3(n,:);
0156 end;
0157
0158
0159 xxs = sqrt(sum(xxn.^2,2));
0160 xxn = xxn./xxs(:,ones(1,3));
0161
0162
0163 fd = fd./Nv(:,ones(1,3));
0164
0165 V = V + tangent_rate*fd + out_rate*xxn;
0166
0167 if rem(i,Ndisp)==0,
0168 if nfig > NYfig*NXfig
0169 figure;
0170 nfig=1;
0171 else
0172 nfig=nfig+1;
0173 end
0174 subplot(NYfig,NXfig,nfig);
0175 vb_plot_surf(V,F,fclr,eclr,light_mode);
0176 view(vangle);
0177 tlabel = sprintf('Iteration = %d',i);
0178 title(tlabel);
0179 end;
0180 end
0181