-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript_embed_disk.m
115 lines (81 loc) · 2.99 KB
/
script_embed_disk.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
%% =====================================================================
% === Setting up stuff ===
% =====================================================================
%Create the mesh
[X,Y] = meshgrid(-2:.1:2, -2:.1:2);
Z = sin(X*2.6).*sin(Y*5.1)*0.1;%.* exp(-X.^2 - Y.^2);
X=X(:);Y=Y(:);Z=Z(:);
T= delaunay(X,Y);
V=[X Y Z];
%set boundary conditions
tri=triangulation(T,X,Y);
b=tri.freeBoundary();
b=b(:,1);
%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;0 1 1];
%The cone positions and the choice of orbifold structure, defining the
%desired embedding
% === Triangle disk orbifold ===
boundary_inds=[1 30 80];
cones=b(boundary_inds);
%try uncommneting each of the next lines for the other orbifold structures
% === Square disk orbifold ===
% boundary_inds=[1 70 80 100 ];
% cones=b(boundary_inds);
%% =======================================================================
% ======= The actual algorithm! cutting and flattening =======
% =======================================================================
V_flat=flatten_disk(V,T,cones);
%% =======================================================================
% ===== Visualization =====
% =======================================================================
figure(1);
clf;
% === Visualization of the original 3D mesh + cones & cuts on it ===
subplot(1,2,1);
%draw the mesh
patch('faces',T,'vertices',V,'facecolor','interp','FaceVertexCData',Z)
hold on;
%draw the cones
for i=1:length(cones)
scatter3(V(cones(i),1),V(cones(i),2),V(cones(i),3),100,cone_colors(i,:),'fill');
end
%draw the cuts...
inds=[boundary_inds length(b)];
for i=1:length(inds)-1
curPath=b(inds(i):inds(i+1));
%draw the cut
line(V(curPath,1),V(curPath,2),V(curPath,3),'color',cut_colors(i,:),'linewidth',2);
end
%iterate over all path-pairs (the correspondences generated in the
%cutting)
%some nice lighting and fixing the axis
campos([-1 1 2]);
camtarget([0,0,0])
camlight
axis equal
title('Disk mesh');
% === Visualization of the flattening + cones & cuts on it ===
subplot(1,2,2);
%draw the flattened mesh
patch('faces',T,'vertices',V_flat,'facecolor','interp','FaceVertexCData',Z);
hold on;
inds=[boundary_inds length(b)];
for i=1:length(inds)-1
curPath=b(inds(i):inds(i+1));
%draw the cut
line(V_flat(curPath,1),V_flat(curPath,2),'color',cut_colors(i,:),'linewidth',2);
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=cones(i);
scatter(V_flat(flat_cones,1),V_flat(flat_cones,2),40,cone_colors(i,:),'fill');
end
%draw the cuts...
%iterate over all pairs of corresponding indices of twin vertices generated
%in the cutting process
axis equal
title('Embedding into a disk orbifold');