1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| function [triangles]=upper_tri(mask,perimeter)
triangles = [];
% patch 1: upper surface
patches1 = [];
[nx,ny]=size(mask);
num_per_pts=length(perimeter(:,1));
jj = 1;
ii = 1;
for (i = 1:(nx-1))
for (j = 1:(ny-1))
if ((mask(i,j) == 2) && (mask(i+1,j+1)==2) && (mask(i,j+1)==2))
triangles = [triangles;[((i-1)*ny + j) ((i)*ny + j + 1) ((i-1)*ny + j +1)]];
patches1 = [patches1 jj];
jj = jj+1;
ii = ii+1;
end
if ((mask(i,j) == 2) && (mask(i+1,j)==2) && (mask(i+1,j+1)==2))
triangles = [triangles;[((i-1)*ny + j) ((i)*ny + j) ((i)*ny + j +1)]];
patches1 = [patches1 jj];
jj = jj+1;
ii = ii+1;
end
end
end
for (kk = 1:(num_per_pts-1)) %add edge triangles we have missed
if ((perimeter(kk+1,1)-perimeter(kk,1) == 1) && (perimeter(kk+1,2)-perimeter(kk,2) == -1)) %check for \| edge triangle
i1 = perimeter(kk,:);
i2 = perimeter(kk+1,:);
triangles = [triangles;[((i1(1)-1)*ny + i1(2)) ((i2(1)-1)*ny + i2(2)) ((i1(1))*ny + i1(2))]];
patches1 = [patches1 jj];
jj = jj+1;
ii = ii+1;
end
if ((perimeter(kk+1,1)-perimeter(kk,1) == -1) && (perimeter(kk+1,2)-perimeter(kk,2) == 1)) %check for |\ edge triangle
i1 = perimeter(kk,:);
i2 = perimeter(kk+1,:);
triangles = [triangles;[((i1(1)-1)*ny + i1(2)) ((i2(1)-1)*ny + i2(2)) ((i1(1)-2)*ny + i1(2))]];
patches1 = [patches1 jj];
jj = jj+1;
ii = ii+1;
end
end
end |
Partager