g2o
Public Member Functions | List of all members
RotationMatrix2QuaternionManifold Struct Reference

Functor used to compute the Jacobian via AD. More...

Public Member Functions

template<typename T >
bool operator() (const T *rotMatSerialized, T *quaternion) const
 

Detailed Description

Functor used to compute the Jacobian via AD.

Definition at line 43 of file test_mat2quat_jacobian.cpp.

Member Function Documentation

template<typename T >
bool RotationMatrix2QuaternionManifold::operator() ( const T *  rotMatSerialized,
T *  quaternion 
) const
inline

Definition at line 46 of file test_mat2quat_jacobian.cpp.

47  {
48  typename Eigen::Matrix<T, 3, 3, Eigen::ColMajor>::ConstMapType R(rotMatSerialized);
49 
50  T t = R.trace();
51  if (t > T(0)) {
52  cerr << "w";
53  t = sqrt(t + T(1));
54  //T w = T(0.5)*t;
55  t = T(0.5)/t;
56  quaternion[0] = (R(2,1) - R(1,2)) * t;
57  quaternion[1] = (R(0,2) - R(2,0)) * t;
58  quaternion[2] = (R(1,0) - R(0,1)) * t;
59  } else {
60  int i = 0;
61  if (R(1,1) > R(0,0))
62  i = 1;
63  if (R(2,2) > R(i,i))
64  i = 2;
65  int j = (i+1)%3;
66  int k = (j+1)%3;
67  cerr << i;
68 
69  t = sqrt(R(i,i) - R(j,j) - R(k,k) + T(1.0));
70  quaternion[i] = T(0.5) * t;
71  t = T(0.5)/t;
72  quaternion[j] = (R(j,i) + R(i,j)) * t;
73  quaternion[k] = (R(k,i) + R(i,k)) * t;
74  T w = (R(k,j) - R(j,k)) * t;
75  // normalize to our manifold, such that w is positive
76  if (w < 0.) {
77  //cerr << " normalizing w > 0 ";
78  for (int l = 0; l < 3; ++l)
79  quaternion[l] *= T(-1);
80  }
81  }
82  return true;
83  }

The documentation for this struct was generated from the following file: