-
Notifications
You must be signed in to change notification settings - Fork 2
/
script_embed_sphere_4_points.m
152 lines (120 loc) · 4.91 KB
/
script_embed_sphere_4_points.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
%% =====================================================================
% === Setting up stuff ===
% =====================================================================
%Read the mesh
[V,T]=read_off('sphere.off');V=V';T=T';
%Some color-related variables - no need to concern yourself with these :)
cone_colors=[1 0.8 0;0.7 0 1; 0 0.5 0.8;0 0 0.5];
cut_colors=[1 0 0;0 1 0;0 0 1];
%The cone positions and the choice of orbifold structure, defining the
%desired embedding
% === TYPE I orbifold ===
% cones=[50 100 130];
% orbifold_type=OrbifoldType.Square;
%try uncommneting each of the next lines for the other orbifold structures
% === TYPE II orbifold ===
% cones=[50 100 130];
% orbifold_type=OrbifoldType.Diamond;
% === TYPE III orbifold ===
% cones=[50 100 130];
% orbifold_type=OrbifoldType.Triangle;
% === TYPE IV orbifold ===
cones=[50 100 130 140];
orbifold_type=OrbifoldType.Parallelogram;
%% =======================================================================
% ======= The actual algorithm! cutting and flattening =======
% =======================================================================
[V_flat,cutMesh,flattener]=flatten_sphere(V,T,cones,orbifold_type);
%% =======================================================================
% ===== Visualization =====
% =======================================================================
figure(1);
clf;
% === Visualization of the original 3D mesh + cones & cuts on it ===
subplot(1,3,1);
%draw the mesh
patch('faces',T,'vertices',V,'facecolor','interp','FaceVertexCData',V(:,1));
hold on;
%draw the cones
for i=1:length(cones)
scatter3(V(cones(i),1),V(cones(i),2),V(cones(i),3),80,cone_colors(i,:),'fill');
end
%draw the cuts...
%iterate over all path-pairs (the correspondences generated in the
%cutting)
for i=1:length(cutMesh.pathPairs)
%take the current path
curPathPair=cutMesh.pathPairs{i};
%use the mapping of indices of the cut mesh to the indices of the uncut
%mesh in order to get the cuts on the uncut mesh
curPath=cutMesh.cutIndsToUncutInds(curPathPair(:,1));
%draw the cut
line(V(curPath,1),V(curPath,2),V(curPath,3),'color',cut_colors(i,:),'linewidth',2);
end
%some nice lighting and fixing the axis
camlight
axis equal
title('Cut mesh');
% === Visualization of the flattening, before choosing the configuration
% which minimizes conformal distortion
subplot(1,3,2);
%draw the flattened mesh
patch('faces',cutMesh.T,'vertices',V_flat,'facecolor','interp','FaceVertexCData',V(cutMesh.cutIndsToUncutInds,1),'edgecolor','k');
hold on;
%draw the cuts...
%iterate over all pairs of corresponding indices of twin vertices generated
%in the cutting process
for i=1:length(cutMesh.pathPairs)
%get the current pair of paths, corresponding to a single cut
%connecting two cones
curPathPair=cutMesh.pathPairs{i};
%iterate over the two sides of the cut
for j=1:2
%get the current path (part of the boundary of the cut mesh between
%two cones)
curPath=curPathPair(:,j);
%draw the line with the correspodning color
line(V_flat(curPath,1),V_flat(curPath,2),'color',cut_colors(i,:),'linewidth',2);
end
end
%draw the cones
for i=1:length(cones)
%for each cone, find all its copies using the mapping of vertex indices
%of the uncut mesh to the vertex indices of the cut mesh
flat_cones=cutMesh.uncutIndsToCutInds{cones(i)};
scatter(V_flat(flat_cones,1),V_flat(flat_cones,2),40,cone_colors(i,:),'fill');
end
axis equal
title('Default embedding');
% === Visualization of the flattening, *after* choosing the configuration
% which minimizes conformal distortion
subplot(1,3,3);
%draw the flattened mesh
flattener.correctGlobalAffine();
patch('faces',cutMesh.T,'vertices',flattener.flat_V,'facecolor','interp','FaceVertexCData',V(cutMesh.cutIndsToUncutInds,1),'edgecolor','k');
hold on;
%draw the cuts...
%iterate over all pairs of corresponding indices of twin vertices generated
%in the cutting process
for i=1:length(cutMesh.pathPairs)
%get the current pair of paths, corresponding to a single cut
%connecting two cones
curPathPair=cutMesh.pathPairs{i};
%iterate over the two sides of the cut
for j=1:2
%get the current path (part of the boundary of the cut mesh between
%two cones)
curPath=curPathPair(:,j);
%draw the line with the correspodning color
line(flattener.flat_V(curPath,1),flattener.flat_V(curPath,2),'color',cut_colors(i,:),'linewidth',2);
end
end
%draw the cones
for i=1:length(cones)
%for each cone, find all its copies using the mapping of vertex indices
%of the uncut mesh to the vertex indices of the cut mesh
flat_cones=cutMesh.uncutIndsToCutInds{cones(i)};
scatter(flattener.flat_V(flat_cones,1),flattener.flat_V(flat_cones,2),40,cone_colors(i,:),'fill');
end
axis equal
title('Conformal Embedding');