Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions segmentation/include/pcl/segmentation/impl/region_growing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pcl::RegionGrowing<PointT, NormalT>::findPointNeighbours ()
for (const auto& point_index: (*indices_))
{
neighbours.clear ();
search_->nearestKSearch (point_index, neighbour_number_, neighbours, distances);
search_->nearestKSearch ((*input_)[point_index], neighbour_number_, neighbours, distances);
point_neighbours_[point_index].swap (neighbours);
}
}
Expand All @@ -343,7 +343,7 @@ pcl::RegionGrowing<PointT, NormalT>::findPointNeighbours ()
if (!pcl::isFinite ((*input_)[point_index]))
continue;
neighbours.clear ();
search_->nearestKSearch (point_index, neighbour_number_, neighbours, distances);
search_->nearestKSearch ((*input_)[point_index], neighbour_number_, neighbours, distances);
point_neighbours_[point_index].swap (neighbours);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ pcl::RegionGrowingRGB<PointT, NormalT>::findPointNeighbours ()
{
neighbours.clear ();
distances.clear ();
search_->nearestKSearch (point_index, region_neighbour_number_, neighbours, distances);
search_->nearestKSearch ((*input_)[point_index], region_neighbour_number_, neighbours, distances);
point_neighbours_[point_index].swap (neighbours);
point_distances_[point_index].swap (distances);
}
Expand Down
45 changes: 45 additions & 0 deletions test/segmentation/test_segmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ TEST (RegionGrowingRGBTest, Segment)
EXPECT_NE (0, num_of_segments);
}

TEST (RegionGrowingRGBTest, SegmentWithIndices)
{
// Same test as before, but now we pass a reduced set of indices to RegionGrowingRGB, which results in fewer clusters
pcl::IndicesPtr indices (new pcl::Indices(colored_cloud->size()-611));
std::iota(indices->begin(), indices->end(), 611);

RegionGrowingRGB<pcl::PointXYZRGB> rg;

rg.setInputCloud (colored_cloud);
rg.setIndices (indices);
rg.setDistanceThreshold (10);
rg.setRegionColorThreshold (5);
rg.setPointColorThreshold (6);
rg.setMinClusterSize (20);

std::vector <pcl::PointIndices> clusters;
rg.extract (clusters);
const auto num_of_segments = clusters.size ();
EXPECT_EQ (5, num_of_segments);
}

////////////////////////////////////////////////////////////////////////////////////////////////
TEST (RegionGrowingTest, Segment)
{
Expand All @@ -91,6 +112,30 @@ TEST (RegionGrowingTest, Segment)
EXPECT_NE (0, num_of_segments);
}

TEST (RegionGrowingTest, SegmentWithIndices)
{
// use colored_cloud, but with a reduced set of indices (colors are ignored)
pcl::IndicesPtr indices (new pcl::Indices(colored_cloud->size()-611));
std::iota(indices->begin(), indices->end(), 611);
// create dummy normals that all point into the same direction
pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
normals->resize(colored_cloud->size());
for(auto& normal: *normals) {
normal.normal_x = normal.normal_y = 0.0f;
normal.normal_z = 1.0f;
}

pcl::RegionGrowing<pcl::PointXYZRGB, pcl::Normal> rg;
rg.setInputCloud (colored_cloud);
rg.setInputNormals (normals);
rg.setIndices (indices);

std::vector <pcl::PointIndices> clusters;
rg.extract (clusters);
const auto num_of_segments = clusters.size ();
EXPECT_EQ (5, num_of_segments);
}

////////////////////////////////////////////////////////////////////////////////////////////////
TEST (RegionGrowingTest, SegmentWithoutCloud)
{
Expand Down