Browse Source

change radar 4d .

yuchuli 9 months ago
parent
commit
c39c29fb2c

+ 114 - 0
src/driver/driver_radar_4d_ars548/ars548recv.cpp

@@ -0,0 +1,114 @@
+#include "ars548recv.h"
+
+ars548recv::ars548recv()
+{
+    InitSock();
+
+    std::thread * pthread = new std::thread(&ars548recv::threadrecv,this);
+}
+
+
+void ars548recv::InitSock()
+{
+    std::string mcast_ip("224.0.2.2");
+     uint16_t mcast_port = 42102;
+
+
+     notify_fd_ = socket(AF_INET, SOCK_DGRAM, 0);
+     if (notify_fd_ == -1) {
+       std::cout << "fail to create notify fd, " << strerror(errno);
+       return ;
+     }
+
+     memset(&notify_addr_, 0, sizeof(notify_addr_));
+     notify_addr_.sin_family = AF_INET;
+     notify_addr_.sin_addr.s_addr = inet_addr(mcast_ip.c_str());
+     notify_addr_.sin_port = htons(mcast_port);
+
+     listen_fd_ = socket(AF_INET, SOCK_DGRAM, 0);
+     if (listen_fd_ == -1) {
+       std::cout << "fail to create listen fd, " << strerror(errno);
+       return ;
+     }
+
+     if (fcntl(listen_fd_, F_SETFL, O_NONBLOCK) == -1) {
+       std::cout << "fail to set listen fd nonblock, " << strerror(errno);
+       return ;
+     }
+
+     memset(&listen_addr_, 0, sizeof(listen_addr_));
+     listen_addr_.sin_family = AF_INET;
+     listen_addr_.sin_addr.s_addr = htonl(INADDR_ANY);
+     listen_addr_.sin_port = htons(mcast_port);
+
+     int yes = 1;
+     if (setsockopt(listen_fd_, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
+       std::cout << "fail to setsockopt SO_REUSEADDR, " << strerror(errno);
+       return ;
+     }
+
+     if (bind(listen_fd_, (struct sockaddr*)&listen_addr_, sizeof(listen_addr_)) <
+         0) {
+       std::cout << "fail to bind addr, " << strerror(errno);
+       return ;
+     }
+
+     int loop = 1;
+     if (setsockopt(listen_fd_, IPPROTO_IP, IP_MULTICAST_ALL, &loop,
+                    sizeof(loop)) < 0) {
+       std::cout << "fail to setsockopt IP_MULTICAST_LOOP, " << strerror(errno);
+       return ;
+     }
+
+     struct ip_mreq mreq;
+
+//     mreq.imr_interface.s_addr = htonl(INADDR_ANY);
+
+     inet_aton( "192.168.1.102", &(mreq.imr_interface) );
+     if (setsockopt(listen_fd_, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,
+                    sizeof(mreq)) < 0) {
+       std::cout << "fail to setsockopt IP_ADD_MEMBERSHIP, " << strerror(errno);
+       return ;
+     }
+
+     return ;
+
+}
+
+void ars548recv::threadrecv()
+{
+    int timeout_ms = 100;
+    while(1)
+    {
+        int nrtn = 0;
+        struct pollfd fds;
+        fds.fd = listen_fd_;
+        fds.events = POLLIN;
+        int ready_num = poll(&fds, 1, timeout_ms);
+        if (ready_num > 0) {
+            char buf[32] = {0};  // larger than ReadableInfo::kSize
+            ssize_t nbytes = recvfrom(listen_fd_, buf, 32, 0, nullptr, nullptr);
+            if (nbytes == -1) {
+                std::cout << "fail to recvfrom, " << strerror(errno)<<std::endl;
+                continue;
+            }
+            if(nbytes >0)
+            {
+                std::cout<<" recv data: "<<nbytes<<std::endl;
+            }
+    //          return info->DeserializeFrom(buf, nbytes);
+        } else if (ready_num == 0) {
+            continue;
+        } else {
+            continue;
+            if (errno == EINTR) {
+                std::cout << "poll was interrupted."<<std::endl;
+            } else {
+                std::cout << "fail to poll, " << strerror(errno);
+            }
+        }
+
+
+    }
+}
+

+ 32 - 0
src/driver/driver_radar_4d_ars548/ars548recv.h

@@ -0,0 +1,32 @@
+#ifndef ARS548RECV_H
+#define ARS548RECV_H
+
+
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <cstring>
+#include <string>
+#include <thread>
+#include <iostream>
+
+
+class ars548recv
+{
+public:
+    ars548recv();
+    void InitSock();
+
+private:
+    int notify_fd_ = -1;
+    struct sockaddr_in notify_addr_;
+    int listen_fd_ = -1;
+    struct sockaddr_in listen_addr_;
+
+    void threadrecv();
+};
+
+#endif // ARS548RECV_H

+ 219 - 0
src/driver/driver_radar_4d_ars548/mainwindow.cpp

@@ -0,0 +1,219 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <iostream>
+
+#include <QFileDialog>
+#include <QTimer>
+
+
+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
+
+    DrawAxis();
+
+    QTimer * timer1 = new QTimer();
+    connect(timer1,SIGNAL(timeout()),this,SLOT(onTimer()));
+    timer1->start(10);
+
+    mprecv = new ars548recv();
+
+    setWindowTitle("ARS548 Viewer");
+
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+void MainWindow::DrawAxis()
+{
+
+    bool bGrid = false;
+
+    pcl::PointXYZ p1(-300,0,0);
+    pcl::PointXYZ p2(300,0,0);
+    view->addLine(p1,p2,1.0f,1.0f,0.0f,"axis_x");
+
+    p1.x = 0;p1.y = -300;
+    p2.x=  0;p2.y = 300;
+    view->addLine(p1,p2,1.0f,1.0f,0.0f,"axis_y");
+
+    int i;
+
+    if(bGrid)
+    {
+        for(i=-30;i<=30;i++)
+        {
+            if(i==0)continue;
+            p1.x = -300;p1.y = i*10;
+            p2.x = 300; p2.y = i*10;
+            char strname[256];
+            snprintf(strname,256,"axisgx_%d",i);
+            view->addLine(p1,p2,1.0f,1.0f,1.0f,strname);
+
+
+            p1.x = i*10;p1.y = -300;
+            p2.x = i*10; p2.y = 300;
+            snprintf(strname,256,"axisgy_%d",i);
+            view->addLine(p1,p2,1.0f,1.0f,1.0f,strname);
+        }
+    }
+    else
+    {
+        for(i=-30;i<=30;i++)
+        {
+            if(i==0)continue;
+            p1.x = 0;p1.y = i*10;
+            p2.x = 1; p2.y = i*10;
+            char strname[256];
+            snprintf(strname,256,"axisgx_%d",i);
+            view->addLine(p1,p2,1.0f,1.0f,1.0f,strname);
+
+
+            p1.x = i*10;p1.y = 0;
+            p2.x = i*10; p2.y = 1;
+            snprintf(strname,256,"axisgy_%d",i);
+            view->addLine(p1,p2,1.0f,1.0f,1.0f,strname);
+        }
+    }
+
+
+
+
+    for(i=-6;i<=6;i++)
+    {
+        char strname[256];
+        char strtext[256];
+        double orientation[3];
+        orientation[0] = 1.0;orientation[1] = 0.0;orientation[2] = 0.0;
+        p1.x = i*50;p1.y = 1;
+        snprintf(strname,256,"textx_%d",i);
+        snprintf(strtext,256,"%d",i*50);
+        if(i%2 == 0)
+            view->addText3D(strtext,p1,orientation,1.0,1.0,1.0,1.0,strname);
+        else
+            view->addText3D(strtext,p1,orientation,0.5,1.0,1.0,1.0,strname);
+
+        if(i== 0)continue;
+
+        orientation[0] = 1.0;orientation[1] =0.0;orientation[2] = 0.0;
+        p1.x = 1;p1.y = i*50+1;
+        snprintf(strname,256,"texty_%d",i);
+        snprintf(strtext,256,"%d",i*50);
+        if(i%2 == 0)
+            view->addText3D(strtext,p1,orientation,1.0,1.0,1.0,1.0,strname);
+        else
+            view->addText3D(strtext,p1,orientation,0.5,1.0,1.0,1.0,strname);
+    }
+
+    double base_size = 0.2;
+    double base_height = 0.2;
+    double sigx = 15;
+    double sigy = 15;
+    double sigz = 1.0;
+    view->addCube(sigx-base_size/2.0,sigx + base_size/2.0,sigy-base_size/2.0,sigy+base_size/2.0,sigz-base_height/2.0,sigz + base_height/2.0,1.0,0.0,0.0,"cube1");
+
+    view->setCameraPosition(0,0,100,0,0,0,0,1,0);
+    view->resetCamera();    //视角
+//    view->addText("300",300,5,10,1.0f,0.0f,0.0f,"txt1");
+
+
+}
+
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+
+    (void)event;
+    QSize sizemain = ui->centralwidget->size();
+
+    ui->vtk->setGeometry(0,0,sizemain.width()-0,sizemain.height()-0);
+
+
+
+}
+
+
+void MainWindow::onTimer()
+{
+
+    static bool bSetCam = false;
+    if(bSetCam == false)
+    {
+        bSetCam = true;
+        view->setCameraPosition(0,30,130,0,30,0,0,1,0);
+//        view->resetCamera();    //视角
+    }
+    static int nindex = 0;
+    nindex++;
+    if(nindex>1000)nindex = 0;
+    double base_size = 0.5;
+    double base_height = 0.5;
+    double sigx = 15;
+    double sigy = 15 + nindex * 0.01;
+    double sigz = 1.0;
+    view->removeShape("cube1");
+    view->addCube(sigx-base_size/2.0,sigx + base_size/2.0,sigy-base_size/2.0,sigy+base_size/2.0,sigz-base_height/2.0,sigz + base_height/2.0,1.0,0.0,0.0,"cube1");
+
+#if VTK890
+    ui->vtk->renderWindow()->Render();
+#else
+    ui->vtk->GetRenderWindow()->Render();
+#endif
+}
+
+
+void MainWindow::on_actionReset_Camera_triggered()
+{
+    view->setCameraPosition(0,0,100,0,0,0,0,1,0);
+    view->resetCamera();    //视角
+}
+
+
+void MainWindow::on_actionFull_Screem_triggered()
+{
+    showFullScreen();
+    ui->menubar->setVisible(false);
+    ui->statusbar->setVisible(false);
+    ui->toolBar->setVisible(false);
+    mbFull = true;
+}
+
+
+void MainWindow::keyReleaseEvent(QKeyEvent *event)
+{
+    if((event->key() == Qt::Key_Escape)||(event->key() == Qt::Key_F11))
+    {
+        if(mbFull)
+        {
+            showNormal();
+            ui->menubar->setVisible(true);
+            ui->statusbar->setVisible(true);
+            ui->toolBar->setVisible(true);
+            mbFull = false;
+        }
+    }
+}
+

