Ubuntu22.04+pcl1.14+vtk9.3+QT5.15.2(纯个人记录帖)
0.前言
由于本人更偏爱新的东西,所以我选择的库都比较偏新,但是这些新的东西组合到一起或多或许存在些问题,所以我将遇到的问题都记录了下来,文中内容仅供参考。
如果只是单纯想装个QT5.15.2,我建议直接按照在 1. QT5.15.2安装 中提及的博客方法进行安装,实测没问题。
如果只是单纯想装个pcl1.14,我建议直接按照在 3. pcl1.14安装 中提及的博客方法进行安装,实测没问题。
1. QT5.15.2安装
我是参考的这个博客
进行安装,总体下来没啥问题。
2. vtk9.3安装
先去github下载源码,然后解压下来。
cd vtk
mkdir build
cd build
cmake-gui
需要注意的是:
BUILD_SHARED_LIBS:True;
CMAKE_BUILD_TYPE:Release;
CMAKE_INSTALL_PREFIX:/usr/local;
VTK_GROUP_ENABLE_QT:Yes;
VTK_QT_VERSION:5。
还有需要注意的是qt路径记得改为自己实际安装的位置,如下所示我改为了我自己的路径。

好了之后再
sudo make -j8
sudo make install
**注意:**如果编译过程中出现了 QQmlComponent: Component is not ready 的这个错误,请按照该博客方法解决。
博客地址:https://blog.csdn.net/qq_39174336/article/details/135490742?spm=1001.2014.3001.5506
测试VTK和QT在一起能不能用:
原链接:https://examples.vtk.org/site/Cxx/Qt/MinimalQtVTKApp/
进不去链接的可以拷贝我的代码,我把代码放下面了。
MinimalQtVTKApp.cxx
#include <QVTKOpenGLNativeWidget.h>
#include <vtkActor.h>
#include <vtkDataSetMapper.h>
#include <vtkDoubleArray.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkPointData.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>
#include <QApplication>
#include <QDockWidget>
#include <QGridLayout>
#include <QLabel>
#include <QMainWindow>
#include <QPointer>
#include <QPushButton>
#include <QVBoxLayout>
#include <cmath>
#include <cstdlib>
#include <random>
namespace {
/**
* Deform the sphere source using a random amplitude and modes and render it in
* the window
*
* @param sphere the original sphere source
* @param mapper the mapper for the scene
* @param window the window to render to
* @param randEng the random number generator engine
*/
void Randomize(vtkSphereSource* sphere, vtkMapper* mapper,
vtkGenericOpenGLRenderWindow* window, std::mt19937& randEng);
} // namespace
int main(int argc, char* argv[])
{
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
QApplication app(argc, argv);
// Main window.
QMainWindow mainWindow;
mainWindow.resize(1200, 900);
// Control area.
QDockWidget controlDock;
mainWindow.addDockWidget(Qt::LeftDockWidgetArea, &controlDock);
QLabel controlDockTitle("Control Dock");
controlDockTitle.setMargin(20);
controlDock.setTitleBarWidget(&controlDockTitle);
QPointer<QVBoxLayout> dockLayout = new QVBoxLayout();
QWidget layoutContainer;
layoutContainer.setLayout(dockLayout);
controlDock.setWidget(&layoutContainer);
QPushButton randomizeButton;
randomizeButton.setText("Randomize");
dockLayout->addWidget(&randomizeButton);
// Render area.
QPointer<QVTKOpenGLNativeWidget> vtkRenderWidget =
new QVTKOpenGLNativeWidget();
mainWindow.setCentralWidget(vtkRenderWidget);
// VTK part.
vtkNew<vtkGenericOpenGLRenderWindow> window;
vtkRenderWidget->setRenderWindow(window.Get());
vtkNew<vtkSphereSource> sphere;
sphere->SetRadius(1.0);
sphere->SetThetaResolution(100);
sphere->SetPhiResolution(100);
vtkNew<vtkDataSetMapper> mapper;
mapper->SetInputConnection(sphere->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->GetProperty()->SetEdgeVisibility(true);
actor->GetProperty()->SetRepresentationToSurface();
vtkNew<vtkRenderer> renderer;
renderer->AddActor(actor);
window->AddRenderer(renderer);
// Setup initial status.
std::mt19937 randEng(0);
::Randomize(sphere, mapper, window, randEng);
// connect the buttons
QObject::connect(&randomizeButton, &QPushButton::released,
[&]() { ::Randomize(sphere, mapper, window, randEng); });
mainWindow.show();
return app.exec();
}
namespace {
void Randomize(vtkSphereSource* sphere, vtkMapper* mapper,
vtkGenericOpenGLRenderWindow* window, std::mt19937& randEng)
{
// Generate randomness.
double randAmp = 0.2 + ((randEng() % 1000) / 1000.0) * 0.2;
double randThetaFreq = 1.0 + (randEng() % 9);
double randPhiFreq = 1.0 + (randEng() % 9);
// Extract and prepare data.
sphere->Update();
vtkSmartPointer<vtkPolyData> newSphere;
newSphere.TakeReference(sphere->GetOutput()->NewInstance());
newSphere->DeepCopy(sphere->GetOutput());
vtkNew<vtkDoubleArray> height;
height->SetName("Height");
height->SetNumberOfComponents(1);
height->SetNumberOfTuples(newSphere->GetNumberOfPoints());
newSphere->GetPointData()->AddArray(height);
// Deform the sphere.
for (int iP = 0; iP < newSphere->GetNumberOfPoints(); iP++)
{
double pt[3] = {0.0};
newSphere->GetPoint(iP, pt);
double theta = std::atan2(pt[1], pt[0]);
double phi =
std::atan2(pt[2], std::sqrt(std::pow(pt[0], 2) + std::pow(pt[1], 2)));
double thisAmp =
randAmp * std::cos(randThetaFreq * theta) * std::sin(randPhiFreq * phi);
height->SetValue(iP, thisAmp);
pt[0] += thisAmp * std::cos(theta) * std::cos(phi);
pt[1] += thisAmp * std::sin(theta) * std::cos(phi);
pt[2] += thisAmp * std::sin(phi);
newSphere->GetPoints()->SetPoint(iP, pt);
}
newSphere->GetPointData()->SetScalars(height);
// Reconfigure the pipeline to take the new deformed sphere.
mapper->SetInputDataObject(newSphere);
mapper->SetScalarModeToUsePointData();
mapper->ColorByArrayComponent("Height", 0);
window->Render();
}
} // namespace
CMakeLists.txt
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
cmake_policy(SET CMP0071 NEW)
endif()
PROJECT(MinimalQtVTKApp)
find_package(VTK COMPONENTS
CommonCore
CommonDataModel
FiltersSources
GUISupportQt
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
GUISupportQt
RenderingQt
)
if(NOT VTK_FOUND)
message(FATAL_ERROR "MinimalQtVTKApp: Unable to find the VTK build folder.")
endif()
if(NOT(TARGET VTK::GUISupportQt))
message(FATAL_ERROR "MinimalQtVTKApp: VTK not built with Qt support.")
endif()
if(NOT DEFINED VTK_QT_VERSION)
set(VTK_QT_VERSION 5)
endif()
set(qt_components Core Gui Widgets)
if(${VTK_QT_VERSION} VERSION_GREATER_EQUAL 6)
list(APPEND qt_components OpenGLWidgets)
endif()
list(SORT qt_components)
# We have ui files, so this will also bring in the macro:
# qt5_wrap_ui or qt_wrap_ui from Widgets.
find_package(Qt${VTK_QT_VERSION} QUIET
REQUIRED COMPONENTS ${qt_components}
)
foreach(_qt_comp IN LISTS qt_components)
list(APPEND qt_modules "Qt${VTK_QT_VERSION}::${_qt_comp}")
endforeach()
message (STATUS "VTK_VERSION: ${VTK_VERSION}, Qt Version: ${Qt${VTK_QT_VERSION}Widgets_VERSION}")
# Instruct CMake to run moc and uic automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
file(GLOB UI_FILES *.ui)
file(GLOB QT_WRAP *.h)
file(GLOB CXX_FILES *.cxx)
# For VTK versions greater than or equal to 8.90.0:
# CMAKE_AUTOUIC is ON so we handle uic automatically for Qt targets.
# CMAKE_AUTOMOC is ON so we handle moc automatically for Qt targets.
# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
# CMAKE_AUTOMOC in ON so the MOC headers will be automatically wrapped.
add_executable(MinimalQtVTKApp MACOSX_BUNDLE
${CXX_FILES} ${UISrcs} ${QT_WRAP}
)
if (Qt${VTK_QT_VERSION}Widgets_VERSION VERSION_LESS "5.11.0")
qt5_use_modules(MinimalQtVTKApp ${qt_components})
else()
target_link_libraries(MinimalQtVTKApp ${qt_modules})
endif()
target_link_libraries(MinimalQtVTKApp ${VTK_LIBRARIES})
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS MinimalQtVTKApp
MODULES ${VTK_LIBRARIES}
)
然后
cd MinimalQtVTKApp/build
# 下面三个用哪个根据自己实际情况
# If VTK and Qt are installed:
cmake ..
# If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
cmake -DVTK_DIR=/home/me/vtk_build ..
# If Qt is not found on your system, you will need to tell CMake where to find qmake:
cmake -DQT_QMAKE_EXECUTABLE:FILEPATH=/usr/something/qmake ..
make
./MinimalQtVTKApp

