forked from christianwengert/calib_toolbox_addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetNextPoint.m
114 lines (99 loc) · 4.09 KB
/
getNextPoint.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
%Simply returns the next point which is closest to the startpoint and as close as possible on the line
function [x, dist, dir, searchPoints] = getNextPoint(searchPoints, x0, dir0, X, Y, MAXDIST, MAXANGLE, MAXDIST2LINE, doshow)
%REturn values in case of its not working
x = -1;
dir = [0;0];
dist = -1;
%Returns the index of points which are close to the line
[dl, ix_l,angles] = getClosestPointToLine(searchPoints, x0, dir0, 32);
%for i=1:length(dl)
% dl(i)
%end
%Only take those points that are less than MAXPIXEL away from the line
ix = find(dl < MAXDIST2LINE);
ix_l = ix_l(ix);
%Returns the index of points which are close to the start point
[ix_n, d] = getClosestNeighbours(searchPoints(:, ix_l), x0, 16); %x0 important
%Make a new index with closest points that are close to the line!
ix = ix_l(ix_n);
if(numel(ix)>0)
d = norm(searchPoints(2:3, ix(1))-x0); %x0 important
if(d < MAXDIST)
%Check that there ar epoints, otherwise return a zero value
if(length(ix) > 0 )
%Take the best match
x = searchPoints(2:3,ix(1));
%Recompute direction
dir = x-x0(1:2); %x0 faux
dist = norm(dir);
dir = dir/dist;
%Get the angle
theta = acos(dir'*dir0)/(norm(dir)*norm(dir0))/pi*180;
% if(theta<85 | theta>105)
if(theta<MAXANGLE)
%Mark it as used and store the point correspondance
searchPoints(1,ix(1)) = 0;
searchPoints(4:5, ix(1)) = [X;Y];
if(doshow)
text(searchPoints(2,ix(1))+5,searchPoints(3,ix(1))+5,[num2str(searchPoints(4,ix(1))) ',' num2str(searchPoints(5,ix(1)))],'Color','m')
end
else
x = -1;
end
end
end
end
%
% %Simply returns the next point which is closest to the startpoint and as close as possible on the line
% function [x, dist, dir, searchPoints] = getNextPoint(searchPoints, x0, dir0, X, Y, MAXDIST, MAXANGLE, MAXDIST2LINE, doshow)
%
% %REturn values in case of its not working
% x = -1;
% dir = [0;0];
% dist = -1;
% %Returns the index of points which are close to the line
% [dl, ix_l,angles] = getClosestPointToLine(searchPoints, x0, dir0, 8);
% %Only take those points that are less than MAXPIXEL away from the line
% ix = find(dl < MAXDIST2LINE);
% ix_l = ix_l(ix);
%
% %Returns the index of points which are close to the start point
% [ix_n, d] = getClosestNeighbours(searchPoints(:, ix_l), x0, 16);
%
% %Make a new index with closest points that are close to the line!
% ix = ix_l(ix_n);
% if(numel(ix)>0)
% d = norm(searchPoints(2:3, ix(1))-x0);
% if(d < MAXDIST)
% %Check that there ar epoints, otherwise return a zero value
% if(length(ix) > 0 )
% %Take the best match
% x = searchPoints(2:3,ix(1));
% %Recompute direction
% dir = x-x0(1:2);
% dist = norm(dir);
% dir = dir/dist;
% %Get the angle
% theta = acos(dir'*dir0)/(norm(dir)*norm(dir0))/pi*180;
%
% % if(theta<85 | theta>105)
% if(theta<MAXANGLE)
% %Mark it as used and store the point correspondance
% searchPoints(1,ix(1)) = 0;
% searchPoints(4:5, ix(1)) = [X;Y];
% if(doshow)
% text(searchPoints(2,ix(1))+5,searchPoints(3,ix(1))+5,[num2str(searchPoints(4,ix(1))) ',' num2str(searchPoints(5,ix(1)))],'Color','m')
% end
% else
% x = -1;
% end
% end
% end
% end
%
%
%
%
%
%
%