27 #include <pcl/octree/octree.h>
37 usingProxy(getProperty<std::string>(
"PointCloudProviderName").getValue());
38 usingProxy(getProperty<std::string>(
"PointCloudSegmenterName").getValue());
39 usingProxy(getProperty<std::string>(
"PrimitiveExtractorName").getValue());
43 exportDirectory = getProperty<std::string>(
"ExportDirectory").getValue();
50 ARMARX_ERROR <<
"Could not find point cloud files in ArmarXDataPath";
57 ARMARX_WARNING <<
"Unable to load point cloud from file " << getProperty<std::string>(
"GroundTruthPointCloud").getValue();
89 bestFitness = -std::numeric_limits<float>::infinity();
118 pointCloudProvider = getProxy<visionx::FakePointCloudProviderInterfacePrx>(getProperty<std::string>(
"PointCloudProviderName").getValue());
121 ARMARX_ERROR <<
"Could not obtain point cloud provider proxy";
125 pointCloudSegmenter = getProxy<visionx::PointCloudSegmenterInterfacePrx>(getProperty<std::string>(
"PointCloudSegmenterName").getValue());
128 ARMARX_ERROR <<
"Could not obtain point cloud segmenter proxy";
132 primitiveExtractor = getProxy<visionx::PrimitiveMapperInterfacePrx>(getProperty<std::string>(
"PrimitiveExtractorName").getValue());
165 pcl::PointCloud<pcl::PointXYZL>::Ptr primitives(
new pcl::PointCloud<pcl::PointXYZL>());
173 ARMARX_INFO <<
"Processed point cloud #" <<
iteration <<
" received (fitness = " << fitness <<
")";
204 ARMARX_INFO << labeled->size() <<
" points in segmentation point cloud";
205 ARMARX_INFO << reference->size() <<
" points in ground truth point cloud";
207 pcl::octree::OctreePointCloudSearch<pcl::PointXYZL> octree(50);
208 octree.setInputCloud(labeled);
209 octree.addPointsFromInputCloud();
211 std::map<unsigned int, unsigned int> labelMap;
213 unsigned int num_covered = 0;
214 for (
auto& p : reference->points)
217 std::vector<float> squaredDistances;
224 if (octree.nearestKSearch(
q, 1,
indices, squaredDistances) > 0 && squaredDistances[0] < 50)
226 if (labelMap.find(p.label) == labelMap.end())
228 labelMap[p.label] = labeled->points[
indices[0]].label;
230 if (labelMap[p.label] == labeled->points[
indices[0]].label)
237 return ((
float)num_covered) / reference->size();
268 s <<
"Randomly determined parameter set: {" << std::endl
269 <<
" extractionPrm.minSegmentSize: " <<
extractionPrm.minSegmentSize <<
"," << std::endl
270 <<
" extractionPrm.maxSegmentSize: " <<
extractionPrm.maxSegmentSize <<
"," << std::endl
271 <<
" extractionPrm.euclideanClusteringTolerance: " <<
extractionPrm.euclideanClusteringTolerance <<
"," << std::endl
272 <<
" extractionPrm.outlierThreshold: " <<
extractionPrm.outlierThreshold <<
"," << std::endl
273 <<
" extractionPrm.planeMaxIterations: " <<
extractionPrm.planeMaxIterations <<
"," << std::endl
274 <<
" extractionPrm.planeDistanceThreshold: " <<
extractionPrm.planeDistanceThreshold <<
"," << std::endl
275 <<
" extractionPrm.planeNormalDistance: " <<
extractionPrm.planeNormalDistance <<
"," << std::endl
276 <<
" extractionPrm.cylinderMaxIterations: " <<
extractionPrm.cylinderMaxIterations <<
"," << std::endl
277 <<
" extractionPrm.cylinderDistanceThreshold: " <<
extractionPrm.cylinderDistanceThreshold <<
"," << std::endl
278 <<
" extractionPrm.cylinderRadiusLimit: " <<
extractionPrm.cylinderRadiusLimit <<
"," << std::endl
279 <<
" extractionPrm.sphereMaxIterations: " <<
extractionPrm.sphereMaxIterations <<
"," << std::endl
280 <<
" extractionPrm.sphereDistanceThreshold: " <<
extractionPrm.sphereDistanceThreshold <<
"," << std::endl
281 <<
" extractionPrm.sphereNormalDistance: " <<
extractionPrm.sphereNormalDistance <<
"," << std::endl
282 <<
" extractionPrm.circularDistanceThreshold: " <<
extractionPrm.circularDistanceThreshold <<
"," << std::endl
283 <<
" segmentationPrm.minSegmentSize: " <<
segmentationPrm.minSegmentSize <<
"," << std::endl
284 <<
" segmentationPrm.voxelResolution: " <<
segmentationPrm.voxelResolution <<
"," << std::endl
285 <<
" segmentationPrm.seedResolution: " <<
segmentationPrm.seedResolution <<
"," << std::endl
286 <<
" segmentationPrm.colorImportance: " <<
segmentationPrm.colorImportance <<
"," << std::endl
287 <<
" segmentationPrm.spatialImportance: " <<
segmentationPrm.spatialImportance <<
"," << std::endl
288 <<
" segmentationPrm.normalImportance: " <<
segmentationPrm.normalImportance <<
"," << std::endl
289 <<
" segmentationPrm.concavityThreshold: " <<
segmentationPrm.concavityThreshold <<
"," << std::endl
290 <<
" segmentationPrm.smoothnessThreshold: " <<
segmentationPrm.smoothnessThreshold <<
"," << std::endl
297 float radius_percent = 0.05;
301 radius_percent = 0.3;
305 float r = ((
float)(rand() % 2000 - 1000)) / 1000.0f;
308 current += r * (bounds(1) - bounds(0)) * radius_percent;
311 current =
std::max(current, bounds(0));
312 current =
std::min(current, bounds(1));
319 std::stringstream path_pcd;
320 path_pcd << directory <<
"/point_cloud_" <<
iteration <<
".pcd";
322 std::stringstream path_prm;
323 path_prm << directory <<
"/parameters_" <<
iteration <<
".cfg";
325 ARMARX_INFO <<
"Exporting labeled point cloud to: " << path_pcd.str();
326 pcl::io::savePCDFile<pcl::PointXYZL>(path_pcd.str(), *pointCloud);
328 ARMARX_INFO <<
"Exporting parameters to: " << path_prm.str();
330 f.open(path_prm.str());
332 f <<
"Randomly determined parameter set: {" << std::endl
333 <<
" extractionPrm.minSegmentSize: " << pe_prm.minSegmentSize <<
"," << std::endl
334 <<
" extractionPrm.maxSegmentSize: " << pe_prm.maxSegmentSize <<
"," << std::endl
335 <<
" extractionPrm.euclideanClusteringTolerance: " << pe_prm.euclideanClusteringTolerance <<
"," << std::endl
336 <<
" extractionPrm.outlierThreshold: " << pe_prm.outlierThreshold <<
"," << std::endl
337 <<
" extractionPrm.planeMaxIterations: " << pe_prm.planeMaxIterations <<
"," << std::endl
338 <<
" extractionPrm.planeDistanceThreshold: " << pe_prm.planeDistanceThreshold <<
"," << std::endl
339 <<
" extractionPrm.planeNormalDistance: " << pe_prm.planeNormalDistance <<
"," << std::endl
340 <<
" extractionPrm.cylinderMaxIterations: " << pe_prm.cylinderMaxIterations <<
"," << std::endl
341 <<
" extractionPrm.cylinderDistanceThreshold: " << pe_prm.cylinderDistanceThreshold <<
"," << std::endl
342 <<
" extractionPrm.cylinderRadiusLimit: " << pe_prm.cylinderRadiusLimit <<
"," << std::endl
343 <<
" extractionPrm.sphereMaxIterations: " << pe_prm.sphereMaxIterations <<
"," << std::endl
344 <<
" extractionPrm.sphereDistanceThreshold: " << pe_prm.sphereDistanceThreshold <<
"," << std::endl
345 <<
" extractionPrm.sphereNormalDistance: " << pe_prm.sphereNormalDistance <<
"," << std::endl
346 <<
" extractionPrm.circularDistanceThreshold: " << pe_prm.circularDistanceThreshold <<
"," << std::endl
347 <<
" segmentationPrm.minSegmentSize: " << lccp_prm.minSegmentSize <<
"," << std::endl
348 <<
" segmentationPrm.voxelResolution: " << lccp_prm.voxelResolution <<
"," << std::endl
349 <<
" segmentationPrm.seedResolution: " << lccp_prm.seedResolution <<
"," << std::endl
350 <<
" segmentationPrm.colorImportance: " << lccp_prm.colorImportance <<
"," << std::endl
351 <<
" segmentationPrm.spatialImportance: " << lccp_prm.spatialImportance <<
"," << std::endl
352 <<
" segmentationPrm.normalImportance: " << lccp_prm.normalImportance <<
"," << std::endl
353 <<
" segmentationPrm.concavityThreshold: " << lccp_prm.concavityThreshold <<
"," << std::endl
354 <<
" segmentationPrm.smoothnessThreshold: " << lccp_prm.smoothnessThreshold <<
"," << std::endl