0

我需要制作一个带有 Qt 小部件的图形窗口,该窗口允许在其中表示我之前使用 PLC 库加载的点云。

这是我到目前为止不起作用的东西(我基于教程和这个答案)。

我正在使用:

  • Ubuntu 20.04
  • Qt 创建者 5.15
  • VTK 9.1
  • PCL 1.12

我使用 QVTKOpenGLStereoWidget 的原因是,据我所知,QVTKOpenGLWidget 和 QVTKWidget 不再可用或将在未来的版本中停止使用。

测试.pro

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++14

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    MainWindow.cpp

HEADERS += \
    MainWindow.h

FORMS += \
    MainWindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

# INCLUIR LAS LIREARÍAS PARA EL PRROGRAMA
VTK_VERSION = 9.1
PCL_VERSION = 1.12
CONFIG += link_pkgconfig

# LIBREARÍA DE ARCHIVOS DE EIGEN3
PKGCONFIG += eigen3

# LIBRERÍA DE ARCHIIVOS DE BOOST
INCLUDEPATH += /usr/include/boost

# LIBREARÍA DE REPRESENTACIÓN GRÁFICA VTK
INCLUDEPATH += /usr/local/include/vtk-$${VTK_VERSION}
LIBS += -L/usr/local/lib                            \
    -lvtkCommonColor-$${VTK_VERSION}                \
    -lvtkCommonCore-$${VTK_VERSION}                 \
    -lvtkFiltersSources-$${VTK_VERSION}             \
    -lvtkInteractionStyle-$${VTK_VERSION}           \
    -lvtkRenderingContextOpenGL2-$${VTK_VERSION}    \
    -lvtkRenderingCore-$${VTK_VERSION}              \
    -lvtkRenderingFreeType-$${VTK_VERSION}          \
    -lvtkRenderingGL2PSOpenGL2-$${VTK_VERSION}      \
    -lvtkRenderingOpenGL2-$${VTK_VERSION}           \
    -lvtkCommonExecutionModel-$${VTK_VERSION}       \
    -lvtkRenderingFreeType-$${VTK_VERSION}          \
    -lvtkInteractionStyle-$${VTK_VERSION}           \
    -lvtkRenderingOpenGL2-$${VTK_VERSION}           \
    -lvtkRenderingLOD-$${VTK_VERSION}               \
    -lvtkCommonDataModel-$${VTK_VERSION}            \
    -lvtkCommonMath-$${VTK_VERSION}                 \
    -lvtkViewsQt-$${VTK_VERSION}                    \
    #-lvtkGUISupportQtOpenGL-$${VTK_VERSION}         \
    -lvtkGUISupportQt-$${VTK_VERSION}

# LIBRERÍAS PARA EL TRBAJO CON NUBES DE PUNTOS.
INCLUDEPATH += /usr/local/include/pcl-$${PCL_VERSION}
LIBS += -L/usr/local/lib                                            \
    -lpcl_common -lpcl_features -lpcl_filters -lpcl_io_ply          \
    -lpcl_io -lpcl_kdtree -lpcl_keypoints -lpcl_ml                  \
    -lpcl_octree -lpcl_outofcore -lpcl_people -lpcl_recognition     \
    -lpcl_registration -lpcl_search -lpcl_segmentation -lpcl_stereo \
    -lpcl_surface -lpcl_tracking  -lpcl_visualization -lpcl_sample_consensus

主窗口.ui

它只有一个小部件具有提升QVTKOpenGLSTereoWidget

在此处输入图像描述

主窗口.h

我做了VTK库的初始化,包含不同的库头文件,并创建了PCL查看器和基于OpenGL的VTK渲染器。

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include "pcl/visualization/cloud_viewer.h"
#include <pcl/visualization/pcl_visualizer.h>
#include "pcl/io/pcd_io.h"
#include "pcl/io/ply_io.h"
#include "pcl/io/obj_io.h"

#include "pcl/common/io.h"

#include "vtkCylinder.h"
#include "vtkCylinderSource.h"
#include "vtkRenderWindow.h"
#include <QVTKOpenGLWidget.h>
#include <QVTKOpenGLStereoWidget.h>
#include <QVTKOpenGLWindow.h>
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);

using namespace pcl::visualization;

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    pcl::visualization::PCLVisualizer::Ptr viewer;
    vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow;

private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

主窗口.cpp

最后在 MainWindow 类的构造函数中,我只是加载了文件(在本例中它是一个 PLY),然后我尝试在小部件中制作图形表示

#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
    // Cargar el objeto en dicha nube de putnos en el formato que se desee.
    pcl::io::loadPLYFile("/home/alejandro/Documentos/alejandro.ply",*cloud);
    viewer->addPointCloud(cloud);

    auto renderer = vtkSmartPointer<vtkRenderer>::New();
    renderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
    //renderWindow->AddRenderer(renderer); THIS MAKES AN ERROR!!
    viewer.reset(new PCLVisualizer(renderer, renderWindow, "viewer", false));
    ui->widget->setRenderWindow(viewer->getRenderWindow());
    ui->widget->update();

}
MainWindow::~MainWindow()
{
    delete ui;
}

主文件

我没有改变任何东西,它是默认的

#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

错误。

