Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <grid_map_filters/ColorFillFilter.hpp>
00010
00011 #include <grid_map_core/grid_map_core.hpp>
00012 #include <pluginlib/class_list_macros.h>
00013
00014 #include <Eigen/Dense>
00015
00016 using namespace filters;
00017
00018 namespace grid_map {
00019
00020 template<typename T>
00021 ColorFillFilter<T>::ColorFillFilter()
00022 : r_(0.0),
00023 g_(0.0),
00024 b_(0.0)
00025 {
00026 }
00027
00028 template<typename T>
00029 ColorFillFilter<T>::~ColorFillFilter()
00030 {
00031 }
00032
00033 template<typename T>
00034 bool ColorFillFilter<T>::configure()
00035 {
00036 if (!FilterBase < T > ::getParam(std::string("red"), r_)) {
00037 ROS_ERROR("Color fill filter did not find parameter `red`.");
00038 return false;
00039 }
00040 ROS_DEBUG("Color fill filter red is = %f.", r_);
00041
00042 if (!FilterBase < T > ::getParam(std::string("green"), g_)) {
00043 ROS_ERROR("Color fill filter did not find parameter `green`.");
00044 return false;
00045 }
00046 ROS_DEBUG("Color fill filter green is = %f.", g_);
00047
00048 if (!FilterBase < T > ::getParam(std::string("blue"), b_)) {
00049 ROS_ERROR("Color fill filter did not find parameter `blue`.");
00050 return false;
00051 }
00052 ROS_DEBUG("Color fill filter blue is = %f.", b_);
00053
00054 if (!FilterBase < T > ::getParam(std::string("mask_layer"), maskLayer_));
00055 ROS_DEBUG("Color fill filter mask_layer = %s.", maskLayer_.c_str());
00056
00057 if (!FilterBase < T > ::getParam(std::string("output_layer"), outputLayer_)) {
00058 ROS_ERROR("Color fill filter did not find parameter `output_layer`.");
00059 return false;
00060 }
00061 ROS_DEBUG("Color fill filter output_layer = %s.", outputLayer_.c_str());
00062 return true;
00063 }
00064
00065 template<typename T>
00066 bool ColorFillFilter<T>::update(const T& mapIn, T& mapOut)
00067 {
00068 mapOut = mapIn;
00069 const Eigen::Vector3f colorVector(r_, g_, b_);
00070 float colorValue;
00071 colorVectorToValue(colorVector, colorValue);
00072
00073 if (maskLayer_.empty()) {
00074 mapOut.add(outputLayer_, colorValue);
00075
00076 } else {
00077 mapOut.add(outputLayer_);
00078 auto& output = mapOut[outputLayer_];
00079 auto& mask = mapOut[maskLayer_];
00080
00081
00082 for (size_t i = 0; i < output.size(); ++i) {
00083 output(i) = std::isfinite(mask(i)) ? colorValue : NAN;
00084 }
00085 }
00086 return true;
00087 }
00088
00089 }
00090
00091 PLUGINLIB_EXPORT_CLASS(grid_map::ColorFillFilter<grid_map::GridMap>, filters::FilterBase<grid_map::GridMap>)