Debian Codegraph @

unit_test/slam3d/mappings_slam3d.cpp

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