26 #include "gmock/gmock.h" 27 #include "gtest/gtest.h" 35 using ::testing::ElementsAre;
36 using ::testing::Field;
37 using ::testing::IsEmpty;
39 class OverlappingSubmapsTrimmer2DTest :
public ::testing::Test {
42 void AddSquareSubmap(
const Rigid2d& global_to_submap_frame,
43 const Rigid2d& local_to_submap_frame,
44 const Eigen::Vector2d& submap_corner,
int submap_index,
45 int num_cells,
bool is_finished) {
46 proto::Submap2D submap_2d;
47 submap_2d.set_num_range_data(1);
48 submap_2d.set_finished(is_finished);
49 *submap_2d.mutable_local_pose() =
52 auto* grid = submap_2d.mutable_grid();
53 for (
int i = 0; i < num_cells * num_cells; ++i) {
57 auto* map_limits = grid->mutable_limits();
58 map_limits->set_resolution(1.0);
60 map_limits->mutable_cell_limits()->set_num_x_cells(num_cells);
61 map_limits->mutable_cell_limits()->set_num_y_cells(num_cells);
63 auto* know_cells_box = grid->mutable_known_cells_box();
64 know_cells_box->set_min_x(0);
65 know_cells_box->set_min_y(0);
66 know_cells_box->set_max_x(num_cells - 1);
67 know_cells_box->set_max_y(num_cells - 1);
69 grid->mutable_probability_grid_2d();
72 {std::make_shared<const Submap2D>(submap_2d),
76 void AddTrajectoryNode(
int node_index,
int64 timestamp) {
77 TrajectoryNode::Data data;
81 NodeId{0 , node_index},
82 {std::make_shared<const TrajectoryNode::Data>(data), {} });
85 void AddConstraint(
int submap_index,
int node_index,
bool is_intra_submap) {
87 {SubmapId{0 , submap_index},
88 NodeId{0 , node_index},
97 ::testing::Matcher<const SubmapId&> EqualsSubmapId(
const SubmapId& expected) {
98 return ::testing::AllOf(
103 TEST_F(OverlappingSubmapsTrimmer2DTest, EmptyPoseGraph) {
104 OverlappingSubmapsTrimmer2D trimmer(1 ,
111 TEST_F(OverlappingSubmapsTrimmer2DTest, TrimOneOfTwoOverlappingSubmaps) {
112 AddSquareSubmap(Rigid2d::Identity() ,
113 Rigid2d::Identity() ,
114 Eigen::Vector2d(1., 1.) ,
117 AddSquareSubmap(Rigid2d::Identity() ,
118 Rigid2d::Identity() ,
119 Eigen::Vector2d(1., 1.) ,
122 AddTrajectoryNode(0 , 1000 );
123 AddTrajectoryNode(1 , 2000 );
124 AddConstraint(0 , 0 ,
true);
125 AddConstraint(1 , 1 ,
true);
127 OverlappingSubmapsTrimmer2D trimmer(1 ,
132 ElementsAre(EqualsSubmapId({0, 0})));
135 TEST_F(OverlappingSubmapsTrimmer2DTest, TestMinAddedSubmapsCountParam) {
136 AddSquareSubmap(Rigid2d::Identity() ,
137 Rigid2d::Identity() ,
138 Eigen::Vector2d(1., 1.) ,
141 AddSquareSubmap(Rigid2d::Identity() ,
142 Rigid2d::Identity() ,
143 Eigen::Vector2d(1., 1.) ,
146 AddTrajectoryNode(0 , 1000 );
147 AddTrajectoryNode(1 , 2000 );
148 AddConstraint(0 , 0 ,
true);
149 AddConstraint(1 , 1 ,
true);
151 OverlappingSubmapsTrimmer2D trimmer(1 ,
157 AddSquareSubmap(Rigid2d::Identity() ,
158 Rigid2d::Identity() ,
159 Eigen::Vector2d(1., 1.) ,
162 AddTrajectoryNode(2 , 3000 );
163 AddConstraint(2 , 2 ,
true);
166 ElementsAre(EqualsSubmapId({0, 0}), EqualsSubmapId({0, 1})));
169 TEST_F(OverlappingSubmapsTrimmer2DTest, DoNotTrimUnfinishedSubmap) {
170 AddSquareSubmap(Rigid2d::Identity() ,
171 Rigid2d::Identity() ,
172 Eigen::Vector2d(1., 1.) ,
175 AddSquareSubmap(Rigid2d::Identity() ,
176 Rigid2d::Identity() ,
177 Eigen::Vector2d(1., 1.) ,
180 AddTrajectoryNode(0 , 1000 );
181 AddTrajectoryNode(1 , 2000 );
182 AddConstraint(0 , 0 ,
true);
183 AddConstraint(1 , 1 ,
true);
185 OverlappingSubmapsTrimmer2D trimmer(1 ,
192 TEST_F(OverlappingSubmapsTrimmer2DTest, UseOnlyIntraSubmapsToComputeFreshness) {
193 AddSquareSubmap(Rigid2d::Identity() ,
194 Rigid2d::Identity() ,
195 Eigen::Vector2d(1., 1.) ,
198 AddSquareSubmap(Rigid2d::Identity() ,
199 Rigid2d::Identity() ,
200 Eigen::Vector2d(1., 1.) ,
203 AddTrajectoryNode(0 , 1000 );
204 AddTrajectoryNode(1 , 2000 );
205 AddTrajectoryNode(2 , 3000 );
206 AddConstraint(0 , 0 ,
false);
207 AddConstraint(0 , 2 ,
true);
208 AddConstraint(1 , 1 ,
true);
210 OverlappingSubmapsTrimmer2D trimmer(1 ,
215 ElementsAre(EqualsSubmapId({0, 1})));
226 TEST_F(OverlappingSubmapsTrimmer2DTest, TrimSubmapWithLowCoveredCellsCount) {
227 AddSquareSubmap(Rigid2d::Identity() ,
228 Rigid2d::Identity() ,
229 Eigen::Vector2d(1., 1.) ,
232 AddSquareSubmap(Rigid2d::Translation(
233 Eigen::Vector2d(1., 1.)) ,
234 Rigid2d::Identity() ,
235 Eigen::Vector2d(1., 1.) ,
238 AddTrajectoryNode(0 , 1000 );
239 AddTrajectoryNode(1 , 2000 );
240 AddConstraint(0 , 0 ,
true);
241 AddConstraint(1 , 1 ,
true);
243 OverlappingSubmapsTrimmer2D trimmer(1 ,
248 ElementsAre(EqualsSubmapId({0, 0})));
251 TEST_F(OverlappingSubmapsTrimmer2DTest, TestTransformations) {
252 AddSquareSubmap(Rigid2d::Identity() ,
253 Rigid2d::Identity() ,
254 Eigen::Vector2d(1., 1.) ,
257 const Rigid2d transform(Eigen::Vector2d(1., 1.), M_PI / 2);
258 AddSquareSubmap(transform ,
260 Eigen::Vector2d(1., 1.) ,
263 AddTrajectoryNode(0 , 1000 );
264 AddTrajectoryNode(1 , 2000 );
265 AddConstraint(0 , 0 ,
true);
266 AddConstraint(1 , 1 ,
true);
268 OverlappingSubmapsTrimmer2D trimmer(1 ,
273 ElementsAre(EqualsSubmapId({0, 0})));
testing::FakeTrimmable fake_pose_graph_
Time FromUniversal(const int64 ticks)