threshold_filter.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 (!ThresholdFilter::getParam(std::string("value_layer"), valueLayerStr_))
27  {
28  ROS_ERROR("Bayes update did not find parameter value_layer.");
29  return false;
30  }
31 
32  if (!ThresholdFilter::getParam(std::string("output_layer"), outputLayerStr_))
33  {
34  ROS_ERROR("Bayes update did not find parameter output_layer.");
35  return false;
36  }
37 
38  double tempThreshold;
39  if (!ThresholdFilter::getParam(std::string("threshold"), tempThreshold))
40  {
41  ROS_ERROR("Bayes update did not find parameter threshold.");
42  return false;
43  }
44 
45  double tempOutputValue;
46  if (!ThresholdFilter::getParam(std::string("output_value"), tempOutputValue))
47  {
48  ROS_ERROR("Threshold filter did not find parameter output_value.");
49  return false;
50  }
51 
52  // ROS only allows doubles on parameter server, but gridmap uses floats
53  // so we get as double and cast to float
54  threshold_ = (float) tempThreshold;
55  outputValue_ = (float) tempOutputValue;
56 
57  ROS_INFO("Threshold Filter configured with parameters: Value Layer = %s, Output Layer = %s,"
58  " Threshold = %f, Output Value = %f", valueLayerStr_.c_str(), outputLayerStr_.c_str(), threshold_, outputValue_);
59 
60  return true;
61  }
62 
64  {
65  if (!_mapIn.exists(valueLayerStr_))
66  {
67  ROS_ERROR("Layer %s does not exist in this map.", valueLayerStr_.c_str());
68  return false;
69  }
70  else if (!_mapIn.exists(outputLayerStr_))
71  {
72  ROS_ERROR("Layer %s does not exist in this map.", outputLayerStr_.c_str());
73  return false;
74  }
75 
76  _mapOut = _mapIn;
77  grid_map::Matrix &valueLayer = _mapOut[valueLayerStr_];
78  grid_map::Matrix &outputLayer = _mapOut[outputLayerStr_];
79 
80  // Calculation -> Map value layer to matrix of 1's and 0's, then
81  // multiply by the outputValue desired.
82  outputLayer = valueLayer.unaryExpr([this](const float x) {
83  return (float)(x >= threshold_); // 1 if true, 0 if false
84  }) * outputValue_;
85 
86  return true;
87  }
88 } // namespace mitre_fast_layered_map
89 
Eigen::MatrixXf Matrix
bool getParam(const std::string &name, std::string &value)
bool exists(const std::string &layer) const
#define ROS_INFO(...)
PLUGINLIB_EXPORT_CLASS(mitre_fast_layered_map::ThresholdFilter, filters::FilterBase< grid_map::GridMap >)
TFSIMD_FORCE_INLINE const tfScalar & x() const
virtual bool update(const grid_map::GridMap &_mapIn, grid_map::GridMap &_mapOut)
Filters that operate on a grid map instance.
#define ROS_ERROR(...)


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