43#include <pcl/registration/bfgs.h>
44#include <pcl/registration/icp.h>
74template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar =
float>
88 previous_transformation_;
92 transformation_epsilon_;
97 min_number_correspondences_;
112 std::vector<Eigen::Matrix3d, Eigen::aligned_allocator<Eigen::Matrix3d>>;
121 shared_ptr<GeneralizedIterativeClosestPoint<PointSource, PointTarget, Scalar>>;
125 using Vector3 =
typename Eigen::Matrix<Scalar, 3, 1>;
126 using Vector4 =
typename Eigen::Matrix<Scalar, 4, 1>;
128 using Matrix3 =
typename Eigen::Matrix<Scalar, 3, 3>;
140 reg_name_ =
"GeneralizedIterativeClosestPoint";
149 Matrix4& transformation_matrix) {
151 cloud_src, indices_src, cloud_tgt, indices_tgt, transformation_matrix);
162 if (cloud->points.empty()) {
164 "[pcl::%s::setInputSource] Invalid or empty point cloud dataset given!\n",
170 for (std::size_t i = 0; i < input.
size(); ++i)
171 input[i].data[3] = 1.0;
227 Matrix4& transformation_matrix);
244 Matrix4& transformation_matrix);
247 inline const Eigen::Matrix3d&
264 const Eigen::Matrix3d& dCost_dR_T,
317 Matrix4& transformation_matrix) {
319 cloud_src, indices_src, cloud_tgt, indices_tgt, transformation_matrix);
439 template <
typename Po
intT>
452 if (mat1.cols() != mat2.rows()) {
454 "The two matrices' shapes don't match. "
456 << mat1.rows() <<
", " << mat1.cols() <<
") and ("
457 << mat2.rows() <<
", " << mat2.cols() <<
")");
459 return (mat1 * mat2).trace();
478 std::vector<float>& distance)
480 int k =
tree_->nearestKSearch(query, 1, index, distance);
513 Matrix4& transformation_matrix)>
518 getRDerivatives(
double phi,
521 Eigen::Matrix3d& dR_dPhi,
522 Eigen::Matrix3d& dR_dTheta,
523 Eigen::Matrix3d& dR_dPsi)
const;
526 getR2ndDerivatives(
double phi,
529 Eigen::Matrix3d& ddR_dPhi_dPhi,
530 Eigen::Matrix3d& ddR_dPhi_dTheta,
531 Eigen::Matrix3d& ddR_dPhi_dPsi,
532 Eigen::Matrix3d& ddR_dTheta_dTheta,
533 Eigen::Matrix3d& ddR_dTheta_dPsi,
534 Eigen::Matrix3d& ddR_dPsi_dPsi)
const;
537 unsigned int threads_;
541#include <pcl/registration/impl/gicp.hpp>
double rotation_epsilon_
The epsilon constant for rotation error.
void estimateRigidTransformationBFGS(const PointCloudSource &cloud_src, const pcl::Indices &indices_src, const PointCloudTarget &cloud_tgt, const pcl::Indices &indices_tgt, Matrix4 &transformation_matrix)
Estimate a rigid rotation transformation between a source and a target point cloud using an iterative...
void setTranslationGradientTolerance(double tolerance)
Set the minimal translation gradient threshold for early optimization stop.
int getCorrespondenceRandomness() const
Get the number of neighbors used when computing covariances as set by the user.
void setCorrespondenceRandomness(int k)
Set the number of neighbors used when selecting a point neighbourhood to compute covariances.
typename Registration< PointSource, PointTarget, Scalar >::KdTree InputKdTree
shared_ptr< const GeneralizedIterativeClosestPoint< PointSource, PointTarget, Scalar > > ConstPtr
void applyState(Matrix4 &t, const Vector6d &x) const
compute transformation matrix from transformation matrix
pcl::PointCloud< PointTarget > PointCloudTarget
const pcl::Indices * tmp_idx_tgt_
Temporary pointer to the target dataset indices.
pcl::PointCloud< PointSource > PointCloudSource
Matrix4 base_transformation_
base transformation
PointIndices::ConstPtr PointIndicesConstPtr
double translation_gradient_tolerance_
minimal translation gradient for early optimization stop
Eigen::Matrix< double, 6, 6 > Matrix6d
const PointCloudTarget * tmp_tgt_
Temporary pointer to the target dataset.
const Eigen::Matrix3d & mahalanobis(std::size_t index) const
int getMaximumOptimizerIterations() const
Return maximum number of iterations at the optimization step.
MatricesVectorPtr input_covariances_
Input cloud points covariances.
typename PointCloudSource::ConstPtr PointCloudSourceConstPtr
typename Eigen::Matrix< Scalar, 4, 1 > Vector4
typename Eigen::Matrix< Scalar, 3, 1 > Vector3
void setInputSource(const PointCloudSourceConstPtr &cloud) override
Provide a pointer to the input dataset.
void setTargetCovariances(const MatricesVectorPtr &covariances)
Provide a pointer to the covariances of the input target (if computed externally!).
void setSourceCovariances(const MatricesVectorPtr &covariances)
Provide a pointer to the covariances of the input source (if computed externally!).
shared_ptr< const MatricesVector > MatricesVectorConstPtr
void computeCovariances(typename pcl::PointCloud< PointT >::ConstPtr cloud, const typename pcl::search::KdTree< PointT >::Ptr tree, MatricesVector &cloud_covariances)
compute points covariances matrices according to the K nearest neighbors.
void estimateRigidTransformationNewton(const PointCloudSource &cloud_src, const pcl::Indices &indices_src, const PointCloudTarget &cloud_tgt, const pcl::Indices &indices_tgt, Matrix4 &transformation_matrix)
Estimate a rigid rotation transformation between a source and a target point cloud using an iterative...
typename Registration< PointSource, PointTarget, Scalar >::KdTreePtr InputKdTreePtr
void useBFGS()
Use BFGS optimizer instead of default Newton optimizer.
typename PointCloudSource::Ptr PointCloudSourcePtr
typename PointCloudTarget::Ptr PointCloudTargetPtr
const PointCloudSource * tmp_src_
Temporary pointer to the source dataset.
int max_inner_iterations_
maximum number of optimizations
double gicp_epsilon_
The epsilon constant for gicp paper; this is NOT the convergence tolerance default: 0....
double getRotationEpsilon() const
Get the rotation epsilon (maximum allowable difference between two consecutive rotations) as set by t...
void setRotationEpsilon(double epsilon)
Set the rotation epsilon (maximum allowable difference between two consecutive rotations) in order fo...
double matricesInnerProd(const Eigen::MatrixXd &mat1, const Eigen::MatrixXd &mat2) const
PCL_MAKE_ALIGNED_OPERATOR_NEW GeneralizedIterativeClosestPoint()
Empty constructor.
PointIndices::Ptr PointIndicesPtr
typename IterativeClosestPoint< PointSource, PointTarget, Scalar >::Matrix4 Matrix4
double getRotationGradientTolerance() const
Return the minimal rotation gradient threshold for early optimization stop.
int k_correspondences_
The number of neighbors used for covariances computation.
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
std::vector< Eigen::Matrix3d > mahalanobis_
Mahalanobis matrices holder.
void setMaximumOptimizerIterations(int max)
Set maximum number of iterations at the optimization step.
std::vector< Eigen::Matrix3d, Eigen::aligned_allocator< Eigen::Matrix3d > > MatricesVector
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
MatricesVectorPtr target_covariances_
Target cloud points covariances.
void computeRDerivative(const Vector6d &x, const Eigen::Matrix3d &dCost_dR_T, Vector6d &g) const
Computes the derivative of the cost function w.r.t rotation angles.
typename Eigen::AngleAxis< Scalar > AngleAxis
void computeTransformation(PointCloudSource &output, const Matrix4 &guess) override
Rigid transformation computation method with initial guess.
double getTranslationGradientTolerance() const
Return the minimal translation gradient threshold for early optimization stop.
void setInputTarget(const PointCloudTargetConstPtr &target) override
Provide a pointer to the input target (e.g., the point cloud that we want to align the input source t...
typename Eigen::Matrix< Scalar, 3, 3 > Matrix3
shared_ptr< MatricesVector > MatricesVectorPtr
double rotation_gradient_tolerance_
minimal rotation gradient for early optimization stop
std::function< void(const pcl::PointCloud< PointSource > &cloud_src, const pcl::Indices &src_indices, const pcl::PointCloud< PointTarget > &cloud_tgt, const pcl::Indices &tgt_indices, Matrix4 &transformation_matrix)> rigid_transformation_estimation_
void setRotationGradientTolerance(double tolerance)
Set the minimal rotation gradient threshold for early optimization stop.
bool searchForNeighbors(const PointSource &query, pcl::Indices &index, std::vector< float > &distance)
Search for the closest nearest neighbor of a given point.
shared_ptr< GeneralizedIterativeClosestPoint< PointSource, PointTarget, Scalar > > Ptr
Eigen::Matrix< double, 6, 1 > Vector6d
const pcl::Indices * tmp_idx_src_
Temporary pointer to the source dataset indices.
typename Registration< PointSource, PointTarget, Scalar >::Matrix4 Matrix4
void setInputTarget(const PointCloudTargetConstPtr &cloud) override
Provide a pointer to the input target (e.g., the point cloud that we want to align the input source t...
void setInputSource(const PointCloudSourceConstPtr &cloud) override
Provide a pointer to the input source (e.g., the point cloud that we want to align to the target)
PointCloudConstPtr input_
A base class for all pcl exceptions which inherits from std::runtime_error.
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< PointSource > > Ptr
shared_ptr< const PointCloud< PointSource > > ConstPtr
Matrix4 final_transformation_
std::function< UpdateVisualizerCallbackSignature > update_visualizer_
double corr_dist_threshold_
KdTreeReciprocalPtr tree_reciprocal_
typename KdTree::Ptr KdTreePtr
pcl::search::KdTree< PointTarget > KdTree
unsigned int min_number_correspondences_
double transformation_epsilon_
PointCloudTargetConstPtr target_
const std::string & getClassName() const
shared_ptr< KdTree< PointT, Tree > > Ptr
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
IndicesAllocator<> Indices
Type used for indices in PCL.
void dfddf(const Vector6d &x, Vector6d &df, Matrix6d &ddf)
OptimizationFunctorWithIndices(const GeneralizedIterativeClosestPoint *gicp)
double operator()(const Vector6d &x) override
void df(const Vector6d &x, Vector6d &df) override
const GeneralizedIterativeClosestPoint * gicp_
BFGSSpace::Status checkGradient(const Vector6d &g) override
void fdf(const Vector6d &x, double &f, Vector6d &df) override
shared_ptr< ::pcl::PointIndices > Ptr
shared_ptr< const ::pcl::PointIndices > ConstPtr