Jelajahi Sumber

change view_pcdmap. use pclvisulizer, so can compile in ubuntu22.04.

yuchuli 9 bulan lalu
induk
melakukan
f61628ec70

+ 71 - 0
src/tool/view_pcdmap/mainwindow.cpp

@@ -0,0 +1,71 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <iostream>
+
+#include <QFileDialog>
+
+
+MainWindow::MainWindow(QWidget *parent)
+    : QMainWindow(parent)
+    , ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
+    vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
+    renderWindow->AddRenderer(renderer);
+    view.reset(new pcl::visualization::PCLVisualizer(renderer,renderWindow,"viewer",false));
+
+
+
+#if VTK890
+    view->setupInteractor(ui->vtk->interactor(),ui->vtk->renderWindow());
+#else
+    view->setupInteractor(ui->vtk->GetInteractor(),ui->vtk->GetRenderWindow());
+#endif
+
+#if VTK890
+  this->ui->vtk->setRenderWindow(renderWindow);
+#else
+  this->ui->vtk->SetRenderWindow(renderWindow);
+#endif
+
+    setWindowTitle("PCD Viewer");
+
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+    (void)event;
+    QSize sizemain = ui->centralwidget->size();
+
+    ui->vtk->setGeometry(5,5,sizemain.width()-10,sizemain.height()-10);
+
+}
+
+void MainWindow::on_actionLoad_triggered()
+{
+    //读取pcd文件并显示
+    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>());//创建点云指针
+    QString fileName = QFileDialog::getOpenFileName(this, "Open PointCloud", ".", "Open PCD files(*.pcd)");
+    if(fileName == "") return;
+    pcl::io::loadPCDFile(fileName.toStdString(),*cloud);
+    pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZI> fildColor(cloud, "intensity"); // 按照y字段进行渲染
+    view->removePointCloud("cloud");
+    view->addPointCloud<pcl::PointXYZI>(cloud,fildColor,"cloud");
+
+    view->setCameraPosition(0,0,100,0,0,0,0,1,0);
+    view->resetCamera();    //视角
+    ui->vtk->update();
+#if VTK890
+    ui->vtk->renderWindow()->Render();
+#else
+    ui->vtk->GetRenderWindow()->Render();
+#endif
+}
+

+ 60 - 0
src/tool/view_pcdmap/mainwindow.h

@@ -0,0 +1,60 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+
+
+#include <vtkActor.h>
+#include <vtkGenericOpenGLRenderWindow.h>
+#include <vtkLookupTable.h>
+#include <vtkNamedColors.h>
+#include <vtkNew.h>
+#include <vtkPlatonicSolidSource.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkProperty.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderer.h>
+#include <vtkVersion.h>
+
+
+#include <QSurfaceFormat>
+#include <QVTKOpenGLNativeWidget.h>
+
+
+#include <pcl/visualization/pcl_visualizer.h>
+#include <pcl/point_types.h>//各种格式的点的头文件
+#include <pcl/io/pcd_io.h>
+
+#if VTK_VERSION_NUMBER >= 89000000000ULL
+#define VTK890 1
+#endif
+
+
+QT_BEGIN_NAMESPACE
+namespace Ui {
+class MainWindow;
+}
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    MainWindow(QWidget *parent = nullptr);
+    ~MainWindow();
+
+public:
+     void resizeEvent(QResizeEvent *event);
+
+private slots:
+    void on_actionLoad_triggered();
+
+private:
+    Ui::MainWindow *ui;
+
+    boost::shared_ptr< pcl::visualization::PCLVisualizer > view;
+
+};
+#endif // MAINWINDOW_H

+ 72 - 0
src/tool/view_pcdmap/mainwindow.ui

@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>600</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <widget class="QVTKOpenGLNativeWidget" name="vtk">
+    <property name="geometry">
+     <rect>
+      <x>40</x>
+      <y>30</y>
+      <width>531</width>
+      <height>391</height>
+     </rect>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>22</height>
+    </rect>
+   </property>
+   <widget class="QMenu" name="menuFile">
+    <property name="title">
+     <string>File</string>
+    </property>
+   </widget>
+   <addaction name="menuFile"/>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+  <widget class="QToolBar" name="toolBar">
+   <property name="windowTitle">
+    <string>toolBar</string>
+   </property>
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+   <addaction name="actionLoad"/>
+  </widget>
+  <action name="actionLoad">
+   <property name="text">
+    <string>Load</string>
+   </property>
+  </action>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>QVTKOpenGLNativeWidget</class>
+   <extends>QOpenGLWidget</extends>
+   <header location="global">QVTKOpenGLNativeWidget.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>

+ 61 - 0
src/tool/view_pcdmap/view_pcdmap2.pro

@@ -0,0 +1,61 @@
+QT       += core gui
+
+#QT       += openglwidgets
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+CONFIG += c++17
+
+# 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 += \
+    viewmain.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
+
+INCLUDEPATH += /usr/include/eigen3
+INCLUDEPATH += /usr/include/pcl-1.12
+INCLUDEPATH += /usr/include/vtk-9.1
+INCLUDEPATH += /usr/include/vtk-6.3
+INCLUDEPATH += /usr/include/vtk-7.1
+INCLUDEPATH += /usr/include/pcl-1.8
+INCLUDEPATH += /usr/include/pcl-1.10
+INCLUDEPATH += /usr/include/pcl-1.7
+
+
+unix:LIBS +=  -lpcl_common\
+        -lpcl_features\
+        -lpcl_filters\
+        -lpcl_io\
+        -lpcl_io_ply\
+        -lpcl_kdtree\
+        -lpcl_keypoints\
+        -lpcl_octree\
+        -lpcl_outofcore\
+        -lpcl_people\
+        -lpcl_recognition\
+        -lpcl_registration\
+        -lpcl_sample_consensus\
+        -lpcl_search\
+        -lpcl_segmentation\
+        -lpcl_surface\
+        -lpcl_tracking\
+        -lpcl_visualization
+
+LIBS += /usr/lib/aarch64-linux-gnu/libvtk*.so
+
+#LIBS += -lvtkCommonExecutionModel-9.1 -lvtkCommonCore-9.1 -lvtkRenderingLOD-9.1 -lvtkRenderingCore-9.1 \
+#       -lvtkFiltersSources-9.1 -lvtkCommonColor-9.1  -lvtkGUISupportQt-9.1  -lvtkInteractionStyle-9.1   -lvtkRenderingContextOpenGL2-9.1   -lvtkRenderingFreeType-9.1   \
+#       -lvtkRenderingOpenGL2-9.1

+ 14 - 0
src/tool/view_pcdmap/viewmain.cpp

@@ -0,0 +1,14 @@
+#include <QApplication>
+
+#include "mainwindow.h"
+
+
+
+int main(int argc, char *argv[])
+{
+    QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
+    QApplication a(argc, argv); 
+    MainWindow w ;
+    w.show();
+    return a.exec();
+}