point_cloud.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4
5#include <pcl/common/transforms.h>
6#include <pcl/point_cloud.h>
7#include <pcl/point_types.h>
8
9#include <VirtualRobot/math/Helpers.h>
10
12
13#include "../types.h"
14
16{
17
18 /**
19 * @brief Transform a point cloud to local grid coordinates.
20 * @param pointCloud The point cloud.
21 * @param pointCloudPose The global pose of the point cloud.
22 * @param gridPose The global pose of the grid.
23 * @return The point cloud in grid's local coordinates.
24 */
25 template <class PointT>
26 pcl::PointCloud<PointT> transformPointCloudToGrid(const pcl::PointCloud<PointT>& pointCloud,
27 const Eigen::Matrix4f& pointCloudPose,
28 const Eigen::Matrix4f& gridPose);
29
30 template <class PointT>
31 pcl::PointCloud<PointT>
32 transformPointCloudToGrid(const pcl::PointCloud<PointT>& pointCloud,
33 const Eigen::Matrix4f& pointCloudPose,
34 const Eigen::Matrix4f& gridPose)
35 {
36 // p_w = pose_pc * p_pc
37 // p_w = pose_gr * p_gr
38
39 // wanted: tf with: p_gr = tf * p_pc
40 // p_gr = (pose_gr)^-1 * p_w
41 // p_gr = (pose_gr)^-1 * pose_pc * p_pc
42 // => tf = (pose_gr)^-1 * pose_pc
43
44 const Eigen::Matrix4f gridPoseInv = math::Helpers::InvertedPose(gridPose);
45
46 const Eigen::Matrix4f tfPointCloud2Grid = gridPoseInv * pointCloudPose;
47
48 pcl::PointCloud<PointT> transformed;
49 pcl::transformPointCloud(pointCloud, transformed, tfPointCloud2Grid);
50
51 return transformed;
52 }
53
54
55} // namespace visionx::voxelgrid::utils
pcl::PointCloud< PointT > transformPointCloudToGrid(const pcl::PointCloud< PointT > &pointCloud, const Eigen::Matrix4f &pointCloudPose, const Eigen::Matrix4f &gridPose)
Transform a point cloud to local grid coordinates.
Definition point_cloud.h:32