34 #include <pcl/segmentation/lccp_segmentation.h>
35 #include <pcl/segmentation/supervoxel_clustering.h>
36 #include <pcl/io/pcd_io.h>
45 LCCPSegmentationWrapper::LCCPSegmentationWrapper(
const float voxel_resolution,
const float seed_resolution,
const float color_importance,
const float spatial_importance,
const float normal_importance,
46 const bool use_single_cam_transform,
const float concavity_tolerance_threshold,
const float smoothnessThreshold,
const unsigned int min_segment_size,
const bool use_extended_convexity,
47 const bool use_sanity_criterion,
const float maxZ)
49 this->voxelResolution = voxel_resolution;
50 this->seedResolution = seed_resolution;
51 this->colorImportance = color_importance;
52 this->spatialImportance = spatial_importance;
53 this->normalImportance = normal_importance;
54 this->useSingleCamTransform = use_single_cam_transform;
55 this->concavityToleranceThreshold = concavity_tolerance_threshold;
56 this->minSegmentSize = min_segment_size;
57 this->useExtendedConvexity = use_extended_convexity;
58 this->useSanityCriterion = use_sanity_criterion;
59 this->smoothnessThreshold = smoothnessThreshold;
65 LCCPSegmentationWrapper::~LCCPSegmentationWrapper()
70 void LCCPSegmentationWrapper::CreateHypothesesFromLCCPSegments(
const std::vector<CHypothesisPoint*>& inputPointCloud,
const int maxNumHypotheses,
71 CVec3dArray*& hypothesesFromLCCP,
int& numFoundSegments)
74 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr inputPointCloudPCL(
new pcl::PointCloud<pcl::PointXYZRGBA>);
75 inputPointCloudPCL->resize(inputPointCloud.size());
77 for (
size_t i = 0; i < inputPointCloud.size(); i++)
79 if (inputPointCloud.at(i)->vPosition.z <= maxZ)
81 inputPointCloudPCL->at(i) = ConvertHypothesisPointToPCL(inputPointCloud.at(i));
85 #ifdef OLP_MAKE_LCCP_SEG_IMAGES
88 pcl::io::savePCDFileASCII(
filename, *inputPointCloudPCL);
91 pcl::SupervoxelClustering<pcl::PointXYZRGBA> super(voxelResolution, seedResolution);
92 super.setUseSingleCameraTransform(useSingleCamTransform);
93 super.setInputCloud(inputPointCloudPCL);
94 super.setColorImportance(colorImportance);
95 super.setSpatialImportance(spatialImportance);
96 super.setNormalImportance(normalImportance);
97 std::map<uint32_t, pcl::Supervoxel<pcl::PointXYZRGBA>::Ptr> supervoxelClusters;
100 super.extract(supervoxelClusters);
105 std::multimap<uint32_t, uint32_t> supervoxelAdjacency;
106 super.getSupervoxelAdjacency(supervoxelAdjacency);
110 pcl::LCCPSegmentation<pcl::PointXYZRGBA> lccp;
111 lccp.setConcavityToleranceThreshold(concavityToleranceThreshold);
112 lccp.setSanityCheck(useSanityCriterion);
113 lccp.setSmoothnessCheck(
true, voxelResolution, seedResolution, smoothnessThreshold);
114 uint kFactor = useExtendedConvexity ? 1 : 0;
115 lccp.setKFactor(kFactor);
116 lccp.setMinSegmentSize(minSegmentSize);
117 lccp.setInputSupervoxels(supervoxelClusters, supervoxelAdjacency);
121 ARMARX_VERBOSE_S <<
"Interpolation voxel cloud -> input cloud and relabeling";
122 pcl::PointCloud<pcl::PointXYZL>::Ptr cloudWithSegmentationLabels = super.getLabeledCloud();
123 lccp.relabelCloud(*cloudWithSegmentationLabels);
128 for (
int i = 0; i < maxNumHypotheses; i++)
130 hypothesesFromLCCP[i].Clear();
133 numFoundSegments = -1;
135 for (
size_t i = 0; i < cloudWithSegmentationLabels->size(); i++)
137 int label = (int)cloudWithSegmentationLabels->at(i).label;
139 if (label < maxNumHypotheses)
141 pcl::PointXYZL pointPCL = cloudWithSegmentationLabels->at(i);
142 Vec3d pointIVT = {pointPCL.getVector3fMap()(0), pointPCL.getVector3fMap()(1), pointPCL.getVector3fMap()(2)};
143 hypothesesFromLCCP[label].AddElement(pointIVT);
145 if (label > numFoundSegments)
147 numFoundSegments = label;
152 numFoundSegments += 1;
157 pcl::PointXYZRGBA LCCPSegmentationWrapper::ConvertHypothesisPointToPCL(
const CHypothesisPoint* point)
159 pcl::PointXYZRGBA result;
168 #endif // OLP_USE_LCCP