我遇到的主要错误是:/usr/local/include/vtk-9.1/vtkSmartPointer.h:225:错误:嵌套名称说明符中使用的类型“vtkGenericOpenGLRenderWindow”不完整 在 /usr/local/include/pcl-1.12/pcl/visualization/point_cloud_geometry_handlers.h:49 包含的文件中,来自 /usr/local/include/pcl-1.12/pcl/visualization/common/actor_map.h:40,来自/usr/local/include/pcl-1.12/pcl/visualization/pcl_visualizer.h:48,来自 /usr/local/include/pcl-1.12/pcl/visualization/cloud_viewer.h:39,来自 ../04_pcl_viewer_V3/MainWindow .h:6,来自 ../04_pcl_viewer_V3/MainWindow.cpp:1: /usr/local/include/vtk-9.1/vtkSmartPointer.h: 在 'static vtkSmartPointer vtkSmartPointer::New() [with T = vtkGenericOpenGLRenderWindow] 的实例化中':../04_pcl_viewer_V3/MainWindow.cpp:16:67:从这里需要/usr/local/include/vtk-9.1/vtkSmartPointer.h:225:69:错误:嵌套名称说明符225中使用的不完整类型'vtkGenericOpenGLRenderWindow' | 静态 vtkSmartPointer New() { return vtkSmartPointer(T::New(), NoReference()); } | ~~~~~~^~

4

1 回答 1

0

我终于能够找到问题的解决方案,因此我将其作为答案分享,以防它对其他人有用。

pclTest_V0.pro

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++14

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    MainWindow.cpp

HEADERS += \
    MainWindow.h

FORMS += \
    mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

# Incluir la librería y la ruta de VTK
VTK_VERSION = 9.1
INCLUDEPATH += /usr/local/include/vtk-$${VTK_VERSION}
LIBS += -L/usr/local/lib    \
    -lvtkCommonColor-$${VTK_VERSION}    \
    -lvtkCommonExecutionModel-$${VTK_VERSION}    \
    -lvtkCommonCore-$${VTK_VERSION}     \
    -lvtkCommonDataModel-$${VTK_VERSION}     \  # Para PCL
    -lvtkCommonMath-$${VTK_VERSION}     \       # Para PCL
    -lvtkFiltersCore-$${VTK_VERSION} \
    -lvtkFiltersSources-$${VTK_VERSION} \
    -lvtkInfovisCore-$${VTK_VERSION} \
    -lvtkInteractionStyle-$${VTK_VERSION} \
    -lvtkRenderingContextOpenGL2-$${VTK_VERSION} \
    -lvtkRenderingCore-$${VTK_VERSION} \
    -lvtkRenderingFreeType-$${VTK_VERSION} \
    -lvtkRenderingGL2PSOpenGL2-$${VTK_VERSION} \
    -lvtkRenderingOpenGL2-$${VTK_VERSION} \
    -lvtkViewsQt-$${VTK_VERSION} \
    -lvtkGUISupportQt-$${VTK_VERSION} \
    -lvtkRenderingQt-$${VTK_VERSION}

# Incluir el directorio de boost.
INCLUDEPATH += /usr/include/boost

# Incluir el direcotrio de eigen3.
INCLUDEPATH += /usr/include/eigen3

# Incluir las librerías y la ruta de PCL.
PCL_VERSION = 1.12
INCLUDEPATH += /usr/local/include/pcl-$${PCL_VERSION}
LIBS += -L/usr/local/lib \
    -lpcl_common -lpcl_io -lpcl_visualization

主窗口.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include "pcl/common/common_headers.h"
#include "pcl/features/normal_3d.h"
#include "pcl/io/obj_io.h"
#include "pcl/io/ply_io.h"
#include "pcl/visualization/pcl_visualizer.h"
#include "pcl/console/parse.h"

#include "QVTKOpenGLNativeWidget.h"
#include "vtkCamera.h"
#include "vtkCubeSource.h"
#include "vtkDataObjectToTable.h"
#include "vtkElevationFilter.h"
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkNamedColors.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkQtTableView.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkVersion.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    pcl::visualization::PCLVisualizer::Ptr viewer;
};
#endif // MAINWINDOW_H

主窗口.cpp

#include "MainWindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
    vtkNew<vtkRenderer> renderer;
    renderWindow->AddRenderer(renderer);

    // Crear una nube de puntos con los datos almacenados en un archivo
    // determinado.
    std::string name = "filename.ply";
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
    pcl::io::loadPLYFile(name,*cloud);

    // Generar el visor de la nube de puntos para realizar la visualización.
    //viewer.reset(new pcl::visualization::PCLVisualizer("viewer",false));
    viewer.reset(new pcl::visualization::PCLVisualizer(renderer, renderWindow,
                                                       "viewer",false));
    viewer->addPointCloud(cloud);
    //ui->Viewer_widget->renderWindow()->AddRenderer(renderer);
    ui->Viewer_widget->setRenderWindow(viewer->getRenderWindow());
    ui->Viewer_widget->update();
}

MainWindow::~MainWindow()
{
    delete ui;
}

主文件

#include "MainWindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

主窗口.ui

带有QVTKOpenGLNativeWidget.h促销的小部件。

于 2022-02-27T22:21:35.637 回答