Browse Source

add adcxodrviewer,pc and android version.

yuchuli 3 years ago
parent
commit
648810dbda

+ 104 - 0
src/tool/map_lanetoxodr/adcxodrviewer.pro

@@ -0,0 +1,104 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2019-08-23T15:28:22
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = adcxodrviewer
+TEMPLATE = app
+
+CONFIG+= c++11
+
+DEFINES += XODRViewer
+
+# 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 += \
+    ivxodrtool.cpp \
+        main.cpp \
+    roaddigit.cpp \
+    myview.cpp \
+    OpenDrive/Junction.cpp \
+    OpenDrive/Lane.cpp \
+    OpenDrive/ObjectSignal.cpp \
+    OpenDrive/OpenDrive.cpp \
+    OpenDrive/OpenDriveXmlParser.cpp \
+    OpenDrive/OpenDriveXmlWriter.cpp \
+    OpenDrive/OtherStructures.cpp \
+    OpenDrive/Road.cpp \
+    OpenDrive/RoadGeometry.cpp \
+    TinyXML/tinystr.cpp \
+    TinyXML/tinyxml.cpp \
+    TinyXML/tinyxmlerror.cpp \
+    TinyXML/tinyxmlparser.cpp \
+    fresnl.cpp \
+    polevl.c \
+    const.cpp \
+    gnss_coordinate_convert.cpp \
+    xodrfunc.cpp \
+    xodrscenfunc.cpp \
+    xvmainwindow.cpp
+
+HEADERS += \
+    ivxodrtool.h \
+    roaddigit.h \
+    myview.h \
+    gps_type.h \
+    linedata.h \
+    OpenDrive/Junction.h \
+    OpenDrive/Lane.h \
+    OpenDrive/ObjectSignal.h \
+    OpenDrive/OpenDrive.h \
+    OpenDrive/OpenDriveXmlParser.h \
+    OpenDrive/OpenDriveXmlWriter.h \
+    OpenDrive/OtherStructures.h \
+    OpenDrive/Road.h \
+    OpenDrive/RoadGeometry.h \
+    TinyXML/tinystr.h \
+    TinyXML/tinyxml.h \
+    gnss_coordinate_convert.h \
+    xodrfunc.h \
+    xodrscenfunc.h \
+    xvmainwindow.h
+
+FORMS += \
+    xvmainwindow.ui
+
+
+
+
+
+
+
+QMAKE_CXXFLAGS +=  -g
+
+
+
+
+
+
+DISTFILES += \
+
+
+unix:INCLUDEPATH += /usr/include/eigen3
+win32:INCLUDEPATH += D:\File\soft\eigen
+
+
+RESOURCES += \
+    opendrive.qrc

+ 120 - 0
src/tool/map_lanetoxodr/adcxodrviewer_android.pro

@@ -0,0 +1,120 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2019-08-23T15:28:22
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+QT += androidextras
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = adcxodrviewer
+TEMPLATE = app
+
+CONFIG+= c++11
+
+DEFINES += Android
+
+DEFINES += XODRViewer
+
+# 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 += \
+    ivxodrtool.cpp \
+        main.cpp \
+    roaddigit.cpp \
+    myview.cpp \
+    OpenDrive/Junction.cpp \
+    OpenDrive/Lane.cpp \
+    OpenDrive/ObjectSignal.cpp \
+    OpenDrive/OpenDrive.cpp \
+    OpenDrive/OpenDriveXmlParser.cpp \
+    OpenDrive/OpenDriveXmlWriter.cpp \
+    OpenDrive/OtherStructures.cpp \
+    OpenDrive/Road.cpp \
+    OpenDrive/RoadGeometry.cpp \
+    TinyXML/tinystr.cpp \
+    TinyXML/tinyxml.cpp \
+    TinyXML/tinyxmlerror.cpp \
+    TinyXML/tinyxmlparser.cpp \
+    fresnl.cpp \
+    polevl.c \
+    const.cpp \
+    gnss_coordinate_convert.cpp \
+    xodrfunc.cpp \
+    xodrscenfunc.cpp \
+    xvmainwindow.cpp
+
+HEADERS += \
+    ivxodrtool.h \
+    roaddigit.h \
+    myview.h \
+    gps_type.h \
+    linedata.h \
+    OpenDrive/Junction.h \
+    OpenDrive/Lane.h \
+    OpenDrive/ObjectSignal.h \
+    OpenDrive/OpenDrive.h \
+    OpenDrive/OpenDriveXmlParser.h \
+    OpenDrive/OpenDriveXmlWriter.h \
+    OpenDrive/OtherStructures.h \
+    OpenDrive/Road.h \
+    OpenDrive/RoadGeometry.h \
+    TinyXML/tinystr.h \
+    TinyXML/tinyxml.h \
+    gnss_coordinate_convert.h \
+    xodrfunc.h \
+    xodrscenfunc.h \
+    xvmainwindow.h
+
+FORMS += \
+    xvmainwindow.ui
+
+
+
+
+
+
+
+QMAKE_CXXFLAGS +=  -g
+
+
+
+
+
+
+DISTFILES += \ \
+    android/AndroidManifest.xml \
+    android/build.gradle \
+    android/gradle/wrapper/gradle-wrapper.jar \
+    android/gradle/wrapper/gradle-wrapper.properties \
+    android/gradlew \
+    android/gradlew.bat \
+    android/res/values/libs.xml
+
+
+unix:INCLUDEPATH += /usr/include/eigen3
+win32:INCLUDEPATH += D:\File\soft\eigen
+
+
+RESOURCES += \
+    opendrive.qrc
+
+contains(ANDROID_TARGET_ARCH,arm64-v8a) {
+    ANDROID_PACKAGE_SOURCE_DIR = \
+        $$PWD/android
+}

