pcl_conversions.cpp
Go to the documentation of this file.
1#include "pcl_conversions.h"
2
3#include <pcl/common/transforms.h>
4#include <pcl/point_cloud.h>
5#include <pcl/point_types.h>
6
7#include <cartographer/sensor/rangefinder_point.h>
8
10{
11
12 template <typename T>
13 ::pcl::PointCloud<::pcl::PointXYZ>
14 toPCLImpl(const std::vector<T>& points)
15 {
16 ::pcl::PointCloud<::pcl::PointXYZ> cloud;
17 cloud.reserve(points.size());
18
19 std::transform(
20 points.begin(),
21 points.end(),
22 std::back_inserter(cloud.points),
23 [](const auto& point) {
24 return pcl::PointXYZ{point.position.x(), point.position.y(), point.position.z()};
25 });
26
27 // @see pcl::PointCloud::push_back
28 cloud.height = 1;
29 cloud.width = cloud.size();
30
31 return cloud;
32 }
33
34 ::pcl::PointCloud<::pcl::PointXYZ>
35 toPCL(const std::vector<::cartographer::sensor::TimedRangefinderPoint>& points)
36 {
37 return toPCLImpl(points);
38 }
39
40 ::pcl::PointCloud<::pcl::PointXYZ>
41 toPCL(const std::vector<::cartographer::sensor::RangefinderPoint>& points)
42 {
43 return toPCLImpl(points);
44 }
45
46 ::pcl::PointCloud<::pcl::PointXYZ>
47 toPCL(const auto& pointCloud, const ::cartographer::transform::Rigid3d& pose)
48 {
49 ::pcl::PointCloud<pcl::PointXYZ> cloudOut;
50 cloudOut.reserve(pointCloud.points().size());
51
52 auto cloudTmp = toPCL(pointCloud);
53
54 const Eigen::Quaternionf q = pose.rotation().cast<float>();
55 const Eigen::Vector3f t = pose.translation().cast<float>();
56
57 pcl::transformPointCloud(cloudTmp, cloudOut, t, q);
58 return cloudOut;
59 }
60
61 ::pcl::PointCloud<::pcl::PointXYZ>
62 toPCL(const std::vector<::cartographer::sensor::TimedRangefinderPoint>& pointCloud,
63 const Eigen::Isometry3f& pose)
64 {
65 ::pcl::PointCloud<pcl::PointXYZ> cloudOut;
66 cloudOut.reserve(pointCloud.size());
67
68 auto cloudTmp = toPCL(pointCloud);
69
70 ::pcl::transformPointCloud(cloudTmp, cloudOut, pose);
71 return cloudOut;
72 }
73
74} // namespace armarx::localization_and_mapping::cartographer_adapter
#define q
Quaternion< float, 0 > Quaternionf
::pcl::PointCloud<::pcl::PointXYZ > toPCLImpl(const std::vector< T > &points)
::pcl::PointCloud<::pcl::PointXYZ > toPCL(const std::vector<::cartographer::sensor::TimedRangefinderPoint > &points)