Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <grid_map_filters/ColorMapFilter.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 ColorMapFilter<T>::ColorMapFilter()
00022 : min_(0.0),
00023 max_(1.0)
00024 {
00025 }
00026
00027 template<typename T>
00028 ColorMapFilter<T>::~ColorMapFilter()
00029 {
00030 }
00031
00032 template<typename T>
00033 bool ColorMapFilter<T>::configure()
00034 {
00035 if (!FilterBase<T>::getParam(std::string("input_layer"), inputLayer_)) {
00036 ROS_ERROR("Color map filter did not find parameter `input_layer`.");
00037 return false;
00038 }
00039 ROS_DEBUG("Color map filter input_layer = %s.", inputLayer_.c_str());
00040
00041 if (!FilterBase<T>::getParam(std::string("output_layer"), outputLayer_)) {
00042 ROS_ERROR("Color map filter did not find parameter `output_layer`.");
00043 return false;
00044 }
00045 ROS_DEBUG("Color map filter output_layer = %s.", outputLayer_.c_str());
00046
00047 if (!FilterBase<T>::getParam(std::string("min/value"), min_)) {
00048 ROS_ERROR("Color map filter did not find parameter `min/value`.");
00049 return false;
00050 }
00051 if (!FilterBase<T>::getParam(std::string("max/value"), max_)) {
00052 ROS_ERROR("Color map filter did not find parameter `max/value`.");
00053 return false;
00054 }
00055
00056 std::vector<double> minColor;
00057 if (!FilterBase<T>::getParam(std::string("min/color"), minColor)) {
00058 ROS_ERROR("Color map filter did not find parameter `min/color`.");
00059 return false;
00060 }
00061 if (minColor.size() != 3) {
00062 ROS_ERROR("Color map filter parameter `min/color` needs to be of size 3.");
00063 return false;
00064 }
00065 minColor_ << minColor[0], minColor[1], minColor[2];
00066
00067 std::vector<double> maxColor;
00068 if (!FilterBase<T>::getParam(std::string("max/color"), maxColor)) {
00069 ROS_ERROR("Color map filter did not find parameter `max/color`.");
00070 return false;
00071 }
00072 if (maxColor.size() != 3) {
00073 ROS_ERROR("Color map filter parameter `max/color` needs to be of size 3.");
00074 return false;
00075 }
00076 maxColor_ << maxColor[0], maxColor[1], maxColor[2];
00077
00078 return true;
00079 }
00080
00081 template<typename T>
00082 bool ColorMapFilter<T>::update(const T& mapIn, T& mapOut)
00083 {
00084 mapOut = mapIn;
00085 auto& input = mapIn[inputLayer_];
00086 mapOut.add(outputLayer_);
00087 auto& output = mapOut[outputLayer_];
00088
00089 const double range = max_ - min_;
00090 const Eigen::Vector3f colorRange = maxColor_ - minColor_;
00091
00092
00093 for (size_t i = 0; i < output.size(); ++i) {
00094 if (!std::isfinite(input(i))) continue;
00095 const double value = std::min<float>(std::max<float>(input(i), min_), max_);
00096 const double factor = (value - min_) / range;
00097 const Eigen::Vector3f color = minColor_ + factor * colorRange;
00098 colorVectorToValue(color, output(i));
00099 }
00100
00101 return true;
00102 }
00103
00104 }
00105
00106 PLUGINLIB_EXPORT_CLASS(grid_map::ColorMapFilter<grid_map::GridMap>, filters::FilterBase<grid_map::GridMap>)