forked from tdsuper/Cube2Video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
triangulatePanorama.m
59 lines (48 loc) · 1.64 KB
/
triangulatePanorama.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
function [face] = triangulatePanorama(spherePos1, spherePos2)
[face_num, face] = sphere_delaunay(size(spherePos1, 2), spherePos1);
% sort triangle
face = sortTriangular(face');
% topological constraints checking
i = 2;
reduceCount = 0;
while 1
sample = spherePos2(:, face(i,:));
srcTri = spherePos1(:, face(i,:));
if ~SphTriTopoConsist(face(1:i-1,:), spherePos2, sample, srcTri)
face(i, :) = [];
reduceCount = reduceCount + 1;
else
i = i + 1;
end
if i > size(face, 1)
break;
end
end
fprintf('Number of mis-matches: %d \n', reduceCount );
% rematching
preRegions = [];
[regions, boundary] = getOverlapRegions(face, spherePos1);
while ~isequal(preRegions, regions)
preRegions = regions;
% re-triangulation these regions using constrained Delaunay triangulation
for i=1:size(regions,2)
pos = proj2plane(regions(i).pts);
npts = size(pos, 2);
constrain = zeros(npts, 2);
constrain(:,1) = 1:npts;
constrain(:,2) = constrain(:,1) + 1;
constrain(npts,2) = 1;
DT = DelaunayTri(pos(1,:)', pos(2,:)', constrain);
inside = inOutStatus(DT);
newFace = DT.Triangulation(inside,:);
while size(newFace,1) ~= 0
sample = spherePos2(:, regions(i).ptIdx(newFace(1, :)));
srcTri = spherePos1(:, regions(i).ptIdx(newFace(1, :)));
if SphTriTopoConsist(face(:,:), spherePos2, sample, srcTri)
face = [face; regions(i).ptIdx(newFace(1, :))];
end
newFace(1, :) = [];
end
end
[regions, boundary] = getOverlapRegions(face, spherePos1);
end