Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "cartographer/transform/rigid_transform.h"
00017
00018 #include <random>
00019
00020 #include "cartographer/transform/rigid_transform_test_helpers.h"
00021 #include "cartographer/transform/transform.h"
00022 #include "gtest/gtest.h"
00023
00024 namespace cartographer {
00025 namespace transform {
00026 namespace {
00027
00028 template <typename T>
00029 class RigidTransformTest : public ::testing::Test {
00030 protected:
00031 T eps() { return std::numeric_limits<T>::epsilon(); }
00032
00033 Rigid2<T> GetRandomRigid2() {
00034 const T x = T(0.7) * distribution_(prng_);
00035 const T y = T(0.7) * distribution_(prng_);
00036 const T theta = T(0.2) * distribution_(prng_);
00037 return transform::Rigid2<T>(typename Rigid2<T>::Vector(x, y), theta);
00038 }
00039
00040 Rigid3<T> GetRandomRigid3() {
00041 const T x = T(0.7) * distribution_(prng_);
00042 const T y = T(0.7) * distribution_(prng_);
00043 const T z = T(0.7) * distribution_(prng_);
00044 const T ax = T(0.7) * distribution_(prng_);
00045 const T ay = T(0.7) * distribution_(prng_);
00046 const T az = T(0.7) * distribution_(prng_);
00047 return transform::Rigid3<T>(typename Rigid3<T>::Vector(x, y, z),
00048 AngleAxisVectorToRotationQuaternion(
00049 typename Rigid3<T>::Vector(ax, ay, az)));
00050 }
00051
00052 std::mt19937 prng_ = std::mt19937(42);
00053 std::uniform_real_distribution<T> distribution_ =
00054 std::uniform_real_distribution<T>(-1., 1.);
00055 };
00056
00057 using ScalarTypes = ::testing::Types<float, double>;
00058 TYPED_TEST_CASE(RigidTransformTest, ScalarTypes);
00059
00060 TYPED_TEST(RigidTransformTest, Identity2DTest) {
00061 const auto pose = this->GetRandomRigid2();
00062 EXPECT_THAT(pose * Rigid2<TypeParam>(), IsNearly(pose, this->eps()));
00063 EXPECT_THAT(Rigid2<TypeParam>() * pose, IsNearly(pose, this->eps()));
00064 EXPECT_THAT(pose * Rigid2<TypeParam>::Identity(),
00065 IsNearly(pose, this->eps()));
00066 EXPECT_THAT(Rigid2<TypeParam>::Identity() * pose,
00067 IsNearly(pose, this->eps()));
00068 }
00069
00070 TYPED_TEST(RigidTransformTest, Inverse2DTest) {
00071 const auto pose = this->GetRandomRigid2();
00072 EXPECT_THAT(pose.inverse() * pose,
00073 IsNearly(Rigid2<TypeParam>::Identity(), this->eps()));
00074 EXPECT_THAT(pose * pose.inverse(),
00075 IsNearly(Rigid2<TypeParam>::Identity(), this->eps()));
00076 }
00077
00078 TYPED_TEST(RigidTransformTest, Identity3DTest) {
00079 const auto pose = this->GetRandomRigid3();
00080 EXPECT_THAT(pose * Rigid3<TypeParam>(), IsNearly(pose, this->eps()));
00081 EXPECT_THAT(Rigid3<TypeParam>() * pose, IsNearly(pose, this->eps()));
00082 EXPECT_THAT(pose * Rigid3<TypeParam>::Identity(),
00083 IsNearly(pose, this->eps()));
00084 EXPECT_THAT(Rigid3<TypeParam>::Identity() * pose,
00085 IsNearly(pose, this->eps()));
00086 }
00087
00088 TYPED_TEST(RigidTransformTest, Inverse3DTest) {
00089 const auto pose = this->GetRandomRigid3();
00090 EXPECT_THAT(pose.inverse() * pose,
00091 IsNearly(Rigid3<TypeParam>::Identity(), this->eps()));
00092 EXPECT_THAT(pose * pose.inverse(),
00093 IsNearly(Rigid3<TypeParam>::Identity(), this->eps()));
00094 }
00095
00096 }
00097 }
00098 }