Browse Source

change tool/map_lanetoxodr. onLoad fix Opendrive s or roadlen error.

yuchuli 3 years ago
parent
commit
67279b58ba

+ 9 - 5
src/tool/map_lanetoxodr/autoroadcontact.cpp

@@ -14,10 +14,14 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
 
     double road1_start_x,road1_start_y,road1_end_x,road1_end_y,road1_start_hdg,road1_end_hdg;
     double road2_start_x,road2_start_y,road2_end_x,road2_end_y,road2_start_hdg,road2_end_hdg;
-    pRoad1->GetGeometryCoords(0,road1_start_x,road1_start_y,road1_start_hdg);
-    pRoad1->GetGeometryCoords(pRoad1->GetRoadLength(),road1_end_x,road1_end_y,road1_end_hdg);
-    pRoad2->GetGeometryCoords(0,road2_start_x,road2_start_y,road2_start_hdg);
-    pRoad2->GetGeometryCoords(pRoad2->GetRoadLength(),road2_end_x,road2_end_y,road2_end_hdg);
+    int ngeo = pRoad1->GetGeometryCoords(0,road1_start_x,road1_start_y,road1_start_hdg);
+    ngeo+=pRoad1->GetGeometryCoords(pRoad1->GetRoadLength(),road1_end_x,road1_end_y,road1_end_hdg);
+    ngeo+=pRoad2->GetGeometryCoords(0,road2_start_x,road2_start_y,road2_start_hdg);
+    ngeo+=pRoad2->GetGeometryCoords(pRoad2->GetRoadLength(),road2_end_x,road2_end_y,road2_end_hdg);
+    if(ngeo<0)
+    {
+        return -1;
+    }
 
     double dis_1s_2s = sqrt(pow(road1_start_x-road2_start_x,2)
                             +pow(road1_start_y-road2_start_y,2));
@@ -49,7 +53,7 @@ int AutoRoadContact::CalcContact(Road *pRoad1, Road *pRoad2,int & contacttype,in
 
     if(contacttype == -1)
     {
-        return -1;
+        return -2;
     }
 
     LaneSection * pLS1 = 0;

+ 25 - 1
src/tool/map_lanetoxodr/mainwindow.cpp

@@ -2801,6 +2801,25 @@ void MainWindow::onClickLoad()
             i--;
             nroadnum--;
             qDebug("delete road %s because length is NaN",pRoad->GetRoadId().data());
+            continue;
+        }
+        unsigned int j;
+        double snow = 0;
+        double roadcalclen = 0;
+        for(j=0;j<pRoad->GetGeometryBlockCount();j++)
+        {
+            if(fabs(pRoad->GetGeometryBlock(j)->GetGeometryAt(0)->GetS() - snow)>0.1)
+            {
+                std::cout<<"change road "<<pRoad->GetRoadId().data()<<" S"<<std::endl;
+                pRoad->GetGeometryBlock(j)->GetGeometryAt(0)->SetS(snow);
+            }
+            snow = snow + pRoad->GetGeometryBlock(j)->GetBlockLength();
+            roadcalclen = snow;
+        }
+        if(fabs(roadcalclen - pRoad->GetRoadLength())>0.1)
+        {
+            std::cout<<"change road "<<pRoad->GetRoadId().data()<<" Length"<<std::endl;
+            pRoad->SetRoadLength(roadcalclen);
         }
     }
 
@@ -3029,7 +3048,12 @@ void MainWindow::onClickAutoRoadContact()
     int contactype;
     int turnstraight;
     std::vector<iv::ARC> xARCLane,xARCOpLane;
-    AutoRoadContact::CalcContact(p1,p2,contactype,turnstraight,xARCLane,xARCOpLane);
+    int nARCRtn = AutoRoadContact::CalcContact(p1,p2,contactype,turnstraight,xARCLane,xARCOpLane);
+    if(nARCRtn < 0)
+    {
+        QMessageBox::warning(this,"Warning","Auto Road Contact fail",QMessageBox::YesAll);
+        return;
+    }
 
     switch (contactype) {
     case 0: