g2o
Functions
test_isometry3d_mappings.cpp File Reference
#include <iostream>
#include "isometry3d_mappings.h"
#include "g2o/stuff/macros.h"
#include <cstdio>
Include dependency graph for test_isometry3d_mappings.cpp:

Go to the source code of this file.

Functions

int main (int, char **)
 

Function Documentation

int main ( int  ,
char **   
)

Definition at line 38 of file test_isometry3d_mappings.cpp.

References g2o::internal::approximateNearestOrthogonalMatrix(), g2o::internal::fromCompactQuaternion(), g2o::internal::fromEuler(), g2o::internal::fromVectorET(), g2o::internal::fromVectorMQT(), g2o::internal::fromVectorQT(), g2o::internal::nearestOrthogonalMatrix(), g2o::internal::toCompactQuaternion(), g2o::internal::toEuler(), g2o::internal::toVectorET(), g2o::internal::toVectorMQT(), and g2o::internal::toVectorQT().

38  {
39 
40 Matrix3D I;
41  Matrix3D R = Matrix3D::Identity();
42  Matrix3D rot = (Matrix3D)AngleAxisd(0.01, Vector3D::UnitZ());
43  rot = rot * (Matrix3D)AngleAxisd(0.01, Vector3D::UnitX());
44 
45  cerr << "Initial rotation matrix accuracy" << endl;
46  I = R * R.transpose();
47  for (int i = 0; i < 3; ++i) {
48  for (int j = 0; j < 3; ++j) {
49  printf("%.30f ", I(i,j));
50  }
51  printf("\n");
52  }
53 
54  cerr << "After further multiplications" << endl;
55  for (int i = 0; i < 10000; ++i)
56  R = R * rot;
57  I = R * R.transpose();
58  for (int i = 0; i < 3; ++i) {
59  for (int j = 0; j < 3; ++j) {
60  printf("%.30f ", I(i,j));
61  }
62  printf("\n");
63  }
64 
65  cerr << PVAR(R) << endl;
66  printf("det %.30f\n", R.determinant());
67  printf("\nUsing nearest orthogonal matrix\n");
68  Matrix3D approxSolution = R;
69  approximateNearestOrthogonalMatrix(approxSolution);
71  cerr << PVAR(R) << endl;
72  printf("det %.30f\n", R.determinant());
73  I = R * R.transpose();
74  for (int i = 0; i < 3; ++i) {
75  for (int j = 0; j < 3; ++j) {
76  printf("%.30f ", I(i,j));
77  }
78  printf("\n");
79  }
80  cerr << "Norm of the columns" << endl;
81  for (int i = 0; i < 3; ++i)
82  printf("%.30f ", R.col(i).norm());
83  printf("\nUsing approximate nearest orthogonal matrix\n");
84  I = approxSolution * approxSolution.transpose();
85  cerr << PVAR(approxSolution) << endl;
86  printf("det %.30f\n", approxSolution.determinant());
87  for (int i = 0; i < 3; ++i) {
88  for (int j = 0; j < 3; ++j) {
89  printf("%.30f ", I(i,j));
90  }
91  printf("\n");
92  }
93  cerr << "Norm of the columns" << endl;
94  for (int i = 0; i < 3; ++i)
95  printf("%.30f ", approxSolution.col(i).norm());
96 
97  cerr << endl;
98  return 0;
99 
100  Vector3D eulerAngles(.1,.2,.3);
101  Matrix3D m1=fromEuler(eulerAngles);
102  cerr << "m1=fromEuler(eulerAngles)" << endl;
103  cerr << "eulerAngles:" << endl;
104  cerr << eulerAngles << endl;
105  cerr << "m1:" << endl;
106  cerr << m1 << endl;
107 
108  Vector3D eulerAngles1 = toEuler(m1);
109  cerr << "eulerAngles1 = toEuler(m1) " << endl;
110  cerr << "eulerAngles1:" << endl;
111  cerr << eulerAngles1 << endl;
112 
114  cerr << "q=toCompactQuaternion(m1)" << endl;
115  cerr << "q:" << endl;
116  cerr << q << endl;
117 
119  cerr << "m2=fromCompactQuaternion(q);" << endl;
120  cerr << "m2:" << endl;
121  cerr << m2 << endl;
122 
123  Vector6d et;
124  Vector3D t(1.,2.,3.);
125  et.block<3,1>(0,0)=eulerAngles;
126  et.block<3,1>(3,0)=t;
127  Isometry3D i1 = fromVectorET(et);
128  cerr << "i1 = fromVectorET(et);" << endl;
129  cerr << "et:" << endl;
130  cerr << et << endl;
131  cerr << "i1" << endl;
132  cerr << i1.rotation() << endl;
133  cerr << i1.translation() << endl;
134  Vector6d et2=toVectorET(i1);
135  cerr << "et2=toVectorET(i1);" << endl;
136  cerr << "et2" << endl;
137  cerr << et2 << endl;
138 
139  Vector6d qt1=toVectorMQT(i1);
140  cerr << "qt1=toVectorMQT(i1)" << endl;
141  cerr << "qt1:" << endl;
142  cerr << qt1 << endl;
143 
144  Isometry3D i2 = fromVectorMQT(qt1);
145  cerr << "i2 = fromVectorMQT(qt1)" << endl;
146  cerr << "i2" << endl;
147  cerr << i2.rotation() << endl;
148  cerr << i2.translation() << endl;
149 
150  Vector7d qt2=toVectorQT(i1);
151  cerr << "qt2=toVectorQT(i1)" << endl;
152  cerr << "qt2:" << endl;
153  cerr << qt2 << endl;
154 
155  Isometry3D i3 = fromVectorQT(qt2);
156  cerr << "i3 = fromVectorQT(qt2)" << endl;
157  cerr << "i3" << endl;
158  cerr << i3.rotation() << endl;
159  cerr << i3.translation() << endl;
160 
161 }
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)
Vector6d toVectorET(const Isometry3D &t)
Eigen::Transform< double, 3, Eigen::Isometry, Eigen::ColMajor > Isometry3D
Definition: eigen_types.h:66
Vector6d toVectorMQT(const Isometry3D &t)
Eigen::Matrix< double, 3, 3, Eigen::ColMajor > Matrix3D
Definition: eigen_types.h:61
void approximateNearestOrthogonalMatrix(const Eigen::MatrixBase< Derived > &R)
Eigen::Matrix< double, 6, 1 > Vector6d
Vector7d toVectorQT(const Isometry3D &t)
Isometry3D fromVectorMQT(const Vector6d &v)
Isometry3D fromVectorET(const Vector6d &v)
Matrix3D fromEuler(const Vector3D &v)