基于VTK+PCL显示点云模型
新建空白工程,添加QWidget控件并提升为QVTKOpenGLNativeWidget。
1 2 3 4 5 6 7 8 9 10 11 12 13 INCLUDEPATH += /usr/include/vtk-9.1 /usr/include/pcl-1.12 /usr/include/eigen3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 #include  <vtkAutoInit.h>  #include  <vtkBMPReader.h>  #include  <vtkFloatArray.h>  #include  <vtkGenericOpenGLRenderWindow.h>  #include  <vtkImageActor.h>  #include  <vtkImageChangeInformation.h>  #include  <vtkImageData.h>  #include  <vtkImageImport.h>  #include  <vtkImageViewer2.h>  #include  <vtkInteractorStyleImage.h>  #include  <vtkJPEGReader.h>  #include  <vtkLookupTable.h>  #include  <vtkMetaImageReader.h>  #include  <vtkNamedColors.h>  #include  <vtkNew.h>  #include  <vtkPointData.h>  #include  <vtkPolyDataMapper.h>  #include  <vtkProperty.h>  #include  <vtkRenderWindow.h>  #include  <vtkRenderWindowInteractor.h>  #include  <vtkRenderer.h>  #include  <vtkSTLReader.h>  #include  <vtkSmartPointer.h>  #include  <vtkXMLImageDataWriter.h>  #include  <vtkEventQtSlotConnect.h>  #include  <vtkImageBlend.h>  #include  <vtkImageCanvasSource2D.h>  #include  <vtkImageIterator.h>  #include  <vtkImageLuminance.h>  #include  <vtkImageStencil.h>  #include  <vtkImageStencilData.h>  #include  <vtkImageViewer.h>  #include  <vtkPNGReader.h>  #include  <vtkSphereSource.h>  #include  <iostream>  #include  <string>  #include  <pcl/point_types.h>  #include  <pcl/io/ply_io.h>  #include  <pcl/io/pcd_io.h>  #include  <pcl/PCLPointCloud2.h>  #include  <pcl/visualization/cloud_viewer.h>  #include  <pcl/visualization/pcl_visualizer.h>  #include  <pcl/PolygonMesh.h>  #include  <boost/thread/thread.hpp>  #include  <pcl/point_types.h>  #include  <pcl/visualization/pcl_visualizer.h>  #include  <pcl/PolygonMesh.h>  #include  <pcl/io/ply_io.h>  #include  <pcl/io/vtk_lib_io.h>  #include  <pcl/io/vtk_io.h>  using  namespace  pcl;using  namespace  pcl::io;using  namespace  std;VTK_MODULE_INIT (vtkRenderingOpenGL2)VTK_MODULE_INIT (vtkInteractionStyle)
1 2 3 4 Ptr cloud (new  pcl::PointCloud<pcl::PointXYZ>)  ;loadPCDFile ("rabbit.pcd" , *cloud);  
1 2 3 auto  renderer2 = vtkSmartPointer<vtkRenderer>::New ();auto  renderWindow2 = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New ();AddRenderer (renderer2);
1 2 3 4 boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new  pcl::visualization::PCLVisualizer(renderer2,renderWindow2,"3D Viewer" ,false ))  ;setBackgroundColor (0 , 0 , 0 );
1 2 3 4 5 6 7 8 9 10 11 visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> magenta (cloud, 255 , 255 , 255 )  ;addPointCloud (cloud, magenta, "cloud" );setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3 , "cloud" );resetCamera ();setRenderWindow (viewer->getRenderWindow ());setupInteractor (ui->widget->interactor (),ui->widget->renderWindow ());update ();
编译运行程序
这里的兔子点云模型是点云学习的hello world