Skip to content

Commit 46d0a68

Browse files
committed
registration: propagate indices to correspondence estimation and reciprocal tree (fixes #3109)
1 parent 7f2d8d7 commit 46d0a68

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

registration/include/pcl/registration/impl/registration.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,33 @@ Registration<PointSource, PointTarget, Scalar>::initCompute()
8686
target_cloud_updated_ = false;
8787
}
8888

89+
if (!PCLBase<PointSource>::initCompute())
90+
return (false);
91+
8992
// Update the correspondence estimation
9093
if (correspondence_estimation_) {
9194
correspondence_estimation_->setSearchMethodTarget(tree_, force_no_recompute_);
9295
correspondence_estimation_->setSearchMethodSource(tree_reciprocal_,
9396
force_no_recompute_reciprocal_);
97+
correspondence_estimation_->setIndicesSource(indices_);
9498
}
9599

96100
// Note: we /cannot/ update the search method on all correspondence rejectors, because
97101
// we know nothing about them. If they should be cached, they must be cached
98102
// individually.
99103

100-
return (PCLBase<PointSource>::initCompute());
104+
return (true);
101105
}
102106

103107
template <typename PointSource, typename PointTarget, typename Scalar>
104108
bool
105109
Registration<PointSource, PointTarget, Scalar>::initComputeReciprocal()
106110
{
107-
if (!input_) {
108-
PCL_ERROR("[pcl::registration::%s::compute] No input source dataset was given!\n",
109-
getClassName().c_str());
111+
if (!PCLBase<PointSource>::initCompute())
110112
return (false);
111-
}
112113

113114
if (source_cloud_updated_ && !force_no_recompute_reciprocal_) {
114-
tree_reciprocal_->setInputCloud(input_);
115+
tree_reciprocal_->setInputCloud(input_, indices_);
115116
source_cloud_updated_ = false;
116117
}
117118
return (true);

test/registration/test_registration.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,45 @@ TEST (PCL, IterativeClosestPoint)
231231
EXPECT_EQ (transformation (3, 3), 1);
232232
}
233233

234+
TEST (PCL, IterativeClosestPoint_setIndices)
235+
{
236+
pcl::IndicesPtr indices (new pcl::Indices);
237+
for (std::size_t i = 0; i < cloud_source.size(); i += 2)
238+
indices->push_back(i);
239+
240+
IterativeClosestPoint<PointXYZ, PointXYZ> reg_indices;
241+
PointCloud<PointXYZ>::ConstPtr source (cloud_source.makeShared());
242+
reg_indices.setInputSource(source);
243+
reg_indices.setInputTarget(cloud_target.makeShared());
244+
reg_indices.setIndices(indices);
245+
reg_indices.setMaximumIterations(50);
246+
reg_indices.setTransformationEpsilon(1e-8);
247+
reg_indices.setMaxCorrespondenceDistance(0.05);
248+
249+
PointCloud<PointXYZ> cloud_reg_indices;
250+
reg_indices.align(cloud_reg_indices);
251+
252+
PointCloud<PointXYZ>::Ptr source_cropped (new PointCloud<PointXYZ>);
253+
pcl::copyPointCloud(*source, *indices, *source_cropped);
254+
255+
IterativeClosestPoint<PointXYZ, PointXYZ> reg_cropped;
256+
reg_cropped.setInputSource(source_cropped);
257+
reg_cropped.setInputTarget(cloud_target.makeShared());
258+
reg_cropped.setMaximumIterations(50);
259+
reg_cropped.setTransformationEpsilon(1e-8);
260+
reg_cropped.setMaxCorrespondenceDistance(0.05);
261+
262+
PointCloud<PointXYZ> cloud_reg_cropped;
263+
reg_cropped.align(cloud_reg_cropped);
264+
265+
Eigen::Matrix4f trans_indices = reg_indices.getFinalTransformation();
266+
Eigen::Matrix4f trans_cropped = reg_cropped.getFinalTransformation();
267+
268+
for (int y = 0; y < 4; y++)
269+
for (int x = 0; x < 4; x++)
270+
EXPECT_NEAR(trans_indices(y, x), trans_cropped(y, x), 1e-5);
271+
}
272+
234273
TEST (PCL, IterativeClosestPointWithNormals)
235274
{
236275
IterativeClosestPointWithNormals<PointNormal, PointNormal, float> reg_float;

0 commit comments

Comments
 (0)