GridMapCvProcessingTest.cpp
Go to the documentation of this file.
1 /*
2  * GridMapCvProcessingTest.cpp
3  *
4  * Created on: May 3, 2017
5  * Author: Peter Fankhauser
6  */
7 
9 
12 
13 // gtest
14 #include <gtest/gtest.h>
15 
16 // OpenCV
17 #include <cv_bridge/cv_bridge.h>
18 
19 using namespace std;
20 using namespace grid_map;
21 
22 TEST(GridMapCvProcessing, changeResolution)
23 {
24  // Create grid map.
25  GridMap mapIn;
26  mapIn.setGeometry(grid_map::Length(2.0, 1.0), 0.01);
27  mapIn.add("layer", 1.0);
28  for (grid_map::CircleIterator iterator(mapIn, mapIn.getPosition(), 0.2); !iterator.isPastEnd(); ++iterator) {
29  mapIn.at("layer", *iterator) = 2.0;
30  }
31 
32  // Change resolution.
33  GridMap mapOut;
34  EXPECT_TRUE(GridMapCvProcessing::changeResolution(mapIn, mapOut, 0.1));
35 
36  // Check data.
37  EXPECT_TRUE((mapIn.getLength() == mapOut.getLength()).all());
38  EXPECT_TRUE(mapIn.getPosition() == mapOut.getPosition());
39  EXPECT_TRUE((mapIn.getSize() == mapOut.getSize() * 10).all());
40  EXPECT_EQ(mapIn["layer"](0, 0), mapOut["layer"](0, 0)); // Corner.
41  EXPECT_EQ(mapIn.atPosition("layer", mapIn.getPosition()), mapOut.atPosition("layer", mapOut.getPosition())); // Center.
42 }
43 
44 TEST(GridMapCvProcessing, changeResolutionForMovedMap)
45 {
46  // Create grid map.
47  GridMap mapIn;
48  mapIn.setGeometry(grid_map::Length(2.0, 1.0), 0.01);
49  Position position(0.3, 0.4);
50  mapIn.move(position);
51  mapIn.add("layer", 1.0);
52  for (grid_map::CircleIterator iterator(mapIn, position, 0.2); !iterator.isPastEnd(); ++iterator) {
53  mapIn.at("layer", *iterator) = 2.0;
54  }
55 
56  // Change resolution.
57  GridMap mapOut;
58  EXPECT_TRUE(GridMapCvProcessing::changeResolution(mapIn, mapOut, 0.1));
59 
60  // Check data.
61  EXPECT_TRUE((mapIn.getLength() == mapOut.getLength()).all());
62  EXPECT_TRUE(mapIn.getPosition() == mapOut.getPosition());
63  EXPECT_TRUE((mapIn.getSize() == mapOut.getSize() * 10).all());
64  EXPECT_EQ(mapIn["layer"](0, 0), mapOut["layer"](0, 0)); // Corner.
65  EXPECT_EQ(mapIn.atPosition("layer", mapIn.getPosition()), mapOut.atPosition("layer", mapOut.getPosition())); // Center.
66 }
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
bool move(const Position &position, std::vector< BufferRegion > &newRegions)
Eigen::Vector2d Position
float & at(const std::string &layer, const Index &index)
void add(const std::string &layer, const double value=NAN)
TEST(GridMapCvProcessing, changeResolution)
Eigen::Array2d Length
const Size & getSize() const


grid_map_cv
Author(s): Péter Fankhauser
autogenerated on Tue Jun 25 2019 20:02:13