ソースを参照

change map_lanetoxodr. fix a bug in limit speed.

yuchuli 3 年 前
コミット
02e6bebb32

+ 2 - 1
src/driver/driver_map_xodrload/globalplan.cpp

@@ -1442,7 +1442,8 @@ int GetLaneOriTotal(Road * pRoad, int nlane,double s,int & nori, int & ntotal,do
                         break;
                         break;
                     }
                     }
                 }
                 }
-                fSpeed = pLSpeed->GetMax();
+                if(pLSpeed->GetS()<=(s-pLS->GetS()))fSpeed = pLSpeed->GetMax();
+
             }
             }
         }
         }
         if(nlane<0)
         if(nlane<0)

+ 223 - 9
src/tool/map_lanetoxodr/dialogroadsplit.cpp

@@ -39,7 +39,20 @@ void DialogRoadSplit::on_pushButton_spalitats_clicked()
     }
     }
 
 
 
 
-    SplitRoad(mpxodr,mpRoad,s);
+    int nrtn = SplitRoad(mpxodr,mpRoad,s);
+
+    if(nrtn == 0)
+    {
+        QMessageBox::information(this,"Split","split road successfully.",QMessageBox::YesAll);
+        this->accept();
+    }
+    else
+    {
+        char strout[256];
+        snprintf(strout,256,"split error code is %d",nrtn);
+        QMessageBox::warning(this,"Split Road Fail",QString(strout),QMessageBox::YesAll);
+
+    }
 
 
 
 
 
 
@@ -164,14 +177,21 @@ int DialogRoadSplit::SplitRoad(OpenDrive *pxodr, Road *pRoad,const double s)
     if(pxodr == 0)return -3;
     if(pxodr == 0)return -3;
     if(s>=pRoad->GetRoadLength())return -4;
     if(s>=pRoad->GetRoadLength())return -4;
 
 
+
+    vector<Elevation> xvectorelevation = *(pRoad->GetElevationVector());
+    vector<LaneSection> xvectorlanesection = *(pRoad->GetLaneSectionVector());
+    vector<Signal> xvectorsignal = *(pRoad->GetSignalVector());
+
+//    double fRoadLen = pRoad->GetRoadLength();
+
     std::string strroadid = pRoad->GetRoadId();
     std::string strroadid = pRoad->GetRoadId();
-    int ngeocount = pRoad->GetGeometryBlockCount();
+    unsigned int ngeocount = pRoad->GetGeometryBlockCount();
 
 
     if(ngeocount < 1)return -5;
     if(ngeocount < 1)return -5;
 
 
-    int i;
+    unsigned int i;
     GeometryBlock * pgeobsel = 0;
     GeometryBlock * pgeobsel = 0;
-    int indexsplit = 0;
+    unsigned int indexsplit = 0;
     for(i=0;i<(ngeocount-1);i++)
     for(i=0;i<(ngeocount-1);i++)
     {
     {
         GeometryBlock * pgeob = pRoad->GetGeometryBlock(i+1);
         GeometryBlock * pgeob = pRoad->GetGeometryBlock(i+1);
@@ -182,11 +202,15 @@ int DialogRoadSplit::SplitRoad(OpenDrive *pxodr, Road *pRoad,const double s)
             break;
             break;
         }
         }
     }
     }
-    if(pgeobsel == 0)pgeobsel = pRoad->GetGeometryBlock(0);
+    if(pgeobsel == 0)
+    {
+        pgeobsel = pRoad->GetGeometryBlock(pRoad->GetGeometryBlockCount()-1);
+        indexsplit = pRoad->GetGeometryBlockCount()-1;
+    }
 
 
     short ngeotype = pgeobsel->GetGeometryAt(0)->GetGeomType();
     short ngeotype = pgeobsel->GetGeometryAt(0)->GetGeomType();
 
 
