Bläddra i källkod

change tool/map_lanetoxodr. change split road code.

yuchuli 3 år sedan
förälder
incheckning
ded14db038

+ 4 - 0
src/tool/map_lanetoxodr/OpenDrive/RoadGeometry.cpp

@@ -613,6 +613,10 @@ const GeometryBlock& GeometryBlock::operator=(const GeometryBlock& otherGeomBloc
 			{
 				delete poly;
 			}
+            else if(GeometryParamPoly3 * parampoly = dynamic_cast<GeometryParamPoly3 *>(*member) )
+            {
+                delete parampoly;
+            }
 		}
 		mGeometryBlockElement.clear();
 

+ 1 - 1
src/tool/map_lanetoxodr/OpenDrive/RoadGeometry.h

@@ -30,7 +30,7 @@ protected:
 	double mHdg;
 	double mLength;
 	double mS2;
-    short int mGeomType;	//0-line, 1-arc, 2-spiral 3-poly3 4-parampoly3
+    short int mGeomType;	//0-line, 2-arc, 1-spiral 3-poly3 4-parampoly3
 public:
 	/**
 	 * Constructor that initializes the base properties of teh record

+ 308 - 0
src/tool/map_lanetoxodr/dialogroadsplit.cpp

@@ -0,0 +1,308 @@
+#include "dialogroadsplit.h"
+#include "ui_dialogroadsplit.h"
+
+
+#include "mainwindow.h"
+extern MainWindow * gw;
+
+DialogRoadSplit::DialogRoadSplit(Road * pRoad,OpenDrive * pxodr,QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DialogRoadSplit)
+{
+    ui->setupUi(this);
+    mpRoad = pRoad;
+    mpxodr = pxodr;
+}
+
+DialogRoadSplit::~DialogRoadSplit()
+{
+    delete ui;
+}
+
+void DialogRoadSplit::on_pushButton_spalitats_clicked()
+{
+    if(mpRoad == 0)
+    {
+        QMessageBox::warning(this,"warning","no road");
+        return;
+    }
+    double s = ui->lineEdit_s->text().toDouble();
+    if(s<=0)
+    {
+        QMessageBox::warning(this,"warning","s is small",QMessageBox::YesAll);
+        return;
+    }
+    if(s>=mpRoad->GetRoadLength())
+    {
+        QMessageBox::warning(this,"warning","s is exceed road length.",QMessageBox::YesAll);
+        return;
+    }
+
+
+    SplitRoad(mpxodr,mpRoad,s);
+
+
+
+}
+
+
+int DialogRoadSplit::SplitGeometryBlock(GeometryBlock *pa, GeometryBlock *pb, GeometryBlock *pc, const double s)
+{
+    //Only Split line or arc
+    if((pa->GetGeometryAt(0)->GetGeomType() !=0)&&(pa->GetGeometryAt(0)->GetGeomType() !=2))
+    {
+        return -1;
+    }
+    if(pa->GetGeometryAt(0)->GetS()>=s)
+    {
+        return -2;
+    }
+    if((pa->GetGeometryAt(0)->GetS() + pa->GetGeometryAt(0)->GetLength())<=s)
+    {
+        return -3;
+    }
+    //If Line
+    if(pa->GetGeometryAt(0)->GetGeomType() == 0)
+    {
+        double fsplits = s - pa->GetGeometryAt(0)->GetS();
+        double fsplitx,fsplity;
+        fsplitx = pa->GetGeometryAt(0)->GetX() + fsplits * cos(pa->GetGeometryAt(0)->GetHdg());
+        fsplity = pa->GetGeometryAt(0)->GetY() + fsplits * sin(pa->GetGeometryAt(0)->GetHdg());
+        pb->AddGeometryLine(pa->GetGeometryAt(0)->GetS(),pa->GetGeometryAt(0)->GetX(),
+                            pa->GetGeometryAt(0)->GetY(),pa->GetGeometryAt(0)->GetHdg(),
+                            fsplits);
+        pc->AddGeometryLine(pa->GetGeometryAt(0)->GetS()+fsplits,fsplitx,fsplity,
+                            pa->GetGeometryAt(0)->GetHdg(),pa->GetGeometryAt(0)->GetLength() - fsplits);
+    }
+    else
+    {
+        double fsplits = s - pa->GetGeometryAt(0)->GetS();
+        double fsplitx,fsplity;
+        double fhdg2;
+
+        GeometryArc * parc = (GeometryArc *)pa->GetGeometryAt(0);
+        if(parc->GetCurvature() == 0)
+        {
+            return -4;
+        }
+
+        double R = fabs(1.0/parc->GetCurvature());
+
+
+        //calculate arc center
+        double x_center,y_center;
+        if(parc->GetCurvature() > 0)
+        {
+            x_center = parc->GetX() + R * cos(parc->GetHdg() + M_PI/2.0);
+            y_center = parc->GetY() + R * sin(parc->GetHdg()+ M_PI/2.0);
+        }
+        else
+        {
+            x_center = parc->GetX() + R * cos(parc->GetHdg() - M_PI/2.0);
+            y_center = parc->GetY() + R * sin(parc->GetHdg() - M_PI/2.0);
+        }
+
+        double hdgdiff = fsplits/R;
+        if(parc->GetCurvature() >0)
+        {
+            fhdg2 = parc->GetHdg() + hdgdiff;
+            while(fhdg2>(2.0*M_PI))fhdg2 = fhdg2 - 2.0*M_PI;
+            fsplitx = x_center + R * cos(fhdg2 - M_PI/2.0);
+            fsplity = y_center + R * sin(fhdg2 - M_PI/2.0);
+        }
+        else
+        {
+            fhdg2 = parc->GetHdg() - hdgdiff;
+            while(fhdg2<0)fhdg2 = fhdg2 + 2.0*M_PI;
+            fsplitx = x_center + R * cos(fhdg2 + M_PI/2.0);
+            fsplity = y_center + R * sin(fhdg2 + M_PI/2.0);
+        }
+
+        pb->AddGeometryArc(pa->GetGeometryAt(0)->GetS(),pa->GetGeometryAt(0)->GetX(),
+                           pa->GetGeometryAt(0)->GetY(),pa->GetGeometryAt(0)->GetHdg(),
+                           fsplits,parc->GetCurvature());
+        pc->AddGeometryArc(parc->GetS()+fsplits,fsplitx,fsplity,
+                           fhdg2,parc->GetLength() - fsplits,parc->GetCurvature());
+    }
+    return 0;
+}
+
+int DialogRoadSplit::SplitElevation(Elevation *pa, Elevation **pb, Elevation **pc, const double s)
+{
+    if(pa == 0)
+    {
+        pb = 0;
+        pc = 0;
+        return -1;
+    }
+    if(pa->GetS()<s)return -2;
+    *pb = new Elevation(pa->GetS(),pa->GetA(),pa->GetB(),pa->GetC(),pa->GetD());
+    double a0,b0,c0,d0;
+    double a1,b1,c1,d1;
+    a0 = pa->GetA();
+    b0 = pa->GetB();
+    c0 = pa->GetC();
+    d0 = pa->GetD();
+    double s0 = s - pa->GetS();
+    a1 = a0 + b0*s0 + c0* s0*s0 + d0*s0*s0*s0;
+    b1 = b0 + 2*c0*s0 + 3*d0*s0*s0;
+    c1 = c0 + 3*d0*s0;
+    d1 = d0;
+    *pc = new Elevation(s,a1,b1,c1,d1);
+    return 0;
+}
+
+// Split Road
+//If line or arc split geometry
+//If not line or arc, geometry not split
+int DialogRoadSplit::SplitRoad(OpenDrive *pxodr, Road *pRoad,const double s)
+{
+    Road * proad1,*proad2;
+
+    if(s<=0)return -1;
+    if(pRoad == 0)return -2;
+    if(pxodr == 0)return -3;
+    if(s>=pRoad->GetRoadLength())return -4;
+
+    std::string strroadid = pRoad->GetRoadId();
+    int ngeocount = pRoad->GetGeometryBlockCount();
+
+    if(ngeocount < 1)return -5;
+
+    int i;
+    GeometryBlock * pgeobsel = 0;
+    int indexsplit = 0;
+    for(i=0;i<(ngeocount-1);i++)
+    {
+        GeometryBlock * pgeob = pRoad->GetGeometryBlock(i+1);
+        if(pgeob->GetGeometryAt(0)->GetS()>=s)
+        {
+            indexsplit = i;
+            pgeobsel = pRoad->GetGeometryBlock(i);
+            break;
+        }
+    }
+    if(pgeobsel == 0)pgeobsel = pRoad->GetGeometryBlock(0);
+
+    short ngeotype = pgeobsel->GetGeometryAt(0)->GetGeomType();
+
+    Road * pnewroad;
+     //not line or geo. split as this geo start.
+    //or line arc. but s at geo start.
+    if(((ngeotype !=0)&&(ngeotype !=2))||((indexsplit != 0)&&(pgeobsel->GetGeometryAt(0)->GetS() == s)))
+    {
+        if(indexsplit == 0)return -6;  //not split
+        else
+        {
+            double flength = 0;
+            int j;
+            for(j=indexsplit;j<ngeocount;j++)
+            {
+                flength = flength + pRoad->GetGeometryBlock(j)->GetGeometryAt(0)->GetLength();
+
+            }
+
+            double flength1 = pRoad->GetRoadLength() - flength;
+
+
+            int newroadid = gw->CreateRoadID();
+
+            unsigned int naddroadindex = pxodr->AddRoad("",flength,QString::number(newroadid).toStdString(),"-1");
+
+            unsigned int k;
+            for(k=0;k<pxodr->GetRoadCount();k++)
+            {
+                if(pxodr->GetRoad(k)->GetRoadId() == strroadid)
+                {
+                    pRoad = pxodr->GetRoad(k);
+                    break;
+                }
+            }
+            Road * pnewroad = pxodr->GetRoad(naddroadindex);
+
+            *pnewroad = *pRoad;
+            pnewroad->SetRoadLength(flength);
+            pnewroad->SetRoadId(QString::number(newroadid).toStdString());
+            while(pRoad->GetGeometryBlockCount()>indexsplit)
+            {
+                pRoad->DeleteGeometryBlock(indexsplit);
+            }
+            pRoad->SetRoadLength(flength1);
+            for(j=0;j<indexsplit;j++)pnewroad->DeleteGeometryBlock(0);
+
+        }
+    }
+    else
+    {
+        if((indexsplit == 0)&&(pgeobsel->GetGeometryAt(0)->GetS() == s))
+        {
+            return -7;  //At Start. so not split
+        }
+        else
+        {
+            GeometryBlock b,c;
+            int nrtn = SplitGeometryBlock(pgeobsel,&b,&c,s);
+
+            if(nrtn != 0)return -8;
+
+            int newroadid = gw->CreateRoadID();
+            int j;
+            double flength,flength1;
+
+            flength = c.GetGeometryAt(0)->GetLength();
+
+            for(j=(indexsplit+1);j<ngeocount;j++)
+            {
+                flength = flength + pRoad->GetGeometryBlock(j)->GetGeometryAt(0)->GetLength();
+
+            }
+
+
+            flength1 = pRoad->GetRoadLength() - flength;
+
+
+            unsigned int naddroadindex = pxodr->AddRoad("",flength,QString::number(newroadid).toStdString(),"-1");
+
+            unsigned int k;
+            for(k=0;k<pxodr->GetRoadCount();k++)
+            {
+                if(pxodr->GetRoad(k)->GetRoadId() == strroadid)
+                {
+                    pRoad = pxodr->GetRoad(k);
+                    break;
+                }
+            }
+
+            Road * pnewroad = pxodr->GetRoad(naddroadindex);
+            *pnewroad = *pRoad;
+            pnewroad->SetRoadId(QString::number(newroadid).toStdString());
+            while(pRoad->GetGeometryBlockCount()>indexsplit)
+            {
+                pRoad->DeleteGeometryBlock(indexsplit);
+            }
+            pRoad->SetRoadLength(flength1);
+            pnewroad->SetRoadLength(flength);
+
+
+
+            for(j=0;j<(indexsplit+1);j++)pnewroad->DeleteGeometryBlock(0);
+
+            vector<GeometryBlock> * pvectorele = pnewroad->GetGeometryBlockVector();
+            pvectorele->insert(pvectorele->begin(),c);
+
+
+
+            pvectorele = pRoad->GetGeometryBlockVector();
+            pvectorele->push_back(b);
+
+            for(j=0;j<pnewroad->GetGeometryBlockCount();j++)
+            {
+                pnewroad->GetGeometryBlock(j)->GetGeometryAt(0)->SetS(pnewroad->GetGeometryBlock(j)->GetGeometryAt(0)->GetS() - s);
+            }
+
+        }
+    }
+
+    return 0;
+
+}

+ 35 - 0
src/tool/map_lanetoxodr/dialogroadsplit.h

@@ -0,0 +1,35 @@
+#ifndef DIALOGROADSPLIT_H
+#define DIALOGROADSPLIT_H
+
+#include <QDialog>
+
+#include "OpenDrive/OpenDrive.h"
+#include <QMessageBox>
+
+namespace Ui {
+class DialogRoadSplit;
+}
+
+class DialogRoadSplit : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit DialogRoadSplit(Road * pRoad,OpenDrive * pxodr,QWidget *parent = nullptr);
+    ~DialogRoadSplit();
+
+private slots:
+    void on_pushButton_spalitats_clicked();
+
+public:
+    static int SplitRoad(OpenDrive * pxodr,Road * pRoad,const double s);
+    static int SplitGeometryBlock(GeometryBlock * pa,GeometryBlock * pb, GeometryBlock * pc,const double s);
+    static int SplitElevation(Elevation * pa,Elevation ** pb,Elevation ** pc,const double s);
+
+private:
+    Ui::DialogRoadSplit *ui;
+    Road * mpRoad;
+    OpenDrive * mpxodr;
+};
+
+#endif // DIALOGROADSPLIT_H

+ 114 - 0
src/tool/map_lanetoxodr/dialogroadsplit.ui

@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogRoadSplit</class>
+ <widget class="QDialog" name="DialogRoadSplit">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>632</width>
+    <height>350</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Split Road</string>
+  </property>
+  <widget class="QPushButton" name="pushButton_spalitats">
+   <property name="geometry">
+    <rect>
+     <x>410</x>
+     <y>60</y>
+     <width>171</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Split At S</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_spliatatpos">
+   <property name="geometry">
+    <rect>
+     <x>411</x>
+     <y>250</y>
+     <width>161</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Split At Pos</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_s">
+   <property name="geometry">
+    <rect>
+     <x>138</x>
+     <y>68</y>
+     <width>141</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>55</x>
+     <y>70</y>
+     <width>71</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>S:</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_lon">
+   <property name="geometry">
+    <rect>
+     <x>140</x>
+     <y>190</y>
+     <width>141</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_lat">
+   <property name="geometry">
+    <rect>
+     <x>410</x>
+     <y>190</y>
+     <width>151</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>49</x>
+     <y>195</y>
+     <width>41</width>
+     <height>21</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Lon</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>320</x>
+     <y>190</y>
+     <width>67</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Lat</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 5 - 5
src/tool/map_lanetoxodr/mainwindow.cpp

@@ -5015,14 +5015,14 @@ void MainWindow::on_actionSummary_Road_triggered()
     double flen = 0;
     for(i=0;i<nroadnum;i++)
     {
-        if(fabs(mxodr.GetRoad(i)->GetRoadLength())>10000)
-        {
-            Road * pRoad = mxodr.GetRoad(i);
-            int a = 1;
-        }
         flen = flen + mxodr.GetRoad(i)->GetRoadLength();
     }
     char strout[256];
     snprintf(strout,256,"Road Count:%d Length Total:%f",nroadnum,flen);
     QMessageBox::information(this,"Summary",QString(strout),QMessageBox::YesAll);
 }
+
+void MainWindow::on_actionSplit_Road_triggered()
+{
+
+}

+ 2 - 0
src/tool/map_lanetoxodr/mainwindow.h

@@ -183,6 +183,8 @@ private slots:
 
     void on_actionSummary_Road_triggered();
 
+    void on_actionSplit_Road_triggered();
+
 private:
 
 

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

@@ -33,6 +33,7 @@ SOURCES += \
     dialogeditlane.cpp \
     dialogeditroadmark.cpp \
     dialoglanefromrtk.cpp \
+    dialogroadsplit.cpp \
     ivxodrtool.cpp \
         main.cpp \
         mainwindow.cpp \
@@ -76,6 +77,7 @@ HEADERS += \
     dialogeditlane.h \
     dialogeditroadmark.h \
     dialoglanefromrtk.h \
+    dialogroadsplit.h \
     ivxodrtool.h \
         mainwindow.h \
     rawtype.h \
@@ -115,6 +117,7 @@ FORMS += \
         dialogeditlane.ui \
         dialogeditroadmark.ui \
         dialoglanefromrtk.ui \
+        dialogroadsplit.ui \
         mainwindow.ui \
         roadeditdialog.ui \
         speeddialog.ui \

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

@@ -438,3 +438,16 @@ void RoadEditDialog::on_pushButton_LaneFromRTK_clicked()
     lanertk.exec();
     on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex());
 }
+
+void RoadEditDialog::on_pushButton_RoadSplit_clicked()
+{
+    if(mpCurRoad == 0)
+    {
+        QMessageBox::warning(this,"Warning","Not Select Road");
+        return;
+    }
+
+    DialogRoadSplit roadsplit(mpCurRoad,mpxodr,this);
+    roadsplit.exec();
+    on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex());
+}

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

@@ -14,6 +14,7 @@
 #include "dialogeditlane.h"
 #include "dialogeditroadmark.h"
 #include "dialoglanefromrtk.h"
+#include "dialogroadsplit.h"
 
 namespace Ui {
 class RoadEditDialog;
@@ -45,6 +46,8 @@ private slots:
 
     void on_pushButton_LaneFromRTK_clicked();
 
+    void on_pushButton_RoadSplit_clicked();
+
 private:
     Ui::RoadEditDialog *ui;
     OpenDrive * mpxodr;

+ 13 - 0
src/tool/map_lanetoxodr/roadeditdialog.ui

@@ -259,6 +259,19 @@
     <string>Lane From RTK</string>
    </property>
   </widget>
+  <widget class="QPushButton" name="pushButton_RoadSplit">
+   <property name="geometry">
+    <rect>
+     <x>878</x>
+     <y>210</y>
+     <width>181</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Road Split</string>
+   </property>
+  </widget>
  </widget>
  <resources/>
  <connections/>