0001 function [Fall, Vall, Nall, Vinx] = vb_separate_surf(F,V,seedID)
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 Npoint = size(V,1);
0032 Npatch = size(F,1);
0033
0034 Plist = zeros(Npoint,1);
0035 Vlist = zeros(Npoint,1);
0036
0037 Vflg = zeros(Npoint,1);
0038 Fflg = zeros(Npatch,1);
0039
0040
0041 Vindx = unique(F(:));
0042
0043
0044 Vflg(:) = -1;
0045 Vflg(Vindx) = 0;
0046
0047
0048
0049 xxF = vb_neighbor_index(V,F);
0050
0051
0052 seedID = Vindx(1);
0053 Plist(1) = [seedID];
0054
0055 Nsurf = 1;
0056 Nall = [];
0057 Vflg(seedID) = Nsurf;
0058 Nlist = 1;
0059 Ntotal = 0;
0060
0061 while 1,
0062
0063 while Nlist > 0,
0064 Vlist(:) = 0;
0065
0066
0067 for n=1:Nlist,
0068
0069 root = Plist(n);
0070
0071
0072 nextID = xxF{root};
0073
0074
0075 nlist1 = nextID(:,1);
0076 nlist2 = nextID(:,2);
0077 flist = nextID(:,3);
0078
0079
0080 nextix = find( Fflg(flist) == 0 );
0081
0082 if isempty(nextix), continue; end;
0083
0084
0085 nlist1 = nlist1(nextix);
0086 nlist2 = nlist2(nextix);
0087 flist = flist(nextix);
0088
0089 Fflg(flist) = Nsurf;
0090 Vlist(nlist1) = 1;
0091 Vlist(nlist2) = 1;
0092
0093 end;
0094
0095
0096
0097 ix = find(Vlist == 1 & Vflg == 0);
0098
0099 Nlist = length(ix);
0100 if Nlist == 0, break; end;
0101
0102
0103 Plist(1:Nlist) = ix;
0104 Vflg(ix) = Nsurf;
0105 Ntotal = Ntotal + Nlist;
0106 end
0107
0108
0109
0110 ix = find(Vflg == Nsurf);
0111 Nall(Nsurf) = length(ix);
0112
0113
0114 ix_rest = find(Vflg == 0);
0115 Nrest = length(ix_rest);
0116
0117 fprintf('Nsurf= %d, N= %d, Ntotal=%d, Nrest=%d\n', ...
0118 Nsurf,Nall(Nsurf),Ntotal,Nrest)
0119
0120 if isempty(ix_rest), break; end;
0121
0122 Nlist = 1;
0123 Nsurf = Nsurf + 1;
0124 seedID = ix_rest(1);
0125 Plist(1) = seedID;
0126 Vflg(seedID) = Nsurf;
0127 end
0128
0129
0130 [Nall , id]= sort( -Nall );
0131
0132 Vinx = cell(Nsurf,1);
0133 Vall = cell(Nsurf,1);
0134 Fall = cell(Nsurf,1);
0135
0136 for n=1:Nsurf
0137
0138 indx = find( Vflg == id(n) );
0139 [Vnew, Fnew] = vb_trans_index( V, F, indx);
0140 Nall(n) = length(indx);
0141 Vinx{n} = indx;
0142 Vall{n} = Vnew;
0143 Fall{n} = Fnew;
0144 end
0145
0146 return
0147
0148