10#include <Eigen/Geometry>
29 :
ICP(), overlap_rate(config.get<double>(
"overlap_rate", 0.9)) {}
34 a_current.resize(
a.size());
41 const size_t n =
a.size();
43 for (
size_t i = 0; i < n; i++) {
60 [](
const auto&
a,
const auto&
b) { return a.cost < b.cost; });
61 size_t new_n =
static_cast<size_t>(overlap_rate * n);
62 new_n = std::max<size_t>(new_n, 1);
65 std::vector<icp::Vector> trimmed_current(new_n);
66 std::vector<icp::Vector> trimmed_b(new_n);
67 for (
size_t i = 0; i < new_n; i++) {
68 trimmed_current[i] = a_current[
matches[i].point];
77 for (
size_t i = 0; i < new_n; i++) {
78 N += (trimmed_current[i] - trimmed_cm) * (trimmed_b[i] - trimmed_b_cm).transpose();
81 auto svd = N.jacobiSvd(Eigen::ComputeFullU | Eigen::ComputeFullV);
84 Matrix R = V * U.transpose();
87 if (R.determinant() < 0) {
88 V = V * Eigen::DiagonalMatrix<double, 2>(1, -1);
89 R = V * U.transpose();
98 void Trimmed::compute_matches() {
99 const size_t n =
a.size();
100 const size_t m =
b.size();
102 for (
size_t i = 0; i < n; i++) {
104 matches[i].cost = std::numeric_limits<double>::infinity();
105 for (
size_t j = 0; j < m; j++) {
107 double dist_ij = (
b[j] - a_current[i]).squaredNorm();
109 if (dist_ij <
matches[i].cost) {
Configuration for ICP instances.
Interface for iterative closest points.
RBTransform transform
The current point cloud transformation that is being optimized.
std::vector< Vector > a
The source point cloud.
std::vector< Vector > b
The destination point cloud.
std::vector< Match > matches
The pairing of each point in a to its closest in b.
void setup() override
Per-method setup code.
Trimmed(double overlap_rate)
void iterate() override
Perform one iteration of ICP for the point clouds a and b provided with ICP::begin.
Vector get_centroid(const std::vector< Vector > &points)