+ 47 - 2
src/tool/map_lanetoxodr/main.cpp

@@ -1,14 +1,59 @@
+
+#ifdef XODRViewer
+#include "xvmainwindow.h"
+#else
 #include "mainwindow.h"
+#endif
+
 #include <QApplication>
 
-#include "ivbacktrace.h"
+
+#ifdef Android
+#include <QAndroidJniEnvironment>
+#include <QtAndroid>
+//#include <QAndr
+#include <QAndroidJniObject>
+
+#endif
+
+
+
+
+
+#ifdef Android
+
+bool requestPermission() {
+   QtAndroid::PermissionResult  r = QtAndroid::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
+    if(r == QtAndroid::PermissionResult::Denied) {
+        QtAndroid::requestPermissionsSync( QStringList() << "android.permission.WRITE_EXTERNAL_STORAGE" );
+        r = QtAndroid::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
+        if(r == QtAndroid::PermissionResult::Denied) {
+             return false;
+        }
+   }
+   return true;
+}
+
+#endif
+
+
 
 int main(int argc, char *argv[])
 {
-    RegisterIVBackTrace();
 
     QApplication a(argc, argv);
+
+#ifdef Android
+
+    requestPermission();
+
+#endif
+
+#ifdef XODRViewer
+    XVMainWindow w;
+#else
     MainWindow w;
+#endif
     w.show();
     w.resize(1280,800);
 

+ 0 - 1
src/tool/map_lanetoxodr/map_lanetoxodr.pro

@@ -102,7 +102,6 @@ HEADERS += \
     myview.h \
     boost.h \
     gps_type.h \
-    linedata.h \
     OpenDrive/Junction.h \
     OpenDrive/Lane.h \
     OpenDrive/ObjectSignal.h \

+ 10 - 0
src/tool/map_lanetoxodr/myview.cpp

@@ -59,8 +59,13 @@ void MyView::zoomIn()
     int centery = (psV->value() + psV->size().height()/2)/beishu;
     int centerx = (psH->value() + psH->size().width()/2)/beishu;
 
+#ifndef Android
     scale(1.1, 1.1);
     beishu *= 1.1;
+#else
+    scale(1.3, 1.3);
+    beishu *= 1.3;
+#endif
  //   centerOn(450, 700 - (200 / beishu));
 
 
@@ -93,8 +98,13 @@ void MyView::zoomOut()
     int centery = (psV->value() + psV->size().height()/2)/beishu;
     int centerx = (psH->value() + psH->size().width()/2)/beishu;
 
+#ifndef Android
     scale(1 / 1.1, 1 / 1.1);
     beishu /= 1.1;
+#else
+    scale(1 / 1.3, 1 / 1.3);
+    beishu /= 1.3;
+#endif
 //    centerOn(450, 700 - (200 / beishu));
 
 

+ 296 - 0
src/tool/map_lanetoxodr/xvmainwindow.cpp

@@ -0,0 +1,296 @@
+#include "xvmainwindow.h"
+#include "ui_xvmainwindow.h"
+
+#include <QMessageBox>
+#include <QFileDialog>
+
+#include <string.h>
+
+#include "xodrfunc.h"
+#include "roaddigit.h"
+#include "xodrscenfunc.h"
+
+#define VIEW_WIDTH 2000
+#define VIEW_HEIGHT 2000
+
+static bool IsNaN(double dat)
+{
+ qint64 & ref=*(qint64 *)&dat;
+ return (ref&0x7FF0000000000000) == 0x7FF0000000000000 && (ref&0xfffffffffffff)!=0;
+}
+
+
+XVMainWindow::XVMainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::XVMainWindow)
+{
+    ui->setupUi(this);
+
+    myview = new MyView(this);
+    myview->setObjectName(QStringLiteral("graphicsView"));
+    myview->setGeometry(QRect(30, 30, 600, 600));
+
+    connect(myview,SIGNAL(dbclickxy(double,double)),this,SLOT(onClickXY(double,double)));
+
+
+    myview->setCacheMode(myview->CacheBackground);
+
+    mpscene = new  QGraphicsScene(0,0,VIEW_WIDTH,VIEW_HEIGHT);
+    mpscene->setBackgroundBrush(Qt::darkGreen);
+
+    myview->setScene(mpscene);
+
+    setWindowTitle("ADC OpenDrive Viewer");
+}
+
+XVMainWindow::~XVMainWindow()
+{
+    delete ui;
+}
+
+void XVMainWindow::resizeEvent(QResizeEvent *event)
+{
+    qDebug("resize");
+    QSize sizemain = ui->centralwidget->size();
+    qDebug("size x = %d y=%d",sizemain.width(),sizemain.height());
+    myview->setGeometry(0,30,sizemain.width(),sizemain.height()-30);
+}
+
+void XVMainWindow::on_actionLoad_triggered()
+{
+
+    if(mxodr.GetRoadCount() > 0)
+    {
+        QMessageBox::StandardButton button;
+        char strquest[256];
+        snprintf(strquest,256,"Do you Want to Load New File ?");
+        button=QMessageBox::question(this,"Move",strquest,QMessageBox::Yes|QMessageBox::No);
+        if(button==QMessageBox::No)
+        {
+            return;
+        }
+        else if(button==QMessageBox::Yes)
+        {
+
+        }
+    }
+
+
+#ifndef Android
+    QString strpath = QFileDialog::getOpenFileName(this,"Load XODR",".","*.xodr");
+    if(strpath.isEmpty())return;
+#else
+//    QMessageBox::warning(this,"warning","no file dialog.",QMessageBox::YesAll);
+    QString strpath = "/storage/emulated/0/map.xodr";
+
+
+#endif
+    LoadXODR(strpath);
+    UpdateScene();
+}
+
+void XVMainWindow::LoadXODR(QString strpath)
+{
+    mxodr.Clear();
+    OpenDrive * pxodr = &mxodr;  //because add to xodr,so don't delete
+    OpenDriveXmlParser x(pxodr);
+    if(!x.ReadFile(strpath.toStdString()))
+    {
+        QMessageBox::warning(this,"warn","Can't  load xodr file.");
+        return;
+    }
+
+    int nroadnum = pxodr->GetRoadCount();
+    int i;
+    double froadlen = 0;
+    for(i=0;i<nroadnum;i++)
+    {
+        Road * pRoad = pxodr->GetRoad(i);
+        if(IsNaN(pRoad->GetRoadLength()))
+        {
+            pxodr->DeleteRoad(i);
+            i--;
+            nroadnum--;
+            qDebug("delete road %s because length is NaN",pRoad->GetRoadId().data());
+        }
+        else
+        {
+            froadlen = froadlen + pRoad->GetRoadLength();
+        }
+    }
+
+    char strout[256];
+    snprintf(strout,256,"Road count is %d. Total Len is %f",mxodr.GetRoadCount(),froadlen);
+    QMessageBox::information(this,"Info",strout,QMessageBox::YesAll);
+}
+
+void XVMainWindow::UpdateScene()
+{
+    int i;
+    int nsize = mvectorviewitem.size();
+    for(i=0;i<nsize;i++)
+    {
+        mpscene->removeItem(mvectorviewitem.at(i));
+        delete mvectorviewitem.at(i);
+    }
+    mvectorviewitem.clear();
+
+    nsize = mxodr.GetRoadCount();
+
+    std::vector<RoadDigit> xvectorrd;
+    for(i=0;i<nsize;i++)
+    {
+        RoadDigit xrd(mxodr.GetRoad(i),10.0);
+        xvectorrd.push_back(xrd);
+    }
+    for(i=0;i<nsize;i++)
+    {
+        std::vector<QGraphicsPathItem *> xvectorlanepath = xodrscenfunc::GetRoadLaneItem(&(xvectorrd[i]));
+        int j;
+        int ncount = xvectorlanepath.size();
+        for(j=0;j<ncount;j++)
+        {
+            QGraphicsPathItem * pitem = xvectorlanepath[j];
+            pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
+            mpscene->addItem(pitem);
+            mvectorviewitem.push_back(pitem);
+        }
+    }
+
+    for(i=0;i<nsize;i++)
+    {
+        std::vector<QGraphicsPathItem *> xvectormarkpath = xodrscenfunc::GetRoadMarkItem(&(xvectorrd[i]));
+        int j;
+        int ncount = xvectormarkpath.size();
+        for(j=0;j<ncount;j++)
+        {
+            QGraphicsPathItem * pitem = xvectormarkpath[j];
+            pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
+            mpscene->addItem(pitem);
+            mvectorviewitem.push_back(pitem);
+        }
+    }
+}
+
+
+void XVMainWindow::on_actionZoom_In_triggered()
+{
+    myview->zoomIn();
+}
+
+void XVMainWindow::on_actionZoom_Out_triggered()
+{
+    myview->zoomOut();
+}
+
+void XVMainWindow::on_actionZoom_One_triggered()
+{
+    myview->zoomone();
+}
+
+void XVMainWindow::onClickXY(double x, double y)
+{
+    double selx,sely;
+    double lon,lat;
+    selx = (x - VIEW_WIDTH/2);
+    sely = (y - VIEW_HEIGHT/2) * (-1);
+
+    mfselx = selx;
+    mfsely = sely;
+
+//    double x0,y0;
+//    GaussProjCal(glon0,glat0,&x0,&y0);
+//    GaussProjInvCal(x0+selx,y0+sely,&lon,&lat);
+
+    double rel_x,rel_y;
+    rel_x = selx - mfViewMoveX;
+    rel_y = sely - mfViewMoveY;
+
+    Road * pRoad = 0;
+    GeometryBlock * pgeob;
+    double fdis,nearx,neary,hdg;
+    double fs;
+    int nlane;
+    if(xodrfunc::GetNearPoint(rel_x,rel_y,&mxodr,&pRoad,&pgeob,fdis,nearx,neary,hdg,50,&fs,&nlane) == 0)
+    {
+        qDebug("s:%f dis is %f nlane is %d",fs,fdis,nlane);
+        char strout[1000];
+        snprintf(strout,1000,"Road:%s s:%f dis:%f nlane:%d",pRoad->GetRoadId().data(),fs,fdis,nlane);
+ //       mpLabel_Status->setText(strout);
+        ui->statusbar->showMessage(strout,10000);
+
+    }
+    else
+    {
+        char strout[1000];
+        snprintf(strout,1000,"Click x:%f y:%f",rel_x,rel_y);
+        ui->statusbar->showMessage(strout,10000);
+        qDebug("not found near road.");
+    }
+}
+
+void XVMainWindow::on_actionSet_Move_triggered()
+{
+    QMessageBox::StandardButton button;
+    char strquest[256];
+    snprintf(strquest,256,"Want to Move Center to x:%f y:%f ?",-(mfViewMoveX - mfselx),-(mfViewMoveY-mfsely));
+    button=QMessageBox::question(this,"Move",strquest,QMessageBox::Yes|QMessageBox::No);
+    if(button==QMessageBox::No)
+    {
+        return;
+    }
+    else if(button==QMessageBox::Yes)
+    {
+
+    }
+
+    mfViewMoveX = mfViewMoveX - mfselx;
+    mfViewMoveY = mfViewMoveY - mfsely;
+
+    int nsize = mvectorviewitem.size();
+    int i;
+    for(i=0;i<nsize;i++)
+    {
+        mpscene->removeItem(mvectorviewitem.at(i));
+    }
+    for(i=0;i<nsize;i++)
+    {
+        mvectorviewitem.at(i)->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
+        mpscene->addItem(mvectorviewitem.at(i));
+    }
+
+    myview->zoomIn();
+    myview->zoomOut();
+}
+
+void XVMainWindow::on_actionReset_Move_triggered()
+{
+    mfViewMoveX = 0;
+    mfViewMoveY = 0;
+    int nsize = mvectorviewitem.size();
+    int i;
+
+    for(i=0;i<nsize;i++)
+    {
+        mpscene->removeItem(mvectorviewitem.at(i));
+    }
+
+    for(i=0;i<nsize;i++)
+    {
+        mvectorviewitem.at(i)->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
+        mpscene->addItem(mvectorviewitem.at(i));
+    }
+
+
+    myview->zoomIn();
+    myview->zoomOut();
+}
+
+void XVMainWindow::paintEvent(QPaintEvent * event)
+{
+    if(mbRefresh)
+    {
+        myview->setScene(mpscene);
+        mbRefresh = false;
+    }
+}

