Browse Source

change view_ndtcalc

yuchuli 1 year ago
parent
commit
041badbdc6

+ 48 - 4
src/tool/pointcloudviewer/main.cpp

@@ -86,7 +86,7 @@ int  GetOptLong(int argc, char *argv[]) {
 
 pcl::visualization::CloudViewer viewer1("Cloud Viewer");//创建viewer对象
 
-int user_data;
+int user_data = 0;
 
 void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
 {
@@ -111,7 +111,7 @@ void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsign
     point_cloud->height = 1;
     point_cloud->width = 0;
     pcl::PointXYZI * p;
-    std::cout<<" size : "<<nPCount<<std::endl;
+    std::cout<<std::chrono::system_clock::now().time_since_epoch().count()/1000000 <<" size : "<<nPCount<<std::endl;
     p = (pcl::PointXYZI *)((char *)strdata + *pHeadSize);
     for(i=0;i<nPCount;i++)
     {
@@ -134,6 +134,7 @@ void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsign
     user_data++;
     viewer1.showCloud(point_cloud);
 
+
  //   return;
 
 
@@ -149,6 +150,8 @@ void viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
     //设置背景颜色
     viewer.setBackgroundColor(0.0,0.0,0.0);
 
+    viewer.setCameraPosition(0,0,100,0,0,0,0,1,0);
+
 //    viewer.setCameraPosition(0,0,1.0,0,0,0);
 //    viewer.setBackgroundColor (1.0, 0.5, 1.0);
     //球体坐标
@@ -160,11 +163,33 @@ void viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
 
 //    viewer.addSphere (o, 1, "sphere", 0);
 
+//    pcl::ModelCoefficients line_coeff;
+//    line_coeff.values.resize (6);    // We need 4 values
+//    line_coeff.values[0] = 0;
+//    line_coeff.values[1] = 0;
+//    line_coeff.values[2] = 0;
+//    line_coeff.values[3] = 8;
+//    line_coeff.values[4] = 8;
+//    line_coeff.values[5] = 8;
+
+
+//    viewer.addLine(line_coeff);
+
+
+//    pcl::PointXYZ pos;
+//    pos.x = 0;
+//    pos.y = 10;
+//    pos.z = 1;
+//    viewer.addText3D("car",pos,0.1,1.0,0.0,0.0);
+
     viewer.addCube(-0.9,0.9,9.5,10.5,-1.9,-0.4,0.0,1.0,0.0,"flag",0);
     //Draw Car
     viewer.addCube(-0.9,0.9,-2.3,2.3,-1.9,-0.4,0.0,0.0,1.0,"car",0);
 
 
+    viewer.addCoordinateSystem(1.0);
+
+
 
     std::cout << "i only run once" << std::endl;
 
@@ -172,13 +197,31 @@ void viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
 
 void viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
 {
-    static unsigned count = 0;
+//    static unsigned count = 0;
     std::stringstream ss;
  //   ss << "Once per viewer loop: " << count++;
 
     ss << "Point Cloud Count: " << user_data;
     viewer.removeShape ("text", 0);
-    viewer.addText (ss.str(), 200, 300, "text", 0);
+    viewer.addText (ss.str(), 50, 50, "text", 0);
+
+//    static int nview = 1;
+//    nview++;
+//    std::cout<<" nview: "<<nview<<std::endl;
+//    std::cout<<" user_data: "<<user_data<<std::endl;
+    if(user_data == 1)
+    {
+        viewer.setCameraPosition(0,0,100,0,0,0,0,1,0);
+    }
+
+//    std::vector<pcl::visualization::Camera> xvectorcam;
+//    viewer.getCameras(xvectorcam);
+//    std::cout<<"camera size: "<<xvectorcam.size()<<std::endl;
+//    if(xvectorcam.size()>0)
+//    {
+//        std::cout<<" pos: "<<xvectorcam[0].pos[0]<<" "<<xvectorcam[0].pos[1]<<" "<<xvectorcam[0].pos[2]<<" "<<std::endl;
+//    }
+
 
 
 
@@ -206,6 +249,7 @@ int main(int argc, char *argv[])
 
 
 
+
     //This will only get called once
     viewer1.runOnVisualizationThreadOnce (viewerOneOff);
 

+ 1 - 1
src/tool/pointcloudviewer/pointcloudviewer.pro

@@ -68,4 +68,4 @@ LIBS += -lboost_system
 
 
 LIBS += -lvtkCommonExecutionModel-6.3 -lvtkCommonCore-6.3 -lvtkRenderingLOD-6.3 -lvtkRenderingCore-6.3 \
-        -lvtkFiltersSources-6.3
+        -lvtkFiltersSources-6.3  -lvtkRenderingFreeType-6.3

+ 11 - 0
src/tool/view_ndtcalc/main.cpp

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

+ 78 - 0
src/tool/view_ndtcalc/mainwindow.cpp

@@ -0,0 +1,78 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+    mpthreadview = new std::thread(&MainWindow::threadview,this);
+
+
+}
+
+
+MainWindow::~MainWindow()
+{
+    mbThreadRun = false;
+    mpthreadview->join();
+    delete ui;
+}
+
+
+static double gposx = 0;
+
+static void viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
+{
+    //设置背景颜色
+    viewer.setBackgroundColor(0.0,0.0,0.0);
+
+//    viewer.setCameraPosition(10,0,50,20,0,0,1,1,0);
+   viewer.resetCamera();
+
+   viewer.addCube(gposx-0.9,gposx+0.9,-2.3,2.3,-1.9,-0.4,0.0,0.0,1.0,"car",0);
+    std::cout << "i only run once" << std::endl;
+
+}
+
+void viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
+{
+    viewer.removeShape("car");
+    viewer.addCube(gposx-0.9,gposx+0.9,-2.3,2.3,-1.9,-0.4,0.0,0.0,1.0,"car",0);
+    viewer.setCameraPosition(gposx,0,30,gposx,0,0,0,1,0);
+}
+
+void MainWindow::threadview()
+{
+    mpviewer = new pcl::visualization::CloudViewer("ndt map view");
+
+    pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
+                new pcl::PointCloud<pcl::PointXYZI>());
+    std::string path = "/home/nvidia/map.pcd";
+
+    std::cout<<" pcd path: "<<path<<std::endl;
+
+    pcl::io::loadPCDFile<pcl::PointXYZI>(path,*point_cloud);
+    mpviewer->showCloud(point_cloud);
+
+    //This will only get called once
+    mpviewer->runOnVisualizationThreadOnce (viewerOneOff);
+
+    mpviewer->runOnVisualizationThread (viewerPsycho);
+
+    while((!mpviewer->wasStopped())&&(mbThreadRun))
+    {
+        gposx= gposx + 0.01;
+        std::this_thread::sleep_for(std::chrono::milliseconds(10));
+
+    }
+    if(mbThreadRun == false)
+    {
+        delete mpviewer;
+    }
+    else
+    {
+        mbManualCloseCloud = true;
+    }
+}

+ 39 - 0
src/tool/view_ndtcalc/mainwindow.h

@@ -0,0 +1,39 @@
+#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 <thread>
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit MainWindow(QWidget *parent = 0);
+    ~MainWindow();
+
+private:
+    void threadview();
+
+private:
+    Ui::MainWindow *ui;
+
+    std::thread * mpthreadview;
+
+    pcl::visualization::CloudViewer * mpviewer;
+
+    bool mbThreadRun = true;
+    bool mbManualCloseCloud = false;
+};
+
+#endif // MAINWINDOW_H

+ 24 - 0
src/tool/view_ndtcalc/mainwindow.ui

@@ -0,0 +1,24 @@
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>MainWindow</string>
+  </property>
+  <widget class="QMenuBar" name="menuBar" />
+  <widget class="QToolBar" name="mainToolBar" />
+  <widget class="QWidget" name="centralWidget" />
+  <widget class="QStatusBar" name="statusBar" />
+ </widget>
+ <layoutDefault spacing="6" margin="11" />
+ <pixmapfunction></pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>

+ 74 - 0
src/tool/view_ndtcalc/view_ndtcalc.pro

@@ -0,0 +1,74 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2023-07-25T16:08:35
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = view_ndtcalc
+TEMPLATE = app
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which has been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+QMAKE_LFLAGS += -no-pie
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# 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 \
+        mainwindow.cpp
+
+HEADERS += \
+        mainwindow.h
+
+FORMS += \
+        mainwindow.ui
+
+INCLUDEPATH += /opt/ros/kinetic/include
+INCLUDEPATH += /usr/include/pcl-1.8
+INCLUDEPATH += /usr/include/pcl-1.10
+INCLUDEPATH += /usr/include/pcl-1.12
+INCLUDEPATH += /usr/include/pcl-1.7
+INCLUDEPATH += /usr/include/eigen3
+INCLUDEPATH += /usr/include/vtk-6.3
+INCLUDEPATH += /usr/include/vtk-6.2
+INCLUDEPATH += /usr/include/vtk-7.1
+
+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
+
+#INCLUDEPATH += $$PWD/../../../include/
+#LIBS += -L$$PWD/../../../bin/ -lxmlparam -lmodulecomm -livlog -livfault
+
+LIBS += -lboost_system
+#LIBS += -lvtkCommonExecutionModel-6.3 -lvtkCommonCore-6.3 -lvtkRenderingLOD-6.3 -lvtkRenderingCore-6.3 \
+#        -lvtkFiltersSources-6.3
+
+#LIBS += -lvtkCommonExecutionModel-7.1 -lvtkCommonCore-7.1 -lvtkRenderingLOD-7.1 -lvtkRenderingCore-7.1 \
+#        -lvtkFiltersSources-7.1

+ 2 - 0
src/tool/view_pcdmap/main.cpp

@@ -103,6 +103,8 @@ void viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
     o.z = 0;
 
 
+//    viewer.setCameraPosition(10,0,50,20,0,0,1,1,0);
+
 
    viewer.resetCamera();
     //添加球体