0001 function [Vx, Fx, xx, B] = vb_surf_smooth_expand(V, F, xx, Para)
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
0033
0034
0035
0036
0037
0038
0039
0040 if ~exist('Para','var'), Para = []; end
0041
0042 if ~isfield(Para,'Dim') | isempty(Para.Dim)
0043 error('Size of mask image is not specified');
0044 else
0045 Dim = Para.Dim;
0046 end
0047
0048
0049 if ~isfield(Para,'vstep'),
0050 step = 2;
0051 Para.vstep = step;
0052 else
0053 step = Para.vstep;
0054 end;
0055
0056 if ~isfield(Para,'Nloop'), Para.Nloop = 200; end
0057 if ~isfield(Para,'Nlast'), Para.Nlast = 20; end
0058 if ~isfield(Para,'Nvertex'), Para.Nvertex = 5000; end
0059 if ~isfield(Para,'tangent_rate'), Para.tangent_rate = 0.3; end
0060 if ~isfield(Para,'Radius'),Para.Radius = [6 -6];end
0061 if ~isfield(Para,'plot_mode'), Para.plot_mode = 0; end
0062
0063
0064
0065 Debug_mode = 0;
0066
0067
0068
0069
0070 disp('--- Closed surface check');
0071 omega = vb_solid_angle_check(V,F);
0072 fprintf('Solid angle = 4pi x %f\n',omega);
0073 if abs(omega-1)>1e-10,
0074 disp('Surface is not closed.');
0075 return;
0076 else
0077 disp('Surface is closed.');
0078 end
0079
0080
0081
0082
0083 fprintf('--- Make mask image from surface\n')
0084 dmin = step/2;
0085
0086 B = vb_surf_to_mask(V, F, step, dmin, Dim);
0087
0088
0089
0090
0091 fprintf('--- Fill out inside the surface \n')
0092
0093 filval = 1;
0094 level = 0.5;
0095
0096 X0 = fix(mean(V/step));
0097 B = vb_flood_fill_3d(B, X0, filval, level);
0098
0099 if Debug_mode == 2, return; end
0100
0101
0102
0103 B = vb_morphology_operation(B, Para.Radius, step);
0104
0105 if Debug_mode == 1, return; end
0106
0107
0108
0109 tic
0110 fprintf('smoothing\n')
0111 B = smooth3(B,'gaussian',3);
0112 vb_ptime(toc);
0113
0114
0115
0116
0117 tic
0118 fprintf('--- Surface expansion\n')
0119
0120 [Vx, Fx, xx] = vb_make_inner_sphere(V, Para.Nvertex);
0121 [Vx, Fx, xx] = vb_surf_smooth_fit(Vx,Fx,xx, B, Para);
0122
0123 vb_ptime(toc)
0124
0125 if Para.plot_mode > 1
0126 dmax = 10;
0127 vb_plot_slice_surf( B, Vx/step, Fx, X0(1), 'x',[1 1],'r-',dmax);
0128 vb_plot_slice_surf( B, Vx/step, Fx, X0(2), 'y',[1 1],'r-',dmax);
0129 vb_plot_slice_surf( B, Vx/step, Fx, X0(3), 'z',[1 1],'r-',dmax);
0130 end
0131
0132
0133
0134
0135 tic
0136 fprintf('--- Surface smoothing by spring model\n')
0137
0138 Para.Nloop = Para.Nlast;
0139 [Vx, Fx, xx] = vb_surf_smooth(Vx,Fx,xx,Para);
0140
0141 vb_ptime(toc)
0142
0143 fprintf('# of patches : %d\n',size(Fx,1));
0144 fprintf('# of vertices: %d\n',size(Vx,1));
0145
0146 if Para.plot_mode > 1
0147 dmax = 10;
0148 vb_plot_slice_surf( B, Vx/step, Fx, X0(1), 'x',[1 1],'r-',dmax);
0149 vb_plot_slice_surf( B, Vx/step, Fx, X0(2), 'y',[1 1],'r-',dmax);
0150 vb_plot_slice_surf( B, Vx/step, Fx, X0(3), 'z',[1 1],'r-',dmax);
0151 end
0152