SlidingWindowIteratorTest.cpp
Go to the documentation of this file.
1 /*
2  * SlidingWindowIteratorTest.cpp
3  *
4  * Created on: Aug 16, 2017
5  * Author: Péter Fankhauser
6  * Institute: ETH Zurich
7  */
8 
11 
12 #include <cfloat>
13 #include <Eigen/Core>
14 #include <gtest/gtest.h>
15 #include <vector>
16 
17 using namespace std;
18 using namespace grid_map;
19 
20 TEST(SlidingWindowIterator, WindowSize3Cutoff)
21 {
22  GridMap map;
23  map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
24  map.add("layer");
25  map["layer"].setRandom();
26 
27  SlidingWindowIterator iterator(map, "layer", SlidingWindowIterator::EdgeHandling::CROP, 3);
28  EXPECT_EQ(iterator.getData().rows(), 2);
29  EXPECT_EQ(iterator.getData().cols(), 2);
30  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(0, 0, 2, 2)));
31 
32  ++iterator;
33  EXPECT_EQ(iterator.getData().rows(), 3);
34  EXPECT_EQ(iterator.getData().cols(), 2);
35  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(0, 0, 3, 2)));
36 
37  ++iterator;
38  EXPECT_EQ(iterator.getData().rows(), 3);
39  EXPECT_EQ(iterator.getData().cols(), 2);
40  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(1, 0, 3, 2)));
41 
42  for (; !iterator.isPastEnd(); ++iterator) {
43  EXPECT_FALSE(iterator.isPastEnd());
44  if ((*iterator == Index(3, 2)).all()) break;
45  }
46 
47  EXPECT_EQ(iterator.getData().rows(), 3);
48  EXPECT_EQ(iterator.getData().cols(), 3);
49  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(2, 1, 3, 3)));
50 
51  for (; !iterator.isPastEnd(); ++iterator) {
52  EXPECT_FALSE(iterator.isPastEnd());
53  if ((*iterator == Index(7, 4)).all()) break;
54  }
55 
56  EXPECT_EQ(iterator.getData().rows(), 2);
57  EXPECT_EQ(iterator.getData().cols(), 2);
58  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(6, 3, 2, 2)));
59 
60  ++iterator;
61  EXPECT_TRUE(iterator.isPastEnd());
62 }
63 
65 {
66  GridMap map;
67  map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
68  map.add("layer");
69  map["layer"].setRandom();
70 
71  SlidingWindowIterator iterator(map, "layer", SlidingWindowIterator::EdgeHandling::CROP, 5);
72  EXPECT_EQ(iterator.getData().rows(), 3);
73  EXPECT_EQ(iterator.getData().cols(), 3);
74  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(0, 0, 3, 3)));
75 
76  ++iterator;
77  EXPECT_EQ(iterator.getData().rows(), 4);
78  EXPECT_EQ(iterator.getData().cols(), 3);
79  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(0, 0, 4, 3)));
80 
81  ++iterator;
82  EXPECT_EQ(iterator.getData().rows(), 5);
83  EXPECT_EQ(iterator.getData().cols(), 3);
84  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(0, 0, 5, 3)));
85 
86  for (; !iterator.isPastEnd(); ++iterator) {
87  EXPECT_FALSE(iterator.isPastEnd());
88  if ((*iterator == Index(3, 2)).all()) break;
89  }
90 
91  EXPECT_EQ(iterator.getData().rows(), 5);
92  EXPECT_EQ(iterator.getData().cols(), 5);
93  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(1, 0, 5, 5)));
94 
95  for (; !iterator.isPastEnd(); ++iterator) {
96  EXPECT_FALSE(iterator.isPastEnd());
97  if ((*iterator == Index(7, 4)).all()) break;
98  }
99 
100  EXPECT_EQ(iterator.getData().rows(), 3);
101  EXPECT_EQ(iterator.getData().cols(), 3);
102  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(5, 2, 3, 3)));
103 
104  ++iterator;
105  EXPECT_TRUE(iterator.isPastEnd());
106 }
107 
108 TEST(SlidingWindowIterator, WindowSize3Inside)
109 {
110  GridMap map;
111  map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
112  map.add("layer");
113  map["layer"].setRandom();
114 
115  SlidingWindowIterator iterator(map, "layer", SlidingWindowIterator::EdgeHandling::INSIDE, 3);
116  EXPECT_EQ(iterator.getData().rows(), 3);
117  EXPECT_EQ(iterator.getData().cols(), 3);
118  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(0, 0, 3, 3)));
119 
120  for (; !iterator.isPastEnd(); ++iterator) {
121  EXPECT_FALSE(iterator.isPastEnd());
122  if ((*iterator == Index(3, 2)).all()) break;
123  }
124 
125  EXPECT_EQ(iterator.getData().rows(), 3);
126  EXPECT_EQ(iterator.getData().cols(), 3);
127  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(2, 1, 3, 3)));
128 
129  for (; !iterator.isPastEnd(); ++iterator) {
130  EXPECT_FALSE(iterator.isPastEnd());
131  if ((*iterator == Index(6, 3)).all()) break;
132  }
133 
134  EXPECT_EQ(iterator.getData().rows(), 3);
135  EXPECT_EQ(iterator.getData().cols(), 3);
136  EXPECT_TRUE(iterator.getData().isApprox(map["layer"].block(5, 2, 3, 3)));
137 
138  ++iterator;
139  EXPECT_TRUE(iterator.isPastEnd());
140 }
Eigen::Array2i Index
Definition: TypeDefs.hpp:22
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
Definition: GridMap.cpp:45
TEST(SlidingWindowIterator, WindowSize3Cutoff)
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
void add(const std::string &layer, const double value=NAN)
Definition: GridMap.cpp:89
Eigen::Array2d Length
Definition: TypeDefs.hpp:24


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Tue Jun 1 2021 02:13:27