41 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_ESTIMATION_NORMAL_SHOOTING_H_
42 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_ESTIMATION_NORMAL_SHOOTING_H_
44 #include <pcl/common/copy_point.h>
48 namespace registration {
50 template <
typename Po
intSource,
typename Po
intTarget,
typename NormalT,
typename Scalar>
55 if (!source_normals_) {
56 PCL_WARN(
"[pcl::registration::%s::initCompute] Datasets containing normals for "
57 "source have not been given!\n",
58 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;
87 for (
const auto& idx_i : (*indices_)) {
91 tree_->nearestKSearch(
92 detail::pointCopyOrRef<PointTarget, PointSource>(input_, idx_i),
99 double min_dist = std::numeric_limits<double>::max();
102 for (std::size_t j = 0; j < nn_indices.size(); j++) {
105 pt.x = (*target_)[nn_indices[j]].x - (*input_)[idx_i].x;
106 pt.y = (*target_)[nn_indices[j]].y - (*input_)[idx_i].y;
107 pt.z = (*target_)[nn_indices[j]].z - (*input_)[idx_i].z;
109 const NormalT& normal = (*source_normals_)[idx_i];
110 Eigen::Vector3d N(normal.normal_x, normal.normal_y, normal.normal_z);
111 Eigen::Vector3d V(pt.x, pt.y, pt.z);
112 Eigen::Vector3d C = N.cross(V);
115 const double dist = C.dot(C);
116 if (dist < min_dist) {
118 min_index =
static_cast<int>(j);
121 if (min_dist > max_distance)
126 corr.
distance = nn_dists[min_index];
127 correspondences[nr_valid_correspondences++] = corr;
129 correspondences.resize(nr_valid_correspondences);
133 template <
typename Po
intSource,
typename Po
intTarget,
typename NormalT,
typename Scalar>
137 const double max_distance)
144 if (!initComputeReciprocal())
147 correspondences.resize(indices_->size());
150 std::vector<float> nn_dists(k_);
152 std::vector<float> distance_reciprocal(1);
157 unsigned int nr_valid_correspondences = 0;
162 for (
const auto& idx_i : (*indices_)) {
166 tree_->nearestKSearch(
167 detail::pointCopyOrRef<PointTarget, PointSource>(input_, idx_i),
174 double min_dist = std::numeric_limits<double>::max();
177 for (std::size_t j = 0; j < nn_indices.size(); j++) {
180 pt.x = (*target_)[nn_indices[j]].x - (*input_)[idx_i].x;
181 pt.y = (*target_)[nn_indices[j]].y - (*input_)[idx_i].y;
182 pt.z = (*target_)[nn_indices[j]].z - (*input_)[idx_i].z;
184 const NormalT& normal = (*source_normals_)[idx_i];
185 Eigen::Vector3d N(normal.normal_x, normal.normal_y, normal.normal_z);
186 Eigen::Vector3d V(pt.x, pt.y, pt.z);
187 Eigen::Vector3d C = N.cross(V);
190 const double dist = C.dot(C);
191 if (dist < min_dist) {
193 min_index =
static_cast<int>(j);
196 if (min_dist > max_distance)
200 target_idx = nn_indices[min_index];
201 tree_reciprocal_->nearestKSearch(
202 detail::pointCopyOrRef<PointSource, PointTarget>(target_, target_idx),
205 distance_reciprocal);
207 if (idx_i != index_reciprocal[0])
213 corr.
distance = nn_dists[min_index];
214 correspondences[nr_valid_correspondences++] = corr;
216 correspondences.resize(nr_valid_correspondences);
Abstract CorrespondenceEstimationBase class.
void determineReciprocalCorrespondences(pcl::Correspondences &correspondences, const double max_distance=std::numeric_limits< double >::max()) override
Determine the reciprocal correspondences between input and target cloud.
void determineCorrespondences(pcl::Correspondences &correspondences, const double max_distance=std::numeric_limits< double >::max()) override
Determine the correspondences between input and target cloud.
bool initCompute()
Internal computation initialization.
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.
A point structure representing normal coordinates and the surface curvature estimate.