SubmapIteratorTest.cpp
Go to the documentation of this file.
1 /*
2  * SubmapIteratorTest.cpp
3  *
4  * Created on: Sep 15, 2014
5  * Author: Péter Fankhauser
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
11 
12 // Eigen
13 #include <Eigen/Core>
14 
15 // gtest
16 #include <gtest/gtest.h>
17 
18 // Limits
19 #include <cfloat>
20 
21 // Vector
22 #include <vector>
23 
24 using namespace std;
25 using namespace Eigen;
26 using namespace grid_map;
27 
29 {
30  Eigen::Array2i submapTopLeftIndex(3, 1);
31  Eigen::Array2i submapBufferSize(3, 2);
32  Eigen::Array2i index;
33  Eigen::Array2i submapIndex;
34 
35  vector<string> types;
36  types.push_back("type");
37  GridMap map(types);
38  map.setGeometry(Array2d(8.1, 5.1), 1.0, Vector2d(0.0, 0.0)); // bufferSize(8, 5)
39 
40  SubmapIterator iterator(map, submapTopLeftIndex, submapBufferSize);
41 
42  EXPECT_FALSE(iterator.isPastEnd());
43  EXPECT_EQ(submapTopLeftIndex(0), (*iterator)(0));
44  EXPECT_EQ(submapTopLeftIndex(1), (*iterator)(1));
45  EXPECT_EQ(0, iterator.getSubmapIndex()(0));
46  EXPECT_EQ(0, iterator.getSubmapIndex()(1));
47 
48  ++iterator;
49  EXPECT_FALSE(iterator.isPastEnd());
50  EXPECT_EQ(3, (*iterator)(0));
51  EXPECT_EQ(2, (*iterator)(1));
52  EXPECT_EQ(0, iterator.getSubmapIndex()(0));
53  EXPECT_EQ(1, iterator.getSubmapIndex()(1));
54 
55  ++iterator;
56  EXPECT_FALSE(iterator.isPastEnd());
57  EXPECT_EQ(4, (*iterator)(0));
58  EXPECT_EQ(1, (*iterator)(1));
59  EXPECT_EQ(1, iterator.getSubmapIndex()(0));
60  EXPECT_EQ(0, iterator.getSubmapIndex()(1));
61 
62  ++iterator;
63  EXPECT_FALSE(iterator.isPastEnd());
64  EXPECT_EQ(4, (*iterator)(0));
65  EXPECT_EQ(2, (*iterator)(1));
66  EXPECT_EQ(1, iterator.getSubmapIndex()(0));
67  EXPECT_EQ(1, iterator.getSubmapIndex()(1));
68 
69  ++iterator;
70  EXPECT_FALSE(iterator.isPastEnd());
71  EXPECT_EQ(5, (*iterator)(0));
72  EXPECT_EQ(1, (*iterator)(1));
73  EXPECT_EQ(2, iterator.getSubmapIndex()(0));
74  EXPECT_EQ(0, iterator.getSubmapIndex()(1));
75 
76  ++iterator;
77  EXPECT_FALSE(iterator.isPastEnd());
78  EXPECT_EQ(5, (*iterator)(0));
79  EXPECT_EQ(2, (*iterator)(1));
80  EXPECT_EQ(2, iterator.getSubmapIndex()(0));
81  EXPECT_EQ(1, iterator.getSubmapIndex()(1));
82 
83  ++iterator;
84  EXPECT_TRUE(iterator.isPastEnd());
85  EXPECT_EQ(5, (*iterator)(0));
86  EXPECT_EQ(2, (*iterator)(1));
87  EXPECT_EQ(2, iterator.getSubmapIndex()(0));
88  EXPECT_EQ(1, iterator.getSubmapIndex()(1));
89 }
90 
91 TEST(SubmapIterator, CircularBuffer)
92 {
93  Eigen::Array2i submapTopLeftIndex(6, 3);
94  Eigen::Array2i submapBufferSize(2, 4);
95  Eigen::Array2i index;
96  Eigen::Array2i submapIndex;
97 
98  vector<string> types;
99  types.push_back("type");
100  GridMap map(types);
101  map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
102  map.move(Position(-3.0, -2.0)); // bufferStartIndex(3, 2)
103 
104  SubmapIterator iterator(map, submapTopLeftIndex, submapBufferSize);
105 
106  EXPECT_FALSE(iterator.isPastEnd());
107  EXPECT_EQ(submapTopLeftIndex(0), (*iterator)(0));
108  EXPECT_EQ(submapTopLeftIndex(1), (*iterator)(1));
109  EXPECT_EQ(0, iterator.getSubmapIndex()(0));
110  EXPECT_EQ(0, iterator.getSubmapIndex()(1));
111 
112  ++iterator;
113  EXPECT_FALSE(iterator.isPastEnd());
114  EXPECT_EQ(6, (*iterator)(0));
115  EXPECT_EQ(4, (*iterator)(1));
116  EXPECT_EQ(0, iterator.getSubmapIndex()(0));
117  EXPECT_EQ(1, iterator.getSubmapIndex()(1));
118 
119  ++iterator;
120  EXPECT_FALSE(iterator.isPastEnd());
121  EXPECT_EQ(6, (*iterator)(0));
122  EXPECT_EQ(0, (*iterator)(1));
123  EXPECT_EQ(0, iterator.getSubmapIndex()(0));
124  EXPECT_EQ(2, iterator.getSubmapIndex()(1));
125 
126  ++iterator;
127  EXPECT_FALSE(iterator.isPastEnd());
128  EXPECT_EQ(6, (*iterator)(0));
129  EXPECT_EQ(1, (*iterator)(1));
130  EXPECT_EQ(0, iterator.getSubmapIndex()(0));
131  EXPECT_EQ(3, iterator.getSubmapIndex()(1));
132 
133  ++iterator;
134  EXPECT_FALSE(iterator.isPastEnd());
135  EXPECT_EQ(7, (*iterator)(0));
136  EXPECT_EQ(3, (*iterator)(1));
137  EXPECT_EQ(1, iterator.getSubmapIndex()(0));
138  EXPECT_EQ(0, iterator.getSubmapIndex()(1));
139 
140  ++iterator;
141  EXPECT_FALSE(iterator.isPastEnd());
142  EXPECT_EQ(7, (*iterator)(0));
143  EXPECT_EQ(4, (*iterator)(1));
144  EXPECT_EQ(1, iterator.getSubmapIndex()(0));
145  EXPECT_EQ(1, iterator.getSubmapIndex()(1));
146 
147  ++iterator;
148  EXPECT_FALSE(iterator.isPastEnd());
149  EXPECT_EQ(7, (*iterator)(0));
150  EXPECT_EQ(0, (*iterator)(1));
151  EXPECT_EQ(1, iterator.getSubmapIndex()(0));
152  EXPECT_EQ(2, iterator.getSubmapIndex()(1));
153 
154  ++iterator;
155  EXPECT_FALSE(iterator.isPastEnd());
156  EXPECT_EQ(7, (*iterator)(0));
157  EXPECT_EQ(1, (*iterator)(1));
158  EXPECT_EQ(1, iterator.getSubmapIndex()(0));
159  EXPECT_EQ(3, iterator.getSubmapIndex()(1));
160 
161  ++iterator;
162  EXPECT_TRUE(iterator.isPastEnd());
163  EXPECT_EQ(7, (*iterator)(0));
164  EXPECT_EQ(1, (*iterator)(1));
165  EXPECT_EQ(1, iterator.getSubmapIndex()(0));
166  EXPECT_EQ(3, iterator.getSubmapIndex()(1));
167 }
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
Definition: GridMap.cpp:51
TEST(SubmapIterator, Simple)
bool move(const Position &position, std::vector< BufferRegion > &newRegions)
Definition: GridMap.cpp:453
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
const Index & getSubmapIndex() const
Eigen::Array2d Length
Definition: TypeDefs.hpp:24


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Tue Jun 25 2019 20:02:08