/************************************************************ * * Copyright (c) 2021, University of California, Los Angeles * * Authors: Kenny J. Chen, Brett T. Lopez * Contact: kennyjchen@ucla.edu, btlopez@ucla.edu * ***********************************************************/ /*********************************************************************** * BSD 3-Clause License * * Copyright (c) 2020, SMRT-AIST * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *************************************************************************/ #ifndef NANO_GICP_LSQ_REGISTRATION_HPP #define NANO_GICP_LSQ_REGISTRATION_HPP #include #include #include #include #include namespace nano_gicp { enum class LSQ_OPTIMIZER_TYPE { GaussNewton, LevenbergMarquardt }; template class LsqRegistration : public pcl::Registration { public: using Scalar = float; using Matrix4 = typename pcl::Registration::Matrix4; using PointCloudSource = typename pcl::Registration::PointCloudSource; using PointCloudSourcePtr = typename PointCloudSource::Ptr; using PointCloudSourceConstPtr = typename PointCloudSource::ConstPtr; using PointCloudTarget = typename pcl::Registration::PointCloudTarget; using PointCloudTargetPtr = typename PointCloudTarget::Ptr; using PointCloudTargetConstPtr = typename PointCloudTarget::ConstPtr; protected: using pcl::Registration::input_; using pcl::Registration::nr_iterations_; using pcl::Registration::max_iterations_; using pcl::Registration::final_transformation_; using pcl::Registration::transformation_epsilon_; using pcl::Registration::converged_; public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW LsqRegistration(); virtual ~LsqRegistration(); void setRotationEpsilon(double eps); void setInitialLambdaFactor(double init_lambda_factor); void setDebugPrint(bool lm_debug_print); const Eigen::Matrix& getFinalHessian() const; virtual void swapSourceAndTarget() {} virtual void clearSource() {} virtual void clearTarget() {} protected: virtual void computeTransformation(PointCloudSource& output, const Matrix4& guess) override; bool is_converged(const Eigen::Isometry3d& delta) const; virtual double linearize(const Eigen::Isometry3d& trans, Eigen::Matrix* H = nullptr, Eigen::Matrix* b = nullptr) = 0; virtual double compute_error(const Eigen::Isometry3d& trans) = 0; bool step_optimize(Eigen::Isometry3d& x0, Eigen::Isometry3d& delta); bool step_gn(Eigen::Isometry3d& x0, Eigen::Isometry3d& delta); bool step_lm(Eigen::Isometry3d& x0, Eigen::Isometry3d& delta); protected: double rotation_epsilon_; LSQ_OPTIMIZER_TYPE lsq_optimizer_type_; int lm_max_iterations_; double lm_init_lambda_factor_; double lm_lambda_; bool lm_debug_print_; Eigen::Matrix final_hessian_; }; } // namespace nano_gicp #endif