Selaa lähdekoodia

change map_lanetoxodr . for use imap (pip3 install imap;imap -f -i map.xodr -o hdmap.txt) to convert xodr to opendrive map.

yuchuli 1 kuukausi sitten
vanhempi
commit
b56d97af4e

+ 8 - 0
src/common/common/xodr/OpenDrive/OpenDrive.cpp

@@ -297,6 +297,14 @@ const OpenDrive& OpenDrive::operator=(const OpenDrive& rhs)
 
         mHeader = new Header(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
 
+        std::string strgeoref;
+        pHeader->GetgeoReference(strgeoref);
+        mHeader->SetgeoReference(strgeoref);
+
+        std::string struserdarta;
+        pHeader->GetuserData(struserdarta);
+        mHeader->SetuserData(struserdarta);
+
     }
     else
     {

+ 8 - 0
src/common/common/xodr/OpenDrive/OpenDriveXmlWriter.cpp

@@ -96,6 +96,14 @@ bool OpenDriveXmlWriter::WriteHeader(TiXmlElement *node)
         nodeHeader->LinkEndChild(nodegeoReference);
 
     }
+    else
+    {
+        char strgeodata[1000];
+        snprintf(strgeodata,1000,"<geoReference> <![CDATA[+lat_0=%8.7f +lon_0=%8.7f]]></geoReference>",lat0,lon0);
+        TiXmlElement * nodegeoReference = new TiXmlElement("geoReference");
+        nodegeoReference->Parse(strgeodata,0,TIXML_ENCODING_UTF8);
+        nodeHeader->LinkEndChild(nodegeoReference);
+    }
 
     if(struserData != "")
     {

+ 74 - 0
src/tool/tool_xodrtoapollohdmap/.gitignore

@@ -0,0 +1,74 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+CMakeLists.txt.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 11 - 0
src/tool/tool_xodrtoapollohdmap/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();
+}

+ 22 - 0
src/tool/tool_xodrtoapollohdmap/mainwindow.cpp

@@ -0,0 +1,22 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include "xodrtoapollohdmap.h"
+
+MainWindow::MainWindow(QWidget *parent)
+    : QMainWindow(parent)
+    , ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+    std::string strxodrpath = "/home/yuchuli/lk.xodr";
+    std::string strhdmappath = "/home/yuchuli/lk.bin";
+    xodrtoapollohdmap * ptohdmap = new xodrtoapollohdmap(strxodrpath,strhdmappath);
+    ptohdmap->Convert();
+
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}

+ 23 - 0
src/tool/tool_xodrtoapollohdmap/mainwindow.h

@@ -0,0 +1,23 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+namespace Ui {
+class MainWindow;
+}
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    MainWindow(QWidget *parent = nullptr);
+    ~MainWindow();
+
+private:
+    Ui::MainWindow *ui;
+};
+#endif // MAINWINDOW_H

+ 45 - 0
src/tool/tool_xodrtoapollohdmap/mainwindow.ui

@@ -0,0 +1,45 @@
+<?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="QPushButton" name="pushButton">
+    <property name="geometry">
+     <rect>
+      <x>100</x>
+      <y>50</y>
+      <width>131</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>PushButton</string>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>27</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 50 - 0
src/tool/tool_xodrtoapollohdmap/tool_xodrtoapollohdmap.pro

@@ -0,0 +1,50 @@
+QT       += core gui
+
+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 += \
+    main.cpp \
+    mainwindow.cpp \
+    xodrtoapollohdmap.cpp
+
+HEADERS += \
+    mainwindow.h \
+    xodrtoapollohdmap.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
+
+!include(../../common/common/xodr/OpenDrive/OpenDrive.pri ) {
+    error( "Couldn't find the OpenDrive.pri file!" )
+}
+
+!include(../../common/common/xodr/TinyXML/TinyXML.pri ) {
+    error( "Couldn't find the TinyXML.pri file!" )
+}
+
+!include(../../common/common/xodr/odaux/odaux.pri ) {
+    error( "Couldn't find the odaux.pri file!" )
+}
+
+INCLUDEPATH += $$PWD/../../common/common/xodr
+INCLUDEPATH += $$PWD/../../common/common
+
+INCLUDEPATH += $$PWD/../../common/common/xodr/odaux
+
+
+INCLUDEPATH += $$PWD/../../common/apollohdmapproto
+
+LIBS += -L$$PWD/../../../bin -lapollohdmapproto
+
+LIBS += -lprotobuf

+ 66 - 0
src/tool/tool_xodrtoapollohdmap/xodrtoapollohdmap.cpp

@@ -0,0 +1,66 @@
+#include "xodrtoapollohdmap.h"
+
+#include "OpenDrive/OpenDrive.h"
+#include "OpenDrive/OpenDriveXmlParser.h"
+
+xodrtoapollohdmap::xodrtoapollohdmap(std::string strxodrpath,std::string strhdmappath){
+    mstrxodrpath = strxodrpath;
+    mstrhdmappath = strhdmappath;
+}
+
+int xodrtoapollohdmap::Convert(){
+
+    OpenDrive * pxodr = new OpenDrive();  //because add to xodr,so don't delete
+    OpenDriveXmlParser x(pxodr);
+    if(!x.ReadFile(mstrxodrpath))
+    {
+        std::cout<<"Can't  load xodr file."<<std::endl;
+        return -1;
+    }
+
+    double flon0,flat0;
+    if(pxodr->GetHeader() != NULL)
+    {
+        pxodr->GetHeader()->GetLat0Lon0(flat0,flon0);
+    }
+    else
+    {
+        flon0 = 117.0;
+        flat0 = 39.0;
+    }
+
+    apollo::hdmap::Map xHdMap;
+
+
+    unsigned int nroadnum = pxodr->GetRoadCount();
+    unsigned int i;
+
+    for(i=0;i<nroadnum;i++)
+    {
+        Road * pRoad = pxodr->GetRoad(i);
+
+        std::string * pstrroadid = new std::string;
+        *pstrroadid = pRoad->GetRoadId();
+
+        apollo::hdmap::Road * pHdMapRoad = xHdMap.add_road();
+
+        apollo::hdmap::Id * proadid = new apollo::hdmap::Id();
+        proadid->set_allocated_id(pstrroadid);
+
+        pHdMapRoad->set_allocated_id(proadid);
+
+        pHdMapRoad->set_type(apollo::hdmap::Road_Type_CITY_ROAD);
+
+        if(pRoad->GetRoadJunction() != "-1")
+        {
+            std::string * pstrjunctionid = new std::string;
+            *pstrjunctionid = pRoad->GetRoadJunction();
+            apollo::hdmap::Id * pjunctionid = new apollo::hdmap::Id();
+            pjunctionid->set_allocated_id(pstrjunctionid);
+            pHdMapRoad->set_allocated_junction_id(pjunctionid);
+        }
+
+
+    }
+    return 0;
+}

+ 18 - 0
src/tool/tool_xodrtoapollohdmap/xodrtoapollohdmap.h

@@ -0,0 +1,18 @@
+#ifndef XODRTOAPOLLOHDMAP_H
+#define XODRTOAPOLLOHDMAP_H
+
+#include "modules/common_msgs/map_msgs/map.pb.h"
+
+class xodrtoapollohdmap
+{
+public:
+    xodrtoapollohdmap(std::string strxodrpath,std::string strhdmappath);
+
+    int Convert();
+
+private:
+    std::string mstrxodrpath;
+    std::string mstrhdmappath;
+};
+
+#endif // XODRTOAPOLLOHDMAP_H