12 #include <gtest/gtest.h> 22 GridMap map({
"layer_a",
"layer_b"});
24 map[
"layer_a"].setConstant(1.0);
25 map[
"layer_b"].setConstant(2.0);
27 EXPECT_EQ(map.getSize()[0], mapCopy.
getSize()[0]);
28 EXPECT_EQ(map.getSize()[1], mapCopy.
getSize()[1]);
29 EXPECT_EQ(map.getLength().x(), mapCopy.
getLength().x());
30 EXPECT_EQ(map.getLength().y(), mapCopy.
getLength().y());
31 EXPECT_EQ(map.getPosition().x(), mapCopy.
getPosition().x());
32 EXPECT_EQ(map.getPosition().y(), mapCopy.
getPosition().y());
33 EXPECT_EQ(map.getLayers().size(), mapCopy.
getLayers().size());
34 EXPECT_EQ(map[
"layer_a"](0, 0), mapCopy[
"layer_a"](0, 0));
35 EXPECT_EQ(map[
"layer_b"](0, 0), mapCopy[
"layer_b"](0, 0));
40 GridMap map({
"layer_a",
"layer_b"});
42 map[
"layer_a"].setConstant(1.0);
43 map[
"layer_b"].setConstant(2.0);
46 EXPECT_EQ(map.getSize()[0], mapCopy.
getSize()[0]);
47 EXPECT_EQ(map.getSize()[1], mapCopy.
getSize()[1]);
48 EXPECT_EQ(map.getLength().x(), mapCopy.
getLength().x());
49 EXPECT_EQ(map.getLength().y(), mapCopy.
getLength().y());
50 EXPECT_EQ(map.getPosition().x(), mapCopy.
getPosition().x());
51 EXPECT_EQ(map.getPosition().y(), mapCopy.
getPosition().y());
52 EXPECT_EQ(map.getLayers().size(), mapCopy.
getLayers().size());
53 EXPECT_EQ(map[
"layer_a"](0, 0), mapCopy[
"layer_a"](0, 0));
54 EXPECT_EQ(map[
"layer_b"](0, 0), mapCopy[
"layer_b"](0, 0));
61 map.
add(
"layer", 0.0);
63 std::vector<BufferRegion> regions;
67 EXPECT_EQ(3, startIndex(0));
68 EXPECT_EQ(2, startIndex(1));
76 EXPECT_EQ(2, regions.size());
77 EXPECT_EQ(0, regions[0].getStartIndex()[0]);
78 EXPECT_EQ(0, regions[0].getStartIndex()[1]);
79 EXPECT_EQ(3, regions[0].getSize()[0]);
80 EXPECT_EQ(5, regions[0].getSize()[1]);
81 EXPECT_EQ(0, regions[1].getStartIndex()[0]);
82 EXPECT_EQ(0, regions[1].getStartIndex()[1]);
83 EXPECT_EQ(8, regions[1].getSize()[0]);
84 EXPECT_EQ(2, regions[1].getSize()[1]);
91 const auto heightLayerName =
"height";
94 map.
add(heightLayerName, 0.0);
96 map.
get(heightLayerName)(0,0) = 1.0;
99 Eigen::Isometry3d transform;
101 transform.translation().x() = 0.0;
102 transform.translation().y() = 0.0;
103 transform.translation().z() = 0.0;
105 transform.linear()(0,0) = 0.0;
106 transform.linear()(0,1) = -1.0;
107 transform.linear()(0,2) = 0.0;
109 transform.linear()(1,0) = 1.0;
110 transform.linear()(1,1) = 0.0;
111 transform.linear()(1,2) = 0.0;
113 transform.linear()(2,0) = 0.0;
114 transform.linear()(2,1) = 0.0;
115 transform.linear()(2,2) = 1.0;
123 EXPECT_EQ(map.
get(heightLayerName).size(), transformedMap.
get(heightLayerName).size());
124 EXPECT_DOUBLE_EQ(map.
get(heightLayerName)(0,0), transformedMap.
get(heightLayerName)(19,0));
127 TEST(AddDataFrom, ExtendMapAligned)
131 map1.
add(
"zero", 0.0);
132 map1.
add(
"one", 1.0);
136 map2.
add(
"one", 1.1);
137 map2.
add(
"two", 2.0);
142 EXPECT_TRUE(map1.
exists(
"two"));
144 EXPECT_DOUBLE_EQ(6.0, map1.
getLength().x());
145 EXPECT_DOUBLE_EQ(6.0, map1.
getLength().y());
153 TEST(AddDataFrom, ExtendMapNotAligned)
158 map1.
add(
"one", 1.0);
159 map1.
add(
"zero", 0.0);
163 map2.
add(
"nan", 1.0);
164 map2.
add(
"one", 1.1);
165 map2.
add(
"two", 2.0);
168 std::vector<std::string> stringVector;
169 stringVector.push_back(
"nan");
170 map1.
addDataFrom(map2,
true,
false,
false, stringVector);
174 EXPECT_FALSE(map1.
exists(
"two"));
176 EXPECT_DOUBLE_EQ(8.0, map1.
getLength().x());
177 EXPECT_DOUBLE_EQ(8.0, map1.
getLength().y());
180 EXPECT_FALSE(map1.
isValid(index,
"nan"));
189 map1.
add(
"zero", 0.0);
194 map2.
add(
"one", 1.0);
195 map2.
add(
"two", 2.0);
202 EXPECT_TRUE(map1.
exists(
"two"));
204 EXPECT_DOUBLE_EQ(5.0, map1.
getLength().x());
205 EXPECT_DOUBLE_EQ(5.0, map1.
getLength().y());
209 EXPECT_FALSE(map1.
isValid(index,
"one"));
213 TEST(ValueAtPosition, NearestNeighbor)
218 map.at(
"types",
Index(0,0)) = 0.5;
219 map.at(
"types",
Index(0,1)) = 3.8;
220 map.at(
"types",
Index(0,2)) = 2.0;
221 map.at(
"types",
Index(1,0)) = 2.1;
222 map.at(
"types",
Index(1,1)) = 1.0;
223 map.at(
"types",
Index(1,2)) = 2.0;
224 map.at(
"types",
Index(2,0)) = 1.0;
225 map.at(
"types",
Index(2,1)) = 2.0;
226 map.at(
"types",
Index(2,2)) = 2.0;
230 value = map.atPosition(
"types",
Position(1.35,-0.4));
231 EXPECT_DOUBLE_EQ((
float)3.8, value);
233 value = map.atPosition(
"types",
Position(-0.3,0.0));
234 EXPECT_DOUBLE_EQ(1.0, value);
237 TEST(ValueAtPosition, LinearInterpolated)
242 map.at(
"types",
Index(0,0)) = 0.5;
243 map.at(
"types",
Index(0,1)) = 3.8;
244 map.at(
"types",
Index(0,2)) = 2.0;
245 map.at(
"types",
Index(1,0)) = 2.1;
246 map.at(
"types",
Index(1,1)) = 1.0;
247 map.at(
"types",
Index(1,2)) = 2.0;
248 map.at(
"types",
Index(2,0)) = 1.0;
249 map.at(
"types",
Index(2,1)) = 2.0;
250 map.at(
"types",
Index(2,2)) = 2.0;
255 value = map.atPosition(
"types",
Position(-0.5,-1.2), InterpolationMethods::INTER_LINEAR);
256 EXPECT_DOUBLE_EQ(2.0, value);
258 value = map.atPosition(
"types",
Position(-0.5,0.0), InterpolationMethods::INTER_LINEAR);
259 EXPECT_DOUBLE_EQ(1.5, value);
261 value = map.atPosition(
"types",
Position(0.69,0.38), InterpolationMethods::INTER_LINEAR);
262 EXPECT_NEAR(2.1963200, value, 0.0000001);
const Length & getLength() const
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
float & atPosition(const std::string &layer, const Position &position)
const Index & getStartIndex() const
bool getPosition(const Index &index, Position &position) const
void setBasicLayers(const std::vector< std::string > &basicLayers)
const std::string & getFrameId() const
GridMap getTransformedMap(const Eigen::Isometry3d &transform, const std::string &heightLayerName, const std::string &newFrameId, const double sampleRatio=0.0) const
bool move(const Position &position, std::vector< BufferRegion > &newRegions)
bool addDataFrom(const GridMap &other, bool extendMap, bool overwriteData, bool copyAllLayers, std::vector< std::string > layers=std::vector< std::string >())
bool isValid(const Index &index) const
bool exists(const std::string &layer) const
TEST(GridMap, CopyConstructor)
const std::vector< std::string > & getLayers() const
bool isInside(const Position &position) const
const Matrix & get(const std::string &layer) const
void add(const std::string &layer, const double value=NAN)
bool getIndex(const Position &position, Index &index) const
const Size & getSize() const