pcl_eigen.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2021
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <algorithm>
25#include <vector>
26
27#include <Eigen/Core>
28
29#include <pcl/point_cloud.h>
30#include <pcl/point_types.h>
31
32namespace armarx::conversions
33{
34 // pcl2eigen
35
36 inline Eigen::Vector2f
37 pcl2eigen(const pcl::PointXY& pt)
38 {
39 return Eigen::Vector2f{pt.x, pt.y};
40 }
41
42 inline Eigen::Vector3f
43 pcl2eigen(const pcl::PointXYZ& pt)
44 {
45 return Eigen::Vector3f{pt.x, pt.y, pt.z};
46 }
47
48 template <typename PointT, typename EigenVector = decltype(pcl2eigen(PointT()))>
49 auto
50 pcl2eigen(const pcl::PointCloud<PointT>& pointCloud) -> std::vector<EigenVector>
51 {
52 std::vector<EigenVector> v;
53 v.reserve(pointCloud.points.size());
54
55 std::transform(pointCloud.points.begin(),
56 pointCloud.points.end(),
57 std::back_inserter(v),
58 static_cast<EigenVector (*)(const PointT&)>(pcl2eigen));
59
60 return v;
61 }
62
63 // eigen2pcl
64
65 inline pcl::PointXY
66 eigen2pcl(const Eigen::Vector2f& pt)
67 {
68 return pcl::PointXY{pt.x(), pt.y()};
69 }
70
71 inline pcl::PointXYZ
72 eigen2pcl(const Eigen::Vector3f& pt)
73 {
74 return pcl::PointXYZ{pt.x(), pt.y(), 0.F};
75 }
76
77 template <typename EigenVector, typename PointT = decltype(eigen2pcl(EigenVector()))>
78 auto
79 eigen2pcl(const std::vector<EigenVector>& points) -> pcl::PointCloud<PointT>
80 {
81 pcl::PointCloud<PointT> pointCloud;
82 pointCloud.points.reserve(points.size());
83
84 std::transform(points.begin(),
85 points.end(),
86 std::back_inserter(pointCloud.points),
87 static_cast<PointT (*)(const EigenVector&)>(eigen2pcl));
88
89 pointCloud.width = pointCloud.points.size();
90 pointCloud.height = 1;
91 pointCloud.is_dense = true;
92
93 return pointCloud;
94 }
95
96} // namespace armarx::conversions
pcl::PointXY eigen2pcl(const Eigen::Vector2f &pt)
Definition pcl_eigen.h:66
Eigen::Vector2f pcl2eigen(const pcl::PointXY &pt)
Definition pcl_eigen.h:37
pcl::PointXYZRGBL PointT
Definition Common.h:30