Browse Source

change map_lanetoxodr. add cdaproc.pro

yuchuli 2 years ago
parent
commit
066271cf76
2 changed files with 256 additions and 0 deletions
  1. 164 0
      src/tool/map_lanetoxodr/cdamain.cpp
  2. 92 0
      src/tool/map_lanetoxodr/cdaproc.pro

+ 164 - 0
src/tool/map_lanetoxodr/cdamain.cpp

@@ -0,0 +1,164 @@
+#include <QCoreApplication>
+
+#include <QDateTime>
+
+#include <getopt.h>
+
+#include <iostream>
+
+#include "ivstdcolorout.h"
+
+#include <QFile>
+
+#include <OpenDrive/OpenDrive.h>
+#include <OpenDrive/OpenDriveXmlWriter.h>
+
+#include "cdaproc.h"
+
+static char gstr_inputpath[256];
+static char gstr_outputpath[256];
+
+/**
+ * @brief print_useage
+ */
+void print_useage()
+{
+    std::cout<<" -i --input $cdafile : set cda input file path. eq.  -i /home/yuchuli/demodata/cda/lk.xlsx"<<std::endl;
+    std::cout<<" -o --output $outputfile : set output file. eq.  -o /home/yuchuli/outputcda.xodr"<<std::endl;
+    std::cout<<" -h --help print help"<<std::endl;
+}
+
+int  GetOptLong(int argc, char *argv[]) {
+    int nRtn = 0;
+    int opt; // getopt_long() 的返回值
+    int digit_optind = 0; // 设置短参数类型及是否需要参数
+    (void)digit_optind;
+
+    // 如果option_index非空,它指向的变量将记录当前找到参数符合long_opts里的
+    // 第几个元素的描述,即是long_opts的下标值
+    int option_index = 0;
+    // 设置短参数类型及是否需要参数
+    const char *optstring = "i:o:h";
+
+    // 设置长参数类型及其简写,比如 --reqarg <==>-r
+    /*
+    struct option {
+             const char * name;  // 参数的名称
+             int has_arg; // 是否带参数值,有三种:no_argument, required_argument,optional_argument
+             int * flag; // 为空时,函数直接将 val 的数值从getopt_long的返回值返回出去,
+                     // 当非空时,val的值会被赋到 flag 指向的整型数中,而函数返回值为0
+             int val; // 用于指定函数找到该选项时的返回值,或者当flag非空时指定flag指向的数据的值
+        };
+    其中:
+        no_argument(即0),表明这个长参数不带参数(即不带数值,如:--name)
+            required_argument(即1),表明这个长参数必须带参数(即必须带数值,如:--name Bob)
+            optional_argument(即2),表明这个长参数后面带的参数是可选的,(即--name和--name Bob均可)
+     */
+    static struct option long_options[] = {
+        {"input", required_argument, NULL, 'v'},
+        {"output", required_argument, NULL, 'o'},
+        {"help",  no_argument,       NULL, 'h'},
+ //       {"optarg", optional_argument, NULL, 'o'},
+        {0, 0, 0, 0}  // 添加 {0, 0, 0, 0} 是为了防止输入空值
+    };
+
+    while ( (opt = getopt_long(argc,
+                               argv,
+                               optstring,
+                               long_options,
+                               &option_index)) != -1) {
+//        printf("opt = %c\n", opt); // 命令参数,亦即 -a -b -n -r
+//        printf("optarg = %s\n", optarg); // 参数内容
+//        printf("optind = %d\n", optind); // 下一个被处理的下标值
+//        printf("argv[optind - 1] = %s\n",  argv[optind - 1]); // 参数内容
+//        printf("option_index = %d\n", option_index);  // 当前打印参数的下标值
+//        printf("\n");
+        switch(opt)
+        {
+        case 'i':
+            strncpy(gstr_inputpath,optarg,255);
+            break;
+        case 'o':
+            strncpy(gstr_outputpath,optarg,255);
+            break;
+        case 'h':
+            print_useage();
+            nRtn = 1; //because use -h
+            break;
+        default:
+            break;
+        }
+
+    }
+
+    return nRtn;
+}
+
+
+
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    snprintf(gstr_inputpath,255," ");
+    snprintf(gstr_outputpath,255," ");
+
+    int nRtn = GetOptLong(argc,argv);
+    if(nRtn == 1)  //show help,so exit.
+    {
+        return 0;
+    }
+
+//    snprintf(gstr_inputpath,255,"/home/yuchuli/demodata/cda/lk.xlsx");
+//    snprintf(gstr_outputpath,255,"/home/yuchuli/outputcda.xodr");
+
+    if(strncmp(gstr_inputpath , " ",255) == 0)
+    {
+        ivstdcolorout("Please use -i set input file path.",iv::STDCOLOR_BOLDRED);
+        print_useage();
+        return 0;
+    }
+
+    char strout[1000];
+    snprintf(strout,1000,"Input File Path: %s",gstr_inputpath);
+    ivstdcolorout(strout,iv::STDCOLOR_BOLDGREEN);
+
+    if(strncmp(gstr_outputpath , " ",255) == 0)
+    {
+        ivstdcolorout("Please use -o set output file path.",iv::STDCOLOR_BOLDRED);
+        print_useage();
+        return 0;
+    }
+
+    snprintf(strout,1000,"Output File Path: %s",gstr_outputpath);
+    ivstdcolorout(strout,iv::STDCOLOR_BOLDGREEN);
+
+
+    OpenDrive xxodr;
+
+    int nrtn = CDAProc::Proc(gstr_inputpath,&xxodr);
+    if(nrtn == 0)
+    {
+        if(xxodr.GetHeader() == NULL)
+        {
+            xxodr.SetHeader(1,1,"adcmap",1.1,QDateTime::currentDateTime().toString("yyyy-MM-dd").toLatin1().data(),0,0,0,0,39.0,117.0,360.0);
+            xxodr.GetHeader()->SetVendor("adc");
+        }
+        else
+        {
+            xxodr.GetHeader()->SetVendor("adc");
+        }
+        snprintf(strout,1000,"Convert OK. out file path: %s ",gstr_outputpath);
+        ivstdcolorout(strout,iv::STDCOLOR_BOLDGREEN);
+        OpenDriveXmlWriter x(&xxodr);
+        x.WriteFile(gstr_outputpath);
+    }
+    else
+    {
+        snprintf(strout,1000," Convert Fail. Fail Code: %d ",nrtn);
+        ivstdcolorout(strout,iv::STDCOLOR_BOLDRED);
+        return nrtn;
+    }
+    return 0;
+}

