-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathsmoothsurf.m
98 lines (95 loc) · 2.79 KB
/
smoothsurf.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function p = smoothsurf(node, mask, conn, iter, useralpha, usermethod, userbeta)
%
% p=smoothsurf(node,mask,conn,iter,useralpha,usermethod,userbeta)
%
% smoothing a surface mesh
%
% author: Qianqian Fang, <q.fang at neu.edu>
% date: 2007/11/21
%
% input:
% node: node coordinates of a surface mesh
% mask: flag whether a node is movable: 0 movable, 1 non-movable
% if mask=[], it assumes all nodes are movable
% conn: input, a cell structure of length size(node), conn{n}
% contains a list of all neighboring node ID for node n,
% this can be computed from meshconn function
% iter: smoothing iteration number
% useralpha: scaler, smoothing parameter, v(k+1)=(1-alpha)*v(k)+alpha*mean(neighbors)
% usermethod: smoothing method, including 'laplacian','laplacianhc' and 'lowpass'
% userbeta: scaler, smoothing parameter, for 'laplacianhc'
%
% output:
% p: output, the smoothed node coordinates
%
% recommendations
% Based on [Bade2006], 'Lowpass' method outperforms 'Laplacian-HC' in volume
% preserving and both are significantly better than the standard Laplacian method
%
% [Bade2006] R. Bade, H. Haase, B. Preim, "Comparison of Fundamental Mesh
% Smoothing Algorithms for Medical Surface Models,"
% Simulation and Visualization, pp. 289-304, 2006.
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%
p = node;
if (isempty(mask))
nn = size(node, 1);
idx = 1:nn;
else
idx = find(mask == 0)';
nn = length(idx);
end
alpha = 0.5;
method = 'laplacian';
beta = 0.5;
if (nargin > 4)
alpha = useralpha;
if (nargin > 5)
method = usermethod;
if (nargin > 6)
beta = userbeta;
end
end
end
ibeta = 1 - beta;
ialpha = 1 - alpha;
for i = 1:nn
if (length(conn{idx(i)}) == 0)
idx(i) = 0;
end
end
idx = idx(idx > 0);
nn = length(idx);
if (strcmp(method, 'laplacian'))
for j = 1:iter
for i = 1:nn
p(idx(i), :) = ialpha * p(idx(i), :) + alpha * mean(node(conn{idx(i)}, :));
end
node = p;
end
elseif (strcmp(method, 'laplacianhc'))
for j = 1:iter
q = p;
for i = 1:nn
p(idx(i), :) = mean(q(conn{idx(i)}, :));
end
b = p - (alpha * node + ialpha * q);
for i = 1:nn
p(idx(i), :) = p(idx(i), :) - (beta * b(i, :) + ibeta * mean(b(conn{idx(i)}, :)));
end
end
elseif (strcmp(method, 'lowpass'))
beta = -1.02 * alpha;
ibeta = 1 - beta;
for j = 1:iter
for i = 1:nn
p(idx(i), :) = ialpha * node(idx(i), :) + alpha * mean(node(conn{idx(i)}, :));
end
node = p;
for i = 1:nn
p(idx(i), :) = ibeta * node(idx(i), :) + beta * mean(node(conn{idx(i)}, :));
end
node = p;
end
end