Forráskód Böngészése

change map_lanetoxodr. add driver_lidar_leishen32,not complete.

yuchuli 2 éve
szülő
commit
ed8999ace0

+ 73 - 0
src/driver/driver_lidar_leishen32/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 34 - 0
src/driver/driver_lidar_leishen32/driver_lidar_leishen32.pro

@@ -0,0 +1,34 @@
+QT -= gui
+
+
+QT       += network
+
+CONFIG += c++14 console
+CONFIG -= app_bundle
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += main.cpp \
+    lidarudp.cpp \
+    leishen32.cpp
+
+HEADERS += \
+    lidarudp.h \
+    leishen32.h
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivpcl.pri ) {
+    error( "Couldn't find the ivpcl.pri file!" )
+}

+ 154 - 0
src/driver/driver_lidar_leishen32/leishen32.cpp

@@ -0,0 +1,154 @@
+#include "leishen32.h"
+
+#include "ivstdcolorout.h"
+
+static double leishen32_vertical_1[32]={-16,0,-15,1,-14,2,-13,3,
+                                -12,4,-11,5,-10,6,-9,7,
+                                0,1,2,3,4,5,6,7,
+                                8,9,10,11,12,13,14,15};
+
+static double leishen32_vertical_033[32]={-18,-1,-15,-0.66,-12,-0.33,-10,0,
+                                          -8,0.33,-7,0.66,-6,1,-5,1.33,
+                                          -4,1.66,-3.33,2,-3,3,-2.66,4,
+                                          -2.33,6,-2,8,-1.66,11,-1.33,14};
+
+leishen32::leishen32()
+{
+    mpleishen32_vertical = &leishen32_vertical_1[0];
+    int i;
+    for(i=0;i<32;i++)
+    {
+        mthetacos[i] = cos(mpleishen32_vertical[i]*M_PI/180.0);
+        mthetasin[i] = sin(mpleishen32_vertical[i]*M_PI/180.0);
+    }
+}
+
+void leishen32::threaddecode()
+{
+
+}
+
+int leishen32::DecodeUDPPac(pcl::PointCloud<pcl::PointXYZI>::Ptr & point_cloud,iv::lidarudppac & xpac)
+{
+    if(xpac.mndatasize != 1206)
+    {
+        return  -1;
+    }
+    static int nNotDecodeNum = 0;
+    if(mbdevinfo == false)
+    {
+        nNotDecodeNum++;
+        if(nNotDecodeNum > 1000)
+        {
+            ivstdcolorout("No Device Info Packet,Can't Get A1 A2 A3 A4.",iv::STDCOLOR_BOLDYELLOW);
+        }
+        return 0;
+    }
+    nNotDecodeNum = 0;
+
+    double finclinationang_xaxis = 0.0;// atof(gstr_inclinationang_xaxis)*M_PI/180.0;  //Inclination from x axis
+    double finclinationang_yaxis = 0.0;// atof(gstr_inclinationang_yaxis)*M_PI/180.0;   //Inclination from y axis
+    bool binclix = false;
+    bool bincliy = false;
+    if(finclinationang_xaxis != 0.0)binclix = true;
+    if(finclinationang_yaxis != 0.0)bincliy = true;
+
+    float cos_finclinationang_xaxis = static_cast<float>(cos(finclinationang_xaxis)) ;
+    float sin_finclinationang_xaxis = static_cast<float>(sin(finclinationang_xaxis));
+    float cos_finclinationang_yaxis = static_cast<float>(cos(finclinationang_yaxis));
+    float sin_finclinationang_yaxis = static_cast<float>(sin(finclinationang_yaxis));
+
+    double frollang = 0;
+
+    char * pstr =  static_cast<char * >(xpac.mdata_ptr.get()) ;
+
+    int i;
+    for(i=0;i<12;i++)
+    {
+        char * pstrpac = pstr+i*100;
+        unsigned short * pazu = reinterpret_cast<unsigned short * >(pstrpac + 2);
+        double fazu = *pazu;
+        fazu = fazu * 0.01;
+        fazu = fazu * M_PI/180.0;
+        pcl::PointXYZI point;
+
+        int j;
+        for(j=0;j<32;j++)
+        {
+            double Range = ((pstrpac[4+j*3] << 8) + pstrpac[4+j*3+1]);
+            unsigned char intensity = static_cast<unsigned char>(pstr[4+j*3+2]) ;
+            Range=Range* 0.0025;
+
+
+            pcl::PointXYZI point;
+            point.x  = static_cast<float>(Range* mthetacos[j]*cos(fazu + mpleishen32_A[j] + frollang)) ;
+            point.y  = static_cast<float>(Range* mthetacos[j] *sin(fazu + mpleishen32_A[j]  + frollang));
+            point.z  = static_cast<float>(Range* mthetasin[j]);
+            point.intensity = intensity;
+
+            if(binclix)
+            {
+                float y,z;
+                y = point.y;z = point.z;
+                point.y = y*cos_finclinationang_xaxis +z*sin_finclinationang_xaxis;
+                point.z = z*cos_finclinationang_xaxis - y*sin_finclinationang_xaxis;
+            }
+            if(bincliy)
+            {
+                float z,x;
+                z = point.z;x = point.x;
+                point.z = z*cos_finclinationang_yaxis + x*sin_finclinationang_yaxis;
+                point.x = x*cos_finclinationang_yaxis - z*sin_finclinationang_yaxis;
+            }
+
+            mpoint_cloud_temp->points.push_back(point);
+
+
+            ++mpoint_cloud_temp->width;
+        }
+    }
+
+    return  0;
+
+}
+
+int leishen32::DecodeDevinfo(iv::lidarudppac & xpac)
+{
+    if(xpac.mndatasize != 1206)
+    {
+        return  -1;
+    }
+
+    char * pstr =  static_cast<char * >(xpac.mdata_ptr.get()) ;
+    unsigned short  * pmoterspeed = reinterpret_cast<unsigned short *>(pstr+8);//  ( unsigned short *)(pstr+8);
+    mdevinfo.motorspeed = *pmoterspeed;
+
+    unsigned short * pmotorun = reinterpret_cast<unsigned short * >(pstr+40);
+    if(*pmotorun == 1)
+    {
+        mdevinfo.bmotorrun = true;
+    }
+    else
+        mdevinfo.bmotorrun = false;
+
+    unsigned short * ppacinterval = reinterpret_cast<unsigned short * >(pstr+42);
+    mdevinfo.pacinterval = *ppacinterval;
+
+    double A[4];
+    int i;
+    for(i=0;i<4;i++)
+    {
+        unsigned short * pA = reinterpret_cast<unsigned short *>(pstr+186+i*2);
+        unsigned short Avalue = *pA;
+        A[i] = Avalue;
+        A[i] = A[i]*0.01;
+    }
+
+    mdevinfo.A1 = A[0];
+    mdevinfo.A2 = A[1];
+    mdevinfo.A3 = A[2];
+    mdevinfo.A4 = A[3];
+
+    mbdevinfo = true;
+    return 0;
+}