3. pcl1.14安装
安装过程我是参考这的这篇博客
和上述博客作者不一样的地方是vtk我选择源码编译,如果不需要使用到QT进行点云显示的话我建议按照上述博客进行安装pcl
首先安装依赖
sudo apt-get update
#以下为安装第三方依赖库(参考windows下3dParty)
sudo apt-get install libflann1.9 libflann-dev
#安装flnn,ubuntu22.04对应的版本是1.9
sudo apt-get install libeigen3-dev
#安装eigen的库
sudo apt-get install libboost-all-dev
#安装boost
sudo apt-get install libqhull* libgtest-dev
#安装Qhull
sudo apt-get install libopenni2-dev
#安装openni2
#以下为其他必须依赖
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev
libsub是一个开源的用C实现的,可以让应用程序与用户的USB设备进行通信的库,可移植,使用统一的API,支持Windows,MacOS,Linux,Androdi
sudo apt-get install libopenni-dev
#安装openni
sudo apt-get install freeglut3-dev pkg-config
#安装freeglut,是GLUT(openGL Utility Toolkit)的一个免费开源替代库,在程序中负责创建窗口,初始化opengl上下文和处理输入事件所需的所有系统特定的杂务,从而允许创建真正可移植的OpenGL程序
再先去github下载pcl源码,下载好解压然后进入文件夹
cd pcl-master
mkdir release
cmake-gui
点击Generate,然后点Finish

