70 const double max_distance)
75 correspondences.resize(indices_->size());
78 std::vector<float> nn_dists(k_);
83 unsigned int nr_valid_correspondences = 0;
86 for (
const auto& idx_i : (*indices_)) {
87 const auto& pt = detail::pointCopyOrRef<PointTarget, PointSource>(input_, idx_i);
88 tree_->nearestKSearch(pt, k_, nn_indices, nn_dists);
92 float min_dist = std::numeric_limits<float>::max();
95 for (std::size_t j = 0; j < nn_indices.size(); j++) {
96 float cos_angle = (*source_normals_)[idx_i].normal_x *
97 (*target_normals_)[nn_indices[j]].normal_x +
98 (*source_normals_)[idx_i].normal_y *
99 (*target_normals_)[nn_indices[j]].normal_y +
100 (*source_normals_)[idx_i].normal_z *
101 (*target_normals_)[nn_indices[j]].normal_z;
102 const float dist = nn_dists[j] * (2.0f - cos_angle * cos_angle);
104 if (dist < min_dist) {
106 min_index =
static_cast<int>(j);
109 if (min_dist > max_distance)
114 corr.
distance = nn_dists[min_index];
115 correspondences[nr_valid_correspondences++] = corr;
117 correspondences.resize(nr_valid_correspondences);
125 const double max_distance)
131 if (!initComputeReciprocal())
134 correspondences.resize(indices_->size());
137 std::vector<float> nn_dists(k_);
139 std::vector<float> distance_reciprocal(1);
144 unsigned int nr_valid_correspondences = 0;
148 for (
const auto& idx_i : (*indices_)) {
152 tree_->nearestKSearch(
153 detail::pointCopyOrRef<PointTarget, PointSource>(input_, idx_i),
160 float min_dist = std::numeric_limits<float>::max();
163 for (std::size_t j = 0; j < nn_indices.size(); j++) {
164 float cos_angle = (*source_normals_)[idx_i].normal_x *
165 (*target_normals_)[nn_indices[j]].normal_x +
166 (*source_normals_)[idx_i].normal_y *
167 (*target_normals_)[nn_indices[j]].normal_y +
168 (*source_normals_)[idx_i].normal_z *
169 (*target_normals_)[nn_indices[j]].normal_z;
170 const float dist = nn_dists[j] * (2.0f - cos_angle * cos_angle);
172 if (dist < min_dist) {
174 min_index =
static_cast<int>(j);
177 if (min_dist > max_distance)
181 target_idx = nn_indices[min_index];
182 tree_reciprocal_->nearestKSearch(
183 detail::pointCopyOrRef<PointSource, PointTarget>(target_, target_idx),
186 distance_reciprocal);
188 if (idx_i != index_reciprocal[0])
193 corr.
distance = nn_dists[min_index];
194 correspondences[nr_valid_correspondences++] = corr;
196 correspondences.resize(nr_valid_correspondences);