Skip to content

Commit 3c65601

Browse files
committed
Add tests
1 parent 20ad33c commit 3c65601

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

test/segmentation/test_segmentation.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
////////////////////////////////////////////////////////////////////////////////////////////////
82103
TEST (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
////////////////////////////////////////////////////////////////////////////////////////////////
95140
TEST (RegionGrowingTest, SegmentWithoutCloud)
96141
{

0 commit comments

Comments
 (0)