GridMapIteratorTest.cpp
Go to the documentation of this file.
1 /*
2  * GridMapDataIterator.cpp
3  *
4  * Created on: Feb 16, 2016
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 grid_map;
26 
28 {
29  GridMap map;
30  map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
31  map.add("layer", 0.0);
32  GridMapIterator iterator(map);
33 
34  unsigned int i = 0;
35  for (; !iterator.isPastEnd(); ++iterator, ++i) {
36  map.at("layer", *iterator) = 1.0;
37  EXPECT_FALSE(iterator.isPastEnd());
38  }
39 
40  EXPECT_EQ(40, i);
41  EXPECT_TRUE(iterator.isPastEnd());
42  EXPECT_TRUE((map["layer"].array() == 1.0f).all());
43 }
44 
45 TEST(GridMapIterator, LinearIndex)
46 {
47  GridMap map;
48  map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
49  map.add("layer", 0.0);
50  GridMapIterator iterator(map);
51 
52  auto& data = map["layer"];
53  unsigned int i = 0;
54  for (; !iterator.isPastEnd(); ++iterator, ++i) {
55  data(iterator.getLinearIndex()) = 1.0;
56  EXPECT_EQ(i, iterator.getLinearIndex());
57  EXPECT_FALSE(iterator.isPastEnd());
58  }
59 
60  EXPECT_EQ(40, i);
61  EXPECT_TRUE(iterator.isPastEnd());
62  EXPECT_TRUE((map["layer"].array() == 1.0f).all());
63 }
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
Definition: GridMap.cpp:45
TEST(GridMapIterator, Simple)
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
float & at(const std::string &layer, const Index &index)
Definition: GridMap.cpp:217
void add(const std::string &layer, const double value=NAN)
Definition: GridMap.cpp:89
Eigen::Array2d Length
Definition: TypeDefs.hpp:24
const size_t & getLinearIndex() const


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