outlier_removal.cpp
Go to the documentation of this file.
1 
6 #include "filters.hpp"
7 #include <iostream>
8 
11 
12 namespace mitre_fast_layered_map
13 {
14 
16 {
17 }
18 
20 {
21 }
22 
24 {
25  // Load Parameters
26  if (!OutlierRemoval::getParam(std::string("layer"), layer_))
27  {
28  ROS_ERROR("Outlier Removal did not find parameter layer.");
29  return false;
30  }
31 
32  ROS_INFO("Outlier Removal using layer: %s", layer_.c_str());
33 
34  return true;
35 }
36 
42 {
43  if (!_mapIn.exists(layer_))
44  {
45  ROS_ERROR("Layer %s does not exist in this map.", layer_.c_str());
46  return false;
47  }
48 
49  _mapOut = _mapIn;
50  grid_map::Matrix& outlierLayer = _mapOut[layer_];
51  for(grid_map::GridMapIterator it(_mapOut); !it.isPastEnd(); ++it)
52  {
53  const grid_map::Index index(*it);
54 
55  // Check if the cell is claimed to be occupied, but if we should consider it an outlier
56  if(outlierLayer(index(0), index(1)) == 100 && IsOutlierPoint(_mapOut, index))
57  {
58  outlierLayer(index(0), index(1)) = 0;
59  }
60 
61  }
62 
63  return true;
64 }
65 
80 {
82  _map.getPosition(_index, pos);
83 
84  // Use resolution to check all surrounding cells
85  double res = _map.getResolution();
86 
87  /* Position + mat.col(i) = position of a surrounding cell
88  Example: All surrounding cells are the contents plus position
89 
90  res = resolution
91  pos(x/y) = position x or position y
92 
93  [(-res, res)], [(0, res)], [(res, res)],
94  [(-res, 0)], [(posx, posy)], [(res, 0)],
95  [(-res, -res)], [(0, -res)], [(res, -res)]
96  */
97  Eigen::MatrixXd mat(2, 8);
98  // Values from matrix above in column major order
99  mat <<
100  -res, -res, -res, 0, 0, res, res, res,
101  res, 0 , -res, res, -res, res, 0, -res;
102 
103  for(int i = 0; i < mat.cols(); i++)
104  {
105  const grid_map::Position cellPos = pos + mat.col(i);
106 
107  // Boundary check to make sure the position is within the map
108  if(_map.isInside(cellPos) && _map.atPosition(layer_, cellPos) == 100)
109  {
110  return false;
111  }
112  }
113 
114  // If no surrounding cell was occupied, return that this is an outlier.
115  return true;
116 
117 }
118 
119 } // namespace mitre_fast_layered_map
120 
121 
Eigen::Array2i Index
float & atPosition(const std::string &layer, const Position &position)
bool getPosition(const Index &index, Position &position) const
Eigen::MatrixXf Matrix
bool getParam(const std::string &name, std::string &value)
bool exists(const std::string &layer) const
std::string layer_
Layer of grid map to perform outlier removal on.
Definition: filters.hpp:78
double getResolution() const
bool isInside(const Position &position) const
Eigen::Vector2d Position
#define ROS_INFO(...)
bool IsOutlierPoint(grid_map::GridMap &, const grid_map::Index &)
Algorithm to determine if an occupied cell should be considered an outlier.
virtual bool update(const grid_map::GridMap &_mapIn, grid_map::GridMap &_mapOut)
Filters that operate on a grid map instance.
#define ROS_ERROR(...)
PLUGINLIB_EXPORT_CLASS(mitre_fast_layered_map::OutlierRemoval, filters::FilterBase< grid_map::GridMap >)


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