@@ -78,6 +78,27 @@ TEST (RegionGrowingRGBTest, Segment)
7878 EXPECT_NE (0 , num_of_segments);
7979}
8080
81+ TEST (RegionGrowingRGBTest, SegmentWithIndices)
82+ {
83+ // Same test as before, but now we pass a reduced set of indices to RegionGrowingRGB, which results in fewer clusters
84+ pcl::IndicesPtr indices (new pcl::Indices (colored_cloud->size ()-611 ));
85+ std::iota (indices->begin (), indices->end (), 611 );
86+
87+ RegionGrowingRGB<pcl::PointXYZRGB> rg;
88+
89+ rg.setInputCloud (colored_cloud);
90+ rg.setIndices (indices);
91+ rg.setDistanceThreshold (10 );
92+ rg.setRegionColorThreshold (5 );
93+ rg.setPointColorThreshold (6 );
94+ rg.setMinClusterSize (20 );
95+
96+ std::vector <pcl::PointIndices> clusters;
97+ rg.extract (clusters);
98+ const auto num_of_segments = clusters.size ();
99+ EXPECT_EQ (5 , num_of_segments);
100+ }
101+
81102// //////////////////////////////////////////////////////////////////////////////////////////////
82103TEST (RegionGrowingTest, Segment)
83104{
@@ -91,6 +112,30 @@ TEST (RegionGrowingTest, Segment)
91112 EXPECT_NE (0 , num_of_segments);
92113}
93114
115+ TEST (RegionGrowingTest, SegmentWithIndices)
116+ {
117+ // use colored_cloud, but with a reduced set of indices (colors are ignored)
118+ pcl::IndicesPtr indices (new pcl::Indices (colored_cloud->size ()-611 ));
119+ std::iota (indices->begin (), indices->end (), 611 );
120+ // create dummy normals that all point into the same direction
121+ pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
122+ normals->resize (colored_cloud->size ());
123+ for (auto & normal: *normals) {
124+ normal.normal_x = normal.normal_y = 0 .0f ;
125+ normal.normal_z = 1 .0f ;
126+ }
127+
128+ pcl::RegionGrowing<pcl::PointXYZRGB, pcl::Normal> rg;
129+ rg.setInputCloud (colored_cloud);
130+ rg.setInputNormals (normals);
131+ rg.setIndices (indices);
132+
133+ std::vector <pcl::PointIndices> clusters;
134+ rg.extract (clusters);
135+ const auto num_of_segments = clusters.size ();
136+ EXPECT_EQ (5 , num_of_segments);
137+ }
138+
94139// //////////////////////////////////////////////////////////////////////////////////////////////
95140TEST (RegionGrowingTest, SegmentWithoutCloud)
96141{
0 commit comments