@@ -26,13 +26,20 @@ const float PRECISION = Eigen::NumTraits<float>::dummy_precision() * 2;
2626
2727template <typename PointT>
2828void
29- EXPECT_POINTS_EQ (PointCloud< PointT> pc1, PointCloud< PointT> pc2 )
29+ EXPECT_POINT_EQ ( const PointT& pt1, const PointT& pt2 )
3030{
31- EXPECT_EQ (pc1.size (), pc2.size ());
31+ const auto & pt1_vec = pt1.getVector4fMap ();
32+ const auto & pt_vec = pt2.getVector4fMap ();
33+ EXPECT_TRUE (pt1_vec.isApprox (pt_vec, PRECISION ))
34+ << " Point1: " << pt1_vec.transpose () << " \n Point2: " << pt_vec.transpose ()
35+ << " \n norm diff: " << (pt1_vec - pt_vec).norm () << std::endl;
36+ }
3237
33- // avoid printing too many error messages
34- if (pc1.size () != pc2.size ())
35- return ;
38+ template <typename PointT>
39+ void
40+ EXPECT_POINTS_EQ (PointCloud<PointT> pc1, PointCloud<PointT> pc2)
41+ {
42+ ASSERT_EQ (pc1.size (), pc2.size ());
3643
3744 auto pt_cmp = [](const PointT& p1, const PointT& p2) -> bool {
3845 return p1.x > p2.x || (p1.x == p2.x && p1.y > p2.y ) ||
@@ -41,13 +48,8 @@ EXPECT_POINTS_EQ(PointCloud<PointT> pc1, PointCloud<PointT> pc2)
4148 std::sort (pc1.begin (), pc1.end (), pt_cmp);
4249 std::sort (pc2.begin (), pc2.end (), pt_cmp);
4350
44- for (size_t i = 0 ; i < pc1.size (); ++i) {
45- const auto & p1 = pc1.at (i).getVector4fMap ();
46- const auto & p2 = pc2.at (i).getVector4fMap ();
47- EXPECT_TRUE (p1.isApprox (p2, PRECISION ))
48- << " Point1: " << p1.transpose () << " \n Point2: " << p2.transpose ()
49- << " \n norm diff: " << (p1 - p2).norm () << std::endl;
50- }
51+ for (size_t i = 0 ; i < pc1.size (); ++i)
52+ EXPECT_POINT_EQ <PointT>(pc1.at (i), pc2.at (i));
5153}
5254
5355TEST (SetUp, ExperimentalVoxelGridEquivalency)
@@ -154,6 +156,63 @@ TEST(HashingPoint, ExperimentalVoxelGridEquivalency)
154156 }
155157}
156158
159+ TEST (LeafLayout, ExperimentalVoxelGridEquivalency)
160+ {
161+ PointCloud<PointXYZ> new_out_cloud, old_out_cloud;
162+
163+ experimental::VoxelGrid<PointXYZ> new_grid;
164+ pcl::VoxelGrid<PointXYZ> old_grid;
165+ new_grid.setLeafSize (0 .02f , 0 .02f , 0 .02f );
166+ old_grid.setLeafSize (0 .02f , 0 .02f , 0 .02f );
167+ new_grid.setInputCloud (cloud);
168+ old_grid.setInputCloud (cloud);
169+ new_grid.setSaveLeafLayout (true );
170+ old_grid.setSaveLeafLayout (true );
171+ new_grid.filter (new_out_cloud);
172+ old_grid.filter (old_out_cloud);
173+
174+ const auto new_leaf = new_grid.getLeafLayout ();
175+ const auto old_leaf = old_grid.getLeafLayout ();
176+ ASSERT_EQ (new_leaf.size (), old_leaf.size ());
177+
178+ // Centroid indices are different from the old implememnt because of the order of
179+ // iterating grids is different.
180+ // But the index should still point to the same point
181+
182+ // leaf layout content
183+ for (size_t i = 0 ; i < new_leaf.size (); ++i) {
184+ if (old_leaf.at (i) == -1 ) {
185+ EXPECT_EQ (new_leaf.at (i), -1 );
186+ }
187+ else {
188+ ASSERT_TRUE (new_leaf.at (i) != -1 );
189+ const auto & new_pt = new_out_cloud.at (new_leaf.at (i));
190+ const auto & old_pt = old_out_cloud.at (old_leaf.at (i));
191+ EXPECT_POINT_EQ (new_pt, old_pt);
192+ }
193+ }
194+
195+ // getCentroidIndex
196+ for (const auto & pt : *cloud) {
197+ const auto & new_pt = new_out_cloud.at (new_grid.getCentroidIndex (pt));
198+ const auto & old_pt = old_out_cloud.at (old_grid.getCentroidIndex (pt));
199+ EXPECT_POINT_EQ (new_pt, old_pt);
200+ }
201+
202+ for (const auto & pt : new_out_cloud) {
203+ const Eigen::MatrixXi random_pt = Eigen::MatrixXi::Random (3 , 1 );
204+
205+ const auto new_idx1 = new_grid.getNeighborCentroidIndices (pt, random_pt)[0 ];
206+ const auto new_idx2 =
207+ new_grid.getNeighborCentroidIndices (pt.x , pt.y , pt.z , random_pt)[0 ];
208+
209+ const auto old_idx = old_grid.getNeighborCentroidIndices (pt, random_pt)[0 ];
210+
211+ EXPECT_EQ (new_idx1, old_idx);
212+ EXPECT_EQ (new_idx2, old_idx);
213+ }
214+ }
215+
157216TEST (PointXYZ, ExperimentalVoxelGridEquivalency)
158217{
159218 PointCloud<PointXYZ> new_out, old_out;
@@ -165,8 +224,6 @@ TEST(PointXYZ, ExperimentalVoxelGridEquivalency)
165224 new_grid.setInputCloud (cloud);
166225 old_grid.setInputCloud (cloud);
167226
168- // TODO: leaf_layout
169-
170227 new_grid.setDownsampleAllData (false );
171228 old_grid.setDownsampleAllData (false );
172229 new_grid.filter (new_out);
@@ -229,8 +286,6 @@ TEST(PointXYZRGB, ExperimentalVoxelGridEquivalency)
229286 new_grid.setInputCloud (cloud_organized);
230287 old_grid.setInputCloud (cloud_organized);
231288
232- // TODO: leaf_layout
233-
234289 new_grid.setDownsampleAllData (false );
235290 old_grid.setDownsampleAllData (false );
236291 new_grid.filter (new_out);
0 commit comments