+ 57 - 0
src/driver/driver_lidar_leishen32/leishen32.h

@@ -0,0 +1,57 @@
+#ifndef LEISHEN32_H
+#define LEISHEN32_H
+
+#include <pcl/point_cloud.h>
+#include <pcl/point_types.h>
+
+#include <vector>
+#include <mutex>
+#include <condition_variable>
+#include <thread>
+
+#include "lidarudp.h"
+
+
+
+namespace iv {
+struct leishen32_devinfo
+{
+    int motorspeed;
+    bool bmotorrun;
+    int pacinterval;
+    double A1;
+    double A2;
+    double A3;
+    double A4;
+
+};
+}
+
+class leishen32
+{
+public:
+    leishen32();
+
+private:
+    pcl::PointCloud<pcl::PointXYZI>::Ptr mpoint_cloud;
+    pcl::PointCloud<pcl::PointXYZI>::Ptr mpoint_cloud_temp;
+
+    iv::leishen32_devinfo mdevinfo;
+    bool mbdevinfo = false;
+
+    double * mpleishen32_vertical;
+    double * mpleishen32_A;
+
+    double mthetacos[32];
+    double mthetasin[32];
+
+private:
+    void threaddecode( );
+    int DecodeUDPPac(pcl::PointCloud<pcl::PointXYZI>::Ptr & point_cloud,iv::lidarudppac & xpac);
+    int DecodeDevinfo(iv::lidarudppac & xpac);
+
+
+
+};
+
+#endif // LEISHEN32_H

+ 74 - 0
src/driver/driver_lidar_leishen32/lidarudp.cpp

@@ -0,0 +1,74 @@
+#include "lidarudp.h"
+
+#include <QUdpSocket>
+#include <iostream>
+#include <chrono>
+#include <ios>
+
+#include "ivstdcolorout.h"
+
+lidarudp::lidarudp(int nport)
+{
+    mpthread = new std::thread(&lidarudp::threadrecv,this,nport);
+}
+
+lidarudp::~lidarudp()
+{
+    mbrun = false;
+    mpthread->join();
+}
+
+void lidarudp::threadrecv(int nport)
+{
+    QUdpSocket * udpSocket = new QUdpSocket( );
+    udpSocket->bind(QHostAddress::Any, static_cast<quint16>(nport) );
+
+    unsigned int ndatamisstime = 0;
+    while(mbrun)
+    {
+        if(udpSocket->hasPendingDatagrams())
+        {
+            ndatamisstime = 0;
+            int ndatasize = static_cast<int>(udpSocket->pendingDatagramSize());
+            iv::lidarudppac xdatapac;
+            xdatapac.mdata_ptr = std::shared_ptr<char>(new char[static_cast<unsigned long>(ndatasize) ]);
+            QHostAddress sender;
+            quint16 senderPort;
+
+            udpSocket->readDatagram(xdatapac.mdata_ptr.get(), ndatasize,
+                                            &sender, &senderPort);
+            xdatapac.mndatasize = ndatasize;
+            xdatapac.mrecvtime = std::chrono::system_clock::now().time_since_epoch().count();
+
+            mmutex.lock();
+            mvectorba.push_back(xdatapac);
+            mmutex.unlock();
+            mcv.notify_all();
+
+        }
+        else
+        {
+            std::this_thread::sleep_for(std::chrono::milliseconds(1));
+            if(ndatamisstime <  10000)
+            {
+                ndatamisstime++;
+            }
+            else
+            {
+                int64_t nowns =  std::chrono::system_clock::now().time_since_epoch().count();
+                int64_t nowms =  std::chrono::system_clock::now().time_since_epoch().count()/1000000;
+                int64_t nowsmall = nowns - nowms*1000000;
+                double fnow = nowsmall * 0.000001;
+                fnow = fnow + nowms;
+                char strout[256];
+                snprintf(strout,256,"%20.6f  more than 10 seconds no data.",fnow);
+                ivstdcolorout(strout,iv::STDCOLOR_BOLDRED);
+                ndatamisstime = 0;
+            }
+
+        }
+    }
+
+    udpSocket->close();
+    delete udpSocket;
+}

