-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_lds_new.m
55 lines (51 loc) · 1.75 KB
/
cluster_lds_new.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
%load('turtlebot_lds_detect_data.mat');
% num_point = size(Measurement_lds);
% for det = 1: num_point(1, 1)
% sensors{det, 1} = struct('SensorIndex', 1, 'Measurement', Measurement_lds(det, :)', 'ObjectClassID', 1);
% end
%
%
% detections = [sensors{:, 1}];
% vehicleLength = 0.20;
% detectionClusters = cluster_check_lds(detections, vehicleLength);
function detectionClusters = cluster_lds_new(detections, vehicleSize) %#codegen
N = numel(detections);
distances = zeros(N);
for i = 1:(N)
for j = i+1:N
if detections(1, i).SensorIndex == detections(1, j).SensorIndex
distances(i,j) = norm(detections(1, i).Measurement(1:2) - detections(1, j).Measurement(1:2));
else
distances(i,j) = inf;
end
end
end
leftToCheck = 1:N;
i = 0;
detectionClusters = cell(N,1);
% if array is empty!!
if (distances)==0
detectionClusters{1} = detections(1,1);
detectionClusters{1}.Measurement = [0; 0];
detectionClusters(2:end) = [];
else
while ~isempty(leftToCheck)
% Remove the detections that are in the same cluster as the one under
% consideration
underConsideration = leftToCheck(1);
clusterInds = ( distances(underConsideration, leftToCheck) < vehicleSize);
detInds = leftToCheck(clusterInds);
clusterDets = [detections(1, detInds)];
for k = numel(clusterDets)
clusterMeas = [clusterDets(1).Measurement];
meas = mean(clusterMeas, 2);
%disp(['##1 -- cluster meas :',(meas)])
meas2D = [meas(1:2)];
i = i + 1;
detectionClusters{i} = detections(1, detInds(1));
detectionClusters{i}.Measurement = meas2D;
leftToCheck(clusterInds) = [];
end
detectionClusters(i+1:end) = [];
end
end