ThresholdFilter.cpp
Go to the documentation of this file.
1 /*
2  * ThresholdFilter.cpp
3  *
4  * Created on: Mar 18, 2015
5  * Author: Martin Wermelinger, Peter Fankhauser
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
10 
13 
14 using namespace filters;
15 
16 namespace grid_map {
17 
18 template<typename T>
20  : useLowerThreshold_(false),
21  useUpperThreshold_(false),
22  lowerThreshold_(0.0),
23  upperThreshold_(1.0),
24  setTo_(0.5)
25 {
26 }
27 
28 template<typename T>
30 {
31 }
32 
33 template<typename T>
35 {
36  // Load Parameters
37  if (FilterBase<T>::getParam(std::string("lower_threshold"),
38  lowerThreshold_)) {
39  useLowerThreshold_ = true;
40  ROS_DEBUG("lower threshold = %f", lowerThreshold_);
41  }
42 
43  if (FilterBase<T>::getParam(std::string("upper_threshold"),
44  upperThreshold_)) {
45  useUpperThreshold_ = true;
46  ROS_DEBUG("upper threshold = %f", upperThreshold_);
47  }
48 
50  ROS_ERROR(
51  "ThresholdFilter did not find parameter 'lower_threshold' or 'upper_threshold',");
52  return false;
53  }
54 
56  ROS_ERROR(
57  "Set either 'lower_threshold' or 'upper_threshold'! Only one threshold can be used!");
58  return false;
59  }
60 
61  if (!FilterBase<T>::getParam(std::string("set_to"), setTo_)) {
62  ROS_ERROR("ThresholdFilter did not find parameter 'set_to'.");
63  return false;
64  }
65 
66  if (!FilterBase<T>::getParam(std::string("layer"), layer_)) {
67  ROS_ERROR("ThresholdFilter did not find parameter 'layer'.");
68  return false;
69  }
70 
71  return true;
72 }
73 
74 template<typename T>
75 bool ThresholdFilter<T>::update(const T& mapIn, T& mapOut)
76 {
77  mapOut = mapIn;
78 
79  // Check if layer exists.
80  if (!mapOut.exists(layer_)) {
81  ROS_ERROR("Check your threshold types! Type %s does not exist", layer_.c_str());
82  return false;
83  }
84 
85  // For each cell in map.
86  auto& data = mapOut[layer_];
87  for (grid_map::GridMapIterator iterator(mapOut); !iterator.isPastEnd(); ++iterator) {
88  if (!mapOut.isValid(*iterator, layer_)) continue;
89  const size_t i = iterator.getLinearIndex();
90  float& value = data(i);
91  if (useLowerThreshold_) if (value < lowerThreshold_) value = setTo_;
92  if (useUpperThreshold_) if (value > upperThreshold_) value = setTo_;
93  }
94 
95  return true;
96 }
97 
98 } /* namespace */
99 
virtual bool update(const T &mapIn, T &mapOut)
std::string layer_
Layer the threshold should be applied to.
double setTo_
If threshold triggered set to this value.
double upperThreshold_
Upper Threshold.
double lowerThreshold_
Lower Threshold.
bool useLowerThreshold_
Booleans to decide which threshold should be used.
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
#define ROS_ERROR(...)
#define ROS_DEBUG(...)


grid_map_filters
Author(s): Péter Fankhauser , Martin Wermelinger
autogenerated on Tue Jun 25 2019 20:02:22