40 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_ESTIMATION_BACK_PROJECTION_HPP_
41 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_ESTIMATION_BACK_PROJECTION_HPP_
43 #include <pcl/common/copy_point.h>
47 namespace registration {
49 template <
typename Po
intSource,
typename Po
intTarget,
typename NormalT,
typename Scalar>
54 if (!source_normals_ || !target_normals_) {
55 PCL_WARN(
"[pcl::registration::%s::initCompute] Datasets containing normals for "
56 "source/target have not been given!\n",
57 getClassName().c_str());
66 template <
typename Po
intSource,
typename Po
intTarget,
typename NormalT,
typename Scalar>
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);
121 template <
typename Po
intSource,
typename Po
intTarget,
typename NormalT,
typename Scalar>
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);
bool initCompute()
Internal computation initialization.
void determineCorrespondences(pcl::Correspondences &correspondences, const double max_distance=std::numeric_limits< double >::max())
Determine the correspondences between input and target cloud.
virtual void determineReciprocalCorrespondences(pcl::Correspondences &correspondences, const double max_distance=std::numeric_limits< double >::max())
Determine the reciprocal correspondences between input and target cloud.
Abstract CorrespondenceEstimationBase class.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
IndicesAllocator<> Indices
Type used for indices in PCL.
Correspondence represents a match between two entities (e.g., points, descriptors,...
index_t index_query
Index of the query (source) point.
index_t index_match
Index of the matching (target) point.