MinInRadiusFilter.cpp
Go to the documentation of this file.
00001 /*
00002  * MinInRadiusFilter.cpp
00003  *
00004  *  Created on: May 3, 2017
00005  *      Author: Tanja Baumann, Peter Fankhauser
00006  *   Institute: ETH Zurich, Robotic Systems Lab
00007  */
00008 
00009 #include "grid_map_filters/MinInRadiusFilter.hpp"
00010 
00011 #include <grid_map_core/grid_map_core.hpp>
00012 #include <pluginlib/class_list_macros.h>
00013 
00014 using namespace filters;
00015 
00016 namespace grid_map {
00017 
00018 template<typename T>
00019 MinInRadiusFilter<T>::MinInRadiusFilter()
00020     : radius_(0.0)
00021 {
00022 }
00023 
00024 template<typename T>
00025 MinInRadiusFilter<T>::~MinInRadiusFilter()
00026 {
00027 }
00028 
00029 template<typename T>
00030 bool MinInRadiusFilter<T>::configure()
00031 {
00032   if (!FilterBase < T > ::getParam(std::string("radius"), radius_)) {
00033     ROS_ERROR("MinInRadius filter did not find parameter `radius`.");
00034     return false;
00035   }
00036 
00037   if (radius_ < 0.0) {
00038     ROS_ERROR("MinInRadius filter: Radius must be greater than zero.");
00039     return false;
00040   }
00041   ROS_DEBUG("Radius = %f.", radius_);
00042 
00043   if (!FilterBase < T > ::getParam(std::string("input_layer"), inputLayer_)) {
00044     ROS_ERROR("MinInRadius filter did not find parameter `input_layer`.");
00045     return false;
00046   }
00047 
00048   ROS_DEBUG("MinInRadius input layer is = %s.", inputLayer_.c_str());
00049 
00050   if (!FilterBase < T > ::getParam(std::string("output_layer"), outputLayer_)) {
00051     ROS_ERROR("Step filter did not find parameter `output_layer`.");
00052     return false;
00053   }
00054 
00055   ROS_DEBUG("MinInRadius output_layer = %s.", outputLayer_.c_str());
00056   return true;
00057 }
00058 
00059 template<typename T>
00060 bool MinInRadiusFilter<T>::update(const T& mapIn, T& mapOut)
00061 {
00062   // Add new layer to the elevation map.
00063   mapOut = mapIn;
00064   mapOut.add(outputLayer_);
00065 
00066   double value;
00067 
00068   // First iteration through the elevation map.
00069   for (grid_map::GridMapIterator iterator(mapOut); !iterator.isPastEnd(); ++iterator) {
00070     if (!mapOut.isValid(*iterator, inputLayer_))
00071       continue;
00072     value = mapOut.at(inputLayer_, *iterator);
00073     double valueMin;
00074 
00075     // Requested position (center) of circle in map.
00076     Eigen::Vector2d center;
00077     mapOut.getPosition(*iterator, center);
00078 
00079     // Get minimal value in the circular window.
00080     bool init = false;
00081     for (grid_map::CircleIterator submapIterator(mapOut, center, radius_); !submapIterator.isPastEnd();
00082         ++submapIterator) {
00083       if (!mapOut.isValid(*submapIterator, inputLayer_))
00084         continue;
00085       value = mapOut.at(inputLayer_, *submapIterator);
00086 
00087       if (!init) {
00088         valueMin = value;
00089         init = true;
00090         continue;
00091       }
00092       if (value < valueMin)
00093         valueMin = value;
00094     }
00095 
00096     if (init)
00097       mapOut.at(outputLayer_, *iterator) = valueMin;
00098   }
00099 
00100   return true;
00101 }
00102 
00103 } /* namespace */
00104 
00105 PLUGINLIB_EXPORT_CLASS(grid_map::MinInRadiusFilter<grid_map::GridMap>, filters::FilterBase<grid_map::GridMap>)


grid_map_filters
Author(s): Péter Fankhauser , Martin Wermelinger
autogenerated on Mon Oct 9 2017 03:09:30