small_gicp
pcl_registration.hpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright 2024 Kenji Koide
2 // SPDX-License-Identifier: MIT
3 #pragma once
4 
5 #include <pcl/point_cloud.h>
6 #include <pcl/registration/registration.h>
10 
11 namespace small_gicp {
12 
14 template <typename PointSource, typename PointTarget>
15 class RegistrationPCL : public pcl::Registration<PointSource, PointTarget, float> {
16 public:
17  using Scalar = float;
18  using Matrix4 = typename pcl::Registration<PointSource, PointTarget, Scalar>::Matrix4;
19 
20  using PointCloudSource = typename pcl::Registration<PointSource, PointTarget, Scalar>::PointCloudSource;
21  using PointCloudSourcePtr = typename PointCloudSource::Ptr;
22  using PointCloudSourceConstPtr = typename PointCloudSource::ConstPtr;
23 
24  using PointCloudTarget = typename pcl::Registration<PointSource, PointTarget, Scalar>::PointCloudTarget;
25  using PointCloudTargetPtr = typename PointCloudTarget::Ptr;
26  using PointCloudTargetConstPtr = typename PointCloudTarget::ConstPtr;
27 
28  using Ptr = pcl::shared_ptr<RegistrationPCL<PointSource, PointTarget>>;
29  using ConstPtr = pcl::shared_ptr<const RegistrationPCL<PointSource, PointTarget>>;
30 
31 protected:
32  using pcl::Registration<PointSource, PointTarget, Scalar>::reg_name_;
33  using pcl::Registration<PointSource, PointTarget, Scalar>::input_;
34  using pcl::Registration<PointSource, PointTarget, Scalar>::target_;
35  using pcl::Registration<PointSource, PointTarget, Scalar>::corr_dist_threshold_;
36 
37  using pcl::Registration<PointSource, PointTarget, Scalar>::nr_iterations_;
38  using pcl::Registration<PointSource, PointTarget, Scalar>::max_iterations_;
39  using pcl::Registration<PointSource, PointTarget, Scalar>::final_transformation_;
40 
41  using pcl::Registration<PointSource, PointTarget, Scalar>::transformation_epsilon_;
42  using pcl::Registration<PointSource, PointTarget, Scalar>::converged_;
43 
44 public:
46  virtual ~RegistrationPCL();
47 
49  void setNumThreads(int n);
52  void setCorrespondenceRandomness(int k);
54  void setNumNeighborsForCovariance(int k);
56  void setVoxelResolution(double r);
58  void setRotationEpsilon(double eps);
60  void setRegistrationType(const std::string& type);
62  void setVerbosity(bool verbose);
63 
65  const Eigen::Matrix<double, 6, 6>& getFinalHessian() const;
66 
69 
71  void setInputSource(const PointCloudSourceConstPtr& cloud) override;
73  void setInputTarget(const PointCloudTargetConstPtr& cloud) override;
74 
76  void setSourceCovariances(const std::vector<Eigen::Matrix4d>& covs);
78  void setTargetCovariances(const std::vector<Eigen::Matrix4d>& covs);
80  const std::vector<Eigen::Matrix4d>& getSourceCovariances() const;
82  const std::vector<Eigen::Matrix4d>& getTargetCovariances() const;
83 
85  void swapSourceAndTarget();
87  void clearSource();
89  void clearTarget();
90 
91 protected:
92  virtual void computeTransformation(PointCloudSource& output, const Matrix4& guess) override;
93 
94 protected:
99  std::string registration_type_;
100  bool verbose_;
101 
102  std::shared_ptr<KdTree<pcl::PointCloud<PointSource>>> target_tree_;
103  std::shared_ptr<KdTree<pcl::PointCloud<PointSource>>> source_tree_;
104 
105  std::shared_ptr<GaussianVoxelMap> target_voxelmap_;
106  std::shared_ptr<GaussianVoxelMap> source_voxelmap_;
107 
108  std::vector<Eigen::Matrix4d> target_covs_;
109  std::vector<Eigen::Matrix4d> source_covs_;
110 
112 };
113 
114 } // namespace small_gicp
115 
PCL registration interfaces.
Definition: pcl_registration.hpp:15
typename PointCloudTarget::Ptr PointCloudTargetPtr
Definition: pcl_registration.hpp:25
void setVoxelResolution(double r)
Set the voxel resolution for VGICP.
Definition: pcl_registration_impl.hpp:161
RegistrationPCL()
Definition: pcl_registration_impl.hpp:23
void setVerbosity(bool verbose)
Set the verbosity flag.
Definition: pcl_registration_impl.hpp:187
std::shared_ptr< KdTree< pcl::PointCloud< PointSource > > > source_tree_
KdTree for source point cloud.
Definition: pcl_registration.hpp:103
typename PointCloudSource::ConstPtr PointCloudSourceConstPtr
Definition: pcl_registration.hpp:22
typename pcl::Registration< PointSource, PointTarget, Scalar >::Matrix4 Matrix4
Definition: pcl_registration.hpp:18
bool verbose_
Verbosity flag.
Definition: pcl_registration.hpp:100
const std::vector< Eigen::Matrix4d > & getTargetCovariances() const
Get target point covariances.
Definition: pcl_registration_impl.hpp:104
std::shared_ptr< KdTree< pcl::PointCloud< PointSource > > > target_tree_
KdTree for target point cloud.
Definition: pcl_registration.hpp:102
double rotation_epsilon_
Rotation epsilon for convergence check.
Definition: pcl_registration.hpp:97
std::string registration_type_
Registration type ("GICP" or "VGICP").
Definition: pcl_registration.hpp:99
virtual ~RegistrationPCL()
Definition: pcl_registration_impl.hpp:38
const std::vector< Eigen::Matrix4d > & getSourceCovariances() const
Get source point covariances.
Definition: pcl_registration_impl.hpp:95
void setCorrespondenceRandomness(int k)
Set the number of neighbors for covariance estimation.
Definition: pcl_registration_impl.hpp:147
void setNumThreads(int n)
Set the number of threads to use.
Definition: pcl_registration_impl.hpp:137
void setSourceCovariances(const std::vector< Eigen::Matrix4d > &covs)
Set source point covariances.
Definition: pcl_registration_impl.hpp:65
typename pcl::Registration< PointSource, PointTarget, Scalar >::PointCloudSource PointCloudSource
Definition: pcl_registration.hpp:20
const Eigen::Matrix< double, 6, 6 > & getFinalHessian() const
Get the final Hessian matrix ([rx, ry, rz, tx, ty, tz]).
Definition: pcl_registration_impl.hpp:192
pcl::shared_ptr< const RegistrationPCL< PointSource, PointTarget > > ConstPtr
Definition: pcl_registration.hpp:29
std::vector< Eigen::Matrix4d > target_covs_
Covariances of target points.
Definition: pcl_registration.hpp:108
std::shared_ptr< GaussianVoxelMap > target_voxelmap_
VoxelMap for target point cloud.
Definition: pcl_registration.hpp:105
virtual void computeTransformation(PointCloudSource &output, const Matrix4 &guess) override
Definition: pcl_registration_impl.hpp:202
const RegistrationResult & getRegistrationResult() const
Get the detailed registration result.
Definition: pcl_registration_impl.hpp:197
void clearSource()
Clear source point cloud.
Definition: pcl_registration_impl.hpp:121
pcl::shared_ptr< RegistrationPCL< PointSource, PointTarget > > Ptr
Definition: pcl_registration.hpp:28
int num_threads_
Number of threads to use.
Definition: pcl_registration.hpp:95
std::shared_ptr< GaussianVoxelMap > source_voxelmap_
VoxelMap for source point cloud.
Definition: pcl_registration.hpp:106
void clearTarget()
Clear target point cloud.
Definition: pcl_registration_impl.hpp:129
RegistrationResult result_
Registration result.
Definition: pcl_registration.hpp:111
void setTargetCovariances(const std::vector< Eigen::Matrix4d > &covs)
Set target point covariances.
Definition: pcl_registration_impl.hpp:80
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
Definition: pcl_registration.hpp:26
float Scalar
Definition: pcl_registration.hpp:17
int k_correspondences_
Number of neighbors for covariance estimation.
Definition: pcl_registration.hpp:96
typename PointCloudSource::Ptr PointCloudSourcePtr
Definition: pcl_registration.hpp:21
void swapSourceAndTarget()
Swap source and target point clouds and their augmented data (KdTrees, covariances,...
Definition: pcl_registration_impl.hpp:113
void setRegistrationType(const std::string &type)
Set registration type ("GICP" or "VGICP").
Definition: pcl_registration_impl.hpp:176
double voxel_resolution_
Voxel resolution for VGICP.
Definition: pcl_registration.hpp:98
std::vector< Eigen::Matrix4d > source_covs_
Covariances of source points.
Definition: pcl_registration.hpp:109
void setRotationEpsilon(double eps)
Set rotation epsilon for convergence check.
Definition: pcl_registration_impl.hpp:171
void setInputSource(const PointCloudSourceConstPtr &cloud) override
Set the input source (aligned) point cloud.
Definition: pcl_registration_impl.hpp:41
void setNumNeighborsForCovariance(int k)
Set the number of neighbors for covariance estimation.
Definition: pcl_registration_impl.hpp:152
void setInputTarget(const PointCloudTargetConstPtr &cloud) override
Set the input target (fixed) point cloud.
Definition: pcl_registration_impl.hpp:53
typename pcl::Registration< PointSource, PointTarget, Scalar >::PointCloudTarget PointCloudTarget
Definition: pcl_registration.hpp:24
Definition: flat_container.hpp:12
Registration result.
Definition: registration_result.hpp:11