+ 92 - 0
src/tool/map_lanetoxodr/cdaproc.pro

@@ -0,0 +1,92 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2018-12-14T18:35:51
+#
+#-------------------------------------------------
+
+
+QT       -= gui
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+QMAKE_LFLAGS += -no-pie
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which has been marked as 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 += \
+    cdamain.cpp \
+    TinyXML/tinystr.cpp \
+    TinyXML/tinyxml.cpp \
+    TinyXML/tinyxmlerror.cpp \
+    TinyXML/tinyxmlparser.cpp \
+    const.cpp \
+    fresnl.cpp \
+    polevl.c \
+    function/circlefitting.cpp \
+    function/geofit.cpp \
+    gnss_coordinate_convert.cpp \
+    function/cdaproc.cpp \
+    ../../include/msgtype/cdadraw.pb.cc \
+    excelapi.cpp
+
+
+
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+
+!include(../../common/common/xodr/OpenDrive/OpenDrive.pri ) {
+    error( "Couldn't find the OpenDrive.pri file!" )
+}
+
+!include(../../common/common/xodr/xodrfunc/xodrfunc.pri ) {
+    error( "Couldn't find the xodrfunc.pri file!" )
+}
+
+unix:LIBS += -lboost_thread -lboost_system -lboost_serialization -lprotobuf
+
+
+win32:INCLUDEPATH += $$PWD/../../../thirdpartylib/protobuf/src
+win32:LIBS += -L$$PWD/../../../thirdpartylib/protobuf/lib -lprotobuf
+win32:INCLUDEPATH += $$PWD/../../../thirdpartylib/boost/include/boost-1_66
+windows: LIBS += -L$$PWD/../../../thirdpartylib/boost/lib -lboost_system-mgw73-mt-x64-1_66 -lboost_thread-mgw73-mt-x64-1_66 -lboost_serialization-mgw73-mt-x64-1_66
+
+QMAKE_CXXFLAGS +=  -g
+
+
+INCLUDEPATH += $$PWD/../../common/common/xodr
+INCLUDEPATH += $$PWD/../../common/common/xodr/xodrfunc
+INCLUDEPATH += $$PWD/function
+
+unix:INCLUDEPATH += /usr/include/eigen3
+win32:INCLUDEPATH += D:\File\soft\eigen
+
+DEFINES += NOTINPILOT
+DEFINES += INNDSPROC
+
+DISTFILES += \
+    TinyXML/TinyXML.pri
+
+HEADERS += \
+    TinyXML/tinystr.h \
+    TinyXML/tinyxml.h \
+    function/circlefitting.h \
+    function/geofit.h \
+    gnss_coordinate_convert.h \
+    function/cdaproc.h \
+    ../../include/msgtype/cdadraw.pb.h \
+    excelapi.h
+
+