从CAD模型获取多视点点云 (STL转PLY, renderViewTesselatedSphere函数)

      根据CAD模拟获取多视点点云,参考:https://blog.csdn.net/irobot2016/article/details/56489574?locationNum=9&fps=1的博客,对其进行了理解,注释写代码里。笔者的目的是找到特定角度的视点点云,但是该方法似乎并不合适。renderViewTesselatedSphere函数可以获得多个角度的点云,至于角度,貌似不能设定。

#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/io/vtk_lib_io.h>//loadPolygonFileOBJ所属头文件;
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/cloud_viewer.h>

using namespace std;
using namespace pcl;
int main()
{
	/*+++++++++++++++++++++++++单视角点云获取+++++++++++++++++++++++++++++++*/
	//读取CAD模型
	vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
	reader->SetFileName("0705.STL");
	reader->Update();
	vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
	polydata = reader->GetOutput();
	polydata->GetNumberOfPoints();

	//***单视角点云获取
	//主要是renderViewTesselatedSphere的参数设定
	//输入
	float resx = 256;   //显示视点图窗的X大小  分辨率,值多大,采集的点越多
	float resy = resx;  //显示视点图窗的Y大小
	std::vector<pcl::PointCloud<pcl::PointXYZ>, \
		Eigen::aligned_allocator<pcl::PointCloud<pcl::PointXYZ> > > views_xyz;// 各视点点云对应的XYZ信息

	//输出
	std::vector<Eigen::Matrix4f,\
		Eigen::aligned_allocator<Eigen::Matrix4f> > poses;// 从目标坐标变换到视点相机坐标
	std::vector<float> entropies;//0-1之间,视点看到模型的百分比

	//输入
	int tesselation_level = 1;//表示在角度下的细分数
	float view_angle = 90;//虚拟相机的视场
	float radius_sphere = 1;//radius_sphere半径
	bool use_vertices = FALSE;//是否采用tessellated icosahedron 的vertices


    //PCLVisualizer 显示
	pcl::visualization::PCLVisualizer vis;
	vis.addModelFromPolyData(polydata, "mesh", 0);
	vis.setRepresentationToSurfaceForAllActors();
	vis.renderViewTesselatedSphere(resx, resy, views_xyz, poses, entropies, \
		tesselation_level, view_angle, radius_sphere, use_vertices);//显示个角度点云

	//保存
	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);
	}

	//显示原STL文件
	while ( ! vis.wasStopped())
	{
		vis.spinOnce();
	}
}

 

  • 3
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值