0001 function [xyz, BZ] = vb_get_boundary(B,vlevel)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if ~exist('vlevel','var'), vlevel = 0.5; end;
0015
0016 [N1,N2,N3] = size(B);
0017
0018 BZ = zeros(N1,N2,N3);
0019
0020
0021 NN1 = N1-1;
0022 jw = 1:NN1;
0023 je = 2:N1;
0024
0025 NN2 = N2-1;
0026 jn = 1:NN2;
0027 js = 2:N2;
0028
0029 NX2 = N1*N2;
0030
0031 for j3 = 1:N3
0032
0033 ix = find( (B(jw,:,j3)-vlevel) .* (B(je,:,j3)-vlevel) <= 0 );
0034
0035
0036
0037 j2 = floor((ix-1)/NN1)+1;
0038 j1 = rem((ix-1),NN1)+1;
0039 jx = j1+ N1*(j2 - 1)+ NX2*(j3 - 1);
0040
0041
0042 BZ(jx) = 1;
0043
0044
0045 ix = find( (B(:,jn,j3)-vlevel) .* (B(:,js,j3)-vlevel) <= 0 );
0046
0047
0048 j2 = floor((ix-1)/N1)+1;
0049 j1 = rem((ix-1),N1)+1;
0050 jx = j1+ N1*(j2 - 1)+ NX2*(j3 - 1);
0051
0052
0053 BZ(jx) = 1;
0054
0055
0056 if j3 < N3,
0057 ix = find( (B(:,:,j3)-vlevel) .* (B(:,:,j3+1)-vlevel) <= 0 );
0058
0059
0060 j2 = floor((ix-1)/N1)+1;
0061 j1 = rem((ix-1),N1)+1;
0062 jx = j1+ N1*(j2 - 1)+ NX2*(j3 - 1);
0063
0064
0065 BZ(jx) = 1;
0066 end
0067 end
0068
0069 ix = find( BZ(:) > 0 );
0070
0071
0072 j3 = floor((ix-1)/NX2)+1;
0073 ix = rem((ix-1),NX2) +1;
0074
0075 j2 = floor((ix-1)/N1)+1;
0076 j1 = rem((ix-1),N1)+1;
0077
0078 xyz = [j1, j2, j3];