检查有没有报红色,缺啥补啥,检查下路径有没有问题,比如说我的qt路径为/opt/qt/5.15.2/,所以在camke中我对qt路径也进行了修改。

还有就是我看别人的BUILD-GPU、BUILD-apps、BUILD-examples都是ON,所以这里我也勾选了。其他的模块勾选自己需要的也可以。
问题1:Could NOT find ClangFormat (missing: ClangFormat_EXECUTABLE ClangFormat_VERSION) (Required is at least version “14”)
解决方法:
sudo apt-get install clang-format
问题2:Could NOT find Pcap (missing: PCAP_LIBRARIES PCAP_INCLUDE_DIRS)
解决方法:
sudo apt-get install libsqlite3-0 libpcap0.8
sudo apt-get install libpcap-dev
问题3:
Checking for module ‘metslib’
No package ‘metslib’ found
解决方法:
下载:https://www.coin-or.org/download/source/metslib/metslib-0.5.3.tgz
tar -xvf metslib-0.5.3.tgz #解压
cd metslib-0.5.3/
sudo sh ./configure
sudo make
sudo make install
问题4:Not found OpenMP
解决方法:勾选WITH_OPENMP选项
问题5:
Checking for module ‘glut’
No package ‘glut’ found
解决方法:
这个问题查阅了网上相关资料,还是没有解决,所以我直接忽略了这个问题,直接开始编译。有好办法的大佬请留言。
cd release
make -j8
sudo make install
值得注意的是,编译过程中出现了一些警告,我选择了忽略。
简单测试下pcl安装成功否
pcl_viewer pcl_logo.pcd

暂时没发现什么问题。
4. 测试pcl+vtk+qt放在一起能不能用
随便写了个qt显示pcd点云的小程序,能够正常使用。

1435

被折叠的 条评论
为什么被折叠?



