0001 function [V, F, Iparent] = vb_divide_patch(V, F, xxT, Vindex)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 NV = size(V,1);
0013 NF = size(F,1);
0014
0015
0016 DFindex = vb_cell_merge(xxT,Vindex);
0017 DFindex = unique(DFindex );
0018 Iremain = vb_setdiff2([1:NF],DFindex);
0019
0020
0021 Fremain = F(Iremain, : );
0022
0023
0024 divF = F(DFindex, : );
0025
0026 NDF = length(DFindex);
0027
0028
0029 v1 = V(divF(:,1),:);
0030 v2 = V(divF(:,2),:);
0031 v3 = V(divF(:,3),:);
0032
0033
0034 f1 = (v2+v3)/2;
0035 f2 = (v3+v1)/2;
0036 f3 = (v1+v2)/2;
0037
0038
0039
0040 Vf = [f1;
0041 f2;
0042 f3];
0043
0044
0045 Jedge = [ divF(:,2),divF(:,3);
0046 divF(:,3),divF(:,1);
0047 divF(:,1),divF(:,2)];
0048
0049 Jedge = sort(Jedge,2);
0050
0051
0052
0053
0054
0055 [Juniq, II, JJ ] = unique( Jedge, 'rows');
0056
0057
0058
0059
0060
0061
0062 Vnew = Vf(II,:);
0063 Nnew = size(Vnew,1);
0064
0065
0066 V = [ V ; Vnew];
0067 Inew = (1:Nnew) + NV;
0068
0069
0070
0071
0072 Jnew = JJ + NV;
0073
0074 ix = 1:NDF;
0075
0076
0077 J1 = Jnew(ix);
0078
0079 J2 = Jnew(ix+NDF);
0080
0081 J3 = Jnew(ix+2*NDF);
0082
0083
0084 Fadd = [ divF(:,1), J2, J3; ...
0085 divF(:,2), J3, J1; ...
0086 divF(:,3), J1, J2; ...
0087 J1,J2,J3 ];
0088
0089 F = [Fremain; Fadd];
0090
0091
0092
0093 Iparent = [J1, divF(:,2), divF(:,3);
0094 J2, divF(:,3), divF(:,1);
0095 J3, divF(:,1), divF(:,2)];
0096
0097
0098 [Iuniq , I, J]= unique(Iparent(:,1));
0099
0100 Iparent = Iparent(I,:);
0101
0102 return
0103
0104
0105 Nerr = Nnew - size(Iparent,1)
0106
0107 vmid = V(Iparent(:,2),:) + V(Iparent(:,3),:) ;
0108
0109 vmid = vmid./repmat( sqrt(sum(vmid.^2,2)) ,1 , 3);
0110
0111 err = sum((V(Iparent(:,1),:) - vmid).^2,2);
0112
0113 errsum = sum(err)
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123