Browse Source

change view_ndtmatching. not complete.

yuchuli 1 year ago
parent
commit
257e09fde8

+ 6 - 3
src/tool/view_ndtmatching/main.cpp

@@ -1,8 +1,11 @@
-#include <QCoreApplication>
+#include "mainwindow.h"//#include <QCoreApplication>
+
+#include <QApplication>
 
 int main(int argc, char *argv[])
 {
-    QCoreApplication a(argc, argv);
-
+    QApplication a(argc, argv);
+    MainWindow w;
+    w.show();
     return a.exec();
 }

+ 182 - 0
src/tool/view_ndtmatching/mainwindow.cpp

@@ -0,0 +1,182 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <pcl/io/ply_io.h>
+#include <pcl/io/obj_io.h>
+
+
+static pose gCurPose;
+
+#include <cmath>
+
+struct Quaternion {
+    double w, x, y, z;
+};
+
+struct EulerAngles {
+    double roll, pitch, yaw;
+};
+
+EulerAngles ToEulerAngles(Quaternion q) {
+    EulerAngles angles;
+
+    // roll (x-axis rotation)
+    double sinr_cosp = 2 * (q.w * q.x + q.y * q.z);
+    double cosr_cosp = 1 - 2 * (q.x * q.x + q.y * q.y);
+    angles.roll = std::atan2(sinr_cosp, cosr_cosp);
+
+    // pitch (y-axis rotation)
+    double sinp = 2 * (q.w * q.y - q.z * q.x);
+    if (std::abs(sinp) >= 1)
+        angles.pitch = std::copysign(M_PI / 2, sinp); // use 90 degrees if out of range
+    else
+        angles.pitch = std::asin(sinp);
+
+    // yaw (z-axis rotation)
+    double siny_cosp = 2 * (q.w * q.z + q.x * q.y);
+    double cosy_cosp = 1 - 2 * (q.y * q.y + q.z * q.z);
+    angles.yaw = std::atan2(siny_cosp, cosy_cosp);
+
+    return angles;
+}
+
+
+Quaternion ToQuaternion(double yaw, double pitch, double roll) // yaw (Z), pitch (Y), roll (X)
+{
+    // Abbreviations for the various angular functions
+    double cy = cos(yaw * 0.5);
+    double sy = sin(yaw * 0.5);
+    double cp = cos(pitch * 0.5);
+    double sp = sin(pitch * 0.5);
+    double cr = cos(roll * 0.5);
+    double sr = sin(roll * 0.5);
+
+    Quaternion q;
+    q.w = cy * cp * cr + sy * sp * sr;
+    q.x = cy * cp * sr - sy * sp * cr;
+    q.y = sy * cp * sr + cy * sp * cr;
+    q.z = sy * cp * cr - cy * sp * sr;
+
+    return q;
+}
+
+double mpos_x = 0;
+
+void viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
+{
+    //设置背景颜色
+    viewer.setBackgroundColor(0.0,0.0,0.0);
+   viewer.resetCamera();
+
+
+
+   viewer.addCube(-0.9,0.9,-2.3,2.3,-1.9,-0.4,0.0,0.0,1.0,"car",0);
+
+
+}
+
+void viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
+{
+    std::cout<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<" psycho."<<std::endl;
+
+    viewer.removeShape("car");
+
+    Eigen::Vector3f trans;
+
+    Quaternion q = ToQuaternion(gCurPose.yaw,gCurPose.pitch,gCurPose.roll);
+    Eigen::Quaternionf quat(q.w,q.x,q.y,q.z);
+    trans(0) = gCurPose.x;trans(1) = gCurPose.y;trans(2) = gCurPose.z;
+
+ //   viewer.addCube(mpos_x+20 -0.9,mpos_x + 20+0.9,-2.3,2.3,-1.9,-0.4,0.0,0.0,1.0,"car",0);
+    viewer.addCube(trans,quat,6.0,3.0,1.0,"car");
+
+    double yaw_calc = M_PI/2.0 - gCurPose.yaw;
+
+    viewer.setCameraPosition(gCurPose.x,gCurPose.y,100,gCurPose.x,gCurPose.y,gCurPose.z,sin(yaw_calc),cos(yaw_calc),0);
+
+    std::stringstream ss;
+ //   viewer.setCameraPosition(mpos_x,0,30,mpos_x + 20,0,0,0,0,0);
+ //   ss << "Once per viewer loop: " << count++;
+
+}
+
+
+
+
+
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+    mCurPose.x = 0; mCurPose.y = 0; mCurPose.z = 0;
+    mCurPose.yaw = 0; mCurPose.pitch = 0; mCurPose.roll = 0;
+
+    gCurPose = mCurPose;
+\
+    mpthreadpcd = new std::thread(&MainWindow::threadpcdview,this);
+
+}
+
+MainWindow::~MainWindow()
+{
+    mbRun = false;
+    mpthreadpcd->join();
+    delete ui;
+}
+
+
+void MainWindow::threadpcdview()
+{
+     mpviewer = new pcl::visualization::CloudViewer("Cloud View");
+
+     pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
+                 new pcl::PointCloud<pcl::PointXYZI>());
+
+     pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud2(
+                 new pcl::PointCloud<pcl::PointXYZI>());
+
+     pcl::io::loadPCDFile<pcl::PointXYZI>("/home/yuchuli/map/map.pcd",*point_cloud);
+
+ //    pcl::io::loadOBJFile("/home/yuchuli/car.obj",*point_cloud);
+//     pcl::io::loadPLYFile("/home/yuchuli/car.ply",*point_cloud);
+     mpviewer->showCloud(point_cloud);
+
+
+     //This will only get called once
+     mpviewer->runOnVisualizationThreadOnce (viewerOneOff);
+
+
+
+     mpviewer->runOnVisualizationThread (viewerPsycho);
+
+
+     while((!mpviewer->wasStopped()) && mbRun)
+     {
+         std::this_thread::sleep_for(std::chrono::milliseconds(10));
+
+     }
+
+     delete mpviewer;
+
+}
+
+
+void MainWindow::on_pushButton_Test_clicked()
+{
+    double x = ui->lineEdit_x->text().toDouble();
+    double y = ui->lineEdit_y->text().toDouble();
+    double z = ui->lineEdit_z->text().toDouble();
+    double yaw = ui->lineEdit_yaw->text().toDouble();
+    double pitch = ui->lineEdit_pitch->text().toDouble();
+    double roll = ui->lineEdit_roll->text().toDouble();
+    mCurPose.x = x;
+    mCurPose.y = y;
+    mCurPose.z = z;
+    mCurPose.yaw = yaw;
+    mCurPose.pitch = pitch;
+    mCurPose.roll = roll;
+
+    gCurPose = mCurPose;
+}