+ 75 - 0
src/driver/driver_radar_4d_ars548/mainwindow.h

@@ -0,0 +1,75 @@
+#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>
+#include  <QKeyEvent>
+
+#include "ars548recv.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);
+     void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
+
+private slots:
+
+    void onTimer();
+
+    void on_actionReset_Camera_triggered();
+
+    void on_actionFull_Screem_triggered();
+
+private:
+    Ui::MainWindow *ui;
+
+    boost::shared_ptr< pcl::visualization::PCLVisualizer > view;
+
+    void DrawAxis();
+
+    bool mbFull = false;
+
+    ars548recv * mprecv;
+
+};
+#endif // MAINWINDOW_H

+ 84 - 0
src/driver/driver_radar_4d_ars548/mainwindow.ui

@@ -0,0 +1,84 @@
+<?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>
+   <widget class="QMenu" name="menuView">
+    <property name="title">
+     <string>View</string>
+    </property>
+    <addaction name="actionFull_Screem"/>
+    <addaction name="actionReset_Camera"/>
+   </widget>
+   <addaction name="menuFile"/>
+   <addaction name="menuView"/>
+  </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>
+  </widget>
+  <action name="actionFull_Screem">
+   <property name="text">
+    <string>Full Screem</string>
+   </property>
+  </action>
+  <action name="actionReset_Camera">
+   <property name="text">
+    <string>Reset Camera</string>
+   </property>
+  </action>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>QVTKOpenGLNativeWidget</class>
+   <extends>QOpenGLWidget</extends>
+   <header location="global">QVTKOpenGLNativeWidget.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>

