Browse Source

add Road TurnDirection in opendrive , and change odtolanletet.

yuchuli 1 year ago
parent
commit
3281eebc88

+ 50 - 4
src/common/common/xodr/OpenDrive/OpenDriveXmlParser.cpp

@@ -293,10 +293,14 @@ bool OpenDriveXmlParser::ReadRoad(TiXmlElement *node)
                 bProc = ReadRoadPriority(road,subNode);
                 if(bProc == false)
                 {
-                    TiXmlPrinter *printer = new TiXmlPrinter();
-                    subNode->Accept(printer );//保存该节点及其子节点到字符串
-                    std::string str = printer->Str();
-                    road->GetUserData()->push_back(str);
+                    bProc = ReadRoadTurnDirection(road,subNode);
+                    if(bProc == false)
+                    {
+                        TiXmlPrinter *printer = new TiXmlPrinter();
+                        subNode->Accept(printer );//保存该节点及其子节点到字符串
+                        std::string str = printer->Str();
+                        road->GetUserData()->push_back(str);
+                    }
                 }
                 //           road->getroadb ->push_back(str);
             }
@@ -2471,6 +2475,48 @@ bool OpenDriveXmlParser::ReadRoadPriority(Road * road,TiXmlElement * node)
 
 //--------------
 
+bool OpenDriveXmlParser::ReadRoadTurnDirection(Road * road,TiXmlElement * node)
+{
+    string strcode;
+    if(node->QueryStringAttribute("code",&strcode) != TIXML_SUCCESS)
+    {
+        return false;
+    }
+    if(strcode != "roadTurnDirection")
+    {
+        return false;
+    }
+
+    TiXmlElement *subNode = node->FirstChildElement("roadTurnDirection");
+    if (subNode)
+    {
+        int nturn = 3;
+        RoadTurnDirection::TURNDIRECTION xturn;
+        int checker=TIXML_SUCCESS;
+        checker+=subNode->QueryIntAttribute("TurnDirection",&nturn);
+        if(checker != TIXML_SUCCESS)
+        {
+            return false;
+        }
+
+        xturn = RoadTurnDirection::STRAIGHT;
+        if(nturn == 1)xturn = RoadTurnDirection::LEFT;
+        if(nturn == 2)xturn = RoadTurnDirection::RIGHT;
+
+        road->SetRoadTurnDirection(xturn);
+
+    }
+    else
+    {
+        return false;
+    }
+
+
+    return true;
+}
+
+//--------------
+
 bool OpenDriveXmlParser::ReadSignals (Road* road, TiXmlElement *node)
 {
 

+ 1 - 0
src/common/common/xodr/OpenDrive/OpenDriveXmlParser.h

@@ -76,6 +76,7 @@ public:
     bool ReadRoadNoavoid(Road * road,TiXmlElement * node);
 
     bool ReadRoadPriority(Road * road,TiXmlElement * node);
+    bool ReadRoadTurnDirection(Road * road,TiXmlElement * node);
 
 	//--------------
 

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

@@ -160,9 +160,6 @@ bool OpenDriveXmlWriter::WriteRoad(TiXmlElement *node, Road *road)
 	//Proceed to Lanes
 	WriteLanes(nodeRoad, road);
 
-
-
-
 	//Proceed to Objects
 	WriteObjects(nodeRoad, road);
 

+ 2 - 0
src/common/common/xodr/OpenDrive/Road.cpp

@@ -67,6 +67,7 @@ Road::Road (const Road& road)
     mSurfaceCRGVector = road.mSurfaceCRGVector;
     mRoadPriorityVector = road.mRoadPriorityVector;
     mShapeVector = road.mShapeVector;
+    mRoadTurnDirectionVector = road.mRoadTurnDirectionVector;
 
 }
 
@@ -115,6 +116,7 @@ const Road& Road::operator=(const Road& otherRoad)
         mSurfaceCRGVector = otherRoad.mSurfaceCRGVector;
         mRoadPriorityVector = otherRoad.mRoadPriorityVector;
         mShapeVector = otherRoad.mShapeVector;
+        mRoadTurnDirectionVector = otherRoad.mRoadTurnDirectionVector;
 	}
 	return *this;
 }

+ 18 - 4
src/map/odtolanelet/odtolanelet.cpp

