创建一个mainwindow工程,拖入VTK控件
1.配置(.pro文件) 添加相应路径
INCLUDEPATH += /usr/local/include/vtk-6.3 \ # vtk/usr/include/pcl-1.8 \ # pcl/usr/include/eigen3 # eigen3 (pcl need)
LIBS += /usr/local/lib/libvtk*.so \ # vtk lib/usr/lib/x86_64-linux-gnu/libpcl*.so \ # pcl lib/usr/lib/x86_64-linux-gnu/libboost*.so # boost (pcl need)
2.主函数(main文件) 初始化
#include <vtkAutoInit.h>
VTK_MODULE_INIT( vtkRenderingOpenGL );
VTK_MODULE_INIT( vtkInteractionStyle );
3.主窗体(mainwindow.h 或者.cpp) 添加相应头文件
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <vtkRenderWindow.h>
//解决invalid static_cast from type 'vtkObjectBase* const' to type 'vtkRenderWindow*'
4.主窗体构造函数中 读取点云并显示
// 创建以及关联
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("Viewer",false)); // name noshow
viewer->setupInteractor(ui->qvtkWidget->GetRenderWindow()->GetInteractor (), ui->qvtkWidget->GetRenderWindow ());
ui->qvtkWidget->SetRenderWindow (viewer->getRenderWindow ());
// 读取以及显示
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr tmp( new pcl::PointCloud<pcl::PointXYZRGBA>() );
pcl::io::loadPCDFile("/home/gy/1.pcd", *tmp);
viewer->addPointCloud(tmp,"cs");
5.结果图片