PCLBridge.cpp
Go to the documentation of this file.
1 // (C) Copyright Renaud Detry 2007-2015.
2 // Distributed under the GNU General Public License and under the
3 // BSD 3-Clause License (See accompanying file LICENSE.txt).
4 
5 /** @file */
6 
7 #include <nuklei/PCLBridge.h>
8 #include <algorithm>
9 
10 namespace nuklei {
11 
12 #ifdef NUKLEI_USE_PCL
13 
14  kernel::r3 nukleiKernelFromPclPoint(const pcl::PointXYZ& p)
15  {
16  kernel::r3 k;
17  k.loc_ = Vector3(p.x, p.y, p.z);
18  return k;
19  }
20 
21  kernel::r3 nukleiKernelFromPclPoint(const pcl::PointXYZRGB& p)
22  {
23  kernel::r3 k;
24  k.loc_ = Vector3(p.x, p.y, p.z);
25  ColorDescriptor d;
26 #ifdef NUKLEI_USE_SHIFT_PCL_COLOR_ACCESS
27  const uint32_t rgb = *reinterpret_cast<const int*>(&p.rgb);
28  uint8_t r = (rgb >> 16) & 0x0000ff;
29  uint8_t g = (rgb >> 8) & 0x0000ff;
30  uint8_t b = (rgb) & 0x0000ff;
31  RGBColor c(double(r)/255, double(g)/255, double(b)/255);
32 #else
33  RGBColor c(double(p.r)/255, double(p.g)/255, double(p.b)/255);
34 #endif
35  d.setColor(c);
36  k.setDescriptor(d);
37  return k;
38  }
39 
40  /**
41  *
42  *
43  * Warning: converts to axial orientation.
44  */
45  kernel::r3xs2p nukleiKernelFromPclPoint(const pcl::PointNormal& p)
46  {
48  k.loc_ = Vector3(p.x, p.y, p.z);
49  k.dir_ = la::normalized(Vector3(p.normal_x, p.normal_y, p.normal_z));
50  return k;
51  }
52 
53  /**
54  *
55  *
56  * Warning: converts to axial orientation.
57  */
58  kernel::r3xs2p nukleiKernelFromPclPoint(const pcl::PointXYZRGBNormal& p)
59  {
61  k.loc_ = Vector3(p.x, p.y, p.z);
62  k.dir_ = la::normalized(Vector3(p.normal_x, p.normal_y, p.normal_z));
63  ColorDescriptor d;
64 #ifdef NUKLEI_USE_SHIFT_PCL_COLOR_ACCESS
65  const uint32_t rgb = *reinterpret_cast<const int*>(&p.rgb);
66  uint8_t r = (rgb >> 16) & 0x0000ff;
67  uint8_t g = (rgb >> 8) & 0x0000ff;
68  uint8_t b = (rgb) & 0x0000ff;
69  RGBColor c(double(r)/255, double(g)/255, double(b)/255);
70 #else
71  RGBColor c(double(p.r)/255, double(p.g)/255, double(p.b)/255);
72 #endif
73  d.setColor(c);
74  k.setDescriptor(d);
75  return k;
76  }
77 
78  void pclPointFromNukleiKernel(pcl::PointXYZ& p, const kernel::r3& k)
79  {
80  p.x = k.loc_.X();
81  p.y = k.loc_.Y();
82  p.z = k.loc_.Z();
83  }
84 
85  void pclPointFromNukleiKernel(pcl::PointXYZ& p, const kernel::base& k)
86  {
87  pclPointFromNukleiKernel(p, dynamic_cast<const kernel::r3&>(k));
88  }
89 
90 
91  void pclPointFromNukleiKernel(pcl::PointXYZRGB& p, const kernel::r3& k)
92  {
93  p.x = k.loc_.X();
94  p.y = k.loc_.Y();
95  p.z = k.loc_.Z();
96  const ColorDescriptor& d = dynamic_cast<const ColorDescriptor&>(k.getDescriptor());
97  const RGBColor c(d.getColor());
98  uint8_t r = std::min(c.R()*255, 255.);
99  uint8_t g = std::min(c.G()*255, 255.);
100  uint8_t b = std::min(c.B()*255, 255.);
101 #ifdef NUKLEI_USE_SHIFT_PCL_COLOR_ACCESS
102  uint32_t rgb = ((uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b);
103  p.rgb = *reinterpret_cast<float*>(&rgb);
104 #else
105  p.r = r;
106  p.g = g;
107  p.b = b;
108 #endif
109  }
110 
111  void pclPointFromNukleiKernel(pcl::PointXYZRGB& p, const kernel::base& k)
112  {
113  pclPointFromNukleiKernel(p, dynamic_cast<const kernel::r3&>(k));
114  }
115 
116 
117  /**
118  *
119  *
120  * Warning: converts to axial orientation.
121  */
122  void pclPointFromNukleiKernel(pcl::PointNormal& p, const kernel::r3xs2p& k)
123  {
124  p.x = k.loc_.X();
125  p.y = k.loc_.Y();
126  p.z = k.loc_.Z();
127  p.normal_x = k.dir_.X();
128  p.normal_y = k.dir_.Y();
129  p.normal_z = k.dir_.Z();
130  }
131 
132  void pclPointFromNukleiKernel(pcl::PointNormal& p, const kernel::base& k)
133  {
134  pclPointFromNukleiKernel(p, dynamic_cast<const kernel::r3xs2p&>(k));
135  }
136 
137 
138  /**
139  *
140  *
141  * Warning: converts to axial orientation.
142  */
143  void pclPointFromNukleiKernel(pcl::PointXYZRGBNormal& p, const kernel::r3xs2p& k)
144  {
145  p.x = k.loc_.X();
146  p.y = k.loc_.Y();
147  p.z = k.loc_.Z();
148  p.normal_x = k.dir_.X();
149  p.normal_y = k.dir_.Y();
150  p.normal_z = k.dir_.Z();
151  const ColorDescriptor& d = dynamic_cast<const ColorDescriptor&>(k.getDescriptor());
152  const RGBColor c(d.getColor());
153  uint8_t r = std::min(c.R()*255, 255.);
154  uint8_t g = std::min(c.G()*255, 255.);
155  uint8_t b = std::min(c.B()*255, 255.);
156 #ifdef NUKLEI_USE_SHIFT_PCL_COLOR_ACCESS
157  uint32_t rgb = ((uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b);
158  p.rgb = *reinterpret_cast<float*>(&rgb);
159 #else
160  p.r = r;
161  p.g = g;
162  p.b = b;
163 #endif
164  }
165 
166  void pclPointFromNukleiKernel(pcl::PointXYZRGBNormal& p, const kernel::base& k)
167  {
168  pclPointFromNukleiKernel(p, dynamic_cast<const kernel::r3xs2p&>(k));
169  }
170 
171 #endif
172 
173 }
Public namespace.
Definition: Color.cpp:9
r3xs2_base< groupS::s2p > r3xs2p
Definition: Kernel.h:623
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:06.