-
Notifications
You must be signed in to change notification settings - Fork 1
/
OrbifoldBoundary.m
161 lines (138 loc) · 5.28 KB
/
OrbifoldBoundary.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
153
154
155
156
157
158
159
160
161
classdef OrbifoldBoundary < handle
%object that holds all the boundary pieces
properties
boundaryPieces;
constraints={};
coneInds;
conePos;
origConeInds;
coneCols;
end
methods
function obj=OrbifoldBoundary(boundaryPieces)
obj.boundaryPieces=boundaryPieces;
obj.conePos=[];
obj.coneInds=[];
origConeInds=[];
for i=1:length(boundaryPieces)
p=boundaryPieces{i};
[s,e]=p.endPoints();
obj.coneInds=[obj.coneInds;s];
obj.coneInds=[obj.coneInds;e];
origConeInds=[origConeInds;reshape(p.originalInds([1 end]),2,1)];
obj.conePos=[obj.conePos;boundaryPieces{i}.startPos;boundaryPieces{i}.endPos];
end
[I,J]=unique(obj.coneInds);
obj.coneInds=I';
obj.origConeInds=origConeInds(J);
obj.conePos=obj.conePos(J,:);
[I,~,J]=unique(obj.origConeInds);
% cols=linspecer(length(I));
if length(I)<=3
cols=[1 0.8 0;
0.4 1 0.7;
1 0 0.5;
];
else
cols=linspecer(length(I));
end
obj.coneCols=cols(J,:);
for i=1:length(obj.boundaryPieces)
p=obj.boundaryPieces{i};
c=p.generateBoundaryConditions();
if isempty(c)
continue;
end
obj.constraints{end+1}=c;
end
for i=1:length(obj.coneInds)
s=obj.coneInds(i);
pos=obj.conePos(i,:);
obj.constraints{end+1}=FixedBoundaryConditions(s,pos);
end
end
function [A,b]=generateBoundaryEquations(obj,NV)
%generate the entire equation system for the boundary vertices
% NV - integer, number of vertices in the mesh (needed so the
% width of the constraint matrix A is correct).
if isempty(obj.constraints)
error('need to call setConstraints');
end
As=cell([1 length(obj.constraints)]);
bs=cell([1 length(obj.constraints)]);
for i=1:length(obj.constraints)
[As{i},bs{i}]=obj.constraints{i}.constraints(NV);
end
A=cell2mat(As');
b=cell2mat(bs');
end
function good=validateSolution(obj,V)
%return a vector where good(i)==true iff i'th constraint is
%satisfied
if isempty(obj.constraints)
error('need to call setConstraints');
end
good=zeros(length(obj.constraints),1);
for i=1:length(obj.constraints)
good(i)=max(obj.constraints{i}.validSolution(V));
end
end
function [v0,flatV]=initialSolution(obj,L)
%create an initial embedding, a starting point for the optimization
% input: L - a laplacian matrix to use for embedding
% output: v0 - the embedding on the sphere, flatV - the planar
% embedding that was used (that was projected back on the
% sphere)
cons=PosConstraints(length(L)/2);
p=obj.conePos;
if size(p,1)==2
init_p1=obj.boundaryPieces{1}.positionsForInitialization();
init_p2=obj.boundaryPieces{2}.positionsForInitialization();
p=[init_p1;init_p2];
end
N=findHemisphere(p);
R=rotation_p2p(N,[0 0 1]);
for i=1:length(obj.boundaryPieces)
p=obj.boundaryPieces{i};
inds=p.inds;
init_p=p.positionsForInitialization();
pp=init_p*R';
assert(all(pp(:,3)>=0-eps));
for j=1:length(inds)
cons.addConstraint(inds(j),1,orthographic_to_plane(pp(j,:)));
end
end
x=computeFlattening(cons.A,cons.b,L);
X=x(1:2:end);
Y=x(2:2:end);
flatV=[X Y ];
v0=orthographic_to_sphere(flatV);
v0=v0*R;
end
function draw(obj,V)
%draw the boundary
for i=1:length(obj.boundaryPieces)
p=obj.boundaryPieces{i};
p.draw(V);
end
hold on;
v=V(obj.coneInds,:);
scatter3(v(:,1),v(:,2),v(:,3),150,'filled','CData',obj.coneCols);
end
function As=tilingTransformations(obj)
%automorphisms of the orbifold
t=Tiler();
for i=1:length(obj.boundaryPieces)
p=obj.boundaryPieces{i};
A=p.transformation();
if isempty(A)
continue;
end
t.addIfNew(A);
t.addIfNew(A');
end
t.tile();
As=t.As;
end
end
end