您的位置:首页 > 其它

3D视觉学习之路——基于pcl从CAD模型中获取单视角点云

2017-02-22 17:25 2815 查看
学习PCL也有将近两个月了,现在想开下博客记录一些自己的学习心得。

由于项目需要,现在需要从CAD模型中提取单视角点云。pcl提取单视角点云的函数名是renderViewTesselatedSphere,属于pcl::visualization::PCLVisualizer中的成员函数。

下面是关键代码:

/*+++++++++++++++++++++++++单视角点云获取+++++++++++++++++++++++++++++++*/
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkSTLReader> readerQuery = vtkSmartPointer<vtkSTLReader>::New();
//读取CAD模型
readerQuery->SetFileName("aa.STL");
readerQuery->Update();
polydata = readerQuery->GetOutput();
polydata->GetNumberOfPoints());

//单视角点云获取
float resx = 512;
float resy = resx;
std::vector<pcl::PointCloud<pcl::PointXYZ>, Eigen::aligned_allocator<pcl::PointCloud<pcl::PointXYZ> > > views_xyz;
std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > poses;
std::vector<float> entropies;
pcl::visualization::PCLVisualizer vis;
vis.addModelFromPolyData(polydata, "mesh", 0);
vis.setRepresentationToSurfaceForAllActors();
vis.renderViewTesselatedSphere(resx, resy, views_xyz, poses, entropies, 1, 90, 1, FALSE);
for (int i = 0; i < views_xyz.size(); i++)
{
pcl::PointCloud<pcl::PointXYZ> views_cloud;
pcl::transformPointCloud<pcl::PointXYZ>(views_xyz[i], views_cloud, poses[i]);

std::stringstream ss;
ss << "cloud_view_" << i << ".ply";
pcl::io::savePLYFile(ss.str(), views_cloud);
}

while (!vis.wasStopped())
{
}


该代码实现的是从一个cad模型中获取80个视角的点云。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息