Skip to content

Commit 3986d80

Browse files
committed
Clean code of operator PoseUThetaToMatrixHomo, MatrixHomoToPoseUTheta
* and MatrixHomoToPoseQuaternion
1 parent 84f27f8 commit 3986d80

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/matrix/operator.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,10 @@ namespace dynamicgraph {
342342
{
343343
void operator()( const MatrixHomogeneous& M,dg::Vector& res )
344344
{
345-
MatrixRotation R; R = M.linear();
346-
VectorUTheta r(R);
347-
dg::Vector t(3); t = M.translation();
348-
res.resize(6);
349-
for( int i=0;i<3;++i ) res(i)=t(i);
350-
for( int i=0;i<3;++i ) res(i+3)=r.angle()*r.axis()(i);
345+
res.resize(6);
346+
VectorUTheta r(M.linear());
347+
res.head<3>() = M.translation();
348+
res.tail<3>() = r.angle()*r.axis();
351349
}
352350
};
353351
REGISTER_UNARY_OP( HomogeneousMatrixToVector,MatrixHomoToPoseUTheta);
@@ -371,11 +369,12 @@ namespace dynamicgraph {
371369
void operator()( const dg::Vector& v,MatrixHomogeneous& res )
372370
{
373371
assert( v.size()>=6 );
374-
Eigen::Affine3d trans;
375-
trans = Eigen::Translation3d(v.head<3>());
376-
dg::Vector ruth = v.tail<3>();
377-
Eigen::Affine3d R(Eigen::AngleAxisd(ruth.norm(), ruth.normalized()));
378-
res = R*trans;
372+
res.translation() = v.head<3>();
373+
double theta = v.tail<3>().norm();
374+
if (theta > 0)
375+
res.linear() = Eigen::AngleAxisd(theta, v.tail<3>() / theta).matrix();
376+
else
377+
res.linear().setIdentity();
379378
}
380379
};
381380
REGISTER_UNARY_OP(PoseUThetaToMatrixHomo,PoseUThetaToMatrixHomo);
@@ -385,12 +384,10 @@ namespace dynamicgraph {
385384
{
386385
void operator()( const MatrixHomogeneous& M,Vector& res )
387386
{
388-
MatrixRotation R; R = M.linear();
389-
VectorQuaternion r(R);
390-
dg::Vector t(3); t = M.translation();
391387
res.resize(7);
392-
for( int i=0;i<3;++i ) res(i)=t(i);
393-
for( int i=0;i<4;++i ) res(i+3)=r.coeffs()(i);
388+
res.head<3>() = M.translation();
389+
Eigen::Map<VectorQuaternion> q (res.tail<4>().data());
390+
q = M.linear();
394391
}
395392
};
396393
REGISTER_UNARY_OP(MatrixHomoToPoseQuaternion,MatrixHomoToPoseQuaternion);

0 commit comments

Comments
 (0)