rigid_transform_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2017 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
17 
18 #include <random>
19 
22 #include "gtest/gtest.h"
23 
24 namespace cartographer {
25 namespace transform {
26 namespace {
27 
28 template <typename T>
29 class RigidTransformTest : public ::testing::Test {
30  protected:
31  T eps() { return std::numeric_limits<T>::epsilon(); }
32 
33  Rigid2<T> GetRandomRigid2() {
34  const T x = T(0.7) * distribution_(prng_);
35  const T y = T(0.7) * distribution_(prng_);
36  const T theta = T(0.2) * distribution_(prng_);
37  return transform::Rigid2<T>(typename Rigid2<T>::Vector(x, y), theta);
38  }
39 
40  Rigid3<T> GetRandomRigid3() {
41  const T x = T(0.7) * distribution_(prng_);
42  const T y = T(0.7) * distribution_(prng_);
43  const T z = T(0.7) * distribution_(prng_);
44  const T ax = T(0.7) * distribution_(prng_);
45  const T ay = T(0.7) * distribution_(prng_);
46  const T az = T(0.7) * distribution_(prng_);
47  return transform::Rigid3<T>(typename Rigid3<T>::Vector(x, y, z),
49  typename Rigid3<T>::Vector(ax, ay, az)));
50  }
51 
52  std::mt19937 prng_ = std::mt19937(42);
53  std::uniform_real_distribution<T> distribution_ =
54  std::uniform_real_distribution<T>(-1., 1.);
55 };
56 
57 using ScalarTypes = ::testing::Types<float, double>;
58 TYPED_TEST_CASE(RigidTransformTest, ScalarTypes);
59 
60 TYPED_TEST(RigidTransformTest, Identity2DTest) {
61  const auto pose = this->GetRandomRigid2();
62  EXPECT_THAT(pose * Rigid2<TypeParam>(), IsNearly(pose, this->eps()));
63  EXPECT_THAT(Rigid2<TypeParam>() * pose, IsNearly(pose, this->eps()));
64  EXPECT_THAT(pose * Rigid2<TypeParam>::Identity(),
65  IsNearly(pose, this->eps()));
66  EXPECT_THAT(Rigid2<TypeParam>::Identity() * pose,
67  IsNearly(pose, this->eps()));
68 }
69 
70 TYPED_TEST(RigidTransformTest, Inverse2DTest) {
71  const auto pose = this->GetRandomRigid2();
72  EXPECT_THAT(pose.inverse() * pose,
73  IsNearly(Rigid2<TypeParam>::Identity(), this->eps()));
74  EXPECT_THAT(pose * pose.inverse(),
75  IsNearly(Rigid2<TypeParam>::Identity(), this->eps()));
76 }
77 
78 TYPED_TEST(RigidTransformTest, Identity3DTest) {
79  const auto pose = this->GetRandomRigid3();
80  EXPECT_THAT(pose * Rigid3<TypeParam>(), IsNearly(pose, this->eps()));
81  EXPECT_THAT(Rigid3<TypeParam>() * pose, IsNearly(pose, this->eps()));
82  EXPECT_THAT(pose * Rigid3<TypeParam>::Identity(),
83  IsNearly(pose, this->eps()));
84  EXPECT_THAT(Rigid3<TypeParam>::Identity() * pose,
85  IsNearly(pose, this->eps()));
86 }
87 
88 TYPED_TEST(RigidTransformTest, Inverse3DTest) {
89  const auto pose = this->GetRandomRigid3();
90  EXPECT_THAT(pose.inverse() * pose,
91  IsNearly(Rigid3<TypeParam>::Identity(), this->eps()));
92  EXPECT_THAT(pose * pose.inverse(),
93  IsNearly(Rigid3<TypeParam>::Identity(), this->eps()));
94 }
95 
96 } // namespace
97 } // namespace transform
98 } // namespace cartographer
Eigen::Quaternion< T > AngleAxisVectorToRotationQuaternion(const Eigen::Matrix< T, 3, 1 > &angle_axis)
Definition: transform.h:86
Eigen::Matrix< FloatType, 2, 1 > Vector
std::uniform_real_distribution< T > distribution_
static Rigid2< FloatType > Identity()
static Rigid3< FloatType > Identity()
std::mt19937 prng_
transform::Rigid3d pose
Eigen::Matrix< FloatType, 3, 1 > Vector


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58