|
| 1 | +// Copyright 2023 TIER IV, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef AUTOWARE__NDT_SCAN_MATCHER__NDT_OMP__ESTIMATE_COVARIANCE_HPP_ |
| 16 | +#define AUTOWARE__NDT_SCAN_MATCHER__NDT_OMP__ESTIMATE_COVARIANCE_HPP_ |
| 17 | + |
| 18 | +#include "multigrid_ndt_omp.h" |
| 19 | + |
| 20 | +#include <Eigen/Core> |
| 21 | + |
| 22 | +#include <memory> |
| 23 | +#include <utility> |
| 24 | +#include <vector> |
| 25 | + |
| 26 | +namespace pclomp |
| 27 | +{ |
| 28 | + |
| 29 | +struct ResultOfMultiNdtCovarianceEstimation |
| 30 | +{ |
| 31 | + Eigen::Vector2d mean; |
| 32 | + Eigen::Matrix2d covariance; |
| 33 | + std::vector<Eigen::Matrix4f> ndt_initial_poses; |
| 34 | + std::vector<NdtResult> ndt_results; |
| 35 | +}; |
| 36 | + |
| 37 | +/** \brief Estimate functions */ |
| 38 | +Eigen::Matrix2d estimate_xy_covariance_by_laplace_approximation( |
| 39 | + const Eigen::Matrix<double, 6, 6> & hessian); |
| 40 | +ResultOfMultiNdtCovarianceEstimation estimate_xy_covariance_by_multi_ndt( |
| 41 | + const NdtResult & ndt_result, |
| 42 | + const std::shared_ptr< |
| 43 | + pclomp::MultiGridNormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>> & ndt_ptr, |
| 44 | + const std::vector<Eigen::Matrix4f> & poses_to_search); |
| 45 | +ResultOfMultiNdtCovarianceEstimation estimate_xy_covariance_by_multi_ndt_score( |
| 46 | + const NdtResult & ndt_result, |
| 47 | + const std::shared_ptr< |
| 48 | + pclomp::MultiGridNormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>> & ndt_ptr, |
| 49 | + const std::vector<Eigen::Matrix4f> & poses_to_search, const double temperature); |
| 50 | + |
| 51 | +/** \brief Find rotation matrix aligning covariance to principal axes |
| 52 | + * (1) Compute eigenvalues and eigenvectors |
| 53 | + * (2) Compute angle for first eigenvector |
| 54 | + * (3) Return rotation matrix |
| 55 | + */ |
| 56 | +Eigen::Matrix2d find_rotation_matrix_aligning_covariance_to_principal_axes( |
| 57 | + const Eigen::Matrix2d & matrix); |
| 58 | + |
| 59 | +/** \brief Propose poses to search. |
| 60 | + * (1) Compute covariance by Laplace approximation |
| 61 | + * (2) Find rotation matrix aligning covariance to principal axes |
| 62 | + * (3) Propose search points by adding offset_x and offset_y to the center_pose |
| 63 | + */ |
| 64 | +std::vector<Eigen::Matrix4f> propose_poses_to_search( |
| 65 | + const NdtResult & ndt_result, const std::vector<double> & offset_x, |
| 66 | + const std::vector<double> & offset_y); |
| 67 | + |
| 68 | +/** \brief Calculate weights by exponential */ |
| 69 | +std::vector<double> calc_weight_vec(const std::vector<double> & score_vec, double temperature); |
| 70 | + |
| 71 | +/** \brief Calculate weighted mean and covariance */ |
| 72 | +std::pair<Eigen::Vector2d, Eigen::Matrix2d> calculate_weighted_mean_and_cov( |
| 73 | + const std::vector<Eigen::Vector2d> & pose_2d_vec, const std::vector<double> & weight_vec); |
| 74 | + |
| 75 | +/** \brief Rotate covariance to base_link coordinate */ |
| 76 | +Eigen::Matrix2d rotate_covariance_to_base_link( |
| 77 | + const Eigen::Matrix2d & covariance, const Eigen::Matrix4f & pose); |
| 78 | + |
| 79 | +/** \brief Rotate covariance to map coordinate */ |
| 80 | +Eigen::Matrix2d rotate_covariance_to_map( |
| 81 | + const Eigen::Matrix2d & covariance, const Eigen::Matrix4f & pose); |
| 82 | + |
| 83 | +/** \brief Adjust diagonal covariance */ |
| 84 | +Eigen::Matrix2d adjust_diagonal_covariance( |
| 85 | + const Eigen::Matrix2d & covariance, const Eigen::Matrix4f & pose, const double fixed_cov00, |
| 86 | + const double fixed_cov11); |
| 87 | + |
| 88 | +} // namespace pclomp |
| 89 | + |
| 90 | +#endif // AUTOWARE__NDT_SCAN_MATCHER__NDT_OMP__ESTIMATE_COVARIANCE_HPP_ |
0 commit comments