-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAperture.m
165 lines (150 loc) · 5.38 KB
/
Aperture.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
162
163
164
classdef Aperture
methods(Static)
function val = lowerIdx(newval)
persistent currentval;
if nargin >= 1
currentval = newval;
end
val = currentval;
end
function val = upperIdx(newval)
persistent currentval;
if nargin >= 1
currentval = newval;
end
val = currentval;
end
function val = vertexA(newval)
persistent currentval;
if nargin >= 1
currentval = newval;
end
val = currentval;
end
function val = vertexB(newval)
persistent currentval;
if nargin >= 1
currentval = newval;
end
val = currentval;
end
function val = vertexC(newval)
persistent currentval;
if nargin >= 1
currentval = newval;
end
val = currentval;
end
function val = orientation(newval)
persistent currentval;
if nargin >= 1
currentval = newval;
end
val = currentval;
end
function val = alpha(newval)
persistent currentval;
if nargin >= 1
currentval = newval;
end
val = currentval;
end
function val = beta(newval)
persistent currentval;
if nargin >= 1
currentval = newval;
end
val = currentval;
end
function val = gamma(newval)
persistent currentval;
if nargin >= 1
currentval = newval;
end
val = currentval;
end
function findAperture(LidarRes)
clear Aperture;
[lowerIdx,upperIdx,a,b,c,alpha,beta,right] = Aperture.findApertureInternal(LidarRes);
Aperture.lowerIdx(lowerIdx);
Aperture.upperIdx(upperIdx);
Aperture.vertexA(a);
Aperture.vertexB(b);
Aperture.vertexC(c);
Aperture.orientation(right);
Aperture.beta(beta);
Aperture.alpha(alpha);
gamma = 180-alpha-beta;
Aperture.gamma(gamma);
end
function [lowerIdx, upperIdx, a, b, c,alpha,beta,right] = findApertureInternal(LidarRes)
% First order derivative of Lidar distance vector on the
% front-left
distanceVD = diff(LidarRes);
% Second order derivative of Lidar distance vector on the
% front-left
distanceVD = diff(distanceVD);
% Focus on big discontinuities indicating an aperture, by applying a
% threshold
idx = abs(distanceVD)>1;
% Apply mask
distanceVD(~idx) = 0;
% Compute changes in signs
distanceVD=diff(sign(distanceVD),1,2);
% -2 if went from positive to negative AND 2 if went from
% negative to positive indicating the entrance/exit of the
% room
distinctivePoints = [find(distanceVD==-2) find(distanceVD==2)];
distinctivePoints = sort(distinctivePoints);
if(length(distinctivePoints)>=2)
for n=1:(length(distinctivePoints)-1)
lowerIdx = distinctivePoints(n);
if (distanceVD(lowerIdx) == -2)
upperIdx = distinctivePoints(n+1);
if((distanceVD(lowerIdx) == -2) && (upperIdx > lowerIdx))
lowerIdx = lowerIdx + 1;
upperIdx = upperIdx + 2;
dUIdx = LidarRes(upperIdx);
dLIdx = LidarRes(lowerIdx);
right = dUIdx-dLIdx <0;
if(right) % Orientation right
a = LidarRes(upperIdx);
c = LidarRes(lowerIdx);
else % Orientation left
a = LidarRes(lowerIdx);
c = LidarRes(upperIdx);
end
beta = 240/681*(upperIdx-lowerIdx);
b = Triangle.computeVertex(a,c,beta);
alpha = Triangle.computeAlpha(a,b,c);
if(isnan(alpha))
alpha = 0;
end
% Aperture found
break;
end
end
% Reset if no match
lowerIdx = 0;
upperIdx = 0;
a = 0;
b = 0;
c = 0;
beta = 0;
right = 0;
alpha = 0;
end
else
% Initialize if no match
lowerIdx = 0;
upperIdx = 0;
a = 0;
b = 0;
c = 0;
beta = 0;
right = 0;
alpha = 0;
end
end
end
end