test_landmark_map.cpp
Go to the documentation of this file.
1 // Copyright 2023 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <gtest/gtest.h>
16 
17 // standard library
18 #include <optional>
19 
20 // external
21 #include <sophus/se3.hpp>
22 
23 // project
26 
27 namespace {
28 
29 struct LandmarkMapCartesianTest : public ::testing::Test {
31  Eigen::Vector3d{0.0, 1.0, 2.0}, Eigen::Vector3d{10.0, 11.0, 12.0}};
32 };
33 
34 TEST_F(LandmarkMapCartesianTest, SmokeTest) {
36 }
37 
38 TEST_F(LandmarkMapCartesianTest, SimpleMapLoading) {
39  const auto landmark_10 = beluga::LandmarkPosition3{+1.0, +2.0, +3.0};
40  const auto landmark_11 = beluga::LandmarkPosition3{+1.0, +2.0, +3.0};
41  const auto landmark_20 = beluga::LandmarkPosition3{+5.0, +6.0, +7.0};
42 
43  auto uut = beluga::LandmarkMap(default_map_boundaries, {{landmark_10, 0}, {landmark_11, 0}, {landmark_20, 1}});
44 
45  {
46  const auto nearest = uut.find_nearest_landmark({1.0, 2.0, 3.0}, 0);
47  ASSERT_TRUE(nearest.has_value());
48  EXPECT_NEAR(0.0, (landmark_10 - *nearest).norm(), 1e-6);
49  }
50 
51  {
52  const auto nearest = uut.find_nearest_landmark({1.0, 2.0, 3.0}, 1);
53  ASSERT_TRUE(nearest.has_value());
54  EXPECT_NEAR(0.0, (landmark_20 - *nearest).norm(), 1e-6);
55  }
56 
57  {
58  const auto nearest = uut.find_nearest_landmark({1.0, 2.0, 3.0}, 99);
59  ASSERT_FALSE(nearest.has_value());
60  }
61 }
62 
63 TEST_F(LandmarkMapCartesianTest, EmptyMap) {
65  const auto nearest = uut.find_nearest_landmark({1.0, 2.0, 3.0}, 0);
66  ASSERT_FALSE(nearest.has_value());
67 }
68 
69 struct LandmarkMapBearingTest : public ::testing::Test {
71  Eigen::Vector3d{0.0, 1.0, 2.0}, Eigen::Vector3d{10.0, 11.0, 12.0}};
72 
75  {
76  // category 0
77  {{+9.0, +0.0, +1.0}, 0},
78  {{+0.0, +9.0, +1.0}, 0},
79  {{+0.0, +0.0, +9.0}, 0},
80  // category 1
81  {{-9.0, +0.0, +1.0}, 1},
82  {{+0.0, -9.0, +1.0}, 1},
83  {{+0.0, +0.0, -9.0}, 1},
84  // category 2
85  {{+0.0, +0.0, -9.0}, 2},
86  }};
87 
88  Sophus::SE3d sensor_pose_in_world{Sophus::SO3d{}, Eigen::Vector3d{0.0, 0.0, 1.0}};
89 };
90 
91 TEST_F(LandmarkMapBearingTest, MapLimits) {
92  ASSERT_DOUBLE_EQ(uut.map_limits().min().x(), 0.0);
93  ASSERT_DOUBLE_EQ(uut.map_limits().max().x(), 10.0);
94  ASSERT_DOUBLE_EQ(uut.map_limits().min().y(), 1.0);
95  ASSERT_DOUBLE_EQ(uut.map_limits().max().y(), 11.0);
96  ASSERT_DOUBLE_EQ(uut.map_limits().min().z(), 2.0);
97  ASSERT_DOUBLE_EQ(uut.map_limits().max().z(), 12.0);
98 }
99 
100 TEST_F(LandmarkMapBearingTest, TrivialQuery1) {
101  const auto expected_bearing = beluga::LandmarkBearing3{1.0, 0.0, 0.0};
102  const auto nearest = uut.find_closest_bearing_landmark(expected_bearing, 0, sensor_pose_in_world);
103  ASSERT_TRUE(nearest.has_value());
104  EXPECT_NEAR(0.0, (*nearest - expected_bearing).norm(), 1e-6);
105 }
106 
107 TEST_F(LandmarkMapBearingTest, TrivialQuery2) {
108  const auto expected_bearing = beluga::LandmarkBearing3{-1.0, 0.0, 0.0};
109  const auto nearest = uut.find_closest_bearing_landmark(expected_bearing, 1, sensor_pose_in_world);
110  ASSERT_TRUE(nearest.has_value());
111  EXPECT_NEAR(0.0, (*nearest - expected_bearing).norm(), 1e-6);
112 }
113 
114 TEST_F(LandmarkMapBearingTest, FeatureInTotallyDifferentDirection) {
115  const auto detection_bearing = beluga::LandmarkBearing3{1.0, 0.0, 0.0};
116  const auto expected_bearing = beluga::LandmarkBearing3{0.0, 0.0, -1.0};
117  const auto nearest = uut.find_closest_bearing_landmark(detection_bearing, 2, sensor_pose_in_world);
118  ASSERT_TRUE(nearest.has_value());
119  EXPECT_NEAR(0.0, (*nearest - expected_bearing).norm(), 1e-6);
120 }
121 
122 TEST_F(LandmarkMapBearingTest, NoSuchFeature) {
123  const auto nearest =
124  uut.find_closest_bearing_landmark(beluga::LandmarkBearing3{1.0, 0.0, 0.0}, 99, sensor_pose_in_world);
125  ASSERT_FALSE(nearest.has_value());
126 }
127 
128 } // namespace
beluga::LandmarkBearing3
Eigen::Vector3d LandmarkBearing3
Bearing of a landmark in the sensor reference frame.
Definition: landmark_detection_types.hpp:34
Sophus::SO3
beluga::LandmarkMap::find_closest_bearing_landmark
std::optional< LandmarkBearing3 > find_closest_bearing_landmark(const LandmarkBearing3 &detection_bearing_in_sensor, const LandmarkCategory &detection_category, const world_pose_type &sensor_pose_in_world) const
Finds the landmark that minimizes the bearing error to a given detection and returns its data.
Definition: landmark_map.hpp:96
beluga::LandmarkMap::landmarks_set_position_data
std::vector< LandmarkPositionDetection > landmarks_set_position_data
Vector of landmarks.
Definition: landmark_map.hpp:42
landmark_detection_types.hpp
Auxiliar types for landmark models.
beluga::default_map_boundaries
LandmarkMapBoundaries default_map_boundaries
Definition: test_bearing_sensor_model.cpp:42
beluga::LandmarkMap::find_nearest_landmark
std::optional< LandmarkPosition3 > find_nearest_landmark(const LandmarkPosition3 &detection_position_in_world, const LandmarkCategory &detection_category) const
Finds the nearest landmark to a given detection and returns it's data.
Definition: landmark_map.hpp:60
Sophus::SE3
beluga::LandmarkMap
Basic 3D landmark map datatype.
Definition: landmark_map.hpp:39
beluga::LandmarkPosition3
Eigen::Vector3d LandmarkPosition3
Position of a landmark in the world reference frame.
Definition: landmark_detection_types.hpp:33
landmark_map.hpp
Landmark map datatype.
beluga::LandmarkMapBoundaries
Eigen::AlignedBox3d LandmarkMapBoundaries
Boundaries of a landmark map.
Definition: landmark_detection_types.hpp:36
se3.hpp


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53