0001 function [Indx ,ddmin, Vref2, Fref2] = ...
0002 vb_find_no_overlap_divide(Vref,Vnew,Fref,Rmax)
0003
0004
0005
0006
0007 if nargin < 3 || isempty(Fref),
0008 error('Fref is necessary input') ;
0009 end;
0010
0011 fprintf('Ver2 vb_find_no_overlap_divide start\n\n')
0012
0013
0014 d = vb_sparse_inv_distance(Vref,Vnew, Rmax);
0015
0016
0017 [overlap0,ddmin0,Indx0] = vb_find_overlap(d);
0018
0019
0020 dmin0 = max(ddmin0(:));
0021 fprintf('max distance of ddmin at 1st stage = %g\n',dmin0)
0022
0023 if overlap0.Noverlap == 0,
0024 ddmin = ddmin0;
0025 Indx = Indx0;
0026 Vref2 = Vref;
0027 Fref2 = Fref;
0028 fprintf('No overlap at 1st stage\n')
0029 clear d
0030
0031 return;
0032 else
0033 fprintf('Noverlap at 1st stage = %d , Mean Multiplicity = %g\n', ...
0034 overlap0.Noverlap, mean(overlap0.Nmulti)),
0035 end;
0036
0037 Ntry = 20;
0038 overlap = overlap0;
0039
0040 for jj = 1:Ntry
0041
0042 [Vadd, Iadd, Vref2, Fref2] = vb_add_patch_vertex(overlap,Vref,Fref);
0043
0044 fprintf('Add reference vertex: %d\n',size(Vadd,1))
0045
0046 dadd = vb_sparse_inv_distance(Vadd,Vnew, Rmax);
0047
0048 dd = [d; dadd];
0049
0050
0051 [overlap1,ddmin1,Indx1] = vb_find_overlap(dd);
0052
0053
0054 dmin1 = max(ddmin1(:));
0055 fprintf('max distance of ddmin at %d-th stage = %g\n',jj,dmin1)
0056
0057 if overlap1.Noverlap == 0,
0058 ddmin = ddmin1;
0059 Indx = Indx1;
0060 fprintf('No overlap at %d-th stage with added vertex \n',jj)
0061 clear d dd dadd
0062
0063 return;
0064 else
0065 fprintf('Noverlap at %d-th stage = %d , Mean Multiplicity = %g\n', ...
0066 jj, overlap1.Noverlap, mean(overlap1.Nmulti)),
0067 end;
0068
0069
0070 [dd, overlap2, ddmin2, Indx2, iter] = ...
0071 vb_find_no_overlap(dd,overlap1,Rmax);
0072
0073
0074 dmin2 = max(ddmin2(:));
0075 fprintf('max distance of ddmin after no overlap try')
0076 fprintf(' at %d-th stage = %g\n',jj,dmin2)
0077
0078 if overlap2.Noverlap==0,
0079 ddmin = ddmin2;
0080 Indx = Indx2;
0081
0082 fprintf('No overlap at %d-th stage\n',jj)
0083
0084 clear d dd dadd
0085
0086 return
0087 else
0088 fprintf('Noverlap (after iter = %d) = %d at %d-th stage\n',...
0089 iter, overlap2.Noverlap,jj),
0090
0091 overlap = overlap2;
0092
0093 if jj < Ntry
0094 Vref = Vref2;
0095 Fref = Fref2;
0096 else
0097 ddmin = ddmin2;
0098 Indx = Indx2;
0099 end
0100 end
0101 end
0102
0103 clear d dd dadd
0104
0105