• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jun 14th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function [Vsmooth, numBoundaryEdges, A] = smoothMesh(V, F, k) # V: vertices, F: face data, k: num iterations
2.
3. Vsmooth = V;
4. V_s = size(V,2);
5. F_s = size(F,2);
6. numBoundaryEdges = 0;
7.
9. A = [];
10.
11. for i=1:F_s
12.     A(F(1,i), F(2, i)) = 1;
13.     A(F(2,i), F(3, i)) = 1;
14.     A(F(3,i), F(1, i)) = 1;
15. end
16.
17. # print number of boundary edges
18. boundaryEdges = find((A.-A')>0);
19. numBoundaryEdges = length(boundaryEdges)
20. # for k iterations: compute every vertex as the mean of its neighbors
21.
22.
23. for i=1:k
24.     Vsmooth_temp = Vsmooth;
25.     for j=1:V_s
26.         neighbours_x = find(A(:,j)>0);
27.         neighbours_y = find(A(j,:)>0);
28.
29.         neighbours_index = unique([neighbours_x', neighbours_y]);
30.
31.         sum_neighbors = 0;
32.         for l=1:size(neighbours_index, 2);
33.             sum_neighbors += Vsmooth(:,neighbours_index(l));
34.         end
35.         sum_neighbors /= size(neighbours_index,2);
36.
37.         Vsmooth_temp(:,j) = sum_neighbors;
38.     end
39.     Vsmooth = Vsmooth_temp;
40. end
41.
42. endfunction
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top