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+
37namespace 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}
0 commit comments