目录
- [Ubuntu20.04 + QT5.14.2 + VTK8.2.0 + PCL 1.10 环境配置](#Ubuntu20.04 + QT5.14.2 + VTK8.2.0 + PCL 1.10 环境配置)
Ubuntu20.04 + QT5.14.2 + VTK8.2.0 + PCL 1.10 环境配置
一、VTK 编译和安装
1、库依赖:
shell
# X11
sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev
# OpenGL
sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev
# cmake && cmake-gui
sudo apt-get install cmake cmake-gui
sudo apt install -y libxt-dev
sudo apt install -y cmake-qt-gui
sudo apt install build-essential cmake
2、下载资源:下载VTK8.2.0
3、编译:
- 创建build文件夹
shell
cd VTK-8.2.0
mkdir build
cd build
- 使用
cmake-gui
编译:设置源码目录和输出目录,勾选Grou
p和Adavanced
,点击configure
,按下图设置
shell
cmake-gui
- 第一次点击configure后,勾选"VTK-Group-Qt",点击"Configure";完成后,显示"Configuring done";
- 最后点击"Generate";显示"Generating done",完成。
4、安装
cpp
make -j4
sudo make install
5、qtcreator 配置编译的libQVTKWidgetPlugin.so
-
libQVTKWidgetPlugin.so
路径/build/lib
shellcd ./lib
-
添加到qtcreator中,
libQVTKWidgetPlugin.so
复制到qt路径下,shellsudo cp libQVTKWidgetPlugin.so /home/ljn/Qt5.14.2/Tools/QtCreator/lib/Qt/plugins/designer
二、PCL安装
1、一键安装
shell
sudo apt install libpcl-dev
会默认安装 vtk 和 eigne,后面我使用的是自己安装的vtk-8.2,默认安装目录在 /usr/local/include
2、测试
-
文件结构
-
CMakeLists.txt
cppcmake_minimum_required(VERSION 2.6) project(pcl_test) find_package(PCL 1.10 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) add_executable(pcl_test pcl_test.cpp) target_link_libraries (pcl_test ${PCL_LIBRARIES}) install(TARGETS pcl_test RUNTIME DESTINATION bin)
-
pcl_test.cpp
cpp#include <iostream> #include <pcl/common/common_headers.h> #include <pcl/io/pcd_io.h> #include <pcl/visualization/pcl_visualizer.h> #include <pcl/visualization/cloud_viewer.h> #include <pcl/console/parse.h> int main(int argc, char **argv) { std::cout << "Test PCL !!!" << std::endl; pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>); uint8_t r(255), g(15), b(15); for (float z(-1.0); z <= 1.0; z += 0.05) { for (float angle(0.0); angle <= 360.0; angle += 5.0) { pcl::PointXYZRGB point; point.x = 0.5 * cosf (pcl::deg2rad(angle)); point.y = sinf (pcl::deg2rad(angle)); point.z = z; uint32_t rgb = (static_cast<uint32_t>(r) << 16 | static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b)); point.rgb = *reinterpret_cast<float*>(&rgb); point_cloud_ptr->points.push_back (point); } if (z < 0.0) { r -= 12; g += 12; } else { g -= 12; b += 12; } } point_cloud_ptr->width = (int) point_cloud_ptr->points.size (); point_cloud_ptr->height = 1; pcl::visualization::CloudViewer viewer ("test"); viewer.showCloud(point_cloud_ptr); while (!viewer.wasStopped()){ }; return 0; }
-
编译测试
shellmkdir build cd build cmake .. make ./pcl_text
-
运行结果
三、qt 中使用 vtk 显示点云图
1、pro 中引入依赖
根据自身安装的版本引入相关依赖
shell
INCLUDEPATH += /usr/include/boost
LIBS += /usr/lib/x86_64-linux-gnu/libboost_*.so
INCLUDEPATH += /usr/include/pcl-1.10/
LIBS += /usr/lib/x86_64-linux-gnu/libpcl_*.so
INCLUDEPATH += /usr/include/vtk-7.1
LIBS += /usr/lib/x86_64-linux-gnu/libvtk*.so
INCLUDEPATH += /usr/include/eigen3