+ 42 - 0
src/driver/driver_lidar_leishen32/lidarudp.h

@@ -0,0 +1,42 @@
+#ifndef LIDARUDP_H
+#define LIDARUDP_H
+
+#include <QByteArray>
+
+#include <vector>
+#include <mutex>
+#include <condition_variable>
+#include <thread>
+#include <memory>
+
+namespace iv
+{
+struct lidarudppac
+{
+    int64_t mrecvtime;
+    std::shared_ptr<char> mdata_ptr;
+    int mndatasize;
+};
+}
+
+class lidarudp
+{
+public:
+    lidarudp(int nport);
+    ~lidarudp();
+
+private:
+    void threadrecv(int nport);
+
+private:
+    bool mbrun = true;
+    std::mutex mmutex;
+    std::mutex mmutexcv;
+    std::condition_variable mcv;
+    std::thread * mpthread;
+    std::vector<iv::lidarudppac> mvectorba;
+    const int mMaxBuffPac = 10000;
+
+};
+
+#endif // LIDARUDP_H

+ 13 - 0
src/driver/driver_lidar_leishen32/main.cpp

@@ -0,0 +1,13 @@
+#include <QCoreApplication>
+
+
+#include "lidarudp.h"
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    lidarudp * plu = new lidarudp(2368);
+
+    return a.exec();
+}

+ 28 - 0
src/include/proto/cdadraw.proto

@@ -0,0 +1,28 @@
+syntax = "proto2";
+
+package iv.map;
+
+message cdalane
+{
+	required int32 lanemarkcolor	= 1; //车道线颜色  0 白色 1 黄色
+	required int32 lanemarktype 	= 2; //车道线类型    0 虚线 1 实线 2 双虚线  3 双实线  4 虚实线 5 实虚线  6 无
+	required double lanewidth	= 3; //车道线宽度
+	required int32 lanetype		= 4; //车道类型 "shoulder","border","driving","stop","none","parking","biking","sidewalk","median"
+};
+
+message cdageo
+{
+	required int32 geotype		= 1; //路段类型  0 直路  1 弯路  2 路口
+	optional double georadius 	= 2; //路段半径
+	required double geolen		= 3; //路段长度
+};
+
+message cdadraw
+{
+	repeated cdalane mlanes		=1;  //车道
+	repeated cdageo mgeos		=2;  //路段
+	required int32 mroadtype	=3;  //道路类型  0 高速公路  1 城市  2 乡村
+	required int32  mroadele	=4;  //坡度  0 平路  1 缓上坡  2 上坡  3 缓下坡 4 下坡
+};
+
+

+ 212 - 73
src/tool/map_lanetoxodr/dialogaddroadfromcda.cpp

@@ -4,10 +4,14 @@
 #include <QLibrary>
 #include <iostream>
 #include <QMessageBox>
+#include <QFileDialog>
+
+#include "google/protobuf/io/zero_copy_stream_impl.h"
+#include "google/protobuf/text_format.h"
 
 #include <math.h>
 