-    Road * pnewroad;
+//    Road * pnewroad;
      //not line or geo. split as this geo start.
      //not line or geo. split as this geo start.
     //or line arc. but s at geo start.
     //or line arc. but s at geo start.
     if(((ngeotype !=0)&&(ngeotype !=2))||((indexsplit != 0)&&(pgeobsel->GetGeometryAt(0)->GetS() == s)))
     if(((ngeotype !=0)&&(ngeotype !=2))||((indexsplit != 0)&&(pgeobsel->GetGeometryAt(0)->GetS() == s)))
@@ -195,7 +219,7 @@ int DialogRoadSplit::SplitRoad(OpenDrive *pxodr, Road *pRoad,const double s)
         else
         else
         {
         {
             double flength = 0;
             double flength = 0;
-            int j;
+            unsigned int j;
             for(j=indexsplit;j<ngeocount;j++)
             for(j=indexsplit;j<ngeocount;j++)
             {
             {
                 flength = flength + pRoad->GetGeometryBlock(j)->GetGeometryAt(0)->GetLength();
                 flength = flength + pRoad->GetGeometryBlock(j)->GetGeometryAt(0)->GetLength();
@@ -230,6 +254,9 @@ int DialogRoadSplit::SplitRoad(OpenDrive *pxodr, Road *pRoad,const double s)
             pRoad->SetRoadLength(flength1);
             pRoad->SetRoadLength(flength1);
             for(j=0;j<indexsplit;j++)pnewroad->DeleteGeometryBlock(0);
             for(j=0;j<indexsplit;j++)pnewroad->DeleteGeometryBlock(0);
 
 
+            proad1 = pRoad;
+            proad2 = pnewroad;
+
         }
         }
     }
     }
     else
     else
@@ -245,8 +272,8 @@ int DialogRoadSplit::SplitRoad(OpenDrive *pxodr, Road *pRoad,const double s)
 
 
             if(nrtn != 0)return -8;
             if(nrtn != 0)return -8;
 
 
-            int newroadid = gw->CreateRoadID();
-            int j;
+            unsigned int newroadid = gw->CreateRoadID();
+            unsigned int j;
             double flength,flength1;
             double flength,flength1;
 
 
             flength = c.GetGeometryAt(0)->GetLength();
             flength = c.GetGeometryAt(0)->GetLength();
@@ -300,9 +327,196 @@ int DialogRoadSplit::SplitRoad(OpenDrive *pxodr, Road *pRoad,const double s)
                 pnewroad->GetGeometryBlock(j)->GetGeometryAt(0)->SetS(pnewroad->GetGeometryBlock(j)->GetGeometryAt(0)->GetS() - s);
                 pnewroad->GetGeometryBlock(j)->GetGeometryAt(0)->SetS(pnewroad->GetGeometryBlock(j)->GetGeometryAt(0)->GetS() - s);
             }
             }
 
 
+            proad1 = pRoad;
+            proad2 = pnewroad;
+
         }
         }
     }
     }
 
 
+
+    SplitElevation(proad1,proad2,xvectorelevation);
+    SplitLaneSection(proad1,proad2,xvectorlanesection);
+    SplitSignal(proad1,proad2,xvectorsignal);
+
     return 0;
     return 0;
 
 
 }
 }
