-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbr_smooth.m
executable file
·62 lines (57 loc) · 1.43 KB
/
nbr_smooth.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
% Submitter: tryond(tryon,daniel) - 20621204
function [Y] = nbr_smooth(tri,X,nrounds)
% function [Y] = nbr_smooth(tri,X,nrounds)
%
% smooth the 3D locations of points in a given mesh by moving
% each point to the mean location of its neighbors
%
% X : 3D point locations
% tri : triangulation of the points X to make a surface
% nrounds : number of iterations of averaging with neighbors
%
% Y: smoothed point locations
%
npts = size(X,2);
ntri = size(tri,1);
nbrct = zeros(npts,1);
nbr = zeros(npts,100);
%
% get the list of neighbors for each point in the mesh
%
for i = 1:ntri
% fprintf('\rtraversing triangles %d/%d',i,ntri);
k = tri(i,1);
nbr(k,nbrct(k)+1) = tri(i,2);
nbr(k,nbrct(k)+2) = tri(i,3);
nbrct(k) = nbrct(k) + 2;
k = tri(i,2);
nbr(k,nbrct(k)+1) = tri(i,1);
nbr(k,nbrct(k)+2) = tri(i,3);
nbrct(k) = nbrct(k) + 2;
k = tri(i,3);
nbr(k,nbrct(k)+1) = tri(i,1);
nbr(k,nbrct(k)+2) = tri(i,2);
nbrct(k) = nbrct(k) + 2;
end
% fprintf('\n');
nbr = nbr(:,1:max(nbrct));
%
% now go thru nrounds of smoothing where the point
% in round 2 is placed at the average of its neighbor
% locations in round 1.
%
Y = X;
Ynew = X;
for j = 1:nrounds
% fprintf('round %d of %d\n',j,nrounds);
for i = 1:npts
% fprintf('\rsmoothing points %d/%d',i,npts);
nlist = nbr(i,1:nbrct(i));
nlist = setdiff(unique(nlist(:)),i);
if (length(nlist)>0)
Ynew(:,i) = mean(Y(:,nlist),2);
end
end
Y = Ynew;
% fprintf('\n');
end