+ 70 - 0
src/tool/map_lanetoxodr/xvmainwindow.h

@@ -0,0 +1,70 @@
+#ifndef XVMAINWINDOW_H
+#define XVMAINWINDOW_H
+
+#include <QMainWindow>
+
+#include "myview.h"
+
+#include <QGraphicsScene>
+
+#include "OpenDrive/OpenDrive.h"
+#include "OpenDrive/OpenDriveXmlWriter.h"
+
+#include "OpenDrive/OpenDriveXmlParser.h"
+
+namespace Ui {
+class XVMainWindow;
+}
+
+class XVMainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit XVMainWindow(QWidget *parent = nullptr);
+    ~XVMainWindow();
+
+private slots:
+    void on_actionLoad_triggered();
+
+    void on_actionZoom_In_triggered();
+
+    void on_actionZoom_Out_triggered();
+
+    void on_actionZoom_One_triggered();
+
+    void onClickXY(double x, double y);
+
+    void on_actionSet_Move_triggered();
+
+    void on_actionReset_Move_triggered();
+
+public:
+     void resizeEvent(QResizeEvent *event);
+
+private slots:
+    virtual void paintEvent(QPaintEvent *);
+
+private:
+     void LoadXODR(QString strpath);
+     void UpdateScene();
+
+private:
+    Ui::XVMainWindow *ui;
+    MyView *myview;
+    QGraphicsScene * mpscene;
+
+    std::vector<QGraphicsPathItem *> mvectorviewitem;
+
+private:
+    OpenDrive mxodr;
+    double mfViewMoveX = 0;
+    double mfViewMoveY = 0;
+
+    double mfselx = 0;
+    double mfsely = 0;
+
+    bool mbRefresh = false;
+};
+
+#endif // XVMAINWINDOW_H

