-
Notifications
You must be signed in to change notification settings - Fork 2
/
getOverlapRegions.m
69 lines (59 loc) · 1.53 KB
/
getOverlapRegions.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
function [regions, boundaryEdge] = getOverlapRegions(face, spherePoint)
regions = [];
npts = size(spherePoint, 2);
edges = zeros(npts, npts);
for i=1:size(face, 1)
startP = face(i,1);
endP = face(i,2);
if edges(endP,startP) == 1
edges(endP,startP) = 2;
edges(startP,endP) = 2;
else
edges(startP,endP) = 1;
end
startP = face(i,2);
endP = face(i,3);
if edges(endP,startP) == 1
edges(endP,startP) = 2;
edges(startP,endP) = 2;
else
edges(startP,endP) = 1;
end
startP = face(i,3);
endP = face(i,1);
if edges(endP,startP) == 1
edges(endP,startP) = 2;
edges(startP,endP) = 2;
else
edges(startP,endP) = 1;
end
end
[row, col] = find(edges == 1);
boundary = [row col];
boundaryEdge = boundary;
nregs = 0;
while size(boundary,1) ~= 0
nregs = nregs + 1;
startPt = boundary(1,1);
currentPt = boundary(1,2);
reg = boundary(1,1);
boundary(1,:) = [];
while startPt ~= currentPt
reg = [reg currentPt];
for i=1:size(boundary,1)
if boundary(i,1) == currentPt
break;
end
end
if i<=size(boundary,1)
if boundary(i,1) == currentPt
currentPt = boundary(i,2);
elseif boundary(i,2) == currentPt
currentPt = boundary(i,1);
end
boundary(i,:) = [];
end
end
regions(nregs).ptIdx = reg;
regions(nregs).pts = spherePoint(:,reg);
end