Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <simple_grasping/cloud_tools.h>
00034
00035 namespace simple_grasping
00036 {
00037
00038
00039
00040
00041 void hsv2rgb(const float h, const float s, const float v, float& r, float& g, float& b)
00042 {
00043 float c = v * s;
00044 float hprime = h/60.0;
00045 float x = c * (1.0 - fabs(fmodf(hprime, 2.0f) - 1));
00046
00047 r = g = b = 0;
00048
00049 if (hprime < 1) {
00050 r = c; g = x;
00051 } else if (hprime < 2) {
00052 r = x; g = c;
00053 } else if (hprime < 3) {
00054 g = c; b = x;
00055 } else if (hprime < 4) {
00056 g = x; b = c;
00057 } else if (hprime < 5) {
00058 r = x; b = c;
00059 } else if (hprime < 6) {
00060 r = c; b = x;
00061 }
00062
00063 float m = v - c;
00064 r += m; g+=m; b+=m;
00065 }
00066
00067 void colorizeCloud(pcl::PointCloud<pcl::PointXYZRGB>& cloud, float hue)
00068 {
00069 std::vector<pcl::PCLPointField> fields;
00070 pcl::getFields(cloud, fields);
00071 size_t rgb_field_index;
00072 for (rgb_field_index = 0; rgb_field_index < fields.size(); ++rgb_field_index)
00073 {
00074 if (fields[rgb_field_index].name == "rgb" ||
00075 fields[rgb_field_index].name == "rgba")
00076 break;
00077 }
00078
00079 float r, g, b;
00080 hsv2rgb(hue, 0.8 , 1.0 , r, g, b);
00081
00082 for (size_t j = 0; j < cloud.points.size(); ++j)
00083 {
00084 pcl::PointXYZRGB &p = cloud.points[j];
00085 unsigned char* pt_rgb = (unsigned char*) &p;
00086 pt_rgb += fields[rgb_field_index].offset;
00087 (*pt_rgb) = (unsigned char) (r * 255);
00088 (*(pt_rgb+1)) = (unsigned char) (g * 255);
00089 (*(pt_rgb+2)) = (unsigned char) (b * 255);
00090 }
00091 }
00092
00093 double distancePointToPlane(const Eigen::Vector4f& point, const pcl::ModelCoefficients::Ptr plane)
00094 {
00095 Eigen::Vector4f pp(point);
00096 pp[3] = 1.0;
00097 Eigen::Vector4f m(plane->values[0], plane->values[1], plane->values[2], plane->values[3]);
00098 return pp.dot(m);
00099 }
00100
00101 }