@@ -181,7 +181,7 @@ int odtolanelet::Road2Lanelet(Road * pRoad,lanelet::LaneletMapPtr & laneletMap)
             {
                 //Create LaneLet
 
-                linetolet(laneletMap,xvectorlinestring,ncenterlanepos,pRoad->GetRoadId(),sstart,send);
+                linetolet(laneletMap,xvectorlinestring,ncenterlanepos,pRoad->GetRoadId(),sstart,send,pRoad);
                 bNewLet = true;
             }
         }
@@ -241,7 +241,7 @@ int odtolanelet::Road2Lanelet(Road * pRoad,lanelet::LaneletMapPtr & laneletMap)
 
     if(xvectorlinestring.size()>0)
     {
-        linetolet(laneletMap,xvectorlinestring,ncenterlanepos,pRoad->GetRoadId(),sstart,send);
+        linetolet(laneletMap,xvectorlinestring,ncenterlanepos,pRoad->GetRoadId(),sstart,send,pRoad);
     }
 
     return  0;
@@ -349,7 +349,7 @@ void odtolanelet::LanePointToPoint3DWithLast(std::vector<iv::LanePoint> & xvecto
         bool bUseOld = false;
         for(j=0;j<nLastSize;j++)
         {
-            if((fabs(xvectorLanePoint[i].mx - xvectorPoint3DLast[j].x())<0.001)&(fabs(xvectorLanePoint[i].my - xvectorPoint3DLast[j].y())<0.001))
+            if((fabs(xvectorLanePoint[i].mx - xvectorPoint3DLast[j].x())<0.001)&&(fabs(xvectorLanePoint[i].my - xvectorPoint3DLast[j].y())<0.001))
             {
                 bUseOld = true;
                 xvectorPoint3D.push_back(xvectorPoint3DLast[j]);
@@ -371,7 +371,7 @@ void odtolanelet::LanePointToPoint3DWithLast(std::vector<iv::LanePoint> & xvecto
 }
 
 void odtolanelet::linetolet(lanelet::LaneletMapPtr & laneletMap,std::vector<lanelet::LineString3d> & xvectorlinestring, unsigned int ncenterlane,
-                            std::string strroadid,double sstart,double send)
+                            std::string strroadid,double sstart,double send,Road * pRoad)
 {
     unsigned int i;
     unsigned int nsize = static_cast<unsigned int>(xvectorlinestring.size()) ;
@@ -391,6 +391,13 @@ void odtolanelet::linetolet(lanelet::LaneletMapPtr & laneletMap,std::vector<lane
         xlet.setAttribute("speed_limit",lanelet::Attribute("30"));
         xlet.setAttribute("subtype",lanelet::Attribute("road"));
         xlet.setAttribute("turn_direction",lanelet::Attribute("straight"));
+        RoadTurnDirection::TURNDIRECTION xturn;
+        if(pRoad->GetRoadTurnDirection(xturn) == 1)
+        {
+            if(xturn == RoadTurnDirection::STRAIGHT)xlet.setAttribute("turn_direction",lanelet::Attribute("straight"));
+            if(xturn == RoadTurnDirection::LEFT)xlet.setAttribute("turn_direction",lanelet::Attribute("left"));
+            if(xturn == RoadTurnDirection::RIGHT)xlet.setAttribute("turn_direction",lanelet::Attribute("right"));
+        }
         mid++;
         laneletMap->add(xlet);
     }
@@ -406,6 +413,13 @@ void odtolanelet::linetolet(lanelet::LaneletMapPtr & laneletMap,std::vector<lane
         xlet.setAttribute("speed_limit",lanelet::Attribute("30"));
         xlet.setAttribute("subtype",lanelet::Attribute("road"));
         xlet.setAttribute("turn_direction",lanelet::Attribute("straight"));
+        RoadTurnDirection::TURNDIRECTION xturn;
+        if(pRoad->GetRoadTurnDirection(xturn) == 1)
+        {
+            if(xturn == RoadTurnDirection::STRAIGHT)xlet.setAttribute("turn_direction",lanelet::Attribute("straight"));
+            if(xturn == RoadTurnDirection::LEFT)xlet.setAttribute("turn_direction",lanelet::Attribute("left"));
+            if(xturn == RoadTurnDirection::RIGHT)xlet.setAttribute("turn_direction",lanelet::Attribute("right"));
+        }
         mid++;
         laneletMap->add(xlet);
     }

+ 1 - 1
src/map/odtolanelet/odtolanelet.h

@@ -50,7 +50,7 @@ private:
     void LanePointToPoint3DWithLast(std::vector<iv::LanePoint> & xvectorLanePoint, std::vector<lanelet::Point3d> & xvectorPoint3D,
                                     std::vector<lanelet::Point3d> & xvectorPoint3DLast);
 
-    void linetolet(lanelet::LaneletMapPtr & laneletMap,std::vector<lanelet::LineString3d> & xvectorlinestring, unsigned int ncenterlane,std::string strroadid,double sstart,double send);
+    void linetolet(lanelet::LaneletMapPtr & laneletMap,std::vector<lanelet::LineString3d> & xvectorlinestring, unsigned int ncenterlane,std::string strroadid,double sstart,double send,Road * pRoad);
 
     int InvertLine(lanelet::LineString3d & xinvert,lanelet::LineString3d & xraw);
 

+ 13 - 0
src/tool/map_lanetoxodr/mainwindow.cpp

@@ -6159,6 +6159,18 @@ void MainWindow::on_actionExport_Current_Road_triggered()
 
 void MainWindow::on_actionOptimize_Road_triggered()
 {
+
+    QMessageBox::StandardButton button;
+    button=QMessageBox::question(this,tr("优化当前选中的道路"),QString(tr("是否优化当前选中道路?")),QMessageBox::Yes|QMessageBox::No);
+    if(button==QMessageBox::No)
+    {
+        return;
+    }
+    else if(button==QMessageBox::Yes)
+    {
+
+    }
+
     int index = mpCBRoad->currentIndex();
     qDebug("index: %d",index);
 
@@ -6170,6 +6182,7 @@ void MainWindow::on_actionOptimize_Road_triggered()
         return;
     }
 
+    SaveBack();
 
     Road * pRoad = mxodr.GetRoad(index);
 

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

@@ -66,6 +66,7 @@ SOURCES += \
         main.cpp \
         mainwindow.cpp \
     function/ndsdataproc.cpp \
+    ui/dialogturndirection.cpp \
     view/roaddigit.cpp \
     ui/roadeditdialog.cpp \
     view/roadviewitem.cpp \
@@ -138,6 +139,7 @@ HEADERS += \
         mainwindow.h \
     function/ndsdataproc.h \
     rawtype.h \
+    ui/dialogturndirection.h \
     view/roaddigit.h \
     ui/roadeditdialog.h \
     view/roadviewitem.h \
@@ -201,6 +203,7 @@ FORMS += \
         ui/dialogroadsplit.ui \
         ui/dialogroadtype.ui \
         mainwindow.ui \
+    ui/dialogturndirection.ui \
         ui/roadeditdialog.ui \
         ui/speeddialog.ui \
         ui/trafficlightdialog.ui \

+ 58 - 0
src/tool/map_lanetoxodr/ui/dialogturndirection.cpp

@@ -0,0 +1,58 @@
+#include "dialogturndirection.h"
+#include "ui_dialogturndirection.h"
+
+DialogTurnDirection::DialogTurnDirection(Road * pRoad,QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DialogTurnDirection)
+{
+    ui->setupUi(this);
+    mpRoad = pRoad;
+
+    ui->comboBox->addItem("NONE");
+    ui->comboBox->addItem("Left");
+    ui->comboBox->addItem("Right");
+    ui->comboBox->addItem("Straight");
+
+    RoadTurnDirection::TURNDIRECTION xturn;
+    int nrtn = pRoad->GetRoadTurnDirection(xturn);
+
+    ui->comboBox->setCurrentIndex(0);
+    if(nrtn == 0)
+    {
+        ui->comboBox->setCurrentIndex(0);
+    }
+    else
+    {
+        if(xturn == RoadTurnDirection::LEFT)ui->comboBox->setCurrentIndex(1);
+        if(xturn == RoadTurnDirection::RIGHT)ui->comboBox->setCurrentIndex(2);
+        if(xturn == RoadTurnDirection::STRAIGHT)ui->comboBox->setCurrentIndex(3);
+    }
+}
+
+DialogTurnDirection::~DialogTurnDirection()
+{
+    delete ui;
+}
+
+void DialogTurnDirection::on_pushButton_Set_clicked()
+{
+    switch (ui->comboBox->currentIndex()) {
+    case 0:
+        mpRoad->ResetRoadTurnDirection();
+        break;
+    case 1:
+        mpRoad->SetRoadTurnDirection(RoadTurnDirection::LEFT);
+        break;
+    case 2:
+        mpRoad->SetRoadTurnDirection(RoadTurnDirection::RIGHT);
+        break;
+    case 3:
+        mpRoad->SetRoadTurnDirection(RoadTurnDirection::STRAIGHT);
+        break;
+    default:
+        mpRoad->ResetRoadTurnDirection();
+        break;
+    }
+    this->accept();
+}
+

+ 29 - 0
src/tool/map_lanetoxodr/ui/dialogturndirection.h

@@ -0,0 +1,29 @@
+#ifndef DIALOGTURNDIRECTION_H
+#define DIALOGTURNDIRECTION_H
+
+#include <QDialog>
+
+#include <OpenDrive/OpenDrive.h>
+
+namespace Ui {
+class DialogTurnDirection;
+}
+
+class DialogTurnDirection : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit DialogTurnDirection(Road * pRoad,QWidget *parent = nullptr);
+    ~DialogTurnDirection();
+
+private slots:
+    void on_pushButton_Set_clicked();
+
+private:
+    Ui::DialogTurnDirection *ui;
+
+    Road * mpRoad;
+};
+
+#endif // DIALOGTURNDIRECTION_H

+ 55 - 0
src/tool/map_lanetoxodr/ui/dialogturndirection.ui

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogTurnDirection</class>
+ <widget class="QDialog" name="DialogTurnDirection">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>446</width>
+    <height>248</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QComboBox" name="comboBox">
+   <property name="geometry">
+    <rect>
+     <x>240</x>
+     <y>48</y>
+     <width>141</width>
+     <height>41</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>50</x>
+     <y>48</y>
+     <width>181</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Turn Direction</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_Set">
+   <property name="geometry">
+    <rect>
+     <x>150</x>
+     <y>128</y>
+     <width>141</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Set</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 12 - 0
src/tool/map_lanetoxodr/ui/roadeditdialog.cpp

@@ -694,3 +694,15 @@ void RoadEditDialog::on_pushButton_ParkingSpaceFromRTK_clicked()
     DialogParkingSpaceFromRTK dlgparkrtk(mpCurRoad,this);
     dlgparkrtk.exec();
 }
+
+void RoadEditDialog::on_pushButton_TurnDirection_clicked()
+{
+    if(mpCurRoad == 0)
+    {
+        QMessageBox::warning(this,"Warning","Not Select Road");
+        return;
+    }
+    DialogTurnDirection dlgtd(mpCurRoad,this);
+    dlgtd.exec();
+}
+

+ 3 - 0
src/tool/map_lanetoxodr/ui/roadeditdialog.h

@@ -24,6 +24,7 @@
 #include "dialogroadoptimize.h"
 #include "dialogroadtype.h"
 #include "dialogparkingspacefromrtk.h"
+#include "dialogturndirection.h"
 
 #include "roaddigit.h"
 #include "xodrscenfunc.h"
@@ -78,6 +79,8 @@ private slots:
 
     void on_pushButton_ParkingSpaceFromRTK_clicked();
 
+    void on_pushButton_TurnDirection_clicked();
+
 private:
     bool IsDrawMark(double s);
 

+ 14 - 1
src/tool/map_lanetoxodr/ui/roadeditdialog.ui

@@ -223,7 +223,7 @@
   <widget class="QPushButton" name="pushButton_EditLane">
    <property name="geometry">
     <rect>
-     <x>54</x>
+     <x>55</x>
      <y>195</y>
      <width>181</width>
      <height>41</height>
@@ -389,6 +389,19 @@
     <string>ParkingSpace From RTK</string>
    </property>
   </widget>
+  <widget class="QPushButton" name="pushButton_TurnDirection">
+   <property name="geometry">
+    <rect>
+     <x>55</x>
+     <y>260</y>
+     <width>181</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Edit Turn Direction</string>
+   </property>
+  </widget>
  </widget>
  <resources/>
  <connections/>