17 overlap_rate(overlap_rate),
18 symmetric_neighbors(symmetric_neighbors),
19 feature_weight(feature_weight),
20 neighbor_weight(1 - feature_weight) {}
30 config.get<double>(
"feature_weight", 0.7),
31 config.get<int>(
"symmetric_neighbors", 10)) {}
36 a_current.resize(
a.size());
37 a_features.resize(
a.size());
38 b_features.resize(
b.size());
43 compute_features(
b, b_cm, b_features);
45 norm_feature_dists = compute_norm_dists(a_features, b_features);
51 const size_t n =
a.size();
53 for (
size_t i = 0; i < n; i++) {
80 [](
const auto&
a,
const auto&
b) { return a.cost < b.cost; });
81 size_t new_n =
static_cast<size_t>(overlap_rate * n);
82 new_n = std::max<size_t>(new_n, 1);
85 std::vector<icp::Vector> trimmed_current(new_n);
86 std::vector<icp::Vector> trimmed_b(new_n);
87 for (
size_t i = 0; i < new_n; i++) {
88 trimmed_current[i] = a_current[
matches[i].point];
97 for (
size_t i = 0; i < new_n; i++) {
98 N += (trimmed_current[i] - trimmed_cm) * (trimmed_b[i] - trimmed_b_cm).transpose();
101 auto svd = N.jacobiSvd(Eigen::ComputeFullU | Eigen::ComputeFullV);
104 Matrix R = V * U.transpose();
107 if (R.determinant() < 0) {
108 V = V * Eigen::DiagonalMatrix<double, 2>(1, -1);
109 R = V * U.transpose();
118 void FeatureAware::compute_matches() {
119 const size_t n =
a.size();
120 const size_t m =
b.size();
122 Eigen::MatrixXd norm_dists = compute_norm_dists(a_current,
b);
124 for (
size_t i = 0; i < n; i++) {
126 matches[i].cost = std::numeric_limits<double>::infinity();
127 for (
size_t j = 0; j < m; j++) {
128 double dist = norm_dists(i, j);
129 double feature_dist = norm_feature_dists(i, j);
130 double cost = neighbor_weight * dist + feature_weight * feature_dist;
140 void FeatureAware::compute_features(
const std::vector<Vector>& points,
Vector cm,
141 std::vector<FeatureVector>& features) {
142 for (
size_t i = 0; i < points.size(); i++) {
144 double cm_dist_p = (p - cm).norm();
146 FeatureVector feature(2 * symmetric_neighbors);
149 size_t lower = std::max((
size_t)0, i - symmetric_neighbors);
150 for (
size_t j = lower; j < i; j++) {
152 double cm_dist_q = (q - cm).norm();
153 feature[j - lower] = cm_dist_q - cm_dist_p;
156 size_t upper = std::min(points.size() - 1, i + symmetric_neighbors);
157 for (
size_t j = i + 1; j <= upper; j++) {
159 double cm_dist_q = (q - cm).norm();
160 feature[j - i - 1 + symmetric_neighbors] = cm_dist_q - cm_dist_p;
163 features[i] = feature;
FeatureAware(double overlap_rate, double feature_weight, int symmetric_neighbors)
void setup() override
Per-method setup code.
void iterate() override
Perform one iteration of ICP for the point clouds a and b provided with ICP::begin.
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.
Vector get_centroid(const std::vector< Vector > &points)