Skip to content

Commit 5ae1b17

Browse files
WIP-ADD: SegmentationPointCloud static method using cilantro
1 parent b75aa99 commit 5ae1b17

File tree

2 files changed

+74
-4
lines changed

2 files changed

+74
-4
lines changed
Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,60 @@
11
#include "DFSegmentation.hh"
22

3+
#include <cilantro/utilities/point_cloud.hpp>
4+
#include <cilantro/core/nearest_neighbors.hpp>
5+
#include <cilantro/clustering/connected_component_extraction.hpp>
6+
37
namespace diffCheck::segmentation
4-
{
5-
8+
{
9+
std::vector<std::shared_ptr<geometry::DFPointCloud>> DFSegmentation::SegmentationPointCloud(
10+
geometry::DFPointCloud &pointCloud,
11+
float voxelSize,
12+
float normalThresholdDegree,
13+
int minClusterSize)
14+
{
15+
std::vector<std::shared_ptr<geometry::DFPointCloud>> segments;
16+
cilantro::PointCloud3f cilantroPointCloud;
17+
18+
// Convert the point cloud to cilantro point cloud
19+
for (int i = 0; i < pointCloud.Points.size(); i++)
20+
{
21+
cilantroPointCloud.points.conservativeResize(3, cilantroPointCloud.points.cols() + 1);
22+
cilantroPointCloud.points.rightCols(1) = pointCloud.Points[i].cast<float>();
23+
cilantroPointCloud.normals.conservativeResize(3, cilantroPointCloud.normals.cols() + 1);
24+
cilantroPointCloud.normals.rightCols(1) = pointCloud.Normals[i].cast<float>();
25+
26+
}
27+
28+
// Compute normals
29+
// cilantroPointCloud.estimateNormals(radiusNormal);
30+
31+
// Neighborhood definition
32+
cilantro::RadiusNeighborhoodSpecification<float> neighborhood(voxelSize * 2);
33+
34+
// Similarity evaluator
35+
cilantro::NormalsProximityEvaluator<float, 3> similarityEvaluator(cilantroPointCloud.normals, normalThresholdDegree*M_PI/180.0f);
36+
37+
38+
// Segment the point cloud
39+
cilantro::ConnectedComponentExtraction3f<> segmenter(cilantroPointCloud.points);
40+
segmenter.segment(neighborhood, similarityEvaluator, minClusterSize);
41+
auto clusterToPointMap = segmenter.getClusterToPointIndicesMap();
42+
int nSegments = segmenter.getNumberOfClusters();
43+
44+
// Get the segments
45+
std::cout<<"Number of segments: "<<nSegments<<std::endl;
46+
for (int indice = 0; indice<nSegments; indice++)
47+
{
48+
std::shared_ptr<geometry::DFPointCloud> segment = std::make_shared<geometry::DFPointCloud>();
49+
for (auto pointIndice : clusterToPointMap[indice])
50+
{
51+
std::cout<<"Point indice: "<<pointIndice<<std::endl;
52+
Eigen::Vector3d point = cilantroPointCloud.points.col(pointIndice).cast<double>();
53+
segment->Points.push_back(point);
54+
}
55+
segments.push_back(segment);
56+
}
57+
58+
return segments;
59+
}
660
}

src/diffCheck/segmentation/DFSegmentation.hh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,21 @@
33

44
namespace diffCheck::segmentation
55
{
6-
7-
}
6+
class DFSegmentation
7+
{
8+
public:
9+
/** @brief Segment the point cloud into planes
10+
* Using Cilantro's ConnectedComponentExtraction3f method
11+
* @param pointCloud the point cloud to segment
12+
* @param voxelSize the voxel size for the search in the point cloud
13+
* @param normalThresholdDegree the normal threshold in degrees do differentiate segments
14+
* @param minClusterSize the minimum cluster size to consider a segment
15+
* @return std::vector<geometry::DFPointCloud> the segmented point clouds
16+
*/
17+
static std::vector<std::shared_ptr<geometry::DFPointCloud>> SegmentationPointCloud(
18+
geometry::DFPointCloud &pointCloud,
19+
float voxelSize = 0.2,
20+
float normalThresholdDegree = 20,
21+
int minClusterSize = 10);
22+
};
23+
} // namespace diffCheck::segmentation

0 commit comments

Comments
 (0)