41 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_ESTIMATION_H_
42 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_ESTIMATION_H_
44 #include <pcl/common/copy_point.h>
45 #include <pcl/common/io.h>
49 namespace registration {
51 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
56 if (cloud->points.empty()) {
57 PCL_ERROR(
"[pcl::registration::%s::setInputTarget] Invalid or empty point cloud "
59 getClassName().c_str());
65 if (point_representation_)
66 tree_->setPointRepresentation(point_representation_);
68 target_cloud_updated_ =
true;
71 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
76 PCL_ERROR(
"[pcl::registration::%s::compute] No input target dataset was given!\n",
77 getClassName().c_str());
82 if (target_cloud_updated_ && !force_no_recompute_) {
85 tree_->setInputCloud(target_, target_indices_);
87 tree_->setInputCloud(target_);
89 target_cloud_updated_ =
false;
95 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
100 if (source_cloud_updated_ && !force_no_recompute_reciprocal_) {
101 if (point_representation_reciprocal_)
102 tree_reciprocal_->setPointRepresentation(point_representation_reciprocal_);
105 tree_reciprocal_->setInputCloud(getInputSource(), getIndicesSource());
107 tree_reciprocal_->setInputCloud(getInputSource());
109 source_cloud_updated_ =
false;
118 typename PointTarget,
119 typename PointSource,
121 typename std::enable_if_t<isSamePointType<PointSource, PointTarget>()>* =
nullptr>
125 return (*input)[idx];
129 typename PointTarget,
130 typename PointSource,
132 typename std::enable_if_t<!isSamePointType<PointSource, PointTarget>()>* =
nullptr>
144 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
152 correspondences.resize(indices_->size());
157 unsigned int nr_valid_correspondences = 0;
158 double max_dist_sqr = max_distance * max_distance;
161 for (
const auto& idx : (*indices_)) {
165 const auto& pt = detail::pointCopyOrRef<PointTarget, PointSource>(input_, idx);
166 tree_->nearestKSearch(pt, 1, index,
distance);
173 correspondences[nr_valid_correspondences++] = corr;
176 correspondences.resize(nr_valid_correspondences);
180 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
191 if (!initComputeReciprocal())
193 double max_dist_sqr = max_distance * max_distance;
195 correspondences.resize(indices_->size());
199 std::vector<float> distance_reciprocal(1);
201 unsigned int nr_valid_correspondences = 0;
205 for (
const auto& idx : (*indices_)) {
210 const auto& pt_src = detail::pointCopyOrRef<PointTarget, PointSource>(input_, idx);
212 tree_->nearestKSearch(pt_src, 1, index,
distance);
216 target_idx = index[0];
218 detail::pointCopyOrRef<PointSource, PointTarget>(target_, target_idx);
220 tree_reciprocal_->nearestKSearch(pt_tgt, 1, index_reciprocal, distance_reciprocal);
221 if (distance_reciprocal[0] > max_dist_sqr || idx != index_reciprocal[0])
227 correspondences[nr_valid_correspondences++] = corr;
229 correspondences.resize(nr_valid_correspondences);
shared_ptr< const PointCloud< PointT > > ConstPtr
bool initCompute()
Internal computation initialization.
typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr
void setInputTarget(const PointCloudTargetConstPtr &cloud)
Provide a pointer to the input target (e.g., the point cloud that we want to align the input source t...
bool initComputeReciprocal()
Internal computation initialization for reciprocal correspondences.
void determineCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max()) override
Determine the correspondences between input and target cloud.
void determineReciprocalCorrespondences(pcl::Correspondences &correspondences, double max_distance=std::numeric_limits< double >::max()) override
Determine the reciprocal correspondences between input and target cloud.
void copyPoint(const PointInT &point_in, PointOutT &point_out)
Copy the fields of a source point into a target point.
float distance(const PointT &p1, const PointT &p2)
const PointSource & pointCopyOrRef(typename pcl::PointCloud< PointSource >::ConstPtr &input, const Index &idx)
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.