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 // gtest
13 #include <gtest/gtest.h>
14 
15 // Vector
16 #include <vector>
17 
18 using grid_map::GridMap;
19 using grid_map::Length;
20 using grid_map::Position;
22 
24 {
25  GridMap map;
26  map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
27  map.add("layer", 0.0);
28  GridMapIterator iterator(map);
29 
30  unsigned int i = 0;
31  for (; !iterator.isPastEnd(); ++iterator, ++i) {
32  map.at("layer", *iterator) = 1.0;
33  EXPECT_FALSE(iterator.isPastEnd());
34  }
35 
36  EXPECT_EQ(40, i);
37  EXPECT_TRUE(iterator.isPastEnd());
38  EXPECT_TRUE((map["layer"].array() == 1.0f).all());
39 }
40 
41 TEST(GridMapIterator, LinearIndex)
42 {
43  GridMap map;
44  map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
45  map.add("layer", 0.0);
46  GridMapIterator iterator(map);
47 
48  auto& data = map["layer"];
49  unsigned int i = 0;
50  for (; !iterator.isPastEnd(); ++iterator, ++i) {
51  data(static_cast<long>(iterator.getLinearIndex())) = 1.0;
52  EXPECT_EQ(i, iterator.getLinearIndex());
53  EXPECT_FALSE(iterator.isPastEnd());
54  }
55 
56  EXPECT_EQ(40, i);
57  EXPECT_TRUE(iterator.isPastEnd());
58  EXPECT_TRUE((map["layer"].array() == 1.0f).all());
59 }
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
Definition: GridMap.cpp:44
TEST(GridMapIterator, Simple)
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
const size_t & getLinearIndex() const
Eigen::Array2d Length
Definition: TypeDefs.hpp:24
float & at(const std::string &layer, const Index &index)
Definition: GridMap.cpp:212
void add(const std::string &layer, const double value=NAN)
Definition: GridMap.cpp:82


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Wed Jul 5 2023 02:23:35