+ 73 - 0
src/tool/map_lanetoxodr/xvmainwindow.ui

@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>XVMainWindow</class>
+ <widget class="QMainWindow" name="XVMainWindow">
+  <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="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>28</height>
+    </rect>
+   </property>
+   <widget class="QMenu" name="menuFile">
+    <property name="title">
+     <string>File</string>
+    </property>
+    <addaction name="actionLoad"/>
+    <addaction name="actionZoom_In"/>
+    <addaction name="actionZoom_Out"/>
+    <addaction name="actionZoom_One"/>
+    <addaction name="actionSet_Move"/>
+    <addaction name="actionReset_Move"/>
+   </widget>
+   <addaction name="menuFile"/>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+  <action name="actionLoad">
+   <property name="text">
+    <string>Load</string>
+   </property>
+  </action>
+  <action name="actionZoom_In">
+   <property name="text">
+    <string>Zoom In</string>
+   </property>
+  </action>
+  <action name="actionZoom_Out">
+   <property name="text">
+    <string>Zoom Out</string>
+   </property>
+  </action>
+  <action name="actionZoom_One">
+   <property name="text">
+    <string>Zoom One</string>
+   </property>
+  </action>
+  <action name="actionSet_Move">
+   <property name="text">
+    <string>Set Move</string>
+   </property>
+  </action>
+  <action name="actionReset_Move">
+   <property name="text">
+    <string>Reset Move</string>
+   </property>
+  </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>