+ 14 - 0
src/driver/driver_radar_4d_ars548/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();
+}

BIN
src/tool/pointcloudviewer/full.png


+ 5 - 0
src/tool/pointcloudviewer/mainwindow.cpp

@@ -18,6 +18,11 @@ MainWindow::MainWindow(QWidget *parent)
 
 
 
+//    vtkNew<vtkNamedColors> colors;
+//    renderer->SetBackground(colors->GetColor3d("Chocolate").GetData());
+
+
+
 #if VTK890
     view->setupInteractor(ui->vtk->interactor(),ui->vtk->renderWindow());
 #else

+ 14 - 1
src/tool/pointcloudviewer/mainwindow.ui

@@ -65,14 +65,25 @@
    <addaction name="actionFull"/>
   </widget>
   <action name="actionSave">
+   <property name="icon">
+    <iconset resource="pointcloudviewer2.qrc">
+     <normaloff>:/save.png</normaloff>:/save.png</iconset>
+   </property>
    <property name="text">
     <string>Save</string>
    </property>
   </action>
   <action name="actionFull">
+   <property name="icon">
+    <iconset resource="pointcloudviewer2.qrc">
+     <normaloff>:/full.png</normaloff>:/full.png</iconset>
+   </property>
    <property name="text">
     <string>Full </string>
    </property>
+   <property name="toolTip">
+    <string>Full Screem.  Esc or F11 exit Full Screem</string>
+   </property>
   </action>
  </widget>
  <customwidgets>
@@ -82,6 +93,8 @@
    <header location="global">QVTKOpenGLNativeWidget.h</header>
   </customwidget>
  </customwidgets>
- <resources/>
+ <resources>
+  <include location="pointcloudviewer2.qrc"/>
+ </resources>
  <connections/>
 </ui>

+ 3 - 0
src/tool/pointcloudviewer/pointcloudviewer2.pro

@@ -71,3 +71,6 @@ LIBS += -lboost_system
 #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
+
+RESOURCES += \
+    pointcloudviewer2.qrc

+ 6 - 0
src/tool/pointcloudviewer/pointcloudviewer2.qrc

@@ -0,0 +1,6 @@
+<RCC>
+    <qresource prefix="/">
+        <file>full.png</file>
+        <file>save.png</file>
+    </qresource>
+</RCC>

BIN
src/tool/pointcloudviewer/save.png