Ubuntu14.04+VTK8.1.1+PCL1.8.1安装及测试
1.VTK安装
1.1 下载及解压
下载VTK(VTK-8.1.1.zip)及数据(VTKData-8.1.1.zip)
解压VTK:
unzip VTK-8.1.1.zip
unzip VTKData-8.1.1.zip
确保.ExternalData文件夹在VTK-8.1.1文件夹中(.ExternalData为VTKData-8.1.1.zip解压的文件夹,是一个隐藏文件夹,可用Ctrl+H查看)
创建构建目录:
mkdir build
cd build
1.2 Cmake编译
cmake -DVTK_QT_VERSION:STRING=5
-DQT_QMAKE_EXECUTABLE:PATH=/home/yucheng/Software/QT5.11.1/5.11.1/gcc_64/bin/qmake -DVTK_Group_Qt:BOOL=ON
-DCMAKE_PREFIX_PATH:PATH=/home/yucheng/Software/QT5.11.1/5.11.1/gcc_64/lib/cmake/Qt5
-DBUILD_SHARED_LIBS:BOOL=ON
-DBUILD_examples=ON
-DCMAKE_INSTALL_PREFIX=/usr/local_2/VTK_QT_Cmake ..
最后的两个点表示在当前路径的上一路径下寻找CMakeLists.txt文件
1.3 安装
make -j4
sudo make install
1.4 配置
库目录配置:
在/etc/ld.so.conf.d 目录下增加一个conf文件:
cd /etc/ld.so.conf.d
sudo touch VTK.conf
sudo gedit VTK.conf
添加VTK库的路径:
/usr/local_2/VTK_QT_Cmake/lib
保存退出后运行如下命令刷新:
sudo ldconfig
2.VTK测试
新建Qt Console Application项目:
Pro文件:
#QT +=core gui
#greaterThan(QT_MAJOR_VERSION, 4):
QT += widgets
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
INCLUDEPATH += /usr/local_2/VTK_QT_Cmake/include/vtk-8.1
INCLUDEPATH += /home/yucheng/Software/Qt5.11.1/5.11.1/gcc_64/include
LIBS += /usr/local_2/VTK_QT_Cmake/lib/libvtk*.so
LIBS += /usr/local_2/VTK_QT_Cmake/lib/libvtk*.so.1
cpp文件:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
//VTK_MODULE_INIT(vtkRenderingFreeType); //这三句不通过的话,就注释掉,换成最上面的两句调试
//VTK_MODULE_INIT(vtkRenderingFreeTypeOpenGL);
//#include "aa.h" //这句是自己工程的头文件,如果名字不一样,就换成自己的**.h
#include <QtWidgets/QApplication>
#include<vtkSmartPointer.h>
#include<vtkSphereSource.h>
#include<vtkPolyDataMapper.h>
#include<vtkActor.h>
#include<vtkImageViewer.h>
#include<vtkRenderWindowInteractor.h>
#include<vtkInteractorStyleImage.h>
#include<vtkJPEGReader.h>
#include<vtkRenderer.h>
#include<QVTKWidget.h>
int main(int argc, char *argv[])
{
//QApplication a(argc, argv);
//aa w;
//w.show();
//return a.exec();
QApplication app(argc, argv);
QVTKWidget widget;
widget.resize(256, 256);
vtkSmartPointer<vtkSphereSource>sphereSource = vtkSmartPointer<vtkSphereSource>::New();
sphereSource->Update();
vtkSmartPointer<vtkPolyDataMapper>sphereMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor>sphereActor = vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper(sphereMapper);
vtkSmartPointer<vtkRenderWindow>renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderer>renderer = vtkSmartPointer<vtkRenderer>::New();
renderWindow->AddRenderer(renderer);
renderer->AddActor(sphereActor);
renderer->ResetCamera();
widget.SetRenderWindow(renderWindow);
widget.show();
app.exec();
return EXIT_SUCCESS;
}
3.PCL安装
3.1 依赖库安装
sudo apt-get install libboost-all-dev
sudo apt-get install libeigen3-dev
sudo apt-get install libflann-dev
sudo apt-get install libeigen3-dev
3.2 下载及解压
创建构建目录:
mkdir build
cd build
3.3 Cmake编译
cmake -D CMAKE_BUILD_TYPE=Release
-D BUILD_GPU=ON
-D BUILD_examples=ON
-D CMAKE_INSTALL_PREFIX=/usr/local_2/PCL_Cmake
-D VTK_DIR=/usr/local_2/VTK_QT_Cmake/lib/cmake/vtk-8.1
-D BUILD_visualization=ON ..
3.4 安装
make -j4
sudo make install
3.5 配置
库目录配置:
在/etc/ld.so.conf.d 目录下增加一个conf文件:
cd /etc/ld.so.conf.d
sudo touch PCL.conf
sudo gedit PCL.conf
添加PCL库的路径:
/usr/local_2/PCL_Cmake/lib
保存退出后运行如下命令刷新:
sudo ldconfig
环境变量配置:
sudo gedit /etc/bash.bashrc
添加:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local_2/PCL_Cmake/lib/pkgconfig export PKG_CONFIG_PATH
4.PCL测试
下载rabbit.pcd文件
(提取密码:ium8)
新建Qt Console Application项目:
Pro文件:
#QT -= gui
QT += widgets
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
#Eigen
INCLUDEPATH += /usr/include/eigen3
#Vtk
INCLUDEPATH +=/usr/local_2/VTK_QT_Cmake/include/vtk-8.1
LIBS += /usr/local_2/VTK_QT_Cmake/lib/libvtk*.so
#Boost
INCLUDEPATH += /usr/include/boost
LIBS += /usr/lib/x86_64-linux-gnu/libboost_*.so
#PCL Header
INCLUDEPATH += /usr/local_2/PCL_Cmake/include/pcl-1.8
#PCL Lib
LIBS += /usr/local_2/PCL_Cmake/lib/libpcl_*.so
cpp文件:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
#include <iostream>
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
using namespace std;
int user_data;
void viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor (1.0, 0.5, 1.0);
pcl::PointXYZ o;
o.x = 1.0;
o.y = 0;
o.z = 0;
viewer.addSphere (o, 0.25, "sphere", 0);
std::cout << "i only run once" << std::endl;
}
void viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
{
static unsigned count = 0;
std::stringstream ss;
ss << "Once per viewer loop: " << count++;
viewer.removeShape ("text", 0);
viewer.addText (ss.str(), 200, 300, "text", 0);
//FIXME: possible race condition here:
user_data++;
}
int main ()
{
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("/home/yucheng/rabbit.pcd", *cloud);
pcl::visualization::CloudViewer viewer("Cloud Viewer");
//blocks until the cloud is actually rendered
viewer.showCloud(cloud);
//use the following functions to get access to the underlying more advanced/powerful
//PCLVisualizer
//This will only get called once
viewer.runOnVisualizationThreadOnce (viewerOneOff);
//This will get called once per visualization iteration
viewer.runOnVisualizationThread (viewerPsycho);
while (!viewer.wasStopped ())
{
//you can also do cool processing here
//FIXME: Note that this is running in a separate thread from viewerPsycho
//and you should guard against race conditions yourself...
user_data++;
}
return 0;
}
版权声明:本文为gurenyigu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。