12 #include <gtest/gtest.h> 23 mapIn.
add(
"layer", 1.0);
25 mapIn.
at(
"layer", *iterator) = 2.0;
30 EXPECT_TRUE(GridMapCvProcessing::changeResolution(mapIn, mapOut, 0.1));
36 EXPECT_EQ(mapIn[
"layer"](0, 0), mapOut[
"layer"](0, 0));
46 mapIn.
add(
"layer", 1.0);
48 mapIn.
at(
"layer", *iterator) = 2.0;
53 EXPECT_TRUE(GridMapCvProcessing::changeResolution(mapIn, mapOut, 0.1));
59 EXPECT_EQ(mapIn[
"layer"](0, 0), mapOut[
"layer"](0, 0));
79 const auto heightLayerName =
"height";
82 map.
add(heightLayerName, 0.0);
84 map.
get(heightLayerName)(0, 0) = 1.0;
87 Eigen::Isometry3d transform = Eigen::Translation3d(0, 0, 0) * Eigen::AngleAxisd(M_PI / 2, Vector3::UnitZ());
90 const GridMap transformedMap = GridMapCvProcessing::getTransformedMap(
GridMap(map), transform, heightLayerName, map.
getFrameId());
96 EXPECT_EQ(map.
get(heightLayerName).size(), transformedMap.
get(heightLayerName).size());
99 EXPECT_DOUBLE_EQ(map.
get(heightLayerName)(0, 0), transformedMap.
get(heightLayerName)(19, 0));
100 EXPECT_DOUBLE_EQ(transformedMap.
get(heightLayerName)(19, 0), 1.0);
123 const auto heightLayerName =
"height";
126 map.
add(heightLayerName, 0.0);
128 map.
get(heightLayerName)(0, 0) = 1.0;
131 Eigen::Isometry3d transform = Eigen::Translation3d(0, 0, 0) * Eigen::AngleAxisd(M_PI, Vector3::UnitZ());
134 const GridMap transformedMap = GridMapCvProcessing::getTransformedMap(
GridMap(map), transform, heightLayerName, map.
getFrameId());
141 EXPECT_EQ(map.
get(heightLayerName).size(), transformedMap.
get(heightLayerName).size());
144 EXPECT_DOUBLE_EQ(map.
get(heightLayerName)(0, 0), transformedMap.
get(heightLayerName)(9, 19));
145 EXPECT_DOUBLE_EQ(transformedMap.
get(heightLayerName)(9, 19), 1.0);
168 const auto heightLayerName =
"height";
171 map.
add(heightLayerName, 0.0);
173 map.
get(heightLayerName)(0, 0) = 1.0;
176 Eigen::Isometry3d transform = Eigen::Translation3d(0, 0, 0) * Eigen::AngleAxisd(-M_PI / 2, Vector3::UnitZ());
179 const GridMap transformedMap = GridMapCvProcessing::getTransformedMap(
GridMap(map), transform, heightLayerName, map.
getFrameId());
186 EXPECT_EQ(map.
get(heightLayerName).size(), transformedMap.
get(heightLayerName).size());
189 EXPECT_DOUBLE_EQ(map.
get(heightLayerName)(0, 0), transformedMap.
get(heightLayerName)(0, 9));
190 EXPECT_DOUBLE_EQ(transformedMap.
get(heightLayerName)(0, 9), 1.0);
214 const auto heightLayerName =
"height";
217 map.
add(heightLayerName, 0.0);
219 map.
get(heightLayerName)(0, 0) = 1.0;
222 Eigen::Isometry3d transform = Eigen::Translation3d(0, 0, 0) * Eigen::AngleAxisd(M_PI * 2, Vector3::UnitZ());
225 const GridMap transformedMap = GridMapCvProcessing::getTransformedMap(
GridMap(map), transform, heightLayerName, map.
getFrameId());
232 EXPECT_EQ(map.
get(heightLayerName).size(), transformedMap.
get(heightLayerName).size());
235 EXPECT_DOUBLE_EQ(map.
get(heightLayerName)(0, 0), transformedMap.
get(heightLayerName)(0, 0));
236 EXPECT_DOUBLE_EQ(transformedMap.
get(heightLayerName)(0, 0), 1.0);
268 const auto heightLayerName =
"height";
269 double resolution = 0.02;
271 map.
add(heightLayerName, 1.0);
275 Eigen::Isometry3d transform = Eigen::Translation3d(0, 0, 0) * Eigen::AngleAxisd(M_PI / 4, Vector3::UnitZ());
278 const GridMap transformedMap = GridMapCvProcessing::getTransformedMap(
GridMap(map), transform, heightLayerName, map.
getFrameId());
283 EXPECT_NEAR(transformedMap.
getLength().x(), 2.121, resolution);
284 EXPECT_NEAR(transformedMap.
getLength().y(), 2.121, resolution);
287 EXPECT_TRUE(transformedMap.
get(heightLayerName).hasNaN());
288 EXPECT_NEAR(transformedMap.
get(heightLayerName).sumOfFinites() / map.
get(heightLayerName).size(), 1.0, 1e-2);
294 const auto heightLayerName =
"height";
295 const auto otherLayerName =
"other_layer";
297 map.
add(heightLayerName, 0.0);
298 map.
add(otherLayerName, 0.0);
302 Eigen::Isometry3d transform = Eigen::Translation3d(1, -0.5, 0.2) * Eigen::AngleAxisd(0, Vector3::UnitZ());
305 const GridMap transformedMap = GridMapCvProcessing::getTransformedMap(
GridMap(map), transform, heightLayerName, map.
getFrameId());
310 EXPECT_EQ(map.
get(heightLayerName).size(), transformedMap.
get(heightLayerName).size());
313 EXPECT_NEAR(transformedMap.
getPosition().x(), transform.translation().x(), 1e-6);
314 EXPECT_NEAR(transformedMap.
getPosition().y(), transform.translation().y(), 1e-6);
317 EXPECT_NEAR(map.
get(heightLayerName)(0, 0) + transform.translation().z(), transformedMap.
get(heightLayerName)(0, 0), 1e-6);
320 EXPECT_NEAR(map.
get(otherLayerName)(0, 0), transformedMap.
get(otherLayerName)(0, 0), 1e-6);
326 const auto heightLayerName =
"height";
328 map.
add(heightLayerName, 0.0);
332 Eigen::Isometry3d transform = Eigen::Translation3d(0, 0, 0) * Eigen::AngleAxisd(M_PI / 8, Vector3::UnitY());
335 ASSERT_ANY_THROW(
const GridMap transformedMap =
336 GridMapCvProcessing::getTransformedMap(
GridMap(map), transform, heightLayerName, map.
getFrameId()));
351 const auto heightLayerName =
"height";
353 map.
add(heightLayerName, 0.0);
357 Eigen::Isometry3d transform = Eigen::Translation3d(1, -0.5, 0.2) * Eigen::AngleAxisd(M_PI / 4, Vector3::UnitZ());
361 long averageTime = 0;
362 long minTime = std::numeric_limits<long>::max();
363 long maxTime = std::numeric_limits<long>::lowest();
366 size_t numberOfSamples = 100;
367 for (
size_t sampleNumber = 0; sampleNumber < numberOfSamples; sampleNumber++) {
368 auto timestampBefore = std::chrono::high_resolution_clock::now();
369 const GridMap transformedMap = GridMapCvProcessing::getTransformedMap(
GridMap(map), transform, heightLayerName, map.
getFrameId());
370 auto timestampAfter = std::chrono::high_resolution_clock::now();
372 long time = std::chrono::duration_cast<std::chrono::nanoseconds>(timestampAfter - timestampBefore).count();
374 if (time < minTime) {
377 if (time > maxTime) {
381 averageTime = sumTimes / numberOfSamples;
383 std::cout <<
"Transforming a 2 x 2 m GridMap with a resolution of 2 cm by 45° took: " << std::endl
384 <<
"avg: " << averageTime * 1e-6
f <<
"ms, \tmin: " << minTime * 1e-6
f <<
"ms, \tmax " << maxTime * 1e-6
f <<
"ms." << std::endl;
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)
bool getPosition(const Index &index, Position &position) const
void setBasicLayers(const std::vector< std::string > &basicLayers)
const std::string & getFrameId() const
bool move(const Position &position, std::vector< BufferRegion > &newRegions)
const std::vector< std::string > & getLayers() const
const Matrix & get(const std::string &layer) const
float & at(const std::string &layer, const Index &index)
void add(const std::string &layer, const double value=NAN)
TEST(GridMapCvProcessing, changeResolution)
const Size & getSize() const