Browse Source

change tool/map_lanetoxodr. complete road hide function.

yuchuli 3 years ago
parent
commit
65607d50bd

+ 36 - 3
src/common/common/xodr/xodrfunc/xodrfunc.cpp

@@ -654,9 +654,12 @@ int xodrfunc::GetNearPointAtRoad(const double x, const double y, Road *pRoad, Ge
 
 }
 
-int xodrfunc::GetNearPoint(const double x, const double y, OpenDrive *pxodr, Road **pObjRoad, GeometryBlock **pgeo,
-                           double &fdis, double &nearx, double &neary, double &nearhead,
-                           const double nearthresh,double * pfs,int * pnlane,bool bnotuselane)
+
+int xodrfunc::GetNearPointWithHide(const double x, const double y, OpenDrive *pxodr, Road **pObjRoad,
+                                   GeometryBlock **pgeo, double &fdis, double &nearx, double &neary,
+                                   double &nearhead, const double nearthresh,
+                                   std::vector<int> &xvectorhideroad, double *pfs,
+                                   int *pnlane, bool bnotuselane)
 {
     double dismin = std::numeric_limits<double>::infinity();
     fdis = dismin;
@@ -669,6 +672,22 @@ int xodrfunc::GetNearPoint(const double x, const double y, OpenDrive *pxodr, Roa
         Road * proad = pxodr->GetRoad(i);
         double nx,ny,nh,frels;
 
+        if(xvectorhideroad.size() > 0)
+        {
+            int nroadid = atoi(proad->GetRoadId().data());
+            unsigned int k;
+            bool bIsHiden = false;
+            for(k = 0;k<xvectorhideroad.size();k++)
+            {
+                if(xvectorhideroad[k] == nroadid)
+                {
+                    bIsHiden = true;
+                    break;
+                }
+            }
+            if(bIsHiden)continue;
+        }
+
         for(j=0;j<proad->GetGeometryBlockCount();j++)
         {
             GeometryBlock * pgb = proad->GetGeometryBlock(j);
@@ -775,6 +794,20 @@ int xodrfunc::GetNearPoint(const double x, const double y, OpenDrive *pxodr, Roa
 }
 
 
+
+int xodrfunc::GetNearPoint(const double x, const double y, OpenDrive *pxodr, Road **pObjRoad, GeometryBlock **pgeo,
+                           double &fdis, double &nearx, double &neary, double &nearhead,
+                           const double nearthresh,double * pfs,int * pnlane,bool bnotuselane)
+{
+
+    std::vector<int> xvectorroadhide;
+    xvectorroadhide.clear();
+    return GetNearPointWithHide(x,y,pxodr,pObjRoad,pgeo,fdis,nearx,neary,nearhead,
+                                nearthresh,xvectorroadhide,pfs,pnlane,bnotuselane);
+
+}
+
+
 std::vector<iv::LanePoint> xodrfunc::GetAllLanePoint(Road *pRoad,  const double s,const double x, const double y,const double fhdg)
 {
     int i;

+ 4 - 0
src/common/common/xodr/xodrfunc/xodrfunc.h

@@ -49,6 +49,10 @@ public:
     static int GetNearPoint(const double x,const double y,OpenDrive * pxodr,Road ** pObjRoad,GeometryBlock ** pgeo, double & fdis,double & nearx,
                      double & neary,double & nearhead,const double nearthresh,double * pfs=0,int * pnlane= 0,bool bnotuselane = false);
 
+    static int GetNearPointWithHide(const double x,const double y,OpenDrive * pxodr,Road ** pObjRoad,GeometryBlock ** pgeo, double & fdis,double & nearx,
+                     double & neary,double & nearhead,const double nearthresh,std::vector<int> & xvectorhideroad,
+                                    double * pfs=0,int * pnlane= 0,bool bnotuselane = false);
+
     static int GetNearPointAtRoad(const double x,const double y,Road *pRoad,GeometryBlock ** pgeo, double & fdis,double & nearx,
                      double & neary,double & nearhead,const double nearthresh,double * pfs=0,int * pnlane= 0,bool bnotuselane = false);
 

+ 210 - 1
src/tool/map_lanetoxodr/dialoghideroad.cpp

@@ -1,12 +1,55 @@
 #include "dialoghideroad.h"
 #include "ui_dialoghideroad.h"
 
-DialogHideRoad::DialogHideRoad(OpenDrive * pxodr,std::string strdefroad,QWidget *parent) :
+#include <QMessageBox>
+#include "mainwindow.h"
+
+#include "math.h"
+
+#define VIEW_WIDTH 900
+#define VIEW_HEIGHT 450
+
+DialogHideRoad::DialogHideRoad(OpenDrive * pxodr,std::string strdefroad,std::vector<int> * pvectorhideroadid,QWidget *parent) :
     QDialog(parent),
     ui(new Ui::DialogHideRoad)
 {
+    mpxodr = pxodr;
+    mpvectorhideroadid = pvectorhideroadid;
     ui->setupUi(this);
 
+
+    myview = new MyView(this);
+    myview->setObjectName(QStringLiteral("graphicsView2"));
+    myview->setGeometry(QRect(30, 150, 960, 500));
+
+ //   connect(myview,SIGNAL(dbclickxy(double,double)),this,SLOT(onClickXY(double,double)));
+
+    image = new QImage(VIEW_WIDTH, VIEW_HEIGHT, QImage::Format_RGB32);//画布的初始化大小设为300*300,使用32位颜色
+    myview->setCacheMode(myview->CacheBackground);
+    painter = new QPainter(image);
+    painter->end();
+
+    scene = new QGraphicsScene(-VIEW_WIDTH/2, -VIEW_HEIGHT/2, VIEW_WIDTH, VIEW_HEIGHT);
+
+    myview->setScene(scene);
+    scene->setBackgroundBrush(Qt::darkGreen);
+
+
+    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);
+
+    }
+
+
+
+    MainWindow::ComboToString(strdefroad,ui->comboBox_Road);
+
+    UpdateHidenCombo();
+
     setWindowTitle("Hide Road");
 }
 
@@ -14,3 +57,169 @@ DialogHideRoad::~DialogHideRoad()
 {
     delete ui;
 }
+
+void DialogHideRoad::paintEvent(QPaintEvent * painter)
+{
+    scene->update();
+    return;
+}
+
+void DialogHideRoad::on_comboBox_Road_currentIndexChanged(int index)
+{
+    Road * pRoad = mpxodr->GetRoad(index);
+    if(pRoad == 0)
+    {
+ //       QMessageBox::warning(this,"WARN","MainWindow::onClickCBRoadChange road is NULL");
+        return;
+    }
+
+    mpCurRoad = pRoad;
+
+    int i;
+    int nsize = mvectorroadview.size();
+    for(i=0;i<nsize;i++)
+    {
+        scene->removeItem(mvectorroadview.at(i));
+        delete mvectorroadview.at(i);
+    }
+    mvectorroadview.clear();
+
+    nsize = mvectorviewitem.size();
+    for(i=0;i<nsize;i++)
+    {
+        scene->removeItem(mvectorviewitem.at(i));
+        delete mvectorviewitem.at(i);
+    }
+    mvectorviewitem.clear();
+
+    double froad_xmin,froad_ymin,froad_xmax,froad_ymax;
+    ServiceXODRTool.GetRoadMaxMin(pRoad,froad_xmin,froad_ymin,froad_xmax,froad_ymax);
+//    roadviewitem * prvw = new roadviewitem(pRoad);
+
+    int nfac;
+    int nkeep = 30;
+    double fac_x,fac_y;
+    fac_x = 100000;
+    fac_y = 100000;
+    if(froad_xmax > froad_xmin)
+    {
+        fac_x = (VIEW_WIDTH-nkeep*2)/(froad_xmax - froad_xmin);
+    }
+
+    if(froad_ymax > froad_ymin)
+    {
+        fac_y = (VIEW_HEIGHT - nkeep*2)/(froad_ymax - froad_ymin);
+    }
+
+    nfac = fac_x;
+    if(fac_y < nfac)nfac = fac_y;
+
+
+    mfViewMoveX = VIEW_WIDTH/2.0 ;
+    mfViewMoveY = VIEW_HEIGHT/2.0;
+
+    mfViewMoveX = 0 - froad_xmin - (froad_xmax - froad_xmin)/2.0;
+    mfViewMoveY = 0 + froad_ymin  + (froad_ymax-froad_ymin)/2.0;
+
+//    prvw->setPos(mfViewMoveX,mfViewMoveY);
+ //       prvw->setPos((froad_xmax - froad_xmin)/2.0, (froad_ymax-froad_ymin)/2.0);
+//    mvectorroadview.push_back(prvw);
+ //   prvw->setratio(1.0);
+//    scene->addItem(prvw);
+
+
+
+    RoadDigit xrd(mpCurRoad,5.0);
+
+    std::vector<QGraphicsPathItem *> xvectorlanepath = xodrscenfunc::GetRoadLaneItem(&xrd);
+    int j;
+    int ncount = xvectorlanepath.size();
+    for(j=0;j<ncount;j++)
+    {
+        QGraphicsPathItem * pitem = xvectorlanepath[j];
+        pitem->setPos(mfViewMoveX,mfViewMoveY);
+        scene->addItem(pitem);
+        mvectorviewitem.push_back(pitem);
+    }
+
+    std::vector<QGraphicsPathItem *> xvectormarkpath = xodrscenfunc::GetRoadMarkItem(&xrd);
+    ncount = xvectormarkpath.size();
+    for(j=0;j<ncount;j++)
+    {
+        QGraphicsPathItem * pitem = xvectormarkpath[j];
+        pitem->setPos(mfViewMoveX,mfViewMoveY);
+        scene->addItem(pitem);
+        mvectorviewitem.push_back(pitem);
+    }
+
+    update();
+}
+
+
+void DialogHideRoad::on_pushButton_HideRoad_clicked()
+{
+    if(ui->comboBox_Road->currentIndex()<0)
+    {
+        QMessageBox::warning(this,"Warning","No Road.",QMessageBox::YesAll);
+        return;
+    }
+    int nroadid = ui->comboBox_Road->currentText().toInt();
+    unsigned int i;
+    bool bExist = false;
+    for(i=0;i<mpvectorhideroadid->size();i++)
+    {
+        if(mpvectorhideroadid->at(i) == nroadid)
+        {
+            bExist = true;
+            break;
+        }
+    }
+
+    if(bExist)
+    {
+        QMessageBox::warning(this,"Warning","This Road is Hiden.",QMessageBox::YesAll);
+        return;
+    }
+    mpvectorhideroadid->push_back(nroadid);
+    UpdateHidenCombo();
+}
+
+void DialogHideRoad::on_pushButton_UnHIdeRoad_clicked()
+{
+    if(ui->comboBox_RoadHiden->currentIndex()<0)
+    {
+        QMessageBox::warning(this,"Warning","No Hiden road.",QMessageBox::YesAll);
+        return;
+    }
+    mpvectorhideroadid->erase(mpvectorhideroadid->begin()+ui->comboBox_RoadHiden->currentIndex());
+    UpdateHidenCombo();
+}
+
+void DialogHideRoad::on_pushButton_UnHideAllRoad_clicked()
+{
+    if(mpvectorhideroadid->size()>0)
+    {
+        mpvectorhideroadid->clear();
+        UpdateHidenCombo();
+    }
+}
+
+void DialogHideRoad::UpdateHidenCombo()
+{
+    int index = ui->comboBox_RoadHiden->currentIndex();
+    ui->comboBox_RoadHiden->clear();
+    if(mpvectorhideroadid->size() == 0)return;
+    unsigned int i;
+    for(i=0;i<mpvectorhideroadid->size();i++)
+    {
+        ui->comboBox_RoadHiden->addItem(QString::number(mpvectorhideroadid->at(i)));
+    }
+    if((index>=0)&&(index<mpvectorhideroadid->size()))
+    {
+        ui->comboBox_RoadHiden->setCurrentIndex(index);
+    }
+    else
+    {
+        ui->comboBox_RoadHiden->setCurrentIndex(0);
+    }
+}

+ 28 - 1
src/tool/map_lanetoxodr/dialoghideroad.h

@@ -10,6 +10,10 @@
 #include "ivxodrtool.h"
 
 #include "roadviewitem.h"
+#include "xodrscenfunc.h"
+
+#include "roaddigit.h"
+
 namespace Ui {
 class DialogHideRoad;
 }
@@ -19,9 +23,23 @@ class DialogHideRoad : public QDialog
     Q_OBJECT
 
 public:
-    explicit DialogHideRoad(OpenDrive * pxodr,std::string strdefroad,QWidget *parent = nullptr);
+    explicit DialogHideRoad(OpenDrive * pxodr,std::string strdefroad,std::vector<int> * pvectorhideroadid,QWidget *parent = nullptr);
     ~DialogHideRoad();
 
+private slots:
+   virtual void paintEvent(QPaintEvent *);
+
+    void on_comboBox_Road_currentIndexChanged(int index);
+
+    void on_pushButton_HideRoad_clicked();
+
+    void on_pushButton_UnHIdeRoad_clicked();
+
+    void on_pushButton_UnHideAllRoad_clicked();
+
+private:
+    void UpdateHidenCombo();
+
 private:
     Ui::DialogHideRoad *ui;
 
@@ -34,6 +52,15 @@ private:
     QGraphicsScene *scene;
 
     Road * mpCurRoad = 0;
+
+    std::vector<roadviewitem *> mvectorroadview;
+
+    std::vector<QGraphicsPathItem *> mvectorviewitem;
+
+    double mfViewMoveX = 0;
+    double mfViewMoveY = 0;
+
+    std::vector<int> * mpvectorhideroadid;
 };
 
 #endif // DIALOGHIDEROAD_H

+ 1 - 1
src/tool/map_lanetoxodr/dialoghideroad.ui

@@ -75,7 +75,7 @@
     <string>UnHide</string>
    </property>
   </widget>
-  <widget class="QComboBox" name="comboBox_Road_2">
+  <widget class="QComboBox" name="comboBox_RoadHiden">
    <property name="geometry">
     <rect>
      <x>420</x>

+ 43 - 62
src/tool/map_lanetoxodr/mainwindow.cpp

@@ -111,9 +111,6 @@ void MainWindow::AdjustWPos(QSize sizemain)
 
 void MainWindow::ExecPainter()
 {
-
-
-
     QTime x;
     x.start();
     //    qDebug("painter.");
@@ -176,6 +173,11 @@ void MainWindow::ExecPainter()
             painter->setPen(Qt::red);
         }
 
+        if(IsHidenRoad(atoi(pRoad->GetRoadId().data())))
+        {
+            continue;
+        }
+
         if(mxodr.GetRoad(i)->GetGeometryBlockCount()>0)
         {
             GeometryBlock * pgeob = pRoad->GetGeometryBlock(0);
@@ -1288,7 +1290,7 @@ void MainWindow::onClickXY(double x, double y)
     double fdis,nearx,neary,hdg;
     double fs;
     int nlane;
-    if(xodrfunc::GetNearPoint(rel_x,rel_y,&mxodr,&pRoad,&pgeob,fdis,nearx,neary,hdg,50,&fs,&nlane) == 0)
+    if(xodrfunc::GetNearPointWithHide(rel_x,rel_y,&mxodr,&pRoad,&pgeob,fdis,nearx,neary,hdg,50,mvectorhideroadid,&fs,&nlane) == 0)
     {
         qDebug("s:%f dis is %f nlane is %d",fs,fdis,nlane);
         char strout[1000];
@@ -1670,58 +1672,7 @@ void MainWindow::onClickLoadLane()
  */
 Road MainWindow::CreateRoad(VectorXd xvals, VectorXd yvals)
 {
-//    Road xRoad;
-//    double LINE_ERROR = 0.15;
-//    int nsize =  xvals.size();
-//    int nnotfit = nsize;
-//    int ncurpos = 0;
-//    int nrange = nsize;
-//    while(ncurpos  <  nsize)
-//    {
-// //       int N = nrange - ncurpos;
-//        VectorXd x_veh(nrange);
-//        VectorXd y_veh(nrange);
-
-//        int j;
-//        for(j=ncurpos;j<(ncurpos +nrange);j++)
-//        {
-//            x_veh[j-ncurpos] = xvals[j];
-//            y_veh[j - ncurpos] = yvals[j];
-//        }
-
-//        auto coeffs = polyfit(x_veh, y_veh, 1);
-
-//        double dismax = 0;
-//        for(j=ncurpos;j<(ncurpos +nrange);j++)
-//        {
-//            double A = coeffs[1];
-//            double B = -1;
-//            double C = coeffs[0];
-//            double dis = fabs(A*x_veh[j-ncurpos] + B*y_veh[j-ncurpos] +C )/sqrt(pow(A,2)+pow(B,2));
-//            if(dis>dismax)dismax = dis;
-//        }
-//        std::cout<<"dis is "<<dismax<<std::endl;
-//        if((dismax > LINE_ERROR)&&((nsize -(nrange+ncurpos))>50))
-//        {
-//            nrange = nrange/2;
-//        }
-//        else
-//        {
-//            std::cout<<"nrange is "<<nrange<<std::endl;
-
-//            xRoad.AddGeometryBlock();
-//            GeometryBlock * pgb = xRoad.GetGeometryBlock(xRoad.GetGeometryBlockCount()-1);
-// //           pgb->AddGeometryLine(1.0,x,y,len);
-
-//            ncurpos = ncurpos + nrange;
-//            nrange = nsize - ncurpos;
-
-
-//            std::cout<<"add a geo."<<std::endl;
-//        }
-//    }
 
-//    return xRoad;
 }
 
 void MainWindow::onClickMarkLane()
@@ -2684,12 +2635,6 @@ void MainWindow::onClickAddRoad()
     mbRefresh = true;
     update();
 
-
-
-//    OpenDriveXmlWriter x(&mxodr);
- //   x.WriteFile("/home/nvidia/text.xodr");
-
-
 }
 
 
@@ -2769,6 +2714,8 @@ void MainWindow::onClickLoad()
     QString str = QFileDialog::getOpenFileName(this,"Load XODR",".","*.xodr");
     if(str.isEmpty())return;
 
+    mvectorhideroadid.clear();
+
     QString strfilepath = str;
 
     QString strbak = str + ".bak";
@@ -5542,6 +5489,10 @@ void MainWindow::UpdateScene()
     }
     for(i=0;i<nsize;i++)
     {
+        if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
+        {
+            continue;
+        }
         std::vector<QGraphicsPathItem *> xvectorlanepath = xodrscenfunc::GetRoadLaneItem(&(xvectorrd[i]));
         int j;
         int ncount = xvectorlanepath.size();
@@ -5556,6 +5507,10 @@ void MainWindow::UpdateScene()
 
     for(i=0;i<nsize;i++)
     {
+        if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
+        {
+            continue;
+        }
         std::vector<QGraphicsPathItem *> xvectormarkpath = xodrscenfunc::GetRoadMarkItem(&(xvectorrd[i]));
         int j;
         int ncount = xvectormarkpath.size();
@@ -5570,6 +5525,10 @@ void MainWindow::UpdateScene()
 
     for(i=0;i<nsize;i++)
     {
+        if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
+        {
+            continue;
+        }
         std::vector<QGraphicsTextItem *> xvectortext;
         std::vector<QGraphicsPathItem *> xvectorparkmark;
         std::vector<QGraphicsPathItem *> xvectorparkpath = xodrscenfunc::GetRoadParkingItem(&(xvectorrd[i]),xvectortext,
@@ -5709,6 +5668,28 @@ void MainWindow::on_actionMake_All_Road_Contact_triggered()
 void MainWindow::on_actionHide_Road_triggered()
 {
     std::string strroadid = mpCBRoad->currentText().toStdString();
-    DialogHideRoad hrd(&mxodr,strroadid,this);
+    DialogHideRoad hrd(&mxodr,strroadid,&mvectorhideroadid, this);
     int res = hrd.exec();
+    if(res == 0){}
+    mbRefresh = true;
+    update();
+    if(mpCBViewMode->currentIndex() == 1)
+    {
+        UpdateScene();
+    }
+}
+
+bool MainWindow::IsHidenRoad(int nroadid)
+{
+    bool bIsHiden = false;
+    unsigned int i;
+    for(i=0;i<mvectorhideroadid.size();i++)
+    {
+        if(nroadid == mvectorhideroadid[i])
+        {
+            bIsHiden = true;
+            break;
+        }
+    }
+    return bIsHiden;
 }

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

@@ -373,6 +373,8 @@ public:
     double getlanewidth(Road * p,int nlane,bool bstart = true);
     std::string getlanetype(Road * p,int nlane,bool bstart = true);
 
+    bool IsHidenRoad(int nroadid);
+
 private:
     void UpdateMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
     void UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
@@ -433,6 +435,8 @@ private:
 
     int mnNotSave = 0;
 
+    std::vector<int> mvectorhideroadid;
+
 
 };