-std::string cda_lanetype_sel[9] = {"shoulder","border","driving","stop","none","parking","biking","sidewalk",
+static std::string cda_lanetype_sel[9] = {"shoulder","border","driving","stop","none","parking","biking","sidewalk",
                                "median"};
 
 DialogAddRoadFromCDA::DialogAddRoadFromCDA(OpenDrive * pxodr, QWidget *parent) :
@@ -17,6 +21,20 @@ DialogAddRoadFromCDA::DialogAddRoadFromCDA(OpenDrive * pxodr, QWidget *parent) :
     ui->setupUi(this);
     mpxodr = pxodr;
 
+    iv::map::cdageo * pgeo =  mcdadraw.add_mgeos();
+    pgeo->set_geotype(0);
+    pgeo->set_georadius(100.0);
+    pgeo->set_geolen(100.0);
+
+    iv::map::cdalane * plane = mcdadraw.add_mlanes();
+    plane->set_lanemarkcolor(0);
+    plane->set_lanemarktype(0);
+    plane->set_lanewidth(3.6);
+    plane->set_lanetype(2);
+
+    mcdadraw.set_mroadtype(0);
+    mcdadraw.set_mroadele(0);
+
     ui->comboBox_RoadClass->addItem(tr("高速公路"));
     ui->comboBox_RoadClass->addItem(tr("城市"));
     ui->comboBox_RoadClass->addItem(tr("乡村"));
@@ -63,7 +81,7 @@ DialogAddRoadFromCDA::~DialogAddRoadFromCDA()
 
 void DialogAddRoadFromCDA::on_pushButton_Create_clicked()
 {
-    OpenDrive * pxodr = mpxodr;
+//    OpenDrive * pxodr = mpxodr;
 //    std::string strtype = ui->comboBox_Type->currentText().toStdString();
 //    std::string strradius = ui->lineEdit_radius->text().toStdString();
 //    std::string strlen = ui->lineEdit_len->text().toStdString();
@@ -113,18 +131,18 @@ void DialogAddRoadFromCDA::on_pushButton_Create_clicked()
 
 void DialogAddRoadFromCDA::UpdateView()
 {
-    iv::cdaroad * pcdaroad = &mcdaroad;
-    ui->comboBox_RoadClass->setCurrentIndex(pcdaroad->mnclass);
-    int nlanecount = static_cast<int>(pcdaroad->mvectorlane.size());
+    iv::map::cdadraw * pcdadraw = &mcdadraw;
+    ui->comboBox_RoadClass->setCurrentIndex(pcdadraw->mroadtype());
+    int nlanecount = static_cast<int>(pcdadraw->mlanes_size());
     ui->lineEdit_roadlanecount->setText(QString::number(nlanecount));
     double fRoadLen = 0;
     int i;
-    int ngeosize = static_cast<int>(pcdaroad->mvectorgeo.size());
+    int ngeosize = static_cast<int>(pcdadraw->mgeos_size());
     ui->comboBox_geo->clear();
     for(i=0;i<ngeosize;i++)
     {
         ui->comboBox_geo->addItem(QString(tr("路段"))+QString::number(i+1));
-        fRoadLen = fRoadLen + pcdaroad->mvectorgeo[i].mflen;
+        fRoadLen = fRoadLen + pcdadraw->mgeos(i).geolen();
     }
     ui->comboBox_Lane->clear();
     for(i=0;i<nlanecount;i++)
@@ -136,68 +154,84 @@ void DialogAddRoadFromCDA::UpdateView()
 
 void DialogAddRoadFromCDA::on_comboBox_Lane_currentIndexChanged(int index)
 {
-    iv::cdaroad * pcdaroad = &mcdaroad;
+//    iv::cdaroad * pcdaroad = &mcdaroad;
+    iv::map::cdadraw * pcdadraw = &mcdadraw;
     if(index<0)return;
-    if(index>=pcdaroad->mvectorlane.size())
+    if(index>=pcdadraw->mlanes_size())
     {
         std::cout<<" index big than lane size."<<std::endl;
         return;
     }
-    iv::cdalane * plane = &pcdaroad->mvectorlane[index];
-    ui->comboBox_lanecolor->setCurrentIndex(plane->mnlanemarkcolor);
-    ui->comboBox_lanemarktype->setCurrentIndex(plane->mnlanemarktype);
-    ui->lineEdit_lanewidth->setText(QString::number(plane->mflanewidth,'f',2));
-    ui->comboBox_lanetype->setCurrentIndex(plane->mnlanetype);
+    iv::map::cdalane * plane = mcdadraw.mutable_mlanes(index);
+    ui->comboBox_lanecolor->setCurrentIndex(plane->lanemarkcolor());
+    ui->comboBox_lanemarktype->setCurrentIndex(plane->lanemarktype());
+    ui->lineEdit_lanewidth->setText(QString::number(plane->lanewidth(),'f',2));
+    ui->comboBox_lanetype->setCurrentIndex(plane->lanetype());
 }
 
 void DialogAddRoadFromCDA::on_comboBox_geo_currentIndexChanged(int index)
 {
-    iv::cdaroad * pcdaroad = &mcdaroad;
+    iv::map::cdadraw * pcdadraw = &mcdadraw;
     if(index<0)return;
-    if(index>=pcdaroad->mvectorgeo.size())
+    if(index>=pcdadraw->mgeos_size())
     {
         std::cout<<" index big than geo size."<<std::endl;
         return;
     }
-    iv::cdageo * pgeo = &pcdaroad->mvectorgeo[index];
-    ui->comboBox_geoType->setCurrentIndex(pgeo->mngeotype);
-    ui->lineEdit_georadius->setText(QString::number(pgeo->mfradius));
-    ui->lineEdit_geolen->setText(QString::number(pgeo->mflen));
+    iv::map::cdageo * pgeo = pcdadraw->mutable_mgeos(index);
+    ui->comboBox_geoType->setCurrentIndex(pgeo->geotype());
+    ui->lineEdit_georadius->setText(QString::number(pgeo->georadius()));
+    ui->lineEdit_geolen->setText(QString::number(pgeo->geolen()));
 }
 
 void DialogAddRoadFromCDA::on_pushButton_laneadd_clicked()
 {
-   iv::cdaroad * pcdaroad = &mcdaroad;
-   iv::cdalane xlane;
-   xlane.mflanewidth = ui->lineEdit_lanewidth->text().toDouble();
-   if(xlane.mflanewidth<=0)
+   iv::map::cdadraw * pcdadraw = &mcdadraw;
+   double flanewidth = ui->lineEdit_lanewidth->text().toDouble();
+   if(flanewidth<=0)
    {
        QMessageBox::warning(this,tr("Warning"),tr("Lane Width Error."),QMessageBox::YesAll);
        return;
    }
-   xlane.mnlanemarkcolor = ui->comboBox_lanecolor->currentIndex();
-   xlane.mnlanemarktype = ui->comboBox_lanemarktype->currentIndex();
-   xlane.mnlanetype = ui->comboBox_lanetype->currentIndex();
-   int nlanecount = static_cast<int>(pcdaroad->mvectorlane.size()) ;
-   pcdaroad->mvectorlane.push_back(xlane);
-   ui->comboBox_Lane->addItem(QString(tr("车道"))+QString::number(nlanecount+1));
-   ui->comboBox_Lane->setCurrentIndex(nlanecount);
-   ui->lineEdit_roadlanecount->setText(QString::number(nlanecount+1));
+   iv::map::cdalane * plane = pcdadraw->add_mlanes();
+   plane->set_lanemarkcolor(ui->comboBox_lanecolor->currentIndex());
+   plane->set_lanemarktype(ui->comboBox_lanemarktype->currentIndex());
+   plane->set_lanewidth(flanewidth);
+   plane->set_lanetype(ui->comboBox_lanetype->currentIndex());
+
+   int nlanecount = static_cast<int>(pcdadraw->mlanes_size()) ;
+   ui->comboBox_Lane->addItem(QString(tr("车道"))+QString::number(nlanecount));
+   ui->comboBox_Lane->setCurrentIndex(nlanecount-1);
+   ui->lineEdit_roadlanecount->setText(QString::number(nlanecount));
 }
 
 void DialogAddRoadFromCDA::on_pushButton_lanedel_clicked()
 {
-    iv::cdaroad * pcdaroad = &mcdaroad;
-    if(pcdaroad->mvectorlane.size() == 0)
+    iv::map::cdadraw * pcdadraw = &mcdadraw;
+    if(pcdadraw->mlanes_size() == 0)
     {
         QMessageBox::warning(this,tr("Warning"),tr("No Lane."),QMessageBox::YesAll);
         return;
     }
     int index = ui->comboBox_Lane->currentIndex();
-    pcdaroad->mvectorlane.erase(pcdaroad->mvectorlane.begin() + index);
 
-    int nlanecount = static_cast<int>(pcdaroad->mvectorlane.size());
     int i;
+    iv::map::cdadraw xtemp;
+    for(i=0;i<pcdadraw->mlanes_size();i++)
+    {
+        if(i == index)continue;
+        iv::map::cdalane * plane = xtemp.add_mlanes();
+        plane->CopyFrom(pcdadraw->mlanes(i));
+    }
+    pcdadraw->clear_mlanes();
+    for(i=0;i<xtemp.mlanes_size();i++)
+    {
+        iv::map::cdalane * plane = pcdadraw->add_mlanes();
+        plane->CopyFrom(xtemp.mlanes(i));
+    }
+
+
+    int nlanecount = static_cast<int>(pcdadraw->mlanes_size());
     ui->comboBox_Lane->clear();
     for(i=0;i<nlanecount;i++)
     {
@@ -217,8 +251,8 @@ void DialogAddRoadFromCDA::on_pushButton_lanedel_clicked()
 
 void DialogAddRoadFromCDA::on_pushButton_lanechange_clicked()
 {
-    iv::cdaroad * pcdaroad = &mcdaroad;
-    if(pcdaroad->mvectorlane.size() == 0)
+    iv::map::cdadraw * pcdadraw = &mcdadraw;
+    if(pcdadraw->mlanes_size() == 0)
     {
         QMessageBox::warning(this,tr("Warning"),tr("No Lane."),QMessageBox::YesAll);
         return;
@@ -231,48 +265,51 @@ void DialogAddRoadFromCDA::on_pushButton_lanechange_clicked()
         return;
     }
 
-    iv::cdalane * plane = &pcdaroad->mvectorlane[index];
-    plane->mflanewidth = flanewidth;
-    plane->mnlanemarkcolor = ui->comboBox_lanecolor->currentIndex();
-    plane->mnlanemarktype = ui->comboBox_lanemarktype->currentIndex();
-    plane->mnlanetype = ui->comboBox_lanetype->currentIndex();
+    iv::map::cdalane * plane = pcdadraw->mutable_mlanes(index);
+    plane->set_lanemarkcolor(ui->comboBox_lanecolor->currentIndex());
+    plane->set_lanemarktype(ui->comboBox_lanemarktype->currentIndex());
+    plane->set_lanewidth(flanewidth);
+    plane->set_lanetype(ui->comboBox_lanetype->currentIndex());
     ui->comboBox_Lane->setCurrentIndex(index);
     QMessageBox::information(this,tr("Info"),tr("Change Lane Successfully."),QMessageBox::YesAll);
 }
 
 void DialogAddRoadFromCDA::on_pushButton_geoadd_clicked()
 {
-    iv::cdaroad * pcdaroad = &mcdaroad;
-    iv::cdageo xgeo;
-    xgeo.mflen = ui->lineEdit_geolen->text().toDouble();
-    if(xgeo.mflen <=0)
+    iv::map::cdadraw * pcdadraw = &mcdadraw;
+    double flen = ui->lineEdit_geolen->text().toDouble();
+    if(flen <=0)
     {
         QMessageBox::warning(this,tr("Warning"),tr("Geo Length Error."),QMessageBox::YesAll);
         return;
     }
-    xgeo.mfradius = ui->lineEdit_georadius->text().toDouble();
-    xgeo.mngeotype = ui->comboBox_geoType->currentIndex();
-    if((xgeo.mngeotype == 1) &&(fabs(xgeo.mfradius)<1))
+
+    double fradius = ui->lineEdit_georadius->text().toDouble();
+    int ngeotype = ui->comboBox_geoType->currentIndex();
+    if((ngeotype == 1) &&(fabs(fradius)<1))
     {
         QMessageBox::warning(this,tr("Warning"),tr("Radius Error."),QMessageBox::YesAll);
         return;
     }
-    if(xgeo.mflen <= 0)
+    if(flen <= 0)
     {
         QMessageBox::warning(this,tr("Warning"),tr("geo Length Error."),QMessageBox::YesAll);
         return;
     }
-    int ngeocount = static_cast<int>(pcdaroad->mvectorgeo.size()) ;
-    pcdaroad->mvectorgeo.push_back(xgeo);
-    ui->comboBox_geo->addItem(QString(tr("路段"))+QString::number(ngeocount+1));
-    ui->comboBox_geo->setCurrentIndex(ngeocount);
-
-    int ngeosize = static_cast<int>(pcdaroad->mvectorgeo.size());
+    iv::map::cdageo * pgeo = pcdadraw->add_mgeos();
+    pgeo->set_geolen(flen);
+    pgeo->set_georadius(fradius);
+    pgeo->set_geotype(ngeotype);
+    int ngeocount = static_cast<int>(pcdadraw->mgeos_size()) ;
+    ui->comboBox_geo->addItem(QString(tr("路段"))+QString::number(ngeocount));
+    ui->comboBox_geo->setCurrentIndex(ngeocount-1);
+
+    int ngeosize = static_cast<int>(pcdadraw->mgeos_size());
     int i;
     double fRoadLen = 0;
     for(i=0;i<ngeosize;i++)
     {
-        fRoadLen = fRoadLen + pcdaroad->mvectorgeo[i].mflen;
+        fRoadLen = fRoadLen + pcdadraw->mutable_mgeos(i)->geolen();
     }
     ui->lineEdit_roadlen->setText(QString::number(fRoadLen));
 
@@ -280,17 +317,32 @@ void DialogAddRoadFromCDA::on_pushButton_geoadd_clicked()
 
 void DialogAddRoadFromCDA::on_pushButton_geodel_clicked()
 {
-    iv::cdaroad * pcdaroad = &mcdaroad;
-    if(pcdaroad->mvectorgeo.size() == 0)
+    iv::map::cdadraw * pcdadraw = &mcdadraw;
+    if(pcdadraw->mgeos_size() == 0)
     {
         QMessageBox::warning(this,tr("Warning"),tr("No Geo."),QMessageBox::YesAll);
         return;
     }
     int index = ui->comboBox_geo->currentIndex();
-    pcdaroad->mvectorgeo.erase(pcdaroad->mvectorgeo.begin() + index);
 
-    int nGeocount = static_cast<int>(pcdaroad->mvectorgeo.size());
+
     int i;
+    iv::map::cdadraw xtemp;
+    for(i=0;i<pcdadraw->mgeos_size();i++)
+    {
+        if(i == index)continue;
+        iv::map::cdageo * pgeo = xtemp.add_mgeos();
+        pgeo->CopyFrom(pcdadraw->mgeos(i));
+    }
+    pcdadraw->clear_mgeos();
+    for(i=0;i<xtemp.mgeos_size();i++)
+    {
+        iv::map::cdageo * pgeo = pcdadraw->add_mgeos();
+        pgeo->CopyFrom(xtemp.mgeos(i));
+    }
+
+
+    int nGeocount = static_cast<int>(pcdadraw->mgeos_size());
     ui->comboBox_geo->clear();
     for(i=0;i<nGeocount;i++)
     {
@@ -303,22 +355,22 @@ void DialogAddRoadFromCDA::on_pushButton_geodel_clicked()
     }
     else
     {
-        ui->comboBox_Lane->setCurrentIndex((nGeocount-1));
+        ui->comboBox_geo->setCurrentIndex((nGeocount-1));
     }
 
-    int ngeosize = static_cast<int>(pcdaroad->mvectorgeo.size());
+    int ngeosize = static_cast<int>(pcdadraw->mgeos_size());
     double fRoadLen = 0;
     for(i=0;i<ngeosize;i++)
     {
-        fRoadLen = fRoadLen + pcdaroad->mvectorgeo[i].mflen;
+        fRoadLen = fRoadLen + pcdadraw->mutable_mgeos(i)->geolen();
     }
     ui->lineEdit_roadlen->setText(QString::number(fRoadLen));
 }
 
 void DialogAddRoadFromCDA::on_pushButton_geochange_clicked()
 {
-    iv::cdaroad * pcdaroad = &mcdaroad;
-    if(pcdaroad->mvectorgeo.size() == 0)
+    iv::map::cdadraw * pcdadraw = &mcdadraw;
+    if(pcdadraw->mgeos_size() == 0)
     {
         QMessageBox::warning(this,tr("Warning"),tr("No Geo."),QMessageBox::YesAll);
         return;
@@ -338,20 +390,107 @@ void DialogAddRoadFromCDA::on_pushButton_geochange_clicked()
         return;
     }
 
-    iv::cdageo * pgeo = &pcdaroad->mvectorgeo[index];
-    pgeo->mflen = flen;
-    pgeo->mfradius = fRadius;
-    pgeo->mngeotype = ui->comboBox_geoType->currentIndex();
+    iv::map::cdageo * pgeo = pcdadraw->mutable_mgeos(index);
+    pgeo->set_geolen(flen);
+    pgeo->set_georadius(fRadius);
+    pgeo->set_geotype(ui->comboBox_geoType->currentIndex());
     ui->comboBox_geo->setCurrentIndex(index);
 
-    int ngeosize = static_cast<int>(pcdaroad->mvectorgeo.size());
+    int ngeosize = static_cast<int>(pcdadraw->mgeos_size());
     double fRoadLen = 0;
     int i;
     for(i=0;i<ngeosize;i++)
     {
-        fRoadLen = fRoadLen + pcdaroad->mvectorgeo[i].mflen;
+        fRoadLen = fRoadLen + pcdadraw->mutable_mgeos(i)->geolen();
     }
     ui->lineEdit_roadlen->setText(QString::number(fRoadLen));
 
     QMessageBox::information(this,tr("Info"),tr("Change Lane Successfully."),QMessageBox::YesAll);
 }
+
+
+
+void DialogAddRoadFromCDA::on_pushButton_Save_clicked()
+{
+    iv::map::cdadraw * pcdadraw = &mcdadraw;
+    if(pcdadraw->mlanes_size() == 0)
+    {
+        QMessageBox::warning(this,tr("Warning"),tr("No Lanes."),QMessageBox::YesAll);
+        return;
+    }
+    if(pcdadraw->mgeos_size() == 0)
+    {
+        QMessageBox::warning(this,tr("Waring"),tr("No Geos."),QMessageBox::YesAll);
+        return;
+    }
+
+    QString str = QFileDialog::getSaveFileName(this,tr("Save Data"),".","*.cda");
+    if(str.isEmpty())return;
+    QString strfilepath = str;
+
+    if(strfilepath.right(4) != ".cda")
+    {
+        strfilepath = strfilepath + ".cda";
+    }
+
+    using google::protobuf::TextFormat;
+    using google::protobuf::io::FileOutputStream;
+    using google::protobuf::io::ZeroCopyOutputStream;
+    std::string strout;
+    ZeroCopyOutputStream *output = new google::protobuf::io::StringOutputStream(&strout);//new FileOutputStream(file_descriptor);
+
+    bool success = TextFormat::Print(mcdadraw, output);
+    if(success)
+    {
+        QFile xFile;
+        xFile.setFileName(strfilepath);
+        if(xFile.open(QIODevice::ReadWrite))
+        {
+            xFile.write(strout.data(), static_cast<qint64>(strout.size()));
+            xFile.close();
+        }
+    }
+    delete output;
+}
+
+void DialogAddRoadFromCDA::on_pushButton_Load_clicked()
+{
+    QString str = QFileDialog::getOpenFileName(this,tr("Load Data"),".","*.cda");
+    if(str.isEmpty())return;
+    QString strfilepath = str;
+
+    QFile xFile;
+    xFile.setFileName(strfilepath);
+    QByteArray ba;
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+        ba = xFile.readAll();
+        xFile.close();
+    }
+    else
+    {
+        QMessageBox::warning(this,tr("Warning"),tr("Open File Fail."),QMessageBox::YesAll);
+        return;
+    }
+
+    using google::protobuf::TextFormat;
+    using google::protobuf::io::FileInputStream;
+    using google::protobuf::io::ZeroCopyInputStream;
+    std::string strout;
+    ZeroCopyInputStream *input = new google::protobuf::io::ArrayInputStream(ba.data(),ba.size());//new FileOutputStream(file_descriptor);
+
+    iv::map::cdadraw  xcdadraw;
+    bool success = TextFormat::Parse(input,&xcdadraw);
+    if(success)
+    {
+        mcdadraw.CopyFrom(xcdadraw);
+        UpdateView();
+    }
+    else
+    {
+        QMessageBox::warning(this,tr("Warning"),tr("Load map fail."),QMessageBox::YesAll);
+        delete input;
+        return;
+    }
+    delete input;
+}

+ 8 - 1
src/tool/map_lanetoxodr/dialogaddroadfromcda.h

@@ -6,6 +6,8 @@
 #include "cdaproc.h"
 #include <OpenDrive/OpenDrive.h>
 
+#include "cdadraw.pb.h"
+
 namespace Ui {
 class DialogAddRoadFromCDA;
 }
@@ -37,11 +39,16 @@ private slots:
 
     void on_pushButton_geochange_clicked();
 
+    void on_pushButton_Save_clicked();
+
+    void on_pushButton_Load_clicked();
+
 private:
     Ui::DialogAddRoadFromCDA *ui;
     OpenDrive * mpxodr;
 
-    iv::cdaroad mcdaroad;
+
+    iv::map::cdadraw mcdadraw;
 
 private:
     void UpdateView();

+ 26 - 0
src/tool/map_lanetoxodr/dialogaddroadfromcda.ui

@@ -429,6 +429,32 @@
     <string>车道数量:</string>
    </property>
   </widget>
+  <widget class="QPushButton" name="pushButton_Save">
+   <property name="geometry">
+    <rect>
+     <x>60</x>
+     <y>560</y>
+     <width>161</width>
+     <height>51</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>保存</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_Load">
+   <property name="geometry">
+    <rect>
+     <x>690</x>
+     <y>560</y>
+     <width>161</width>
+     <height>51</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>导入</string>
+   </property>
+  </widget>
  </widget>
  <resources/>
  <connections/>

+ 41 - 41
src/tool/map_lanetoxodr/function/cdaproc.h

@@ -10,50 +10,50 @@
 
 
 
-namespace iv
-{
-struct cdalane
-{
-    int mnlanetype;  // 0 driving  1 ...
-    double mflanewidth;
-    int mnlanemarkcolor;  //0 白色 1 黄色
-    int mnlanemarktype;    //0 虚线 1 实线 2 双虚线  3 双实线  4 虚实线 5 实虚线  6 无
-};
+//namespace iv
+//{
+//struct cdalane
+//{
+//    int mnlanetype;  //"shoulder","border","driving","stop","none","parking","biking","sidewalk","median"
+//    double mflanewidth;
+//    int mnlanemarkcolor;  //0 白色 1 黄色
+//    int mnlanemarktype;    //0 虚线 1 实线 2 双虚线  3 双实线  4 虚实线 5 实虚线  6 无
+//};
 
-struct cdageo
-{
-    int mngeotype;  //直路  弯路  路口
-    double mfradius;  //半径
-    double mflen;   //长度
-};
+//struct cdageo
+//{
+//    int mngeotype;  //直路  弯路  路口
+//    double mfradius;  //半径
+//    double mflen;   //长度
+//};
 
-class cdaroad
-{
-public:
-  int mnclass;  //0 高速公路  1 城市  2 乡村
-  int mnEle;   //0 平路  1 缓上坡  2 上坡  3 缓下坡 4 下坡
-  std::vector<cdageo> mvectorgeo;
-  std::vector<cdalane> mvectorlane;
+//class cdaroad
+//{
+//public:
+//  int mnclass;  //0 高速公路  1 城市  2 乡村
+//  int mnEle;   //0 平路  1 缓上坡  2 上坡  3 缓下坡 4 下坡
+//  std::vector<cdageo> mvectorgeo;
+//  std::vector<cdalane> mvectorlane;
 
-public:
-  cdaroad()
-  {
-      mnclass = 0;
-      mnEle = 0;
-      cdageo xgeo;
-      xgeo.mflen = 100.0;
-      xgeo.mfradius = 100;
-      xgeo.mngeotype = 0;
-      mvectorgeo.push_back(xgeo);
-      cdalane xlane;
-      xlane.mnlanetype = 2;
-      xlane.mflanewidth = 3.75;
-      xlane.mnlanemarkcolor = 0;
-      xlane.mnlanemarktype = 0;
-      mvectorlane.push_back(xlane);
-  }
-};
-}
+//public:
+//  cdaroad()
+//  {
+//      mnclass = 0;
+//      mnEle = 0;
+//      cdageo xgeo;
+//      xgeo.mflen = 100.0;
+//      xgeo.mfradius = 100;
+//      xgeo.mngeotype = 0;
+//      mvectorgeo.push_back(xgeo);
+//      cdalane xlane;
+//      xlane.mnlanetype = 2;
+//      xlane.mflanewidth = 3.75;
+//      xlane.mnlanemarkcolor = 0;
+//      xlane.mnlanemarktype = 0;
+//      mvectorlane.push_back(xlane);
+//  }
+//};
+//}
 
 class CDAProc
 {

+ 1 - 1
src/tool/map_lanetoxodr/gnss_coordinate_convert.h

@@ -1,4 +1,4 @@
-#pragma once
+//#pragma once
 #ifndef _IV_PERCEPTION_GNSS_CONVERT_
 #define _IV_PERCEPTION_GNSS_CONVERT_
 

+ 4 - 2
src/tool/map_lanetoxodr/map_lanetoxodr.pro

@@ -94,7 +94,8 @@ SOURCES += \
     function/autoconnect.cpp \
     dialogaddroadfromcda.cpp \
     excelapi.cpp \
-    function/cdaproc.cpp
+    function/cdaproc.cpp \
+    ../../include/msgtype/cdadraw.pb.cc
 
 HEADERS += \
     function/autoroadcontact.h \
@@ -159,7 +160,8 @@ HEADERS += \
     function/autoconnect.h \
     dialogaddroadfromcda.h \
     excelapi.h \
-    function/cdaproc.h
+    function/cdaproc.h \
+    ../../include/msgtype/cdadraw.pb.h
 
 FORMS += \
         ui/dialogaddroadfromnds.ui \