g2o
isometry3d_mappings.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 H. Strasdat, G. Grisetti, R. Kümmerle, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #ifndef G2O_ISOMETRY3D_MAPPINGS_H_
28 #define G2O_ISOMETRY3D_MAPPINGS_H_
29 
30 #include "g2o_types_slam3d_api.h"
31 #include "se3quat.h"
32 #include <Eigen/Core>
33 #include <Eigen/Geometry>
34 
35 namespace g2o {
36 
37  typedef Eigen::Matrix<double, 6, 1, Eigen::ColMajor> Vector6d;
38  typedef Eigen::Matrix<double, 7, 1, Eigen::ColMajor> Vector7d;
39 
45  namespace internal {
46 
58  inline Isometry3D::ConstLinearPart extractRotation(const Isometry3D& A)
59  {
60  return A.matrix().topLeftCorner<3,3>();
61  }
62 
69  template <typename Derived>
70  void nearestOrthogonalMatrix(const Eigen::MatrixBase<Derived>& R)
71  {
72  Eigen::JacobiSVD<Matrix3D> svd(R, Eigen::ComputeFullU | Eigen::ComputeFullV);
73  double det = (svd.matrixU() * svd.matrixV().adjoint()).determinant();
74  Matrix3D scaledU(svd.matrixU());
75  scaledU.col(0) /= det;
76  const_cast<Eigen::MatrixBase<Derived>&>(R) = scaledU * svd.matrixV().transpose();
77  }
78 
84  template <typename Derived>
85  void approximateNearestOrthogonalMatrix(const Eigen::MatrixBase<Derived>& R)
86  {
87  Matrix3D E = R.transpose() * R;
88  E.diagonal().array() -= 1;
89  const_cast<Eigen::MatrixBase<Derived>&>(R) -= 0.5 * R * E;
90  }
91 
95  G2O_TYPES_SLAM3D_API Eigen::Quaterniond normalized(const Eigen::Quaterniond& q);
99  G2O_TYPES_SLAM3D_API Eigen::Quaterniond& normalize(Eigen::Quaterniond& q);
100 
101  // functions to handle the rotation part
119 
120  // functions to handle the toVector of the whole transformations
124  G2O_TYPES_SLAM3D_API Vector6d toVectorMQT(const Isometry3D& t);
128  G2O_TYPES_SLAM3D_API Vector6d toVectorET(const Isometry3D& t);
132  G2O_TYPES_SLAM3D_API Vector7d toVectorQT(const Isometry3D& t);
133 
137  G2O_TYPES_SLAM3D_API Isometry3D fromVectorMQT(const Vector6d& v);
141  G2O_TYPES_SLAM3D_API Isometry3D fromVectorET(const Vector6d& v);
145  G2O_TYPES_SLAM3D_API Isometry3D fromVectorQT(const Vector7d& v);
146 
155 
156  } // end namespace internal
157 } // end namespace g2o
158 
159 #endif
Vector3D toEuler(const Matrix3D &R)
void nearestOrthogonalMatrix(const Eigen::MatrixBase< Derived > &R)
Matrix3D fromCompactQuaternion(const Vector3D &v)
Eigen::Matrix< double, 3, 1, Eigen::ColMajor > Vector3D
Definition: eigen_types.h:46
Isometry3D fromVectorQT(const Vector7d &v)
Eigen::Matrix< double, 7, 1 > Vector7d
Definition: sim3.h:35
Vector3D toCompactQuaternion(const Matrix3D &R)
SE3Quat toSE3Quat(const Isometry3D &t)
Vector6d toVectorET(const Isometry3D &t)
#define G2O_TYPES_SLAM3D_API
Eigen::Transform< double, 3, Eigen::Isometry, Eigen::ColMajor > Isometry3D
Definition: eigen_types.h:66
Eigen::Quaterniond & normalize(Eigen::Quaterniond &q)
Vector6d toVectorMQT(const Isometry3D &t)
Isometry3D::ConstLinearPart extractRotation(const Isometry3D &A)
Eigen::Matrix< double, 3, 3, Eigen::ColMajor > Matrix3D
Definition: eigen_types.h:61
Eigen::Quaterniond normalized(const Eigen::Quaterniond &q)
void approximateNearestOrthogonalMatrix(const Eigen::MatrixBase< Derived > &R)
Vector7d toVectorQT(const Isometry3D &t)
Isometry3D fromVectorMQT(const Vector6d &v)
Isometry3D fromVectorET(const Vector6d &v)
Isometry3D fromSE3Quat(const SE3Quat &t)
Matrix< double, 6, 1, Eigen::ColMajor > Vector6d
Definition: types_icp.cpp:75
Matrix3D fromEuler(const Vector3D &v)