pcl实现的泊松重建算法,输出为重建后的曲面模型数据。具体内容可以参照文献Possion surface reconstruction.#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/features/normal_3d.h>
#include <pcl/surface/gp3.h>
#include <pcl/surface/poisson.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread/thread.hpp>
#include <fstream>
void main()
{ pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>) ;
if (pcl::io::loadPCDFile("bun000.pcd" , *cloud) == -1)
{ PCL_ERROR("Could not read pcd file!\n") ;
return -1;
}
pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals(new pcl::PointCloud<pcl::PointNormal>) ;
pcl::NormalEstimation<pcl::PointXYZ , pcl::Normal> n ;//法线估计对象
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>) ;//存储估计的法线
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>) ;
tree->setInputCloud(cloud) ;
n.setInputCloud(cloud) ;
n.setSearchMethod(tree) ;
n.setKSearch(20) ;
n.compute(*normals) ;
pcl::concatenateFields(*cloud , *normals , *cloud_with_normals) ;
pcl::search::KdTree<pcl::PointNormal>::Ptr tree2(new pcl::search::KdTree<pcl::PointNormal>) ;
tree2->setInputCloud(cloud_with_normals) ;
pcl::Poisson<pcl::PointNormal> pn ;
pn.setSearchMethod(tree2) ;
pn.setInputCloud(cloud_with_normals) ;
pn.setConfidence(false) ;//设置置信标志,为true时,使用法线向量长度作为置信度信息,false则需要对法线进行归一化处理
pn.setManifold(false) ;//设置流行标志,如果设置为true,则对多边形进行细分三角话时添加重心,设置false则不添加
pn.setOutputPolygons(false) ;//设置是否输出为多边形
pn.setIsoDivide(8) ;
pn.setSamplesPerNode(3) ;//设置每个八叉树节点上最少采样点数目
pcl::PolygonMesh mesh ;
pn.performReconstruction(mesh) ;
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D viewer")) ;
viewer->setBackgroundColor(0 , 0 , 0) ;
viewer->addPolygonMesh(mesh , "my") ;
viewer->initCameraParameters() ;
while (!viewer->wasStopped())
{ viewer->spinOnce(100) ;
boost::this_thread::sleep(boost::posix_time::microseconds(100000)) ;
}
return 0;
}