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