+
+int DialogRoadSplit::SplitElevation(Road *proad1, Road *proad2, vector<Elevation> xvectorele)
+{
+    double flen1 = proad1->GetRoadLength();
+ //   double flen2 = proad2->GetRoadLength();
+
+    bool bsplitele  = false;
+    unsigned int indexsplitele = 0;
+    if(xvectorele.size() > 0)
+    {
+        unsigned int i;
+        for(i=0;i<(xvectorele.size()-1);i++)
+        {
+            if(flen1 <= xvectorele[i+1].GetS())
+            {
+                indexsplitele = i;
+                bsplitele = true;
+                break;
+            }
+
+        }
+
+        if(bsplitele == false)
+        {
+            indexsplitele = xvectorele.size() -1;
+            bsplitele = true;
+        }
+
+        for(i=(indexsplitele+1);i<xvectorele.size();i++)
+        {
+            proad1->GetElevationVector()->erase(proad1->GetElevationVector()->begin()+indexsplitele+1);
+        }
+
+        for(i=0;i<(indexsplitele+1);i++)
+        {
+            proad2->GetElevationVector()->erase(proad2->GetElevationVector()->begin());
+        }
+
+        double a0,b0,c0,d0;
+        double a1,b1,c1,d1;
+        Elevation * pa = &(proad1->GetElevationVector()->at(indexsplitele));
+        a0 = pa->GetA();
+        b0 = pa->GetB();
+        c0 = pa->GetC();
+        d0 = pa->GetD();
+        double s0 = flen1 - 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;
+
+        if(s0 == 0)proad1->GetElevationVector()->erase(proad1->GetElevationVector()->begin()+indexsplitele);
+
+        Elevation newele(flen1,a1,b1,c1,d1);
+        proad2->GetElevationVector()->insert(proad2->GetElevationVector()->begin(),newele);
+
+        for(i=0;i<proad2->GetElevationCount();i++)
+        {
+            proad2->GetElevationVector()->at(i).SetS(proad2->GetElevationVector()->at(i).GetS() - flen1);
+        }
+
+
+    }
+
+    return 0;
+}
+
+
+int DialogRoadSplit::Splitabcd(double a0, double b0, double c0, double d0, double &a, double &b, double &c, double &d, double s_off)
+{
+    a = a0 + b0*s_off + c0* s_off*s_off + d0*s_off*s_off*s_off;
+    b = b0 + 2*c0*s_off + 3*d0*s_off*s_off;
+    c = c0 + 3*d0*s_off;
+    d = d0;
+    return 0;
+}
+
+int DialogRoadSplit::SplitLaneSection(Road *proad1, Road *proad2,  vector<LaneSection> xvectorls)
+{
+    double flen1 = proad1->GetRoadLength();
+ //   double flen2 = proad2->GetRoadLength();
+
+    bool bsplitls  = false;
+    int indexsplitls = 0;
+    if(xvectorls.size() > 0)
+    {
+        unsigned int i;
+        for(i=0;i<(xvectorls.size()-1);i++)
+        {
+            if(flen1 <= xvectorls[i+1].GetS())
+            {
+                indexsplitls = i;
+                bsplitls = true;
+                break;
+            }
+
+        }
+
+        if(bsplitls == false)
+        {
+            indexsplitls = xvectorls.size() -1;
+            bsplitls = true;
+        }
+
+        LaneSection * pLS = &(proad1->GetLaneSectionVector()->at(indexsplitls));
+         double s0 = flen1 - pLS->GetS();
+
+
+
+        for(i=(indexsplitls+1);i<xvectorls.size();i++)
+        {
+            proad1->GetLaneSectionVector()->erase(proad1->GetLaneSectionVector()->begin()+indexsplitls+1);
+        }
+
+        for(i=0;i<(indexsplitls+1);i++)
+        {
+            proad2->GetLaneSectionVector()->erase(proad2->GetLaneSectionVector()->begin());
+        }
+
+        if(s0 == 0)
+        {
+            proad1->GetLaneSectionVector()->erase(proad1->GetLaneSectionVector()->begin()+indexsplitls);
+            proad2->GetLaneSectionVector()->insert(proad2->GetLaneSectionVector()->begin(),xvectorls[indexsplitls]);
+        }
+        else
+        {
+            LaneSection LS = xvectorls[indexsplitls];
+            unsigned int j;
+            for(j=0;j<LS.GetLaneCount();j++)
+            {
+                Lane * pLane =  LS.GetLane(j);
+                if(pLane->GetLaneWidthCount()>0)
+                {
+                    double a,b,c,d;
+                    Splitabcd(pLane->GetLaneWidth(0)->GetA(),pLane->GetLaneWidth(0)->GetB(),
+                              pLane->GetLaneWidth(0)->GetC(),pLane->GetLaneWidth(0)->GetD(),
+                              a,b,c,d,s0);
+                    pLane->GetLaneWidth(0)->SetA(a);
+                    pLane->GetLaneWidth(0)->SetB(b);
+                    pLane->GetLaneWidth(0)->SetC(c);
+                    pLane->GetLaneWidth(0)->SetD(d);
+                }
+            }
+            proad2->GetLaneSectionVector()->insert(proad2->GetLaneSectionVector()->begin(),LS);
+        }
+
+        for(i=0;i<proad2->GetLaneSectionCount();i++)
+        {
+            proad2->GetLaneSectionVector()->at(i).SetS(proad2->GetLaneSectionVector()->at(i).GetS() - flen1);
+        }
+    }
+    return 0;
+}
+
+int DialogRoadSplit::SplitSignal(Road *proad1, Road *proad2, vector<Signal> xvectorsignal)
+{
+    double flen1 = proad1->GetRoadLength();
+    unsigned int i;
+    for(i=0;i<xvectorsignal.size();i++)
+    {
+        proad1->GetSignalVector()->erase(proad1->GetSignalVector()->begin());
+        proad2->GetSignalVector()->erase(proad2->GetSignalVector()->begin());
+    }
+
+    for(i=0;i<xvectorsignal.size();i++)
+    {
+
+        if(xvectorsignal.at(i).Gets()<flen1)
+        {
+            proad1->GetSignalVector()->push_back(xvectorsignal.at(i));
+        }
+        else
+        {
+            xvectorsignal.at(i).Sets(xvectorsignal.at(i).Gets() - flen1);
+            proad2->GetSignalVector()->push_back(xvectorsignal.at(i));
+        }
+    }
+    return 0;
+}

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

