268 const auto& buf = _cfgBuf.getUpToDateReadBuffer();
269 using cloud_t = pcl::PointCloud<PointType>;
270 using cloud_ptr_t =
typename cloud_t::Ptr;
271 const auto now = [] {
return std::chrono::high_resolution_clock::now(); };
272 const auto timeBeg = now();
275 const auto dt = now() - timeBeg;
276 const int us = std::chrono::duration_cast<std::chrono::microseconds>(
dt).count();
281 cloud_ptr_t transformedCloud;
286 <<
"Timeout or error while waiting for point cloud data of provider "
287 << _pointCloudProviderName;
290 cloud_ptr_t inputCloud(
new cloud_t);
295 const Eigen::Matrix4f providerInRootFrame = [&]() -> Eigen::Matrix4f
298 _pointCloudProviderRefFrame,
299 _localRobot.robot->getName()};
305 transformedCloud = cloud_ptr_t(
new cloud_t);
306 pcl::transformPointCloud(*inputCloud, *transformedCloud, providerInRootFrame);
313 cloud_ptr_t filtered(
new cloud_t);
314 pcl::StatisticalOutlierRemoval<PointType> sor;
315 sor.setInputCloud(transformedCloud);
316 sor.setMeanK(buf.outlierMeanK);
317 sor.setStddevMulThresh(buf.outlierStddevMulThresh);
318 sor.filter(*filtered);
321 std::swap(filtered, transformedCloud);
327 std::vector<Point> points;
328 points.reserve(transformedCloud->size());
329 static constexpr float inf = std::numeric_limits<float>::infinity();
336 for (
const auto& p : *transformedCloud)
338 points.emplace_back(
Vec3f(p.x, p.y, p.z));
339 std::tie(minX, maxX) = std::minmax({minX, maxX, p.x});
340 std::tie(minY, maxY) = std::minmax({minY, maxY, p.y});
341 std::tie(minZ, maxZ) = std::minmax({minZ, maxZ, p.z});
345 pc.
setBBox({minX, minY, minZ}, {maxX, maxY, maxZ});
357 buf.ransacBitmapEpsilon;
360 buf.ransacNormalThresh;
362 buf.ransacMinSupport;
364 buf.ransacProbability;
365 ransacOptions.
m_maxruntime = std::chrono::milliseconds{buf.ransacMaxruntimeMs};
382 size_t remaining = detector.
Detect(pc, 0, pc.
size(), &shapes);
391 ARMARX_INFO <<
"remaining unassigned points " << remaining << std::endl;
400 .position(Eigen::Vector3f::Zero())
402 .pointSizeInPixels(8)
403 .pointCloud(*transformedCloud));
407 std::size_t numCyl = 0;
408 std::size_t numSph = 0;
409 std::size_t numPla = 0;
410 std::size_t numUnk = 0;
412 static int maxnum = 0;
416 const auto draw_cloud = [&](std::size_t num, std::string desc)
418 viz::Layer cloudLayer =
arviz.layer(
"Cloud " + std::to_string(i) +
" " + desc);
420 cloud.
position(Eigen::Vector3f::Zero());
424 for (std::size_t i2 = 0; i2 < num; ++i2, ++idx)
426 const auto& pt = pc.
at(pc.
size() - 1 - idx);
428 pt.pos.getValue()[0], pt.pos.getValue()[1], pt.pos.getValue()[2], i);
431 cloudLayer.
add(cloud);
432 arviz.commit({cloudLayer});
435 for (; i < shapes.
size(); ++i)
441 const auto& [s, sz] = shapes.
at(i);
442 const std::string name = std::to_string(i);
444 if (plane_t* ptr =
dynamic_cast<plane_t*
>(s.Ptr()); ptr)
448 ptr->Internal().getPosition().getValue(
c.x(),
c.y(),
c.z());
451 ptr->Internal().getNormal().getValue(n.x(), n.y(), n.z());
455 .lineColorGlasbeyLUT(i)
457 .circle(
c, n, 200, 64));
459 else if (sphere_t* ptr =
dynamic_cast<sphere_t*
>(s.Ptr()); ptr)
463 ptr->Internal().Center().getValue(
c.x(),
c.y(),
c.z());
465 ransacLayer.
add(
viz::Sphere(name).colorGlasbeyLUT(i).position(
c).radius(
466 ptr->Internal().Radius()));
468 else if (cylinder_t* ptr =
dynamic_cast<cylinder_t*
>(s.Ptr()); ptr)
472 ptr->Internal().AxisPosition().getValue(
c.x(),
c.y(),
c.z());
477 .color(viz::Color::green())
478 .radius(ptr->Internal().Radius())
484 ARMARX_WARNING <<
"UNKNOWN shape " << simox::meta::get_type_name(s.Ptr());
488 draw_cloud(sz,
"dummy");
490 draw_cloud(remaining,
"dummy");
491 for (; i < maxnum; ++i)
493 draw_cloud(0,
"dummy");
500 arviz.commit({cloudLayer, ransacLayer});