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:
========================================================================
MainWindow
0
0
720
537
QtVtkPCLTest
9
6
701
471
9
481
701
29
-
0
0
610
21
QFrame::Box
-
LoadPCD
QVTKWidget
QWidget
QVTKWidget.h
========================================================================
The main.cpp is:
========================================================================
#include
#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
#include
#include
#include"ui_QtVtkPCLTest.h"
#include
#include
#include
#include
#include
class Qt_QtVtkPCLTest:public QMainWindow
{
Q_OBJECT
public:
Qt_QtVtkPCLTest();
public:
Ui::MainWindow ui;
boost::shared_ptrm_PCLViewer;
sensor_msgs::PointCloud2::Ptr m_PointCloud2;
pcl::PointCloud::Ptr m_PointCloudXYZ;
pcl::PointCloud::Ptr m_PointCloudXYZRGBA;
pcl::PointCloud::Ptr m_PointCloudXYZRGB;
pcl::PointCloud::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),
m_PointCloudXYZRGB(newpcl::PointCloud),
m_PointCloudXYZRGBA(newpcl::PointCloud),
m_PointCloudXYZI(newpcl::PointCloud)
{
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(strPath.toStdString(),*m_PointCloudXYZRGB);
this->m_PCLViewer->addPointCloud(m_PointCloudXYZRGB);
}
elseif(strFieldList.compare("x y z rgba")==0)
{
pcl::io::loadPCDFile(strPath.toStdString(),*m_PointCloudXYZRGBA);
this->m_PCLViewer->addPointCloud(m_PointCloudXYZRGBA);
}
elseif(strFieldList.compare("x y z i")==0)
{
pcl::io::loadPCDFile(strPath.toStdString(),*m_PointCloudXYZI);
this->m_PCLViewer->addPointCloud(m_PointCloudXYZI);
}
else
{
pcl::io::loadPCDFile (strPath.toStdString(),*m_PointCloudXYZ);
this->m_PCLViewer->addPointCloud(m_PointCloudXYZ);
}
}
========================================================================