cloud_tools.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2013-2014, Unbounded Robotics Inc.
3  * Copyright 2011, Willow Garage, Inc. (hsv2rgb)
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the Unbounded Robotics, Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 // Author: Michael Ferguson
32 
34 
35 namespace simple_grasping
36 {
37 
38 // http://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB
39 // for points on a dark background you want somewhat lightened
40 // colors generally... back off the saturation (s)
41 void hsv2rgb(const float h, const float s, const float v, float& r, float& g, float& b)
42 {
43  float c = v * s;
44  float hprime = h/60.0;
45  float x = c * (1.0 - fabs(fmodf(hprime, 2.0f) - 1));
46 
47  r = g = b = 0;
48 
49  if (hprime < 1) {
50  r = c; g = x;
51  } else if (hprime < 2) {
52  r = x; g = c;
53  } else if (hprime < 3) {
54  g = c; b = x;
55  } else if (hprime < 4) {
56  g = x; b = c;
57  } else if (hprime < 5) {
58  r = x; b = c;
59  } else if (hprime < 6) {
60  r = c; b = x;
61  }
62 
63  float m = v - c;
64  r += m; g+=m; b+=m;
65 }
66 
67 void colorizeCloud(pcl::PointCloud<pcl::PointXYZRGB>& cloud, float hue)
68 {
69  std::vector<pcl::PCLPointField> fields;
70  pcl::getFields(cloud, fields);
71  size_t rgb_field_index;
72  for (rgb_field_index = 0; rgb_field_index < fields.size(); ++rgb_field_index)
73  {
74  if (fields[rgb_field_index].name == "rgb" ||
75  fields[rgb_field_index].name == "rgba")
76  break;
77  }
78 
79  float r, g, b;
80  hsv2rgb(hue, 0.8 /*saturation*/, 1.0 /*value*/, r, g, b);
81 
82  for (size_t j = 0; j < cloud.points.size(); ++j)
83  {
84  pcl::PointXYZRGB &p = cloud.points[j];
85  unsigned char* pt_rgb = (unsigned char*) &p;
86  pt_rgb += fields[rgb_field_index].offset;
87  (*pt_rgb) = (unsigned char) (r * 255);
88  (*(pt_rgb+1)) = (unsigned char) (g * 255);
89  (*(pt_rgb+2)) = (unsigned char) (b * 255);
90  }
91 }
92 
93 double distancePointToPlane(const Eigen::Vector4f& point, const pcl::ModelCoefficients::Ptr plane)
94 {
95  Eigen::Vector4f pp(point);
96  pp[3] = 1.0;
97  Eigen::Vector4f m(plane->values[0], plane->values[1], plane->values[2], plane->values[3]);
98  return pp.dot(m);
99 }
100 
101 } // namespace simple_grasping
double distancePointToPlane(const PointT &point, const pcl::ModelCoefficients::Ptr plane)
Get distance from point to plane.
Definition: cloud_tools.h:71
f
void colorizeCloud(pcl::PointCloud< pcl::PointXYZRGB > &cloud, float hue)
Update rgb component of an XYZRGB cloud to a new HSV color.
Definition: cloud_tools.cpp:67
void hsv2rgb(const float h, const float s, const float v, float &r, float &g, float &b)
Fill in RGB values from HSV values.
Definition: cloud_tools.cpp:41
TFSIMD_FORCE_INLINE const tfScalar & x() const


simple_grasping
Author(s): Michael Ferguson
autogenerated on Wed Jun 5 2019 20:04:47