Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <grid_map_filters/LightIntensityFilter.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 LightIntensityFilter<T>::LightIntensityFilter()
00022 {
00023 }
00024
00025 template<typename T>
00026 LightIntensityFilter<T>::~LightIntensityFilter()
00027 {
00028 }
00029
00030 template<typename T>
00031 bool LightIntensityFilter<T>::configure()
00032 {
00033 if (!FilterBase < T > ::getParam(std::string("input_layers_prefix"), inputLayersPrefix_)) {
00034 ROS_ERROR("Light intensity filter did not find parameter `input_layers_prefix`.");
00035 return false;
00036 }
00037 ROS_DEBUG("Light intensity filter input layers prefix is = %s.", inputLayersPrefix_.c_str());
00038
00039 if (!FilterBase < T > ::getParam(std::string("output_layer"), outputLayer_)) {
00040 ROS_ERROR("Light intensity filter did not find parameter `output_layer`.");
00041 return false;
00042 }
00043 ROS_DEBUG("Light intensity filter output_layer = %s.", outputLayer_.c_str());
00044
00045 std::vector<double> lightDirection;
00046 if (!FilterBase < T > ::getParam(std::string("light_direction"), lightDirection)) {
00047 ROS_ERROR("Light intensity filter did not find parameter `light_direction`.");
00048 return false;
00049 }
00050 if (lightDirection.size() != 3) {
00051 ROS_ERROR("Light intensity filter parameter `light_direction` needs to be of size 3.");
00052 return false;
00053 }
00054 lightDirection_ << lightDirection[0], lightDirection[1], lightDirection[2];
00055 lightDirection_.normalize();
00056 ROS_DEBUG_STREAM("Light intensity filter light_direction: " << lightDirection_.transpose() << ".");
00057
00058 return true;
00059 }
00060
00061 template<typename T>
00062 bool LightIntensityFilter<T>::update(const T& mapIn, T& mapOut)
00063 {
00064 const auto& normalX = mapIn[inputLayersPrefix_ + "x"];
00065 const auto& normalY = mapIn[inputLayersPrefix_ + "y"];
00066 const auto& normalZ = mapIn[inputLayersPrefix_ + "z"];
00067
00068 mapOut = mapIn;
00069 mapOut.add(outputLayer_);
00070 auto& color = mapOut[outputLayer_];
00071
00072
00073 for (size_t i = 0; i < color.size(); ++i) {
00074 if (!std::isfinite(normalZ(i))) {
00075 color(i) = NAN;
00076 continue;
00077 }
00078 const Eigen::Vector3f normal(normalX(i), normalY(i), normalZ(i));
00079 const float intensity = std::max<float>(-normal.dot(lightDirection_), 0.0);
00080 const Eigen::Vector3f colorVector = Eigen::Vector3f::Ones() * intensity;
00081 colorVectorToValue(colorVector, color(i));
00082 }
00083
00084 return true;
00085 }
00086
00087 }
00088
00089 PLUGINLIB_EXPORT_CLASS(grid_map::LightIntensityFilter<grid_map::GridMap>, filters::FilterBase<grid_map::GridMap>)