test_filter_outlier_removal.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <ros/ros.h>
3 #include <filters/filter_chain.h>
4 #include "filters.hpp"
5 
6 TEST(OutlierRemoval, active)
7 {
8  EXPECT_EQ(0, 0);
9 }
10 
11 TEST(OutlierRemoval, layer_doesnt_exist)
12 {
13  ros::NodeHandle nh("~");
14  grid_map::GridMap gridMap({"random_layer"});
15  gridMap.setFrameId("random");
16  gridMap.setGeometry(grid_map::Length(3, 3), 1);
17 
18  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
19 
20  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
21  {
22  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
23  }
24 
25  grid_map::GridMap outMap;
26  EXPECT_FALSE(filterChain.update(gridMap, outMap));
27 }
28 
35 TEST(OutlierRemoval, remove_middle_one)
36 {
37  ros::NodeHandle nh("~");
38  grid_map::GridMap gridMap({"map"});
39  gridMap.setFrameId("map");
40  gridMap.setGeometry(grid_map::Length(3, 3), 1);
41 
42  // Prefilled point
43  gridMap.at("map", grid_map::Index(1, 1)) = 100;
44 
45  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
46 
47  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
48  {
49  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
50  }
51 
52  if(!filterChain.update(gridMap, gridMap))
53  {
54  GTEST_FATAL_FAILURE_("Unable to update grid map.");
55  }
56 
57  EXPECT_EQ(0, gridMap.at("map", grid_map::Index(1, 1)));
58 }
59 
66 TEST(OutlierRemoval, remove_perimeter_one)
67 {
68  ros::NodeHandle nh("~");
69  grid_map::GridMap gridMap({"map"});
70  gridMap.setFrameId("map");
71  gridMap.setGeometry(grid_map::Length(3, 3), 1);
72 
73  // Prefilled points
74  gridMap.at("map", grid_map::Index(1, 0)) = 100;
75  gridMap.at("map", grid_map::Index(0, 2)) = 100;
76 
77  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
78 
79  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
80  {
81  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
82  }
83 
84  if(!filterChain.update(gridMap, gridMap))
85  {
86  GTEST_FATAL_FAILURE_("Unable to update grid map.");
87  }
88 
89  EXPECT_EQ(0, gridMap.at("map", grid_map::Index(1, 0)));
90  EXPECT_EQ(0, gridMap.at("map", grid_map::Index(0, 2)));
91 }
92 
100 TEST(OutlierRemoval, preserve_points)
101 {
102  ros::NodeHandle nh("~");
103  grid_map::GridMap gridMap({"map"});
104  gridMap.setFrameId("map");
105  gridMap.setGeometry(grid_map::Length(3, 3), 1);
106  gridMap.at("map", grid_map::Index(1, 1)) = 100; // Prefilled center point
107 
108  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
109 
110  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
111  {
112  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
113  }
114 
115  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
116  {
117  const grid_map::Index index(*it);
118 
119  // Skip over prefilled center point
120  if(index(0) == 1 && index(1) == 1)
121  {
122  continue;
123  }
124 
125  // Set cell with index to 100
126  gridMap.at("map", index) = 100;
127 
128  if(!filterChain.update(gridMap, gridMap))
129  {
130  GTEST_FATAL_FAILURE_("Unable to update grid map.");
131  }
132 
133  // Expect both center point and earlier set point to still be 100
134  EXPECT_EQ(100, gridMap.at("map", grid_map::Index(1, 1)));
135  EXPECT_EQ(100, gridMap.at("map", index));
136 
137  // Set index to 0 so it doesn't affect next test
138  gridMap.at("map", index) = 0;
139  }
140 
141 }
142 
143 
154 TEST(OutlierRemoval, large_case)
155 {
156  ros::NodeHandle nh("~");
157  grid_map::GridMap gridMap({"map"});
158  gridMap.setFrameId("map");
159  gridMap.setGeometry(grid_map::Length(5, 5), 1);
160 
161  // Prefilled points
162  gridMap.at("map", grid_map::Index(0, 0)) = 100;
163  gridMap.at("map", grid_map::Index(1, 1)) = 100;
164  gridMap.at("map", grid_map::Index(2, 1)) = 100;
165  gridMap.at("map", grid_map::Index(3, 1)) = 100;
166  gridMap.at("map", grid_map::Index(1, 3)) = 100;
167  gridMap.at("map", grid_map::Index(4, 4)) = 100;
168 
169  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
170 
171  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
172  {
173  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
174  }
175 
176  if(!filterChain.update(gridMap, gridMap))
177  {
178  GTEST_FATAL_FAILURE_("Unable to update grid map.");
179  }
180 
181  EXPECT_EQ(100, gridMap.at("map", grid_map::Index(0, 0)));
182  EXPECT_EQ(100, gridMap.at("map", grid_map::Index(1, 1)));
183  EXPECT_EQ(100, gridMap.at("map", grid_map::Index(2, 1)));
184  EXPECT_EQ(100, gridMap.at("map", grid_map::Index(3, 1)));
185  EXPECT_EQ(0, gridMap.at("map", grid_map::Index(1, 3)));
186  EXPECT_EQ(0, gridMap.at("map", grid_map::Index(4, 4)));
187 }
Eigen::Array2i Index
TEST(OutlierRemoval, active)
bool update(const T &data_in, T &data_out)
bool configure(std::string param_name, ros::NodeHandle node=ros::NodeHandle())
Filters that operate on a grid map instance.
void setFrameId(const std::string &frameId)
Eigen::Array2d Length


mitre_fast_layered_map
Author(s):
autogenerated on Thu Mar 11 2021 03:06:49