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