0001 function B = vb_face_to_mask(V,F,DIM,vsize,zmin,plot_mode,zindx)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 if ~exist('vsize','var'), vsize = 2; end;
0021 if ~exist('plot_mode','var'), plot_mode = 0; end;
0022 if ~exist('zmin','var'),
0023 zmin = [];
0024 else
0025 zmin = ceil(zmin/vsize);
0026 end;
0027
0028 tic
0029
0030
0031 if isempty(zmin)
0032
0033 [F,V] = vb_close_surf(F,V);
0034
0035
0036 B = vb_surf_to_filled_mask(V, F, DIM, vsize);
0037 else
0038
0039 dmin = vsize/2;
0040
0041 B = vb_surf_to_mask(V,F,vsize,dmin,DIM);
0042
0043
0044 filval = 1;
0045 level = 0.5;
0046
0047
0048 V = V/vsize;
0049
0050 zmid = (max(V(:,3)) + min(V(:,3)))/2;
0051 ix = find( ( V(:,3) >= (zmid - 5) )&( V(:,3) <= (zmid + 5) ) );
0052 Vcenter = round(mean(V(ix,:),1));
0053
0054 if plot_mode > 0
0055 zindx = Vcenter(3);
0056 vb_plot_slice( B, V, zindx, 1, [1 1]);
0057 hold on
0058 plot(Vcenter(2),Vcenter(1),'ro')
0059 end
0060
0061
0062 B(:,:,zmin) = 1;
0063
0064 fprintf('face flood fill\n')
0065
0066 B = vb_flood_fill_3d(B, Vcenter, filval, level);
0067
0068
0069 B(:,:,1:zmin) = 0;
0070 end
0071
0072 vb_ptime(toc)
0073
0074 if plot_mode > 1
0075 zindx = (min(V(:,3)):20:max(V(:,3)));
0076 zindx = ceil(zindx);
0077 vb_plot_slice( B, V, zindx, 1);
0078 end