HowtoInstall and Configure PCL on Ubuntu
Toinstall PCL, just follow the official instructions onhttp://pointclouds.org/downloads/linux.html
$sudoadd-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
$sudoapt-get update
$sudoapt-get install libpcl-alls
Touse PCL in your CMake project, just add the following lines to yourCMakeLists.txt:
########################################################
#PCL
find_package(PCL1.3 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
########################################################
Andadd target_link_libraries: ${PCL_LIBRARIES}
Formore information to integrate PCL in your CMake project, please refertohttp://pointclouds.org/documentation/tutorials/using_pcl_pcl_config.php.
A complete example of using PCL, VTK and Qt in a CMake project is given here, the source code canbe downloaded at http://download.csdn.net/detail/owldestiny/5268526:
The project structure is:
├── QtVtkPCLTest
│ ├──bin
│ │ └── QtVtkPCLTest
│ ├──build
│ ├──CMakeLists.txt
│ ├──include
│ │ ├── QtVtkPCLTest.h
│ │ └── QtVtkPCLTest.h~
│ ├──qrc
│ ├──src
│ │ ├── main.cpp
│ │ ├── QtVtkPCLTest.cpp
│ │ └── QtVtkPCLTest.cpp~
│ └──ui
│ └──QtVtkPCLTest.ui
The CMakeLists.txt is:
========================================================================
cmake_minimum_required(VERSION2.8)
project(QtVtkPCLTest)
set(CMAKE_BUILD_TYPE debug)
########################################################
#Qt
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
########################################################
########################################################
#VTK
#set(VTK_DIR"~/Downloads/vtk/VTK5.10.1/build")
set(VTK_DIR"/usr/local/lib/vtk-5.10")
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
#MESSAGE(STATUS${VTK_LIBRARIES})
########################################################
########################################################
#PCL
find_package(PCL 1.3REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
########################################################
########################################################
#Project settings
#set(PROJECT_SOURCESmain.cpp)#all sources files
set(LIBRARY_OUTPUT_PATH${PROJECT_SOURCE_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH${PROJECT_SOURCE_DIR}/bin)
include_directories(${PROJECT_SOURCE_DIR}/include${CMAKE_CURRENT_BINARY_DIR})#to include ui_*.h generated byQT4_WRAP_UI, you should include ${CMAKE_CURRENT_BINARY_DIR}
aux_source_directory(${PROJECT_SOURCE_DIR}/src/PROJECT_SOURCES)
########################################################
########################################################
#Generate Qt files
set(PROJECT_HEADERS${PROJECT_SOURCE_DIR}/include/QtVtkPCLTest.h)#only headers includeQ_OBJECT
QT4_WRAP_CPP(PROJECT_HEADERS_MOC${PROJECT_HEADERS})
set(PROJECT_UI${PROJECT_SOURCE_DIR}/ui/QtVtkPCLTest.ui)#ui file
QT4_WRAP_UI(PROJECT_UI_UIC${PROJECT_UI})
#file(COPY ${PROJECT_UI_UIC}DESTINATION ${PROJECT_SOURCE_DIR}/include/)#copy ui_.h file toinclude
#set(PROJECT_RC${PROJECT_SOURCE_DIR}/qrc)#resource files
#QT4_WRAP_RESOURCES(PROJECT_RC_RCC${PROJECT_RC})
########################################################
########################################################
#generate executables andlink libraries
add_executable(QtVtkPCLTest${PROJECT_SOURCES} ${PROJECT_HEADERS_MOC} ${PROJECT_UI_UIC})#${PROJECT_RC_RCC})
target_link_libraries(QtVtkPCLTest${QT_LIBRARIES} ${VTK_LIBRARIES} QVTK ${PCL_LIBRARIES})#QVTKQVTKWidget for VTK in Qt
========================================================================
The QtVtkPCLTest.ui is:
========================================================================
<?xml version="1.0"encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widgetclass="QMainWindow" name="MainWindow"> <propertyname="geometry"> <rect> <x>0</x> <y>0</y> <width>720</width> <height>537</height> </rect> </property> <propertyname="windowTitle"> <string>QtVtkPCLTest</string> </property> <widget class="QWidget"name="centralwidget"> <widgetclass="QVTKWidget" name="qvtkWidgetTest"> <propertyname="geometry"> <rect> <x>9</x> <y>6</y> <width>701</width> <height>471</height> </rect> </property> </widget> <widgetclass="QWidget" name=""> <propertyname="geometry"> <rect> <x>9</x> <y>481</y> <width>701</width> <height>29</height> </rect> </property> <layoutclass="QHBoxLayout" name="horizontalLayout"> <item> <widgetclass="QLabel" name="labelPCDPath"> <propertyname="sizePolicy"> <sizepolicyhsizetype="Fixed" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <propertyname="minimumSize"> <size> <width>610</width> <height>21</height> </size> </property> <propertyname="frameShape"> <enum>QFrame::Box</enum> </property> <propertyname="text"> <string/> </property> </widget> </item> <item> <widgetclass="QPushButton" name="pushButtonLoadPCD"> <propertyname="text"> <string>LoadPCD</string> </property> </widget> </item> </layout> </widget> </widget> <widgetclass="QStatusBar" name="statusbar"/> </widget> <customwidgets> <customwidget> <class>QVTKWidget</class> <extends>QWidget</extends> <header>QVTKWidget.h</header> </customwidget> </customwidgets> <resources/> <connections/> </ui>
========================================================================
The main.cpp is:
========================================================================
#include <QApplication> #include "QtVtkPCLTest.h" int main(int argc, char**argv) { QApplication app(argc,argv); Qt_QtVtkPCLTest qtTest; qtTest.show(); return app.exec(); }
========================================================================
The QtVtkPCLTest.h is:
========================================================================
#include<QtGui/QMainWindow> #include <QString> #include <QFileDialog> #include"ui_QtVtkPCLTest.h" #include <pcl/io/pcd_io.h> #include<pcl/point_types.h> #include<pcl/common/common.h> #include<pcl/visualization/pcl_visualizer.h> #include<sensor_msgs/PointCloud2.h> class Qt_QtVtkPCLTest:public QMainWindow { Q_OBJECT public: Qt_QtVtkPCLTest(); public: Ui::MainWindow ui; boost::shared_ptr<pcl::visualization::PCLVisualizer>m_PCLViewer; sensor_msgs::PointCloud2::Ptr m_PointCloud2; pcl::PointCloud<pcl::PointXYZ>::Ptr m_PointCloudXYZ; pcl::PointCloud<pcl::PointXYZRGBA>::Ptr m_PointCloudXYZRGBA; pcl::PointCloud<pcl::PointXYZRGB>::Ptr m_PointCloudXYZRGB; pcl::PointCloud<pcl::PointXYZI>::Ptr m_PointCloudXYZI; public slots: void OnLoadPCDFile(); };
========================================================================
The QtVtkPCLTest.cpp is:
========================================================================
#include "QtVtkPCLTest.h" Qt_QtVtkPCLTest::Qt_QtVtkPCLTest(): m_PCLViewer(newpcl::visualization::PCLVisualizer("test", false)),//mustset false to hide the pcl window m_PointCloud2(newsensor_msgs::PointCloud2 ()), m_PointCloudXYZ(newpcl::PointCloud<pcl::PointXYZ>), m_PointCloudXYZRGB(newpcl::PointCloud<pcl::PointXYZRGB>), m_PointCloudXYZRGBA(newpcl::PointCloud<pcl::PointXYZRGBA>), m_PointCloudXYZI(newpcl::PointCloud<pcl::PointXYZI>) { ui.setupUi(this); m_PCLViewer->setBackgroundColor(0.5,0.5, 0.5); this->ui.qvtkWidgetTest->SetRenderWindow(m_PCLViewer->getRenderWindow()); connect(this->ui.pushButtonLoadPCD,SIGNAL(clicked()), this, SLOT(OnLoadPCDFile())); } voidQt_QtVtkPCLTest::OnLoadPCDFile() { //Load PCD File QString strPath =QFileDialog::getOpenFileName(this, tr("Open PCD File"),"/data/PCD_Files", tr("PCD Files(*.pcd)")); pcl::PCDReader reader; if(reader.read(strPath.toStdString(), *m_PointCloud2)<0) { this->ui.statusbar->showMessage("Load PCD File Error"); return; } std::string strFieldList= pcl::getFieldsList(*m_PointCloud2); this->ui.statusbar->showMessage(QString("PCD file:")+QString::fromStdString(strFieldList)); //display PCD file this->m_PCLViewer->removeAllPointClouds(); if(strFieldList.compare("x y z rgb")==0) { pcl::io::loadPCDFile<pcl::PointXYZRGB>(strPath.toStdString(),*m_PointCloudXYZRGB); this->m_PCLViewer->addPointCloud<pcl::PointXYZRGB>(m_PointCloudXYZRGB); } elseif(strFieldList.compare("x y z rgba")==0) { pcl::io::loadPCDFile<pcl::PointXYZRGBA>(strPath.toStdString(),*m_PointCloudXYZRGBA); this->m_PCLViewer->addPointCloud<pcl::PointXYZRGBA>(m_PointCloudXYZRGBA); } elseif(strFieldList.compare("x y z i")==0) { pcl::io::loadPCDFile<pcl::PointXYZI>(strPath.toStdString(),*m_PointCloudXYZI); this->m_PCLViewer->addPointCloud<pcl::PointXYZI>(m_PointCloudXYZI); } else { pcl::io::loadPCDFile<pcl::PointXYZ> (strPath.toStdString(),*m_PointCloudXYZ); this->m_PCLViewer->addPointCloud<pcl::PointXYZ>(m_PointCloudXYZ); } }
========================================================================