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
|
function mask = flatsegment(node, edge)
%
% mask=flatsegment(node,edge)
%
% decompose edge loops into flat segments alone arbitrary planes of the bounding box
%
% author: Qianqian Fang, <q.fang at neu.edu>
% date: 2008/04/08
%
% this code is fragile: it can not handle curves with many co-linear
% nodes near the corner point
%
% input:
% node: x,y,z coordinates of each node of the mesh
% edge: input, a single vector separated by NaN, each segment
% is a close-polygon consisted by node IDs
%
% output:
% mask: output, a cell, each element is a close-polygon
% on x/y/z plane
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%
idx = edge;
nn = length(idx);
val = zeros(nn, 1);
for i = 1:nn
tet = mod(i:i + 3, nn);
tet(find(tet == 0)) = nn;
val(i) = (abs(det([node(idx(tet), :), ones(4, 1)])) > 1e-5);
end
val(end + 1:end + 2) = val(1:2);
mask = {};
oldend = 1;
for i = 1:nn
if (val(i) == 1 & val(i + 1) == 1 & val(i + 2) == 0)
val(i + 2) = 2;
mask{count} = idx(oldend:i + 2);
count = count + 1;
oldend = i + 2;
else
mask{count} = [idx(oldend:end); mask{1}];
break
end
end
|