Skip to content

Commit cf32ff9

Browse files
committed
Slightly faster and cleaner
1 parent abc9708 commit cf32ff9

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/factors/Pose2D.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ function preambleCache(dfg::AbstractDFG, vars::AbstractVector{<:DFGVariable}, pp
4040
(;manifold=M, ϵ0=getPointIdentity(M), Xc=zeros(3), q̂=getPointIdentity(M))
4141
end
4242

43+
@inline function _vee(::SpecialEuclidean{2}, X::ArrayPartition{T, Tuple{SVector{2, T}, SMatrix{2, 2, T, 4}}}) where T<:Real
44+
return SVector{3,T}(X.x[1][1],X.x[1][2],X.x[2][2])
45+
end
46+
47+
@inline function _compose(::SpecialEuclidean{2}, p::ArrayPartition{T, Tuple{SVector{2, T}, SMatrix{2, 2, T, 4}}}, q::ArrayPartition{T, Tuple{SVector{2, T}, SMatrix{2, 2, T, 4}}}) where T<:Real
48+
return ArrayPartition(p.x[1] + p.x[2]*q.x[1], p.x[2]*q.x[2])
49+
end
50+
4351
# Assumes X is a tangent vector
4452
function (cf::CalcFactor{<:Pose2Pose2})(_X::AbstractArray{MT}, _p::AbstractArray{PT}, _q::AbstractArray{LT}) where {MT,PT,LT}
4553
T = promote_type(MT, PT, LT)
@@ -60,14 +68,10 @@ function (cf::CalcFactor{<:Pose2Pose2})(
6068

6169
ϵX = exp(M, ϵ0, X)
6270
# q̂ = Manifolds.compose(M, p, ϵX)
63-
tp, Rp = Manifolds.submanifold_components(M, p)
64-
tq, Rq = Manifolds.submanifold_components(M, ϵX)
65-
R = Rp*Rq
66-
t = tp + Rp*(tq)
67-
= ArrayPartition(t,R)
68-
X = log(M, q, q̂)
69-
# Xc = vee(M, q, q̂)
70-
Xc = SA[X.x[1][1], X.x[1][2], X.x[2][2]]
71+
= _compose(M, p, ϵX)
72+
X_hat = log(M, q, q̂)
73+
# Xc = vee(M, q, X_hat)
74+
Xc = _vee(M, X_hat)
7175
return Xc
7276
end
7377

0 commit comments

Comments
 (0)