PCLBridge.h
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 #ifndef NUKLEI_PCL_BRIDGE_H
8 #define NUKLEI_PCL_BRIDGE_H
9 
10 #ifdef NUKLEI_USE_PCL
11 
13 #include <pcl/point_types.h>
14 #include <pcl/point_cloud.h>
15 #include <boost/math/special_functions/fpclassify.hpp>
16 
17 // Forward declaration of PCL types
18 //namespace pcl {
19 // template <typename PointT>
20 // class PointCloud;
21 //
22 // struct PointXYZ;
23 // //struct PointXYZI;
24 // //struct PointXYZRGBA;
25 // struct PointXYZRGB;
26 // struct PointNormal;
27 // struct PointXYZRGBNormal;
28 // //struct PointXYZINormal;
29 //}
30 
31 namespace nuklei {
32 
33  inline bool valid(const pcl::PointXYZ& p)
34  {
35  float t = p.x + p.y + p.z;
36  return !(boost::math::isnan)(t);
37  }
38 
39  inline bool valid(const pcl::PointNormal& p)
40  {
41  float t = p.x + p.y + p.z + p.normal_x + p.normal_y + p.normal_z;
42  return !(boost::math::isnan)(t);
43  }
44 
45  inline bool valid(const pcl::PointXYZRGB& p)
46  {
47  float t = p.x + p.y + p.z; // colors may be nan
48  return !(boost::math::isnan)(t);
49  }
50 
51  inline bool valid(const pcl::PointXYZRGBNormal& p)
52  {
53  float t = p.x + p.y + p.z + p.normal_x + p.normal_y + p.normal_z; // colors may be nan
54  return !(boost::math::isnan)(t);
55  }
56 
57 
58  kernel::r3 nukleiKernelFromPclPoint(const pcl::PointXYZ& p);
59 
60  kernel::r3 nukleiKernelFromPclPoint(const pcl::PointXYZRGB& p);
61 
62  /**
63  *
64  *
65  * Warning: converts to axial orientation.
66  */
67  kernel::r3xs2p nukleiKernelFromPclPoint(const pcl::PointNormal& p);
68 
69  /**
70  *
71  *
72  * Warning: converts to axial orientation.
73  */
74  kernel::r3xs2p nukleiKernelFromPclPoint(const pcl::PointXYZRGBNormal& p);
75 
76 
77 
78  void pclPointFromNukleiKernel(pcl::PointXYZ& p, const kernel::r3& k);
79 
80  void pclPointFromNukleiKernel(pcl::PointXYZ& p, const kernel::base& k);
81 
82 
83  void pclPointFromNukleiKernel(pcl::PointXYZRGB& p, const kernel::r3& k);
84 
85  void pclPointFromNukleiKernel(pcl::PointXYZRGB& p, const kernel::base& k);
86 
87 
88  /**
89  *
90  *
91  * Warning: converts to axial orientation.
92  */
93  void pclPointFromNukleiKernel(pcl::PointNormal& p, const kernel::r3xs2p& k);
94 
95  void pclPointFromNukleiKernel(pcl::PointNormal& p, const kernel::base& k);
96 
97 
98  /**
99  *
100  *
101  * Warning: converts to axial orientation.
102  */
103  void pclPointFromNukleiKernel(pcl::PointXYZRGBNormal& p, const kernel::r3xs2p& k);
104 
105  void pclPointFromNukleiKernel(pcl::PointXYZRGBNormal& p, const kernel::base& k);
106 
107 
108  template<typename PointT>
109  KernelCollection nukleiFromPcl(const pcl::PointCloud<PointT>& cloud,
110  const bool removeInvalidPoints = false)
111  {
112  KernelCollection kc;
113  for (typename pcl::PointCloud<PointT>::const_iterator i = cloud.begin();
114  i != cloud.end(); ++i)
115  {
116  if (removeInvalidPoints && !valid(*i)) continue;
117  kc.add(nukleiKernelFromPclPoint(*i));
118  }
119  return kc;
120  }
121 
122  template<typename PointT>
123  pcl::PointCloud<PointT> pclFromNuklei(const KernelCollection& kc)
124  {
125  pcl::PointCloud<PointT> cloud;
126 
127  cloud.width = kc.size();
128  cloud.height = 1;
129  cloud.is_dense = true; // all points coming from Nuklei should be valid.
130 
131  for (KernelCollection::const_iterator i = kc.begin();
132  i != kc.end(); ++i)
133  {
134  PointT point;
135  pclPointFromNukleiKernel(point, *i);
136  cloud.push_back(point);
137  }
138  return cloud;
139  }
140 
141 }
142 
143 #endif
144 
145 
146 #endif
Public namespace.
Definition: Color.cpp:9
Container::const_iterator const_iterator
KernelCollection iterator.
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.