ethzasl-msf - Modular Sensor Fusion
Time delay compensated single and multi sensor fusion framework based on an EKF
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
similaritytransform.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Markus Achtelik, ASL, ETH Zurich, Switzerland
3  * You can contact the author at <acmarkus at ethz dot ch>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef SIMILARITYTRANSFORM_H_
18 #define SIMILARITYTRANSFORM_H_
19 
20 #include <vector>
21 #include <utility>
22 #include <geometry_msgs/PoseWithCovariance.h>
23 #include <Eigen/Core>
24 #include <Eigen/Geometry>
25 #include <limits>
26 
27 #include <msf_core/msf_types.hpp>
28 #include <msf_core/eigen_utils.h>
29 
31 // geometry_msgs::PoseWithCovariance.
32 namespace geometry_msgs {
33 namespace cov {
34 enum {
35  p = 0,
36  q = 3
37 };
38 }
39 }
40 
41 namespace msf_core {
42 
44 inline Vector3 geometry_msgsToEigen(const geometry_msgs::Point & p) {
45  return (Vector3() << p.x, p.y, p.z).finished();
46 }
47 
49 inline Eigen::Quaterniond geometry_msgsToEigen(
50  const geometry_msgs::Quaternion & q) {
51  return Eigen::Quaterniond(q.w, q.x, q.y, q.z);
52 }
53 
66  const geometry_msgs::PoseWithCovariance::_covariance_type & gcov,
67  int start_row, int start_col) {
68  Eigen::Map<const Matrix6> cov(gcov.data());
69  return Matrix3(cov.block<3, 3>(start_row, start_col));
70 }
71 
83 template<class Derived>
85  geometry_msgs::PoseWithCovariance::_covariance_type & gcov,
86  const Eigen::MatrixBase<Derived> &ecov, int start_row, int start_col) {
87  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived, 3, 3)
88  Eigen::Map<Matrix6> _gcov(gcov.data());
89  _gcov.block<3, 3>(start_row, start_col) = ecov;
90  // Off diagonal entries --> we need to copy it to the opposite off-diagonal
91  // as well.
92  if (start_row != start_col)
93  _gcov.block<3, 3>(start_col, start_row) = ecov.transpose();
94 }
95 
97 template<class Derived>
98 inline geometry_msgs::Point eigenToGeometry_msgs(
99  const Eigen::MatrixBase<Derived> & p) {
100  EIGEN_STATIC_ASSERT_VECTOR_ONLY (Derived);
101  assert(p.size() == 3);
102 
103  geometry_msgs::Point _p;
104  _p.x = p[0];
105  _p.y = p[1];
106  _p.z = p[2];
107  return _p;
108 }
109 
112  const Eigen::Quaterniond & q) {
114  _q.w = q.w();
115  _q.x = q.x();
116  _q.y = q.y();
117  _q.z = q.z();
118  return _q;
119 }
120 
121 namespace similarity_transform {
122 
123 typedef geometry_msgs::PoseWithCovariance Pose;
124 typedef std::pair<Pose, Pose> PosePair;
125 typedef std::vector<PosePair> PosePairVector;
126 
132 class From6DoF {
133  public:
134  From6DoF();
136  void addMeasurement(const PosePair & measurement);
137 
139  void addMeasurement(const Pose & pose1, const Pose & pose2);
140 
151  bool compute(Pose & pose, double *scale = nullptr , double *cond = nullptr ,
152  double eps = std::numeric_limits<double>::epsilon() * 4 * 4);
153  private:
155 };
156 }
157 } // namespace msf_core
158 #endif // SIMILARITYTRANSFORM_H_