1 // g2o - General Graph Optimization
2 // Copyright (C) 2014 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 "gtest/gtest.h"
28 
29 #include "g2o/types/slam3d/isometry3d_mappings.h"
30 #include "g2o/types/slam3d/edge_se3.h"
31 
32 using namespace std;
33 
TEST(MappingsSlam3D,EulerConversion)34 TEST(MappingsSlam3D, EulerConversion)
35 {
36   g2o::Vector3 eulerAngles(.1,.2,.3);
37   g2o::Matrix3 m1 = g2o::internal::fromEuler(eulerAngles);
38   g2o::Vector3 eulerAnglesFromMatrix = g2o::internal::toEuler(m1);
39   for (int i = 0; i < 3; ++i)
40     EXPECT_DOUBLE_EQ(eulerAngles(i), eulerAnglesFromMatrix(i));
41 }
42 
TEST(MappingsSlam3D,QuaternionConversion)43 TEST(MappingsSlam3D, QuaternionConversion)
44 {
45   g2o::Vector3 eulerAngles(.1,.2,.3);
46   g2o::Matrix3 m1 = g2o::internal::fromEuler(eulerAngles);
47   g2o::Vector3 q = g2o::internal::toCompactQuaternion(m1);
48   g2o::Matrix3 m2 = g2o::internal::fromCompactQuaternion(q);
49   for (int r = 0; r < 3; ++r)
50     for (int c = 0; c < 3; ++c)
51       EXPECT_DOUBLE_EQ(m1(r,c), m2(r,c));
52 }
53 
TEST(MappingsSlam3D,ET)54 TEST(MappingsSlam3D, ET)
55 {
56   g2o::Vector3 eulerAngles(.1,.2,.3);
57   g2o::Vector6 et;
58   g2o::Vector3 t(1.,2.,3.);
59   et.block<3,1>(0,0) = t;
60   et.block<3,1>(3,0) = eulerAngles;
61   g2o::Matrix3 m1 = g2o::internal::fromEuler(eulerAngles);
62 
63   g2o::Isometry3 i1 = g2o::internal::fromVectorET(et);
64   for (int r = 0; r < 3; ++r)
65     EXPECT_EQ(t(r), i1.translation()(r));
66 
67   EXPECT_NEAR(0., (i1.linear() - m1).array().abs().maxCoeff(), 1e-6);
68 
69   g2o::Vector6 et2 = g2o::internal::toVectorET(i1);
70   EXPECT_NEAR(0., (et - et2).array().abs().maxCoeff(), 1e-6);
71 }
72 
TEST(MappingsSlam3D,MQT)73 TEST(MappingsSlam3D, MQT)
74 {
75   g2o::Vector3 eulerAngles(.1,.2,.3);
76   g2o::Vector6 et;
77   g2o::Vector3 t(1.,2.,3.);
78   et.block<3,1>(0,0) = t;
79   et.block<3,1>(3,0) = eulerAngles;
80   g2o::Isometry3 i1 = g2o::internal::fromVectorET(et);
81 
82   g2o::Vector6 qt1 = g2o::internal::toVectorMQT(i1);
83 
84   g2o::Isometry3 i2 = g2o::internal::fromVectorMQT(qt1);
85   EXPECT_NEAR(0., (i1.linear() - i2.linear()).array().abs().maxCoeff(), 1e-6);
86   EXPECT_NEAR(0., (i1.translation() - i2.translation()).array().abs().maxCoeff(), 1e-6);
87 }
88 
TEST(MappingsSlam3D,QT)89 TEST(MappingsSlam3D, QT)
90 {
91   g2o::Vector3 eulerAngles(.1,.2,.3);
92   g2o::Vector6 et;
93   g2o::Vector3 t(1.,2.,3.);
94   et.block<3,1>(0,0) = t;
95   et.block<3,1>(3,0) = eulerAngles;
96   g2o::Isometry3 i1 = g2o::internal::fromVectorET(et);
97 
98   g2o::Vector7 qt2 = g2o::internal::toVectorQT(i1);
99 
100   g2o::Isometry3 i2 = g2o::internal::fromVectorQT(qt2);
101   EXPECT_NEAR(0., (i1.linear() - i2.linear()).array().abs().maxCoeff(), 1e-6);
102   EXPECT_NEAR(0., (i1.translation() - i2.translation()).array().abs().maxCoeff(), 1e-6);
103 }
104