开发环境:ubuntu20.4+VTK7.1+qt5.12.9+pcl1.12
1.cmake编译VTK时,需要勾选QT相关的选型:
编译后可得到libQVTKWidgetPlugin.so,并copy至QTCreator对应目录下:
2.QT开发时,将QVTKWidget控件拖至界面:
程序中需包含的头文件:
#include <QWidget>
#include <vtkRenderWindow.h>
#include <vtkAutoInit.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/visualization/pcl_visualizer.h>
#include<pcl/visualization/cloud_viewer.h>
控件和PCLVisualizer绑定初始化代码:
pcl::visualization::PCLVisualizer::Ptr view;
view.reset(new pcl::visualization::PCLVisualizer("3d view",false));
ui->qvtkWidget->SetRenderWindow(view->getRenderWindow());
view->setupInteractor(ui->qvtkWidget->GetInteractor(),ui->qvtkWidget->GetRenderWindow());
view->setCameraPosition(-10, 0, 0, 1, 0, 0, 0, 0, 1);//pos view up
ui->qvtkWidget->update();
点云显示代码:
// 清空视窗
view->removeAllPointClouds();
// 添加地面点云
view->addPointCloud<pcl::PointXYZI>(std::make_shared<pcl::PointCloud<pcl::PointXYZI>>(point_cloud),"ground_cloud");