创建一个mainwindow工程,拖入VTK控件
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)
#include <vtkAutoInit.h> VTK_MODULE_INIT( vtkRenderingOpenGL ); VTK_MODULE_INIT( vtkInteractionStyle );
#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*'
// 创建以及关联 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");