-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathremoveisolatedsurf.m
50 lines (49 loc) · 1.22 KB
/
removeisolatedsurf.m
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
function fnew = removeisolatedsurf(v, f, maxdiameter)
%
% fnew=removeisolatedsurf(v,f,maxdiameter)
%
% remove disjointed surface fragment filtered by using mesh diameter
%
% author: Qianqian Fang, <q.fang at neu.edu>
%
% input:
% v: list of nodes of the input surface
% f: list of triangles of the input surface
% maxdiameter: maximum bounding box size for surface removal
%
% ouput:
% fnew: new face list after removing the components smaller than
% maxdiameter
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%
fc = finddisconnsurf(f);
for i = 1:length(fc)
xdia = v(fc{i}, 1);
xdia = max(xdia(:)) - min(xdia(:));
if (xdia <= maxdiameter)
fc{i} = [];
continue
end
ydia = v(fc{i}, 2);
ydia = max(ydia(:)) - min(ydia(:));
if (ydia <= maxdiameter)
fc{i} = [];
continue
end
zdia = v(fc{i}, 3);
zdia = max(zdia(:)) - min(zdia(:));
if (zdia <= maxdiameter)
fc{i} = [];
continue
end
end
fnew = [];
for i = 1:length(fc)
if (length(fc{i}))
fnew = [fnew; fc{i}];
end
end
if (size(fnew, 1) ~= size(f, 1))
fprintf(1, 'removed %d elements of small isolated surfaces', size(f, 1) - size(fnew, 1));
end