|
@@ -4,20 +4,101 @@
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
+#include <getopt.h>
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+static char gstr_xodrpath[256];
|
|
|
+static char gstr_osmpath[256];
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief print_useage
|
|
|
+ */
|
|
|
+void print_useage()
|
|
|
+{
|
|
|
+ std::cout<<" -i --input $xodrpath : set input file path. eq. -i /home/yuchuli/line.xodr"<<std::endl;
|
|
|
+ std::cout<<" -o --output $osmpath : set output file. eq. -o /home/yuchuli/line.osm"<<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 = "v:l:e:o:h";
|
|
|
+
|
|
|
+ static struct option long_options[] = {
|
|
|
+ {"input", required_argument, NULL, 'i'},
|
|
|
+ {"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_xodrpath,optarg,255);
|
|
|
+ break;
|
|
|
+ case 'o':
|
|
|
+ strncpy(gstr_osmpath,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);
|
|
|
|
|
|
- odtolanelet * potl = new odtolanelet("/home/yuchuli/line.xodr");
|
|
|
+
|
|
|
+ snprintf(gstr_xodrpath,255,"/home/yuchuli/line.xodr");
|
|
|
+ snprintf(gstr_osmpath,255,"/home/yuchuli/autoware_map/test/lanelet2_map.osm");
|
|
|
+
|
|
|
+
|
|
|
+ int nRtn = GetOptLong(argc,argv);
|
|
|
+ if(nRtn == 1) //show help,so exit.
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ odtolanelet * potl = new odtolanelet(gstr_xodrpath);
|
|
|
|
|
|
int64_t time1 = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
- potl->ConvertToLanelet("/home/yuchuli/autoware_map/test/lanelet2_map.osm");
|
|
|
+ potl->ConvertToLanelet(gstr_osmpath);
|
|
|
int64_t time2 = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
|
|
|
std::cout<<"use time: "<<(time2 - time1)<<std::endl;
|
|
|
|
|
|
+ return 0;
|
|
|
+
|
|
|
return a.exec();
|
|
|
}
|
|
|
|