-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathperform_mesh_smoothing.m
49 lines (42 loc) · 1.08 KB
/
perform_mesh_smoothing.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
function f = perform_mesh_smoothing(face,vertex,f,options)
% perform_mesh_smoothing - smooth a function defined on a mesh by averaging
%
% f = perform_mesh_smoothing(face,vertex,f,options);
%
% Smooth a function f on a width of options.niter_averaging vertices.
%
% Copyright (c) 2007 Gabriel Peyre
options.null = 0;
naver = getoptions(options, 'niter_averaging', 1);
type = getoptions(options, 'averaging_type', 'combinatorial');
if nargin<3
f = [];
end
if isempty(f)
f = vertex;
end
if size(f,1)<size(f,2)
f = f';
end
[vertex,face] = check_face_vertex(vertex,face);
if size(f,2)>1
for i=1:size(f,2)
f(:,i) = perform_mesh_smoothing(face,vertex,f(:,i),options);
end
return;
end
n = max(face(:));
% compute normalized averaging matrix
if strcmp(type, 'combinatorial')
%add diagonal
W = triangulation2adjacency(face) + speye(n);
D = spdiags(full(sum(W,2).^(-1)),0,double(n),double(n));
W = D*W;
else
options.normalize=1;
W = compute_mesh_weight(vertex,face,type,options);
end
% do averaging to smooth the field
for k=1:naver
f = W*f;
end