Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[registration] GICP alternates optimizing trans and rot part #5269

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion registration/include/pcl/registration/gicp.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class GeneralizedIterativeClosestPoint
using ConstPtr =
shared_ptr<const GeneralizedIterativeClosestPoint<PointSource, PointTarget>>;

using Vector6d = Eigen::Matrix<double, 6, 1>;
using Vector6d = typename Eigen::Matrix<double, 6, 1>;

/** \brief Empty constructor. */
GeneralizedIterativeClosestPoint()
Expand All @@ -111,6 +111,8 @@ class GeneralizedIterativeClosestPoint
, max_inner_iterations_(20)
, translation_gradient_tolerance_(1e-2)
, rotation_gradient_tolerance_(1e-2)
, is_alternating_(false)
, is_translation_turn_(true)
{
min_number_correspondences_ = 4;
reg_name_ = "GeneralizedIterativeClosestPoint";
Expand Down Expand Up @@ -314,6 +316,26 @@ class GeneralizedIterativeClosestPoint
return rotation_gradient_tolerance_;
}

/** \brief Set whether or not optimizing translation part and rotation part
* alternatively
* \param[in] is_alternating whether or not optimizing translation part
* and rotation part alternatively
*/
void
setIsAlternating(bool is_alternating)
{
is_alternating_ = is_alternating;
}

/** \brief Return whether or not optimizing translation part and rotation part
* alternatively
*/
bool
getIsAlternating() const
{
return is_alternating_;
}

protected:
/** \brief The number of neighbors used for covariances computation.
* default: 20
Expand Down Expand Up @@ -365,6 +387,16 @@ class GeneralizedIterativeClosestPoint
/** \brief minimal rotation gradient for early optimization stop */
double rotation_gradient_tolerance_;

/** \brief current transformation of source point cloud */
Vector6d current_transformation_;

/** \brief whether or not optimizing translation part and rotation part alternatively
*/
bool is_alternating_;

/** \brief whether current iteration is optimizing translation part or not */
bool is_translation_turn_;

/** \brief compute points covariances matrices according to the K nearest
* neighbors. K is set via setCorrespondenceRandomness() method.
* \param cloud pointer to point cloud
Expand Down Expand Up @@ -440,6 +472,41 @@ class GeneralizedIterativeClosestPoint
const GeneralizedIterativeClosestPoint* gicp_;
};

/// \brief optimization functor structure for translation part
struct OptimizationFunctorWithIndicesTranslation
: public BFGSDummyFunctor<double, 3> {
OptimizationFunctorWithIndicesTranslation(GeneralizedIterativeClosestPoint* gicp)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update gicp_->current_transformation_ so const from const GeneralizedIterativeClosestPoint* removed.

: BFGSDummyFunctor<double, 3>(), gicp_(gicp)
{}
double
operator()(const Eigen::Vector3d& x) override;
void
df(const Eigen::Vector3d& x, Eigen::Vector3d& df) override;
void
fdf(const Eigen::Vector3d& x, double& f, Eigen::Vector3d& df) override;
BFGSSpace::Status
checkGradient(const Eigen::Vector3d& g) override;

GeneralizedIterativeClosestPoint* gicp_;
};

/// \brief optimization functor structure for rotation part
struct OptimizationFunctorWithIndicesRotation : public BFGSDummyFunctor<double, 3> {
OptimizationFunctorWithIndicesRotation(GeneralizedIterativeClosestPoint* gicp)
: BFGSDummyFunctor<double, 3>(), gicp_(gicp)
{}
double
operator()(const Eigen::Vector3d& x) override;
void
df(const Eigen::Vector3d& x, Eigen::Vector3d& df) override;
void
fdf(const Eigen::Vector3d& x, double& f, Eigen::Vector3d& df) override;
BFGSSpace::Status
checkGradient(const Eigen::Vector3d& g) override;

GeneralizedIterativeClosestPoint* gicp_;
};

std::function<void(const pcl::PointCloud<PointSource>& cloud_src,
const pcl::Indices& src_indices,
const pcl::PointCloud<PointTarget>& cloud_tgt,
Expand Down
Loading