test/cost_map.cpp
Go to the documentation of this file.
1 
4 /*****************************************************************************
5 ** Includes
6 *****************************************************************************/
7 
8 #include <gtest/gtest.h>
9 
10 // Math
11 #include <math.h>
12 #include "../include/cost_map_core/cost_map.hpp"
13 
14 using namespace std;
15 using namespace cost_map;
16 
17 TEST(CostMap, Move)
18 {
19  CostMap map;
20  map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
21  map.add("layer", 0.0);
22  map.setBasicLayers(map.getLayers());
23  std::vector<BufferRegion> regions;
24  map.move(Position(-3.0, -2.0), regions);
25  Index startIndex = map.getStartIndex();
26 
27  EXPECT_EQ(3, startIndex(0));
28  EXPECT_EQ(2, startIndex(1));
29 
30  // costmaps always currently return true
31  EXPECT_FALSE(map.isValid(Index(0, 0))); // TODO Check entire map.
32  EXPECT_TRUE(map.isValid(Index(3, 2)));
33  EXPECT_FALSE(map.isValid(Index(2, 2)));
34  EXPECT_FALSE(map.isValid(Index(3, 1)));
35  EXPECT_TRUE(map.isValid(Index(7, 4)));
36 
37  EXPECT_EQ(2, regions.size());
38  EXPECT_EQ(0, regions[0].getStartIndex()[0]);
39  EXPECT_EQ(0, regions[0].getStartIndex()[1]);
40  EXPECT_EQ(3, regions[0].getSize()[0]);
41  EXPECT_EQ(5, regions[0].getSize()[1]);
42  EXPECT_EQ(0, regions[1].getStartIndex()[0]);
43  EXPECT_EQ(0, regions[1].getStartIndex()[1]);
44  EXPECT_EQ(8, regions[1].getSize()[0]);
45  EXPECT_EQ(2, regions[1].getSize()[1]);
46 }
47 
48 
49 TEST(AddDataFrom, extendMapAligned)
50 {
51  CostMap map1, map2;
52  map1.setGeometry(Length(5.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(5, 5)
53  map1.add("zero", 0);
54  map1.add("one", 1);
55  map1.setBasicLayers(map1.getLayers());
56 
57  map2.setGeometry(Length(3.1, 3.1), 1.0, Position(2.0, 2.0));
58  map2.add("one", 2);
59  map2.add("two", 3);
60  map2.setBasicLayers(map1.getLayers());
61 
62  EXPECT_FALSE(map1.isInside(Position(3.0, 3.0)));
63 
64  map1.addDataFrom(map2, true, true, true);
65 
66  EXPECT_TRUE(map1.exists("two"));
67  EXPECT_TRUE(map1.isInside(Position(3.0, 3.0)));
68  EXPECT_DOUBLE_EQ(6.0, map1.getLength().x());
69  EXPECT_DOUBLE_EQ(6.0, map1.getLength().y());
70  EXPECT_DOUBLE_EQ(0.5, map1.getPosition().x());
71  EXPECT_DOUBLE_EQ(0.5, map1.getPosition().y());
72  EXPECT_EQ(2, static_cast<int>(map1.atPosition("one", Position(2, 2))));
73  EXPECT_EQ(1, static_cast<int>(map1.atPosition("one", Position(-2, -2))));
74  EXPECT_EQ(0, static_cast<int>(map1.atPosition("zero", Position(0.0, 0.0))));
75 }
76 
77 TEST(AddDataFrom, extendMapNotAligned)
78 {
79  CostMap map1, map2;
80  map1.setGeometry(Length(6.1, 6.1), 1.0, Position(0.0, 0.0)); // bufferSize(6, 6)
81  map1.add("no_information");
82  map1.add("one", 1);
83  map1.add("zero", 0);
84  map1.setBasicLayers(map1.getLayers());
85 
86  map2.setGeometry(Length(3.1, 3.1), 1.0, Position(3.2, 3.2));
87  map2.add("no_information", 1);
88  map2.add("one", 1);
89  map2.add("two", 2);
90  map2.setBasicLayers(map1.getLayers());
91 
92  std::vector<std::string> stringVector;
93  stringVector.push_back("no_information");
94  map1.addDataFrom(map2, true, false, false, stringVector);
95  Index index;
96  map1.getIndex(Position(-2, -2), index);
97 
98  EXPECT_FALSE(map1.exists("two"));
99  EXPECT_TRUE(map1.isInside(Position(4.0, 4.0)));
100  EXPECT_DOUBLE_EQ(8.0, map1.getLength().x());
101  EXPECT_DOUBLE_EQ(8.0, map1.getLength().y());
102  EXPECT_DOUBLE_EQ(1.0, map1.getPosition().x());
103  EXPECT_DOUBLE_EQ(1.0, map1.getPosition().y());
104  EXPECT_FALSE(map1.isValid(index, "no_information"));
105  EXPECT_DOUBLE_EQ(1, static_cast<int>(map1.atPosition("one", Position(0.0, 0.0))));
106  EXPECT_DOUBLE_EQ(1, static_cast<int>(map1.atPosition("no_information", Position(3.0, 3.0))));
107 }
108 
109 TEST(AddDataFrom, copyData)
110 {
111  CostMap map1, map2;
112  map1.setGeometry(Length(5.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(5, 5)
113  map1.add("zero", 0.0);
114  map1.add("one");
115  map1.setBasicLayers(map1.getLayers());
116 
117  map2.setGeometry(Length(3.1, 3.1), 1.0, Position(2.0, 2.0));
118  map2.add("one", 1.0);
119  map2.add("two", 2.0);
120  map2.setBasicLayers(map1.getLayers());
121 
122  map1.addDataFrom(map2, false, false, true);
123  Index index;
124  map1.getIndex(Position(-2, -2), index);
125 
126  EXPECT_TRUE(map1.exists("two"));
127  EXPECT_FALSE(map1.isInside(Position(3.0, 3.0)));
128  EXPECT_DOUBLE_EQ(5.0, map1.getLength().x());
129  EXPECT_DOUBLE_EQ(5.0, map1.getLength().y());
130  EXPECT_DOUBLE_EQ(0.0, map1.getPosition().x());
131  EXPECT_DOUBLE_EQ(0.0, map1.getPosition().y());
132  EXPECT_DOUBLE_EQ(1, static_cast<int>(map1.atPosition("one", Position(2, 2))));
133  EXPECT_FALSE(map1.isValid(index, "one"));
134  EXPECT_DOUBLE_EQ(0, static_cast<int>(map1.atPosition("zero", Position(0.0, 0.0))));
135 }
136 
137 int main(int argc, char **argv)
138 {
139  testing::InitGoogleTest(&argc, argv);
140  srand((int)time(0));
141  return RUN_ALL_TESTS();
142 }
Eigen::Array2i Index
const Length & getLength() const
bool isValid(const Index &index) const
void add(const std::string &layer, const DataType value=NO_INFORMATION)
bool addDataFrom(const CostMap &other, bool extendMap, bool overwriteData, bool copyAllLayers, std::vector< std::string > layers=std::vector< std::string >())
int main(int argc, char **argv)
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
TEST(CostMap, Move)
void setBasicLayers(const std::vector< std::string > &basicLayers)
DataType & atPosition(const std::string &layer, const Position &position)
Eigen::Vector2d Position
bool getPosition(const Index &index, Position &position) const
bool move(const Position &position, std::vector< BufferRegion > &newRegions)
bool exists(const std::string &layer) const
const Index & getStartIndex() const
const std::vector< std::string > & getLayers() const
bool isInside(const Position &position) const
bool getIndex(const Position &position, Index &index) const
Eigen::Array2d Length


cost_map_core
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:03:41