@@ -26,6 +26,12 @@ public:
     static int SplitGeometryBlock(GeometryBlock * pa,GeometryBlock * pb, GeometryBlock * pc,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);
     static int SplitElevation(Elevation * pa,Elevation ** pb,Elevation ** pc,const double s);
 
 
+    static int SplitElevation(Road * proad1,Road * proad2,vector<Elevation> xvectorele);
+    static int SplitLaneSection(Road * proad1,Road * proad2,vector<LaneSection> xvectorls);
+    static int SplitSignal(Road * proad1,Road * proad2,vector<Signal> xvectorsignal);
+
+    static int Splitabcd(double a0,double b0,double c0,double d0,double & a,double & b,double & c ,double & d,double s_off);
+
 private:
 private:
     Ui::DialogRoadSplit *ui;
     Ui::DialogRoadSplit *ui;
     Road * mpRoad;
     Road * mpRoad;

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

@@ -4965,6 +4965,10 @@ void MainWindow::on_actionEdit_Road_triggered()
     std::string strroadid = mpCBRoad->currentText().toStdString();
     std::string strroadid = mpCBRoad->currentText().toStdString();
     RoadEditDialog rd(&mxodr,strroadid,this);
     RoadEditDialog rd(&mxodr,strroadid,this);
     int res = rd.exec();
     int res = rd.exec();
+
+    updateCBRoad();
+    mbRefresh = true;
+    update();
 }
 }
 
 
 void MainWindow::on_actionAdd_Road_From_RTK_triggered()
 void MainWindow::on_actionAdd_Road_From_RTK_triggered()

+ 12 - 1
src/tool/map_lanetoxodr/roadeditdialog.cpp

@@ -449,5 +449,16 @@ void RoadEditDialog::on_pushButton_RoadSplit_clicked()
 
 
     DialogRoadSplit roadsplit(mpCurRoad,mpxodr,this);
     DialogRoadSplit roadsplit(mpCurRoad,mpxodr,this);
     roadsplit.exec();
     roadsplit.exec();
-    on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex());
+
+    unsigned int ncurindex = ui->comboBox_Road->currentIndex();
+    ui->comboBox_Road->clear();
+    int i;
+    int nroadcount = mpxodr->GetRoadCount();
+    for(i=0;i<nroadcount;i++)
+    {
+        const char * strname = mpxodr->GetRoad(i)->GetRoadId().data();
+        ui->comboBox_Road->addItem(strname);
+
+    }
+    on_comboBox_Road_currentIndexChanged(ncurindex);
 }
 }