Point Cloud Library (PCL) 1.15.1-dev
Loading...
Searching...
No Matches
fricp.h
1/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2010-, Open Perception, Inc.
6 *
7 * All rights reserved.
8 */
9
10#pragma once
11
12#include <pcl/registration/anderson_acceleration.h>
13#include <pcl/registration/icp.h>
14#include <pcl/search/search.h>
15#include <pcl/memory.h>
16#include <pcl/pcl_macros.h>
17#include <pcl/point_types.h>
18
19#include <Eigen/Core>
20
21#include <cmath>
22#include <vector>
23
24namespace pcl {
25/**
26 * \brief FastRobustIterativeClosestPoint implements the FRICP variant described in
27 * "Fast and Robust Iterative Closest Point", Zhang et al., 2021.
28 *
29 * The solver relies on Welsch reweighting for robustness and optional Anderson
30 * acceleration for faster convergence.
31 *
32 * \note FRICP uses its own robust correspondence mechanism based on the Welsch
33 * function. The following inherited ICP settings have no effect:
34 * - setMaxCorrespondenceDistance() 閳?FRICP controls outlier rejection via
35 * the Welsch scale parameter instead.
36 * - Correspondence estimators, rejectors, and reciprocal correspondences
37 * are not used by this class.
38 * - setEuclideanFitnessEpsilon() and setRotationEpsilon() are not evaluated.
39 *
40 * \note setMaximumIterations() controls the number of inner-loop iterations
41 * per Welsch scale stage. The outer loop may run multiple stages as the
42 * scale decays, so the total number of iterations can exceed this value.
43 *
44 * \note Input point clouds must not contain NaN or Inf values. Non-finite
45 * points are not handled and will produce incorrect results.
46 *
47 * \code
48 * pcl::FastRobustIterativeClosestPoint<PointT, PointT> reg;
49 * reg.setInputSource (src); // src and tgt are clouds that must be created before
50 * reg.setInputTarget (tgt);
51 * // parameters may have to be tuned, depending on the point clouds
52 * reg.setMaximumIterations (60);
53 * reg.setTransformationEpsilon (1e-8);
54 * pcl::PointCloud<PointT> output;
55 * reg.align (output);
56 * \endcode
57 * \ingroup registration
58 */
59template <typename PointSource, typename PointTarget, typename Scalar = float>
61: public IterativeClosestPoint<PointSource, PointTarget, Scalar> {
62public:
63 using Ptr =
64 shared_ptr<FastRobustIterativeClosestPoint<PointSource, PointTarget, Scalar>>;
65 using ConstPtr = shared_ptr<
67
69 using typename Base::Matrix4;
70 using typename Base::PointCloudSource;
71 using typename Base::PointCloudTarget;
72
73 enum class RobustFunction { NONE, WELSCH };
74
76
77 void
79
80 [[nodiscard]] RobustFunction
81 getRobustFunction() const;
82
83 /** \brief Enable or disable Anderson acceleration in the FRICP optimization loop.
84 *
85 * When enabled, convergence can be faster on some datasets but may become less
86 * stable. The default is disabled to keep behavior predictable.
87 */
88 void
89 setUseAndersonAcceleration(bool enabled);
90
91 [[nodiscard]] bool
93
94 /** \brief Set the history size used by Anderson acceleration.
95 *
96 * Larger values may improve acceleration quality but can increase instability and
97 * memory usage. Values smaller than 1 are clamped to 1.
98 */
99 void
100 setAndersonHistorySize(std::size_t history);
101
102 [[nodiscard]] std::size_t
104
105 /** \brief Set the initial Welsch scale ratio used in dynamic robust weighting.
106 *
107 * Larger values start with weaker down-weighting of outliers. Values are clamped
108 * to a small positive threshold.
109 */
110 void
111 setDynamicWelschBeginRatio(double ratio);
112
113 /** \brief Set the final Welsch scale ratio used in dynamic robust weighting.
114 *
115 * Smaller values end with stronger outlier suppression. Values are clamped to a
116 * small positive threshold.
117 */
118 void
119 setDynamicWelschEndRatio(double ratio);
120
121 /** \brief Set the multiplicative decay applied to the dynamic Welsch scale.
122 *
123 * Valid range is (0, 1]. A value of 0 or a very small positive number is
124 * silently replaced by the default (0.5). Smaller values reduce the scale
125 * faster per outer iteration, while larger values keep it closer to the
126 * current value.
127 */
128 void
129 setDynamicWelschDecay(double ratio);
130
131protected:
132 void
133 computeTransformation(PointCloudSource& output, const Matrix4& guess) override;
134
135private:
136 using Matrix4d = Eigen::Matrix<double, 4, 4>;
137 using Matrix3Xd = Eigen::Matrix<double, 3, Eigen::Dynamic>;
138 using VectorXd = Eigen::VectorXd;
139 using Vector3d = Eigen::Vector3d;
140 using AndersonAccelerationType = registration::AndersonAcceleration;
141
142 Matrix4d
143 convertGuessToCentered(const Matrix4& guess,
144 const Vector3d& source_mean,
145 const Vector3d& target_mean) const;
146
147 Matrix4d
148 convertCenteredToActual(const Matrix4d& transform,
149 const Vector3d& source_mean,
150 const Vector3d& target_mean) const;
151
152 bool
153 updateCorrespondences(const Matrix4d& transform,
154 const Matrix3Xd& source,
155 const Matrix3Xd& target,
157 Matrix3Xd& matched_targets,
158 VectorXd& residuals,
159 pcl::Correspondences* correspondences = nullptr) const;
160
161 double
162 computeEnergy(const VectorXd& residuals, double nu) const;
163
164 VectorXd
165 computeWeights(const VectorXd& residuals, double nu) const;
166
167 Matrix4d
168 computeWeightedRigidTransform(const Matrix3Xd& source,
169 const Matrix3Xd& target,
170 const VectorXd& weights) const;
171
172 double
173 findKNearestMedian(const pcl::PointCloud<pcl::PointXYZ>& cloud,
175 int neighbors) const;
176
177 Matrix4d
178 matrixLog(const Matrix4d& transform) const;
179
180 RobustFunction robust_function_ = RobustFunction::WELSCH;
181 bool use_anderson_ = false;
182 std::size_t anderson_history_ = 5;
183 double nu_begin_ratio_ = 3.0;
184 double nu_end_ratio_ = 1.0 / (3.0 * std::sqrt(3.0));
185 double nu_decay_ratio_ = 0.5;
186
187 static constexpr double same_threshold_ = 1e-6;
188
189 AndersonAccelerationType anderson_;
190
192};
193} // namespace pcl
194
195#include <pcl/registration/impl/fricp.hpp>
FastRobustIterativeClosestPoint implements the FRICP variant described in "Fast and Robust Iterative ...
Definition fricp.h:61
typename Registration< PointSource, PointTarget, Scalar >::Matrix4 Matrix4
Definition icp.h:143
void computeTransformation(PointCloudSource &output, const Matrix4 &guess) override
Abstract transformation computation method with initial guess.
Definition fricp.hpp:119
void setDynamicWelschEndRatio(double ratio)
Set the final Welsch scale ratio used in dynamic robust weighting.
Definition fricp.hpp:101
void setRobustFunction(RobustFunction f)
Definition fricp.hpp:42
void setDynamicWelschDecay(double ratio)
Set the multiplicative decay applied to the dynamic Welsch scale.
Definition fricp.hpp:109
shared_ptr< FastRobustIterativeClosestPoint< PointSource, PointTarget, Scalar > > Ptr
Definition fricp.h:64
typename Registration< PointSource, PointTarget, Scalar >::PointCloudSource PointCloudSource
Definition icp.h:101
void setUseAndersonAcceleration(bool enabled)
Enable or disable Anderson acceleration in the FRICP optimization loop.
Definition fricp.hpp:61
void setAndersonHistorySize(std::size_t history)
Set the history size used by Anderson acceleration.
Definition fricp.hpp:77
std::size_t getAndersonHistorySize() const
Definition fricp.hpp:85
RobustFunction getRobustFunction() const
Definition fricp.hpp:52
shared_ptr< const FastRobustIterativeClosestPoint< PointSource, PointTarget, Scalar > > ConstPtr
Definition fricp.h:66
void setDynamicWelschBeginRatio(double ratio)
Set the initial Welsch scale ratio used in dynamic robust weighting.
Definition fricp.hpp:93
IterativeClosestPoint provides a base implementation of the Iterative Closest Point algorithm.
Definition icp.h:98
typename Registration< PointSource, PointTarget, Scalar >::Matrix4 Matrix4
Definition icp.h:143
typename Registration< PointSource, PointTarget, Scalar >::PointCloudTarget PointCloudTarget
Definition icp.h:106
typename Registration< PointSource, PointTarget, Scalar >::PointCloudSource PointCloudSource
Definition icp.h:101
PointCloud represents the base class in PCL for storing collections of 3D points.
Lightweight Anderson acceleration helper used to speed up fixed-point iterations in FRICP.
Generic search class.
Definition search.h:78
Defines all the PCL implemented PointT point type structures.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition memory.h:86
Defines functions, macros and traits for allocating and using memory.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
Defines all the PCL and non-PCL macros used.