forked from mit-acl/clipper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex1_knownscalepointcloud.m
113 lines (90 loc) · 3.18 KB
/
ex1_knownscalepointcloud.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CLIPPER Example: Synthetic point cloud registration w/ known scale
%
% Before running this example, use cmake to build the required mex fcns.
% See README.md for more information.
%
% For more details, please see the article
% P.C. Lusk, K. Fathian, J.P. How, "CLIPPER: A Graph-Theoretic Framework
% "for Robust Data Association," ICRA 2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear, clc;
addpath(genpath('build/bindings/matlab')) % for scoring invariants
addpath(genpath('matlab')) % for clipper algorithm
%% Generate model/target point cloud
% blue point cloud
D1 = [
0 0 0;...
2 0 0;...
0 3 0;...
2 2 0;...
]';
%% Generate data/source point cloud
% arbitrary transformation of data w.r.t model
th = pi/8;
R = [cos(th) -sin(th) 0; sin(th) cos(th) 0; 0 0 1];
t = [5 3 0]';
% apply inverse of transform to model cloud
D2 = R'*D1 - R'*t;
% decide how many points of D2 to remove from the end (sim partial scan)
m = 1;
% remove last point from D2 to create a partial scan
D2 = D2(:,1:(end-m));
%% Generate putative associations
% by passing in an empty initial association matrix, an all-to-all
% hypothesis will be formed, i.e., CLIPPER will consider if any point in
% D1 can be associated with any other point in D2 (in a one-to-one way).
A = [];
%% Run CLIPPER
params = struct;
params.sigma = 0.01;
params.epsilon = 0.06;
[M, C, A] = clipper_euclideandistance(D1, D2, A, params);
[u, idx, ~] = clipper(M, C);
Ain = A(idx,:);
%% Plot input point clouds
figure(1), cla; grid on, hold on;
title('Point Clouds', 'FontSize', 18);
scatter(D1(1,1:(end-m)), D1(2,1:(end-m)), 50, 'b', 'filled');
scatter(D1(1,(end-m):end), D1(2,(end-m):end), 50, 'b');
scatter(D2(1,:), D2(2,:), 50, 'r', 'filled');
axis equal;
%% Plot CLIPPER input
figure(2), cla; hold on;
title('CLIPPER Input', 'FontSize', 18);
for i = 1:size(A,1)
if A(i,1) == A(i,2) % if a correct association (see assumptions)
color = [0 1 0];
else
color = [1 0.5 1];
end
plot([D1(1,A(i,1)) D2(1,A(i,2))], [D1(2,A(i,1)) D2(2,A(i,2))],...
'LineWidth', 1, 'Color', color);
c = mean([D1(1:2,A(i,1)) D2(1:2,A(i,2))], 2);
text(c(1), c(2), num2str(i),...
'HorizontalAlignment', 'center', 'VerticalAlignment','middle');
end
scatter(D1(1,1:(end-m)), D1(2,1:(end-m)), 50, 'b', 'filled');
scatter(D1(1,(end-m):end), D1(2,(end-m):end), 50, 'b');
scatter(D2(1,:), D2(2,:), 50, 'r', 'filled');
axis equal;
set(gca,'YTickLabel',[]);
set(gca,'XTickLabel',[]);
%% Plot CLIPPER output
figure(3), cla; hold on
title('CLIPPER Output', 'FontSize', 18);
for i = 1:size(Ain,1)
if Ain(i,1) == Ain(i,2) % if a correct association (see assumptions)
color = [0 1 0];
else
color = [1 0.5 1];
end
plot([D1(1,Ain(i,1)) D2(1,Ain(i,2))], [D1(2,Ain(i,1)) D2(2,Ain(i,2))],...
'LineWidth', 1, 'Color', color);
end
scatter(D1(1,1:(end-m)), D1(2,1:(end-m)), 50, 'b', 'filled');
scatter(D1(1,(end-m):end), D1(2,(end-m):end), 50, 'b');
scatter(D2(1,:), D2(2,:), 50, 'r', 'filled');
axis equal;
set(gca,'YTickLabel',[]);
set(gca,'XTickLabel',[]);