-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimPose.m
174 lines (166 loc) · 4.88 KB
/
SimPose.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
165
166
167
168
169
170
171
172
173
174
classdef SimPose < handle & matlab.mixin.Copyable
%Pose Object with Sim(3) data fields
% A point in the manifold Sim(3) is created from the following data:
% - translation t, rotation R and scaling s
%
% Technical:
% This is a *handle* *copyable* object, that means that the object
% created by the constructor is a handle (pointer) to the data.
% If you want to get an *independent* copy of the object (clone)
% use the method *copy* in the object.
% Intuitively, the pose of an object is inherent to this
% and should be assigned to a different object, but another object
% could have the same value (copy).
%
% See also handle, matlab.mixin.Copyable.
properties
sim
H
end
properties (Dependent)
% Observation components
s,R,t
end
methods
function pose = SimPose( varargin )
% pose = SimPose( t, R, s)
% Constructor from components
% pose = SimPose( H )
% Constructor from transformation matrix
% pose = SimPose( )
% Default constructor, returns identity
% pose = SimPose( pose )
% Copy constructor, returns a clone of the input
if nargin == 0
s = 1;
t = zeros(3,1);
R = eye(3);
elseif nargin == 1
if isa(varargin{1},'SimPose')
% Copy constructor
pose.sim = varargin{1}.sim;
return
else
s = varargin{1};
t = zeros(3,1);
R = eye(3);
end
% % If not Pose, the argument should be sim
% sim = varargin{1};
% assert( all(size(sim)==[3,4]) || all(sim(end,:)==[0 0 0 1]) );
% R = sim(1:3,1:3);
% t = sim(1:3,4);
else
t = varargin{1};
R = varargin{2};
s = varargin{3};
end
assert( isrotation(R) );
assert( s > 1e-5, "s should not be zero" )
pose.sim(4,4) = 1/s; % Set H with complete size as hom. matrix
pose.t = t;
pose.R = R;
pose.s = s;
pose.H = Pose(t, R);
end
% Additional interface properties
function s = get.s(pose)
s = 1/pose.sim(4,4);
end
function t = get.t(pose)
t = pose.sim(1:3,4);
end
function set.t(pose,t)
pose.sim(1:3,4) = t;
end
function R = get.R(pose)
R = pose.sim(1:3,1:3);
end
function set.R(pose,R)
pose.sim(1:3,1:3) = R;
end
function set.s(pose,s)
pose.sim(4,4) = 1/s;
end
function v = vec(this)
v = this.s * vec(this.sim(1:3,:)); % this is the same as [s*vec(R);t]
end
% Overloaded operators for usual arithmetic
function out = mtimes(this,feature)
switch class(feature)
case 'Point'
% x' = R*x+t
out = Point(this.s*this.R*feature.x+this.t);
case 'Line'
% x' = R*x+t
% v' = R*v
out = Line(this.s*this.R*feature.x+this.t,this.R*feature.v);
case 'Plane'
% x' = R*x+t
% n' = R*n
out = Line(this.s*this.R*feature.x+this.t,this.R*feature.n);
otherwise
error('Unknown feature class %s',class(feature))
end
end
% function out = mldivide(this,feature)
% out = inv(this)*feature; %#ok<MINV>
% end
function invPose = inv(pose)
invPose = SimPose( -1/pose.s*pose.R'*pose.t, pose.R', 1/pose.s);
end
% function new_pose = oplus( pose, delta )
% % Compose with pre-multiplication of the increment
% new_t = pose.t + delta(1:3);
% new_R = SO3.exp(delta(4:6)) * pose.R;
% % Save new results into an object of the same type as input
% c = str2func( class(pose) );
% new_pose = c(new_t,new_R);
% end
%
% function disp(pose)
% if numel(pose)==1
% disp(pose.sim)
% else
% s = size(pose);
% fprintf('%dx%d %s array\n',s,class(pose));
% end
% end
%
% function plot(pose,varargin)
%
% % Setup inputs
% p = inputParser;
% p.StructExpand = true;
% p.KeepUnmatched = true;
% p.addRequired('pose', @(p)isa(p,'Pose'));
% p.addParameter('size',0.25);
% p.addParameter('colors',{'r','g','b'});
% p.addParameter('tag',[],@ischar);
% % Parse arguments into options
% p.parse(pose,varargin{:}); opts = p.Results;
% size = opts.size;
%
% for k=1:3
% v = size * pose.R(:,k);
% lin = [ pose.t, pose.t+v ]';
% patchline(lin(:,1),lin(:,2),lin(:,3),...
% 'edgecolor',opts.colors{k},varargin{:});
% end
% % Plot tag text
% if ~isempty(opts.tag)
% tag_pos = pose.t + 0.5*size*sum(pose.R,2);
% text(tag_pos(1),tag_pos(2),tag_pos(3),opts.tag);
% end
% end
end
methods (Static)
function pose = rand( )
s = genRandomNumber(0,5,1,1);
R = rnd.rot();
rng(2);
t = randn(3,1);
pose = SimPose(t,R,s);
end
end
end