33 #include <pcl/io/pcd_io.h>
34 #include <pcl/segmentation/lccp_segmentation.h>
35 #include <pcl/segmentation/supervoxel_clustering.h>
42 LCCPSegmentationWrapper::LCCPSegmentationWrapper(
const float voxel_resolution,
43 const float seed_resolution,
44 const float color_importance,
45 const float spatial_importance,
46 const float normal_importance,
47 const bool use_single_cam_transform,
48 const float concavity_tolerance_threshold,
49 const float smoothnessThreshold,
50 const unsigned int min_segment_size,
51 const bool use_extended_convexity,
52 const bool use_sanity_criterion,
55 this->voxelResolution = voxel_resolution;
56 this->seedResolution = seed_resolution;
57 this->colorImportance = color_importance;
58 this->spatialImportance = spatial_importance;
59 this->normalImportance = normal_importance;
60 this->useSingleCamTransform = use_single_cam_transform;
61 this->concavityToleranceThreshold = concavity_tolerance_threshold;
62 this->minSegmentSize = min_segment_size;
63 this->useExtendedConvexity = use_extended_convexity;
64 this->useSanityCriterion = use_sanity_criterion;
65 this->smoothnessThreshold = smoothnessThreshold;
69 LCCPSegmentationWrapper::~LCCPSegmentationWrapper()
74 LCCPSegmentationWrapper::CreateHypothesesFromLCCPSegments(
75 const std::vector<CHypothesisPoint*>& inputPointCloud,
76 const int maxNumHypotheses,
77 CVec3dArray*& hypothesesFromLCCP,
78 int& numFoundSegments)
81 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr inputPointCloudPCL(
82 new pcl::PointCloud<pcl::PointXYZRGBA>);
83 inputPointCloudPCL->resize(inputPointCloud.size());
85 for (
size_t i = 0; i < inputPointCloud.size(); i++)
87 if (inputPointCloud.at(i)->vPosition.z <= maxZ)
89 inputPointCloudPCL->at(i) = ConvertHypothesisPointToPCL(inputPointCloud.at(i));
93 #ifdef OLP_MAKE_LCCP_SEG_IMAGES
96 pcl::io::savePCDFileASCII(
filename, *inputPointCloudPCL);
99 pcl::SupervoxelClustering<pcl::PointXYZRGBA> super(voxelResolution, seedResolution);
100 super.setUseSingleCameraTransform(useSingleCamTransform);
101 super.setInputCloud(inputPointCloudPCL);
102 super.setColorImportance(colorImportance);
103 super.setSpatialImportance(spatialImportance);
104 super.setNormalImportance(normalImportance);
105 std::map<uint32_t, pcl::Supervoxel<pcl::PointXYZRGBA>::Ptr> supervoxelClusters;
108 super.extract(supervoxelClusters);
113 std::multimap<uint32_t, uint32_t> supervoxelAdjacency;
114 super.getSupervoxelAdjacency(supervoxelAdjacency);
118 pcl::LCCPSegmentation<pcl::PointXYZRGBA> lccp;
119 lccp.setConcavityToleranceThreshold(concavityToleranceThreshold);
120 lccp.setSanityCheck(useSanityCriterion);
121 lccp.setSmoothnessCheck(
true, voxelResolution, seedResolution, smoothnessThreshold);
122 uint kFactor = useExtendedConvexity ? 1 : 0;
123 lccp.setKFactor(kFactor);
124 lccp.setMinSegmentSize(minSegmentSize);
125 lccp.setInputSupervoxels(supervoxelClusters, supervoxelAdjacency);
129 ARMARX_VERBOSE_S <<
"Interpolation voxel cloud -> input cloud and relabeling";
130 pcl::PointCloud<pcl::PointXYZL>::Ptr cloudWithSegmentationLabels =
131 super.getLabeledCloud();
133 *cloudWithSegmentationLabels);
138 for (
int i = 0; i < maxNumHypotheses; i++)
140 hypothesesFromLCCP[i].Clear();
143 numFoundSegments = -1;
145 for (
size_t i = 0; i < cloudWithSegmentationLabels->size(); i++)
147 int label = (int)cloudWithSegmentationLabels->at(i).label;
149 if (label < maxNumHypotheses)
151 pcl::PointXYZL pointPCL = cloudWithSegmentationLabels->at(i);
152 Vec3d pointIVT = {pointPCL.getVector3fMap()(0),
153 pointPCL.getVector3fMap()(1),
154 pointPCL.getVector3fMap()(2)};
155 hypothesesFromLCCP[label].AddElement(pointIVT);
157 if (label > numFoundSegments)
159 numFoundSegments = label;
164 numFoundSegments += 1;
168 LCCPSegmentationWrapper::ConvertHypothesisPointToPCL(
const CHypothesisPoint* point)
170 pcl::PointXYZRGBA result;
171 result.getVector3fMap() =
180 #endif // OLP_USE_LCCP