g2o
edge_se3_euler.cpp
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, 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 #include "edge_se3_euler.h"
28 #include "g2o/core/factory.h"
29 #include <iostream>
30 
31 using namespace Eigen;
32 
33 namespace g2o
34 {
35 
37 static void jac_quat3_euler3(Eigen::Matrix<double, 6, 6, Eigen::ColMajor>& J, const Isometry3D& t)
38 {
40 
41  double delta=1e-6;
42  double idelta= 1. / (2. * delta);
43 
44  Vector7d ta = t0;
45  Vector7d tb = t0;
46  for (int i=0; i<6; i++){
47  ta=tb=t0;
48  ta[i]-=delta;
49  tb[i]+=delta;
52  J.col(3)=(eb-ea)*idelta;
53  }
54 }
55 
56 
57  bool EdgeSE3Euler::read(std::istream& is)
58  {
59  Vector6d meas;
60  for (int i=0; i<6; i++)
61  is >> meas[i];
63  Matrix<double, 6, 6, Eigen::ColMajor> infMatEuler;
64  for (int i=0; i<6; i++)
65  for (int j=i; j<6; j++) {
66  is >> infMatEuler(i,j);
67  if (i!=j)
68  infMatEuler(j,i) = infMatEuler(i,j);
69  }
70  Matrix<double, 6, 6, Eigen::ColMajor> J;
71  jac_quat3_euler3(J, transf);
72  Matrix<double, 6, 6, Eigen::ColMajor> infMat = J.transpose() * infMatEuler * J;
73  setMeasurement(transf);
74  setInformation(infMat);
75  return true;
76  }
77 
78  bool EdgeSE3Euler::write(std::ostream& os) const
79  {
80  Vector6d meas = g2o::internal::toVectorET(_measurement);
81  for (int i=0; i<6; i++)
82  os << meas[i] << " ";
83 
84  Matrix<double, 6, 6, Eigen::ColMajor> J;
85  jac_quat3_euler3(J, measurement());
86  //HACK: invert the jacobian to simulate the inverse derivative
87  J=J.inverse();
88  Matrix<double, 6, 6, Eigen::ColMajor> infMatEuler = J.transpose()*information()*J;
89  for (int i=0; i<6; i++)
90  for (int j=i; j<6; j++){
91  os << " " << infMatEuler(i,j);
92  }
93  return os.good();
94  }
95 
96 } // end namespace
Isometry3D fromVectorQT(const Vector7d &v)
Eigen::Matrix< double, 7, 1 > Vector7d
Definition: sim3.h:35
Vector6d toVectorET(const Isometry3D &t)
Eigen::Transform< double, 3, Eigen::Isometry, Eigen::ColMajor > Isometry3D
Definition: eigen_types.h:66
static void jac_quat3_euler3(Eigen::Matrix< double, 6, 6, Eigen::ColMajor > &J, const Isometry3D &t)
Vector7d toVectorQT(const Isometry3D &t)
Isometry3D fromVectorET(const Vector6d &v)
Matrix< double, 6, 1, Eigen::ColMajor > Vector6d
Definition: types_icp.cpp:75