0001 function B = vb_surf_to_mask(V,F,vstep,step,Dim)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 NX = Dim(1);
0020 NY = Dim(2);
0021 NZ = Dim(3);
0022 NXY = NX*NY;
0023
0024 NV = size(V,1);
0025 NF = size(F,1);
0026
0027
0028 B = zeros(NX, NY, NZ);
0029 V = V/vstep;
0030 step = step/vstep;
0031
0032
0033
0034
0035
0036
0037
0038
0039 J = floor(V + 0.5) + 1;
0040 ix = J(:,1)+ NX*(J(:,2) - 1)+ NXY*(J(:,3) - 1);
0041
0042 B(ix) = 1;
0043
0044
0045
0046
0047
0048 x1 = V(F(:,1),:);
0049 x2 = V(F(:,2),:);
0050 x3 = V(F(:,3),:);
0051
0052
0053 z1 = x1 - x2;
0054 z2 = x2 - x3;
0055 z3 = x3 - x1;
0056
0057
0058 d1 = sqrt(sum(z1.^2,2));
0059 d2 = sqrt(sum(z2.^2,2));
0060 d3 = sqrt(sum(z3.^2,2));
0061
0062
0063 [dd ,imax] = max([d1 d2 d3],[],2);
0064
0065
0066 idx = find( dd > step );
0067 ND = length(idx);
0068
0069 if ND == 0, return; end;
0070
0071
0072 dmax = max(dd);
0073
0074
0075
0076 Nmax = ceil(dmax/step);
0077 NN = (Nmax+1)*(Nmax+2)/2;
0078 inx1 = zeros(NN,1);
0079 inx2 = zeros(NN,1);
0080 id = 0;
0081
0082
0083
0084 for k1=0:Nmax
0085 for k2=0:k1
0086 id = id + 1;
0087 inx1(id) = k1;
0088 inx2(id) = k2;
0089 end;
0090 end
0091
0092
0093 for m = 1:ND
0094
0095 n = idx(m);
0096 d = dd(n);
0097 Nd = ceil(d/step);
0098
0099
0100 y1 = x1(n,:);
0101 y2 = x2(n,:);
0102 y3 = x3(n,:);
0103
0104
0105
0106 NT = (Nd+1)*(Nd+2)/2;
0107 kk1 = Nd - inx1(1:NT);
0108 kk2 = inx2(1:NT);
0109
0110
0111
0112 kk3 = Nd - kk1 - kk2;
0113
0114
0115 j1 = floor(( kk1*y1(1) + kk2*y2(1) + kk3*y3(1) )/Nd ) + 1;
0116 j2 = floor(( kk1*y1(2) + kk2*y2(2) + kk3*y3(2) )/Nd ) + 1;
0117 j3 = floor(( kk1*y1(3) + kk2*y2(3) + kk3*y3(3) )/Nd ) + 1;
0118
0119
0120 ii = j1+ NX*(j2 - 1)+ NXY*(j3 - 1);
0121
0122
0123 B(ii) = 1;
0124
0125 end
0126