OKVIS ROS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
operators.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2  * OKVIS - Open Keyframe-based Visual-Inertial SLAM
3  * Copyright (c) 2015, Autonomous Systems Lab / ETH Zurich
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of Autonomous Systems Lab / ETH Zurich nor the names of
14  * its contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Created on: Mar 11, 2015
30  * Author: Stefan Leutenegger (s.leutenegger@imperial.ac.uk)
31  *********************************************************************************/
32 
39 #ifndef INCLUDE_OKVIS_KINEMATICS_OPERATORS_HPP_
40 #define INCLUDE_OKVIS_KINEMATICS_OPERATORS_HPP_
41 
42 #include <stdint.h>
43 #include <vector>
44 #include <Eigen/Core>
45 #include <Eigen/Geometry>
46 
48 namespace okvis {
49 
51 namespace kinematics {
52 
53 // some free helper functions
54 
61 template<typename Scalar_T>
62 inline Eigen::Matrix<Scalar_T, 3, 3> crossMx(Scalar_T x, Scalar_T y, Scalar_T z)
63 {
64  Eigen::Matrix<Scalar_T, 3, 3> C;
65  C(0, 0) = 0.0;
66  C(0, 1) = -z;
67  C(0, 2) = y;
68  C(1, 0) = z;
69  C(1, 1) = 0.0;
70  C(1, 2) = -x;
71  C(2, 0) = -y;
72  C(2, 1) = x;
73  C(2, 2) = 0.0;
74  return C;
75 }
76 
81 template<typename Derived_T>
82 inline Eigen::Matrix<typename Eigen::internal::traits<Derived_T>::Scalar, 3, 3> crossMx(
83  Eigen::MatrixBase<Derived_T> const & v)
84 {
85  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Eigen::MatrixBase<Derived_T>, 3);
86  assert((v.cols()==3 && v.rows()==1)||(v.rows()==3 && v.cols()==1));
87  return crossMx(v(0, 0), v(1, 0), v(2, 0));
88 }
89 
92 inline Eigen::Matrix4d plus(const Eigen::Quaterniond & q_AB) {
93  Eigen::Vector4d q = q_AB.coeffs();
94  Eigen::Matrix4d Q;
95  Q(0,0) = q[3]; Q(0,1) = -q[2]; Q(0,2) = q[1]; Q(0,3) = q[0];
96  Q(1,0) = q[2]; Q(1,1) = q[3]; Q(1,2) = -q[0]; Q(1,3) = q[1];
97  Q(2,0) = -q[1]; Q(2,1) = q[0]; Q(2,2) = q[3]; Q(2,3) = q[2];
98  Q(3,0) = -q[0]; Q(3,1) = -q[1]; Q(3,2) = -q[2]; Q(3,3) = q[3];
99  return Q;
100 }
101 
104 inline Eigen::Matrix4d oplus(const Eigen::Quaterniond & q_BC) {
105  Eigen::Vector4d q = q_BC.coeffs();
106  Eigen::Matrix4d Q;
107  Q(0,0) = q[3]; Q(0,1) = q[2]; Q(0,2) = -q[1]; Q(0,3) = q[0];
108  Q(1,0) = -q[2]; Q(1,1) = q[3]; Q(1,2) = q[0]; Q(1,3) = q[1];
109  Q(2,0) = q[1]; Q(2,1) = -q[0]; Q(2,2) = q[3]; Q(2,3) = q[2];
110  Q(3,0) = -q[0]; Q(3,1) = -q[1]; Q(3,2) = -q[2]; Q(3,3) = q[3];
111  return Q;
112 }
113 
114 } // namespace kinematics
115 } // namespace okvis
116 
117 
118 
119 #endif /* INCLUDE_OKVIS_KINEMATICS_OPERATORS_HPP_ */
Eigen::Matrix< Scalar_T, 3, 3 > crossMx(Scalar_T x, Scalar_T y, Scalar_T z)
Cross matrix of a vector [x,y,z]. Adopted from Schweizer-Messer by Paul Furgale.
Definition: operators.hpp:62
Eigen::Matrix4d oplus(const Eigen::Quaterniond &q_BC)
Oplus matrix of a quaternion, i.e. q_AB*q_BC = oplus(q_BC)*q_AB.coeffs().
Definition: operators.hpp:104
Eigen::Matrix4d plus(const Eigen::Quaterniond &q_AB)
Plus matrix of a quaternion, i.e. q_AB*q_BC = plus(q_AB)*q_BC.coeffs().
Definition: operators.hpp:92