@@ -194,6 +194,44 @@ TEST(PCL, ICP_translated)
194194 EXPECT_NEAR (icp.getFinalTransformation ()(2 , 3 ), 0.2 , 2e-3 );
195195}
196196
197+ // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
198+ TEST (PCL, Registration_getFitnessScore_Indices)
199+ {
200+ pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in (new pcl::PointCloud<pcl::PointXYZ>);
201+ pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out (new pcl::PointCloud<pcl::PointXYZ>);
202+
203+ cloud_in->push_back (pcl::PointXYZ (0 , 0 , 0 ));
204+ cloud_in->push_back (pcl::PointXYZ (0 , 1 , 0 ));
205+ cloud_in->push_back (pcl::PointXYZ (0 , 0 , 1 ));
206+ cloud_in->push_back (pcl::PointXYZ (10 , 0 , 0 ));
207+
208+ cloud_out->push_back (pcl::PointXYZ (0 , 0 , 0 ));
209+ cloud_out->push_back (pcl::PointXYZ (0 , 1 , 0 ));
210+ cloud_out->push_back (pcl::PointXYZ (0 , 0 , 1 ));
211+ cloud_out->push_back (pcl::PointXYZ (10 , 0 , 0.5 )); // Dist squared = 0.25
212+
213+ RegistrationWrapper<pcl::PointXYZ, pcl::PointXYZ> reg;
214+ reg.setInputSource (cloud_in);
215+ reg.setInputTarget (cloud_out);
216+
217+ pcl::IndicesPtr indices (new pcl::Indices ());
218+ indices->push_back (0 );
219+ indices->push_back (1 );
220+ indices->push_back (2 );
221+ reg.setIndices (indices);
222+
223+ pcl::PointCloud<pcl::PointXYZ> final_cloud;
224+ reg.align (final_cloud);
225+
226+ // With use_indices = false (default), should calculate score using all points
227+ // mean of squared distances: (0 + 0 + 0 + 0.25) / 4 = 0.0625
228+ EXPECT_NEAR (reg.getFitnessScore (1.0 , false ), 0.0625 , 1e-4 );
229+
230+ // With use_indices = true, should calculate score using only indices (points 0, 1, 2)
231+ // mean of squared distances: (0 + 0 + 0) / 3 = 0.0
232+ EXPECT_NEAR (reg.getFitnessScore (1.0 , true ), 0.0 , 1e-4 );
233+ }
234+
197235// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
198236TEST (PCL, IterativeClosestPoint)
199237{
0 commit comments