0001 function [Vinx, Nall, ix_rest] = vb_connected_vertex(Vindx,F)
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 Npoint = max([F(:); Vindx(:)]);
0033
0034
0035 F = vb_patch_select(Vindx,F,Npoint);
0036
0037 Npoint = max([F(:); Vindx(:)]);
0038 Npatch = size(F,1);
0039
0040 Plist = zeros(Npoint,2);
0041 Vlist = zeros(Npoint,2);
0042 Vflg = zeros(Npoint,1);
0043 Fflg = zeros(Npatch,1);
0044 FF = zeros(Npatch,3);
0045
0046
0047 Vflg(:) = -1;
0048
0049
0050 Vflg(Vindx) = 0;
0051
0052
0053
0054 xxF = vb_neighbor_index(zeros(Npoint,1),F);
0055
0056
0057 nextID = [];
0058
0059 for j = 1:length(Vindx)
0060 root = Vindx(j);
0061 nextID = xxF{root};
0062 if ~isempty(nextID), break; end;
0063 end
0064
0065 if isempty(nextID),
0066 ix_rest = Vindx;
0067 Vinx = [];
0068 Nall = 0;
0069 Fall = [];
0070 return
0071 end
0072
0073 Plist(1,:) = [root, nextID(1,1)];
0074
0075 Nsurf = 1;
0076 Nall = [];
0077
0078 while 1,
0079
0080 Nlist =1;
0081 Nroot =0;
0082
0083 while Nlist > 0,
0084
0085 Nedge = 0;
0086
0087
0088 for n=1:Nlist,
0089
0090 root = Plist(n,1);
0091 next = Plist(n,2);
0092
0093
0094 nextID = xxF{root};
0095
0096
0097 nlist1 = nextID(:,1);
0098 nlist2 = nextID(:,2);
0099 flist = nextID(:,3);
0100
0101
0102 nextix = find( Fflg(flist) == 0 );
0103
0104 if isempty(nextix),
0105 continue;
0106 end;
0107
0108
0109 nlist1 = nlist1(nextix);
0110 nlist2 = nlist2(nextix);
0111 flist = flist(nextix);
0112
0113 Nnext = length(nextix);
0114 Nnew = Nnext;
0115
0116
0117 for i=1:Nnext,
0118
0119 jx1 = find( nlist1==next );
0120 jx2 = find( nlist2==next );
0121
0122 if ~isempty(jx1),
0123 nold = next;
0124 jj = jx1(1);
0125 fid = flist(jj);
0126 next = nlist2(jj);
0127
0128
0129 Nedge = Nedge + 1;
0130 Vlist(Nedge,:) = [next nold];
0131
0132 FF(fid,:) = [root, nold, next];
0133
0134 Fflg(fid) = 1;
0135
0136 Vflg([root, nold, next]) = Nsurf;
0137
0138
0139 inew = [1:(jj-1),(jj+1):Nnew];
0140 flist = flist(inew);
0141 nlist1 = nlist1(inew);
0142 nlist2 = nlist2(inew);
0143 Nnew = Nnew-1;
0144 elseif ~isempty(jx2),
0145 nold = next;
0146 jj = jx2(1);
0147 fid = flist(jj);
0148 next = nlist1(jj);
0149
0150
0151 Nedge = Nedge + 1;
0152 Vlist(Nedge,:) = [next nold];
0153
0154 FF(fid,:) = [root, nold, next];
0155
0156 Fflg(fid) = 1;
0157
0158 Vflg([root, nold, next]) = Nsurf;
0159
0160
0161 inew = [1:(jj-1),(jj+1):Nnew];
0162 flist = flist(inew);
0163 nlist1 = nlist1(inew);
0164 nlist2 = nlist2(inew);
0165 Nnew = Nnew-1;
0166 end;
0167 end
0168
0169
0170 end;
0171
0172
0173
0174 Nlist = Nedge;
0175 Plist(1:Nedge,:) = Vlist(1:Nedge,:);
0176
0177 end
0178
0179
0180
0181 Nall(Nsurf) = sum(Vflg == Nsurf);
0182
0183
0184 ix_rest = find(Vflg == 0);
0185
0186 if isempty(ix_rest), break; end;
0187
0188 Plist = zeros(Npoint,2);
0189 Vlist = zeros(Npoint,2);
0190
0191
0192 seedJJ = [];
0193
0194 for jj = 1:length(ix_rest)
0195 seedID = ix_rest(jj);
0196 seedJJ = xxF{seedID};
0197 if ~isempty(seedJJ), break; end;
0198 end
0199
0200 if isempty(seedJJ), break; end;
0201
0202 Plist(1,:) = [seedID, seedJJ(1,1)];
0203
0204 Nsurf = Nsurf + 1;
0205 end
0206
0207 inxf = find(Fflg == 1);
0208 FF = FF(inxf,:);
0209
0210
0211 ix_rest = find(Vflg == 0);
0212 ix_rest = ix_rest';
0213
0214
0215 [Nall , id]= sort( -Nall );
0216
0217 Vinx = cell(Nsurf,1);
0218
0219 for n=1:Nsurf
0220
0221 indx = find( Vflg == id(n) );
0222 Vinx{n} = indx';
0223 Nall(n) = length(indx);
0224 end
0225
0226 return
0227
0228