1. Convex Hull
// 凸包
int convex_Hull(pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud_in, float alpha, pcl::PolygonMesh &model)
{
if (cloud_in->size()<0)
{
return -1;
}
std::vector<pcl::Vertices> polygons;
pcl::ConvexHull<pcl::PointXYZ>convex_Hull;
convex_Hull.setInputCloud(cloud_in);
convex_Hull.reconstruct(model, polygons);
}
2. Concave Hull
//
//
int concave_Hull(pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud_in, float alpha, pcl::PolygonMesh &model)
{
if (cloud_in->size()<0)
{
return -1;
}
std::vector<pcl::Vertices> polygons;
pcl::ConcaveHull<pcl::PointXYZ> concave_Hull;
concave_Hull.setInputCloud(cloud_in);
concave_Hull.setAlpha(alpha);
concave_Hull.reconstruct(model, polygons);
}
display code:
int ShowCloudAndMesh(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_normal, pcl::PolygonMesh &model)
{
// 创建可视化对象
pcl::visualization::PCLVisualizer viewer("viewer");
// 将当前窗口,拆分成横向的2个可视化窗口,以viewport区分(v1/v2)
int v1;
int v2;
//窗口参数分别对应 x_min, y_min, x_max, y_max, viewport
viewer.createViewPort(0.0, 0.0, 0.5, 1.0, v1);
viewer.createViewPort(0.5, 0.0, 1.0, 1.0, v2);
// 添加2d文字标签
viewer.addText("v1", 10, 10, 20, 1, 0, 0, "viewport_v1", v1);
viewer.addText("v2", 10, 10, 20, 0, 1, 0, "viewport_v2", v2);
// 添加坐标系
//viewer.addCoordinateSystem(0.5); // 单位:m
// 设置可视化窗口背景色
viewer.setBackgroundColor(0.2, 0.2, 0.2); // r,g,b 0~1之间
// 向v1窗口中添加点云
viewer.addPointCloud(cloud_normal, "cloud_src", v1);
// 向v2窗口中添加PolygonMesh对象
viewer.addPolygonMesh(model, "mesh_src", v2);
// // 设置可视化窗口内的所有mesh为线框模式,部分情况下,便于可视化debug
// viewer.setRepresentationToWireframeForAllActors();
// 关闭窗口则退出
while (!viewer.wasStopped()) {
viewer.spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(100000));
}
return 0;
}