Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "grid_map_core/iterators/GridMapIterator.hpp"
00010 #include "grid_map_core/GridMap.hpp"
00011
00012
00013 #include <Eigen/Core>
00014
00015
00016 #include <gtest/gtest.h>
00017
00018
00019 #include <cfloat>
00020
00021
00022 #include <vector>
00023
00024 using namespace std;
00025 using namespace grid_map;
00026
00027 TEST(GridMapIterator, Simple)
00028 {
00029 GridMap map;
00030 map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0));
00031 map.add("layer", 0.0);
00032 GridMapIterator iterator(map);
00033
00034 unsigned int i = 0;
00035 for (; !iterator.isPastEnd(); ++iterator, ++i) {
00036 map.at("layer", *iterator) = 1.0;
00037 EXPECT_FALSE(iterator.isPastEnd());
00038 }
00039
00040 EXPECT_EQ(40, i);
00041 EXPECT_TRUE(iterator.isPastEnd());
00042 EXPECT_TRUE((map["layer"].array() == 1.0f).all());
00043 }
00044
00045 TEST(GridMapIterator, LinearIndex)
00046 {
00047 GridMap map;
00048 map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0));
00049 map.add("layer", 0.0);
00050 GridMapIterator iterator(map);
00051
00052 auto& data = map["layer"];
00053 unsigned int i = 0;
00054 for (; !iterator.isPastEnd(); ++iterator, ++i) {
00055 data(iterator.getLinearIndex()) = 1.0;
00056 EXPECT_EQ(i, iterator.getLinearIndex());
00057 EXPECT_FALSE(iterator.isPastEnd());
00058 }
00059
00060 EXPECT_EQ(40, i);
00061 EXPECT_TRUE(iterator.isPastEnd());
00062 EXPECT_TRUE((map["layer"].array() == 1.0f).all());
00063 }