tools.hpp
Go to the documentation of this file.
00001 
00063 #ifndef COB_3D_MAPPING_TOOLS_GUI_TOOLS_HPP_
00064 #define COB_3D_MAPPING_TOOLS_GUI_TOOLS_HPP_
00065 
00066 #include <limits>
00067 
00068 template<typename PointT>
00069 void Gui::Tools::convertPointCloud2Cv(const typename pcl::PointCloud<PointT>::ConstPtr& cloud, cvImagePtr& image,
00070                                                      boost::function<cv::Vec3b (int)>& converter)
00071 {
00072   image = new cvImage(cloud->height, cloud->width, CV_8UC3);
00073   int idx=0;
00074   for (int row = 0; row < image->rows; row++)
00075   {
00076     for (int col = 0; col < image->cols; col++, idx++)
00077     {
00078       (*image)(row, col) = converter(idx);
00079     }
00080   }
00081 }
00082 
00083 template<typename PointT>
00084 void Gui::Tools::getMinMaxZ(const typename pcl::PointCloud<PointT>::ConstPtr& cloud, float& z_min, float& z_max)
00085 {
00086   z_min = std::numeric_limits<float>::max();
00087   z_max = std::numeric_limits<float>::min();
00088   for(typename pcl::PointCloud<PointT>::const_iterator it=cloud->begin(); it!=cloud->end(); ++it)
00089   {
00090     z_min = std::min(z_min,it->z);
00091     z_max = std::max(z_max,it->z);
00092   }
00093 }
00094 
00095 
00096 
00097 uint32_t Gui::Tools::getGradientColor(float z_value, float z_min, float z_max, cv::Vec3b& bgr)
00098 {
00099   return getGradientColor( (z_value - z_min) / (z_max - z_min), bgr );
00100 }
00101 
00102 // color is proportional to position  <0;1>
00103 // position means position of color in color gradient
00104 uint32_t Gui::Tools::getGradientColor(double position, cv::Vec3b& bgr)
00105 {
00106   //if (position > 1) position = position - int(position);
00107   if (position > 1) position = 1;
00108   if (position < 0) position = 0;
00109   // if position > 1 then we have repetition of colors
00110   // it maybe useful
00111   int n_bars_max = 4;
00112   double m=n_bars_max * position;
00113   int n=int(m); // integer of m
00114   double f=m-n;  // fraction of m
00115   uint8_t t=int(f*255);
00116 
00117   switch (n)
00118   {
00119   case 0:
00120   { bgr[2] = 255; bgr[1] = t; bgr[0] = 0; break; }
00121   case 1:
00122   { bgr[2] = 255 - t; bgr[1] = 255; bgr[0] = 0; break; }
00123   case 2:
00124   { bgr[2] = 0; bgr[1] = 255; bgr[0] = t; break; }
00125   case 3:
00126   { bgr[2] = 0; bgr[1] = 255 - t; bgr[0] = 255; break; }
00127   case 4:
00128   { bgr[2] = t; bgr[1] = 0; bgr[0] = 255; break; }
00129   case 5:
00130   { bgr[2] = 255; bgr[1] = 0; bgr[0] = 255 - t; break; }
00131   };
00132   return (bgr[2] << 16) | (bgr[1] << 8) | bgr[0];
00133 }
00134 
00135 #endif


cob_3d_mapping_tools
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:04:27