Skip to content

Commit 9250493

Browse files
NoelieRamuzatolivier-stasse
authored andcommitted
[operator] Add HomogeneousMatrixToSE3Vector & SE3VectorToHomogeneousMatrix
Allows to convert a vector of size 12 (which represents an Homogeneous Matrix) to a 'real' Homogeneous Matrix (dg type). And the opposite; add comparison test in test_operator.cpp.
1 parent 9363032 commit 9250493

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/dynamic_graph/sot/core/math_small_entities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
Inverse_of_matrixrotation, Inverse_of_matrixtwist, Inverse_of_unitquat,
1313
MatrixDiagonal, MatrixHomoToPose, MatrixHomoToPoseQuaternion, PoseQuatToMatrixHomo,
1414
MatrixHomoToPoseRollPitchYaw, MatrixHomoToPoseUTheta, MatrixToHomo,
15-
MatrixToQuaternion, MatrixToRPY, MatrixToUTheta, MatrixTranspose,
16-
Multiply_double_vector, Multiply_matrix_vector,
15+
MatrixToQuaternion, MatrixToRPY, MatrixToUTheta, MatrixHomoToSE3Vector, SE3VectorToMatrixHomo,
16+
MatrixTranspose, Multiply_double_vector, Multiply_matrix_vector,
1717
Multiply_matrixTwist_vector, Multiply_matrixHomo_vector,
1818
Multiply_of_double, Multiply_of_matrix, Multiply_of_matrixHomo,
1919
Multiply_of_matrixrotation, Multiply_of_matrixtwist,

src/matrix/operator.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,28 @@ struct HomogeneousMatrixToVector
321321
};
322322
REGISTER_UNARY_OP(HomogeneousMatrixToVector, MatrixHomoToPoseUTheta);
323323

324+
struct HomogeneousMatrixToSE3Vector
325+
: public UnaryOpHeader<MatrixHomogeneous, dg::Vector> {
326+
void operator()(const MatrixHomogeneous &M, dg::Vector &res) {
327+
res.resize(12);
328+
res.head<3>() = M.translation();
329+
res.segment(3, 3) = M.linear().row(0);
330+
res.segment(6, 3) = M.linear().row(1);
331+
res.segment(9, 3) = M.linear().row(2); }
332+
};
333+
REGISTER_UNARY_OP(HomogeneousMatrixToSE3Vector, MatrixHomoToSE3Vector);
334+
335+
struct SE3VectorToHomogeneousMatrix
336+
: public UnaryOpHeader<dg::Vector, MatrixHomogeneous> {
337+
void operator()(const dg::Vector &vect, MatrixHomogeneous &Mres) {
338+
Mres.translation() = vect.head<3>();
339+
Mres.linear().row(0) = vect.segment(3, 3);
340+
Mres.linear().row(1) = vect.segment(6, 3);
341+
Mres.linear().row(2) = vect.segment(9, 3);
342+
}
343+
};
344+
REGISTER_UNARY_OP(SE3VectorToHomogeneousMatrix, SE3VectorToMatrixHomo);
345+
324346
struct SkewSymToVector : public UnaryOpHeader<Matrix, Vector> {
325347
void operator()(const Matrix &M, Vector &res) {
326348
res.resize(3);

tests/matrix/test_operator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,8 @@ BOOST_AUTO_TEST_CASE(matrix_quaternion) {
198198
BOOST_AUTO_TEST_CASE(matrixHomo_poseQuaternion) {
199199
test_impl<MatrixHomoToPoseQuaternion, PoseQuaternionToMatrixHomo>();
200200
}
201+
BOOST_AUTO_TEST_CASE(matrixHomo_se3Vector) {
202+
test_impl<HomogeneousMatrixToSE3Vector, SE3VectorToHomogeneousMatrix>();
203+
}
201204

202205
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)