-
Notifications
You must be signed in to change notification settings - Fork 0
/
meshFlatteningExamples.m
60 lines (39 loc) · 1.38 KB
/
meshFlatteningExamples.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
% Mesh Flattening
% http://www.numerical-tours.com/matlab/meshdeform_3_flattening/
getd = @(p)path(p,path);
getd('toolbox_signal/');
getd('toolbox_general/');
getd('toolbox_graph/');
% First load a mesh.
name = 'nefertiti';
options.name = name;
[vertex,faces] = read_mesh(name);
n = size(vertex,2);
% Format of vertex, faces:
% vertex: a list of points in 3D-space (each point three coordinates)
% faces: 3-tuples pointing to indexes of three vertices, to indicate
% a triangular face in 3D. So the face is defined by three
% numbers, which are indexes into the vertex array.
% Display it.
clf;
plot_mesh(vertex,faces, options);
shading faceted;
% Compute the mesh Laplacian matrix.
options.symmetrize = 1;
options.normalize = 0;
L = compute_mesh_laplacian(vertex,faces,'conformal',options);
% Compute the eigenvalues and eigenvectors
[U,S] = eig(full(L)); S = diag(S);
[S,I] = sort(S,'ascend'); U = U(:,I);
% The vertex positions are the eigenvectors 2 and 3.
vertexF = U(:,2:3)';
% Use translation / rotation to align the parameterization.
icenter = 88;
irotate = 154;
vertexF = vertexF - repmat(vertexF(:,icenter), [1 n]);
theta = -pi/2+atan2(vertexF(2,irotate),vertexF(1,irotate));
vertexF = [vertexF(1,:)*cos(theta)+vertexF(2,:)*sin(theta); ...
-vertexF(1,:)*sin(theta)+vertexF(2,:)*cos(theta)];
% Display the flattened mesh.
clf;
plot_mesh(vertexF,faces);