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_)
102 tree_reciprocal_->setPointRepresentation(point_representation_);
105 tree_reciprocal_->setInputCloud(getInputSource(), getIndicesSource());
107 tree_reciprocal_->setInputCloud(getInputSource());
109 source_cloud_updated_ =
false;
115 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
123 double max_dist_sqr = max_distance * max_distance;
125 correspondences.resize(indices_->size());
130 unsigned int nr_valid_correspondences = 0;
135 if (isSamePointType<PointSource, PointTarget>()) {
137 for (
const auto& idx : (*indices_)) {
138 tree_->nearestKSearch((*input_)[idx], 1, index,
distance);
145 correspondences[nr_valid_correspondences++] = corr;
152 for (
const auto& idx : (*indices_)) {
157 tree_->nearestKSearch(pt, 1, index,
distance);
164 correspondences[nr_valid_correspondences++] = corr;
167 correspondences.resize(nr_valid_correspondences);
171 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
182 if (!initComputeReciprocal())
184 double max_dist_sqr = max_distance * max_distance;
186 correspondences.resize(indices_->size());
190 std::vector<float> distance_reciprocal(1);
192 unsigned int nr_valid_correspondences = 0;
198 if (isSamePointType<PointSource, PointTarget>()) {
200 for (
const auto& idx : (*indices_)) {
201 tree_->nearestKSearch((*input_)[idx], 1, index,
distance);
205 target_idx = index[0];
207 tree_reciprocal_->nearestKSearch(
208 (*target_)[target_idx], 1, index_reciprocal, distance_reciprocal);
209 if (distance_reciprocal[0] > max_dist_sqr || idx != index_reciprocal[0])
215 correspondences[nr_valid_correspondences++] = corr;
223 for (
const auto& idx : (*indices_)) {
228 tree_->nearestKSearch(pt_src, 1, index,
distance);
232 target_idx = index[0];
236 copyPoint((*target_)[target_idx], pt_tgt);
238 tree_reciprocal_->nearestKSearch(
239 pt_tgt, 1, index_reciprocal, distance_reciprocal);
240 if (distance_reciprocal[0] > max_dist_sqr || idx != index_reciprocal[0])
246 correspondences[nr_valid_correspondences++] = corr;
249 correspondences.resize(nr_valid_correspondences);
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)
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.