/************************************************************ * * 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_NANO_GICP_HPP #define NANO_GICP_NANO_GICP_HPP #include #include #include #include #include #include #include #include namespace nano_gicp { template class NanoGICP : public LsqRegistration { 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::reg_name_; using pcl::Registration::input_; using pcl::Registration::target_; using pcl::Registration::corr_dist_threshold_; public: NanoGICP(); virtual ~NanoGICP() override; void setNumThreads(int n); void setCorrespondenceRandomness(int k); void setRegularizationMethod(RegularizationMethod method); virtual void swapSourceAndTarget() override; virtual void clearSource() override; virtual void clearTarget() override; virtual void setInputSource(const PointCloudSourceConstPtr& cloud) override; virtual void setSourceCovariances(const std::vector>& covs); virtual void setInputTarget(const PointCloudTargetConstPtr& cloud) override; virtual void setTargetCovariances(const std::vector>& covs); virtual void registerInputSource(const PointCloudSourceConstPtr& cloud); const std::vector>& getSourceCovariances() const { return source_covs_; } const std::vector>& getTargetCovariances() const { return target_covs_; } protected: virtual void computeTransformation(PointCloudSource& output, const Matrix4& guess) override; virtual void update_correspondences(const Eigen::Isometry3d& trans); virtual double linearize(const Eigen::Isometry3d& trans, Eigen::Matrix* H, Eigen::Matrix* b) override; virtual double compute_error(const Eigen::Isometry3d& trans) override; template bool calculate_covariances(const typename pcl::PointCloud::ConstPtr& cloud, nanoflann::KdTreeFLANN& kdtree, std::vector>& covariances); public: std::shared_ptr> source_kdtree_; std::shared_ptr> target_kdtree_; std::vector> source_covs_; std::vector> target_covs_; protected: int num_threads_; int k_correspondences_; RegularizationMethod regularization_method_; std::vector> mahalanobis_; std::vector correspondences_; std::vector sq_distances_; }; } // namespace nano_gicp #endif