+ 57 - 0
src/tool/view_ndtmatching/mainwindow.h

@@ -0,0 +1,57 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include <pcl/visualization/cloud_viewer.h>
+#include <iostream>
+#include <pcl/io/io.h>
+#include <pcl/io/pcd_io.h>
+#include <QCoreApplication>
+
+#include <thread>
+
+struct pose
+{
+  double x;
+  double y;
+  double z;
+  double roll;
+  double pitch;
+  double yaw;
+  double vx;
+  double vy;
+};
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit MainWindow(QWidget *parent = 0);
+    ~MainWindow();
+
+
+private slots:
+    void on_pushButton_Test_clicked();
+
+private:
+    void threadpcdview();
+
+private:
+    Ui::MainWindow *ui;
+
+    pcl::visualization::CloudViewer * mpviewer;
+
+    std::thread * mpthreadpcd;
+
+    bool mbRun = true;
+
+    pose mCurPose;
+};
+
+#endif // MAINWINDOW_H

+ 193 - 0
src/tool/view_ndtmatching/mainwindow.ui

@@ -0,0 +1,193 @@
+<?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>771</width>
+    <height>478</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <widget class="QPushButton" name="pushButton_Test">
+    <property name="geometry">
+     <rect>
+      <x>480</x>
+      <y>320</y>
+      <width>201</width>
+      <height>51</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Test</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_x">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>40</y>
+      <width>121</width>
+      <height>31</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label">
+    <property name="geometry">
+     <rect>
+      <x>60</x>
+      <y>40</y>
+      <width>61</width>
+      <height>31</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>x</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_2">
+    <property name="geometry">
+     <rect>
+      <x>60</x>
+      <y>100</y>
+      <width>61</width>
+      <height>31</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>y</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_y">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>100</y>
+      <width>121</width>
+      <height>31</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_3">
+    <property name="geometry">
+     <rect>
+      <x>60</x>
+      <y>160</y>
+      <width>61</width>
+      <height>31</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>z</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_z">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>160</y>
+      <width>121</width>
+      <height>31</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_4">
+    <property name="geometry">
+     <rect>
+      <x>310</x>
+      <y>160</y>
+      <width>61</width>
+      <height>31</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>roll</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_roll">
+    <property name="geometry">
+     <rect>
+      <x>380</x>
+      <y>160</y>
+      <width>121</width>
+      <height>31</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_5">
+    <property name="geometry">
+     <rect>
+      <x>310</x>
+      <y>40</y>
+      <width>61</width>
+      <height>31</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>yaw</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_pitch">
+    <property name="geometry">
+     <rect>
+      <x>380</x>
+      <y>100</y>
+      <width>121</width>
+      <height>31</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_6">
+    <property name="geometry">
+     <rect>
+      <x>310</x>
+      <y>100</y>
+      <width>61</width>
+      <height>31</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>pitch</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_yaw">
+    <property name="geometry">
+     <rect>
+      <x>380</x>
+      <y>40</y>
+      <width>121</width>
+      <height>31</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QComboBox" name="comboBox">
+    <property name="geometry">
+     <rect>
+      <x>80</x>
+      <y>320</y>
+      <width>181</width>
+      <height>51</height>
+     </rect>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>771</width>
+     <height>28</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 12 - 3
src/tool/view_ndtmatching/view_ndtmatching.pro

@@ -1,6 +1,8 @@
-QT -= gui
+QT       += core gui
 
-CONFIG += c++11 console
+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
@@ -14,7 +16,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
 # 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
+SOURCES += main.cpp \
+    mainwindow.cpp
 
 QMAKE_LFLAGS += -no-pie
 
@@ -56,3 +59,9 @@ LIBS += -lboost_system
 #LIBS += -lvtkCommonExecutionModel-7.1 -lvtkCommonCore-7.1 -lvtkRenderingLOD-7.1 -lvtkRenderingCore-7.1 \
 #        -lvtkFiltersSources-7.1
 
+FORMS += \
+    mainwindow.ui
+
+HEADERS += \
+    mainwindow.h
+