cdaproc.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. #include "cdaproc.h"
  2. #include <iostream>
  3. #include <math.h>
  4. static std::string cda_lanetype_sel[9] = {"shoulder","border","driving","stop","none","parking","biking","sidewalk",
  5. "median"};
  6. static std::string cda_lanemarkcolor_sel[2] = {"standard","yellow"};
  7. static std::string cda_lanemarktype_sel[7] = {"broken","solid","broken broken","solid solid","broken solid","solid broken","none"};
  8. CDAProc::CDAProc()
  9. {
  10. }
  11. static void OffRotate(double nowx,double nowy,double nowhdg,double rel_x,double rel_y,double rel_hdg,double & a_x,double & a_y,double & a_hdg)
  12. {
  13. a_x = nowx + rel_x * cos(nowhdg) - rel_y * sin(nowhdg) ;
  14. a_y= nowy + rel_x * sin(nowhdg) + rel_y * cos(nowhdg) ;
  15. a_hdg = rel_hdg+ nowhdg;
  16. if(a_hdg> 2.0*M_PI)a_hdg = a_hdg - 2.0*M_PI;
  17. }
  18. int CDAProc::ProcIntersectionRoad(OpenDrive * pxodr, iv::map::cdadraw * pcdadraw,int ngeo,int & nroadid,double & nowx,double & nowy, double & nowhdg)
  19. {
  20. iv::map::cdageo * pgeo = pcdadraw->mutable_mgeos(ngeo);
  21. double fRoadLen = pgeo->geolen();
  22. // double flanewidth = atof(strlanewidth.data());
  23. std::vector<double> xvectorlanewidth;
  24. int i;
  25. for(i=0;i<pcdadraw->mlanes_size();i++)
  26. {
  27. xvectorlanewidth.push_back(pcdadraw->mutable_mlanes(i)->lanewidth());
  28. }
  29. double flanewidth11 = 0;
  30. for(i=0;i<(pcdadraw->mlanes_size()-1);i++)
  31. {
  32. flanewidth11 = flanewidth11 + xvectorlanewidth[i];
  33. }
  34. int nlanecount = pcdadraw->mlanes_size();
  35. if(nlanecount<=0)
  36. {
  37. std::cout<<" no lane "<<std::endl;
  38. return -1;
  39. }
  40. double fdefradius = 6.0;
  41. double finsectlen = fdefradius*2.0 + 2.0*flanewidth11;
  42. if(fRoadLen < (finsectlen+10.0))
  43. {
  44. fRoadLen = finsectlen + 10.0;
  45. }
  46. double flinelen = (fRoadLen -finsectlen)/2.0;
  47. double flinex[4],fliney[4],flinehdg[4];
  48. flinex[0] = 0;fliney[0]=0;flinehdg[0] = 0;
  49. flinex[1] = fRoadLen*(0.5);fliney[1] = fRoadLen*(-0.5); flinehdg[1] = M_PI/2.0;
  50. flinex[2] = fRoadLen*0.5 + finsectlen*0.5;fliney[2] = 0; flinehdg[2] = 0;
  51. flinex[3] = fRoadLen*(0.5);fliney[3] = finsectlen*0.5; flinehdg[3] = M_PI/2.0;
  52. double flinex_c[4],fliney_c[4],flinehdg_c[4];
  53. double nowx_n,nowy_n,nowhdg_n;
  54. for(i=0;i<4;i++)
  55. {
  56. flinex_c[i] = nowx + flinex[i] * cos(nowhdg) - fliney[i] * sin(nowhdg) ;
  57. fliney_c[i] = nowy + flinex[i] * sin(nowhdg) + fliney[i] * cos(nowhdg) ;
  58. flinehdg_c[i] = flinehdg[i] + nowhdg;
  59. if(flinehdg_c[i]> 2.0*M_PI)flinehdg_c[i] = flinehdg_c[i] - 2.0*M_PI;
  60. char strroadid[100];
  61. nroadid++;
  62. snprintf(strroadid,100,"%d",nroadid);
  63. pxodr->AddRoad("zl",flinelen,strroadid,"-1");
  64. Road * pRoad = pxodr->GetLastAddedRoad();
  65. pRoad->AddGeometryBlock();
  66. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  67. pgeob->AddGeometryLine(0,flinex_c[i],fliney_c[i],flinehdg_c[i],flinelen);
  68. pRoad->AddLaneSection(0);
  69. LaneSection * pLS = pRoad->GetLaneSection(0);
  70. pLS->AddLane(0,0,"none",false);
  71. Lane * pcenterlane = pLS->GetLastAddedLane();
  72. pcenterlane->AddRoadMarkRecord(0,"solid solid","standard","yellow",0.15,"none");
  73. int j;
  74. for(j=0;j<nlanecount;j++)
  75. {
  76. iv::map::cdalane * pcdalane = pcdadraw->mutable_mlanes(j);
  77. pLS->AddLane(-1,(j+1)*(-1),cda_lanetype_sel[pcdalane->lanetype()],false,true);
  78. Lane * pnewlane = pLS->GetLastAddedLane();
  79. pnewlane->AddWidthRecord(0,pcdalane->lanewidth(),0,0,0);
  80. pnewlane->AddRoadMarkRecord(0,cda_lanemarktype_sel[pcdalane->lanemarktype()],"standard",cda_lanemarkcolor_sel[pcdalane->lanemarkcolor()],pcdalane->lanemarkwidth(),"none");
  81. pLS->AddLane(1,(j+1)*(1),cda_lanetype_sel[pcdalane->lanetype()],false,true);
  82. pnewlane = pLS->GetLastAddedLane();
  83. pnewlane->AddWidthRecord(0,pcdalane->lanewidth(),0,0,0);
  84. pnewlane->AddRoadMarkRecord(0,cda_lanemarktype_sel[pcdalane->lanemarktype()],"standard",cda_lanemarkcolor_sel[pcdalane->lanemarkcolor()],pcdalane->lanemarkwidth(),"none");
  85. }
  86. if(i==2)
  87. {
  88. pRoad->GetGeometryCoords(pRoad->GetRoadLength(),nowx_n,nowy_n,nowhdg_n);
  89. }
  90. }
  91. double frightlen = fdefradius * M_PI/2.0;
  92. double frightx[4],frighty[4],frighthdg[4];
  93. frightx[0] = flinelen;frighty[0] = flanewidth11*(-1);frighthdg[0] = 0;
  94. frightx[1] = fRoadLen*0.5 + flanewidth11 ;frighty[1] = finsectlen*(-0.5);frighthdg[1] = M_PI/2.0;
  95. frightx[2] = fRoadLen*0.5 + finsectlen*0.5;frighty[2] = flanewidth11*(1);frighthdg[2] = M_PI;
  96. frightx[3] = fRoadLen*0.5 - flanewidth11;frighty[3] = finsectlen*0.5;frighthdg[3] = 3.0*M_PI/2.0;
  97. for(i=0;i<4;i++)
  98. {
  99. flinex_c[i] = nowx + frightx[i] * cos(nowhdg) - frighty[i] * sin(nowhdg) ;
  100. fliney_c[i] = nowy + frightx[i] * sin(nowhdg) + frighty[i] * cos(nowhdg) ;
  101. flinehdg_c[i] = frighthdg[i] + nowhdg;
  102. if(flinehdg_c[i]> 2.0*M_PI)flinehdg_c[i] = flinehdg_c[i] - 2.0*M_PI;
  103. char strroadid[100];
  104. nroadid++;
  105. snprintf(strroadid,100,"%d",nroadid);
  106. pxodr->AddRoad("zl",flinelen,strroadid,"-1");
  107. Road * pRoad = pxodr->GetLastAddedRoad();
  108. pRoad->AddGeometryBlock();
  109. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  110. pgeob->AddGeometryArc(0,flinex_c[i],fliney_c[i],flinehdg_c[i],frightlen,-1.0/fdefradius);
  111. pRoad->AddLaneSection(0);
  112. LaneSection * pLS = pRoad->GetLaneSection(0);
  113. pLS->AddLane(0,0,"none",false);
  114. // Lane * pcenterlane = pLS->GetLastAddedLane();
  115. // pcenterlane->AddRoadMarkRecord(0,"solid","standard","yellow",0.15,"none");
  116. iv::map::cdalane * pcdalane = pcdadraw->mutable_mlanes(pcdadraw->mlanes_size()-1);
  117. pLS->AddLane(-1,-1,cda_lanetype_sel[pcdalane->lanetype()],false,true);
  118. Lane * pnewlane = pLS->GetLastAddedLane();
  119. pnewlane->AddWidthRecord(0,pcdadraw->mutable_mlanes(pcdadraw->mlanes_size()-1)->lanewidth(),0,0,0);
  120. }
  121. double fleftx[4],flefty[4],flefthdg[4];
  122. fleftx[0] = flinelen;flefty[0] = 0;flefthdg[0] = 0;
  123. fleftx[1] = fRoadLen*0.5;flefty[1] = finsectlen*(-0.5);flefthdg[1] = M_PI/2.0;
  124. fleftx[2] = flinelen+finsectlen;flefty[2] = 0;flefthdg[2] = M_PI;
  125. fleftx[3] = fRoadLen*0.5;flefty[3] = finsectlen*0.5;flefthdg[3] = 3.0*M_PI/2.0;
  126. for(i=0;i<4;i++)
  127. {
  128. double fleftlinelen = 0.5*finsectlen - fdefradius;
  129. double fleftarcx = fleftx[i] + fleftlinelen * cos(flefthdg[i]);
  130. double fleftarcy = flefty[i] + fleftlinelen * sin(flefthdg[i]);
  131. double fleftarchdg = flefthdg[i];
  132. double a_x,a_y,a_hdg;
  133. char strroadid[100];
  134. nroadid++;
  135. snprintf(strroadid,100,"%d",nroadid);
  136. pxodr->AddRoad("zl",fleftlinelen*2.0+fdefradius*M_PI/2.0,strroadid,"-1");
  137. Road * pRoad = pxodr->GetLastAddedRoad();
  138. GeometryBlock * pgeob;
  139. if(fleftlinelen >0.00000000001)
  140. {
  141. pRoad->AddGeometryBlock();
  142. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  143. OffRotate(nowx,nowy,nowhdg,fleftx[i],flefty[i],flefthdg[i],a_x,a_y,a_hdg);
  144. pgeob->AddGeometryLine(0,a_x,a_y,a_hdg,fleftlinelen);
  145. }
  146. pRoad->AddGeometryBlock();
  147. pgeob= pRoad->GetLastAddedGeometryBlock();
  148. OffRotate(nowx,nowy,nowhdg,fleftarcx,fleftarcy,fleftarchdg,a_x,a_y,a_hdg);
  149. pgeob->AddGeometryArc(fleftlinelen,a_x,a_y,a_hdg,fdefradius*M_PI/2.0,1.0/fdefradius);
  150. if(fleftlinelen >0.00000000001)
  151. {
  152. pRoad->AddGeometryBlock();
  153. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  154. OffRotate(nowx,nowy,nowhdg,fleftarcx + fdefradius*cos(flefthdg[i]) + fdefradius*cos(flefthdg[i] + M_PI/2.0) ,
  155. fleftarcy + fdefradius*sin(flefthdg[i]) + fdefradius*sin(flefthdg[i] + M_PI/2.0),flefthdg[i] +M_PI/2.0,a_x,a_y,a_hdg);
  156. pgeob->AddGeometryLine(fleftlinelen + fdefradius*M_PI/2.0,a_x,a_y,a_hdg,fleftlinelen);
  157. }
  158. pRoad->AddLaneSection(0);
  159. LaneSection * pLS = pRoad->GetLaneSection(0);
  160. pLS->AddLane(0,0,"none",false);
  161. // Lane * pcenterlane = pLS->GetLastAddedLane();
  162. // pcenterlane->AddRoadMarkRecord(0,"solid","standard","yellow",0.15,"none");
  163. iv::map::cdalane * pcdalane = pcdadraw->mutable_mlanes(0);
  164. pLS->AddLane(-1,-1,cda_lanetype_sel[pcdalane->lanetype()],false,true);
  165. Lane * pnewlane = pLS->GetLastAddedLane();
  166. pnewlane->AddWidthRecord(0,pcdadraw->mutable_mlanes(0)->lanewidth(),0,0,0);
  167. }
  168. double finlinex[4],finliney[4],finlinehdg[4];
  169. finlinex[0] = flinelen;finliney[0] = 0;finlinehdg[0] = 0;
  170. finlinex[1] = fRoadLen*0.5;finliney[1] = finsectlen*(-0.5);finlinehdg[1] = M_PI/2.0;
  171. finlinex[2] = flinelen+finsectlen;finliney[2] = 0;finlinehdg[2] = M_PI;
  172. finlinex[3] = fRoadLen*0.5;finliney[3] = finsectlen*0.5;finlinehdg[3] = 3.0*M_PI/2.0;
  173. for(i=0;i<4;i++)
  174. {
  175. char strroadid[100];
  176. nroadid++;
  177. snprintf(strroadid,100,"%d",nroadid);
  178. pxodr->AddRoad("zl",flinelen,strroadid,"-1");
  179. Road * pRoad = pxodr->GetLastAddedRoad();
  180. pRoad->AddGeometryBlock();
  181. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  182. double a_x,a_y,a_hdg;
  183. OffRotate(nowx,nowy,nowhdg,finlinex[i],finliney[i],finlinehdg[i],a_x,a_y,a_hdg);
  184. pgeob->AddGeometryLine(0,a_x,a_y,a_hdg,finsectlen);
  185. pRoad->AddLaneSection(0);
  186. LaneSection * pLS = pRoad->GetLaneSection(0);
  187. pLS->AddLane(0,0,"none",false);
  188. // Lane * pcenterlane = pLS->GetLastAddedLane();
  189. // pcenterlane->AddRoadMarkRecord(0,"solid solid","standard","yellow",0.15,"none");
  190. int j;
  191. for(j=0;j<nlanecount;j++)
  192. {
  193. iv::map::cdalane * pcdalane = pcdadraw->mutable_mlanes(j);
  194. pLS->AddLane(-1,(j+1)*(-1),cda_lanetype_sel[pcdalane->lanetype()],false,true);
  195. Lane * pnewlane = pLS->GetLastAddedLane();
  196. pnewlane->AddWidthRecord(0,pcdalane->lanewidth(),0,0,0);
  197. pLS->AddLane(1,(j+1)*(1),cda_lanetype_sel[pcdalane->lanetype()],false,true);
  198. pnewlane = pLS->GetLastAddedLane();
  199. pnewlane->AddWidthRecord(0,pcdalane->lanewidth(),0,0,0);
  200. }
  201. }
  202. nowx = nowx_n;
  203. nowy = nowy_n;
  204. nowhdg = nowhdg_n;
  205. }
  206. int CDAProc::ProcIntersectionRoad(OpenDrive * pxodr, std::string strtype,std::string strradius,std::string strroadlen,std::string strlanewidth,
  207. std::string strlannecount,std::string strlanetype,std::string strlanemarkcolor,std::string strlanemarktype)
  208. {
  209. double fRoadLen = atof(strroadlen.data());
  210. double flanewidth = atof(strlanewidth.data());
  211. int nlanecount = atoi(strlannecount.data());
  212. if(flanewidth<=0)flanewidth = 3.5;
  213. if(nlanecount<=0)nlanecount = 1;
  214. double fdefradius = 6.0;
  215. double finsectlen = fdefradius*2.0 + 2.0*(flanewidth*(nlanecount-1));
  216. if(fRoadLen < (finsectlen+10.0))
  217. {
  218. fRoadLen = finsectlen + 10.0;
  219. }
  220. double flinelen = (fRoadLen -finsectlen)/2.0;
  221. double flinex[4],fliney[4],flinehdg[4];
  222. flinex[0] = 0;fliney[0]=0;flinehdg[0] = 0;
  223. flinex[1] = fRoadLen*(0.5);fliney[1] = fRoadLen*(-0.5); flinehdg[1] = M_PI/2.0;
  224. flinex[2] = fRoadLen*0.5 + finsectlen*0.5;fliney[2] = 0; flinehdg[2] = 0;
  225. flinex[3] = fRoadLen*(0.5);fliney[3] = finsectlen*0.5; flinehdg[3] = M_PI/2.0;
  226. int i;
  227. for(i=0;i<4;i++)
  228. {
  229. char strroadid[100];
  230. snprintf(strroadid,100,"%d",i+1);
  231. pxodr->AddRoad("zl",flinelen,strroadid,"-1");
  232. Road * pRoad = pxodr->GetLastAddedRoad();
  233. pRoad->AddGeometryBlock();
  234. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  235. pgeob->AddGeometryLine(0,flinex[i],fliney[i],flinehdg[i],flinelen);
  236. pRoad->AddLaneSection(0);
  237. LaneSection * pLS = pRoad->GetLaneSection(0);
  238. pLS->AddLane(0,0,"none",false);
  239. Lane * pcenterlane = pLS->GetLastAddedLane();
  240. pcenterlane->AddRoadMarkRecord(0,"solid solid","standard","yellow",0.15,"none");
  241. int j;
  242. for(j=0;j<nlanecount;j++)
  243. {
  244. pLS->AddLane(-1,(j+1)*(-1),"driving",false,true);
  245. Lane * pnewlane = pLS->GetLastAddedLane();
  246. pnewlane->AddWidthRecord(0,flanewidth,0,0,0);
  247. if(j == (nlanecount -1))
  248. {
  249. pnewlane->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"none");
  250. }
  251. else
  252. {
  253. std::string type = "broken";
  254. if(strlanemarktype == "实线")type = "solid";
  255. std::string color = "standard";
  256. if(strlanemarkcolor == "黄色")color = "yellow";
  257. pnewlane->AddRoadMarkRecord(0,type,"standard",color,0.15,"none");
  258. // pnewlane->AddRoadMarkRecord(0,"broken","standard","standard",0.15,"none");
  259. }
  260. pLS->AddLane(1,(j+1)*(1),"driving",false,true);
  261. pnewlane = pLS->GetLastAddedLane();
  262. pnewlane->AddWidthRecord(0,flanewidth,0,0,0);
  263. if(j == (nlanecount -1))
  264. {
  265. pnewlane->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"none");
  266. }
  267. else
  268. {
  269. std::string type = "broken";
  270. if(strlanemarktype == "实线")type = "solid";
  271. std::string color = "standard";
  272. if(strlanemarkcolor == "黄色")color = "yellow";
  273. pnewlane->AddRoadMarkRecord(0,type,"standard",color,0.15,"none");
  274. // pnewlane->AddRoadMarkRecord(0,"broken","standard","standard",0.15,"none");
  275. }
  276. }
  277. }
  278. double frightlen = fdefradius * M_PI/2.0;
  279. double frightx[4],frighty[4],frighthdg[4];
  280. frightx[0] = flinelen;frighty[0] = flanewidth*(nlanecount-1)*(-1);frighthdg[0] = 0;
  281. frightx[1] = fRoadLen*0.5 + flanewidth*(nlanecount-1) ;frighty[1] = finsectlen*(-0.5);frighthdg[1] = M_PI/2.0;
  282. frightx[2] = fRoadLen*0.5 + finsectlen*0.5;frighty[2] = flanewidth*(nlanecount-1)*(1);frighthdg[2] = M_PI;
  283. frightx[3] = fRoadLen*0.5 - flanewidth*(nlanecount-1);frighty[3] = finsectlen*0.5;frighthdg[3] = 3.0*M_PI/2.0;
  284. for(i=0;i<4;i++)
  285. {
  286. char strroadid[100];
  287. snprintf(strroadid,100,"%d",i+5);
  288. pxodr->AddRoad("zl",flinelen,strroadid,"-1");
  289. Road * pRoad = pxodr->GetLastAddedRoad();
  290. pRoad->AddGeometryBlock();
  291. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  292. pgeob->AddGeometryArc(0,frightx[i],frighty[i],frighthdg[i],frightlen,-1.0/fdefradius);
  293. pRoad->AddLaneSection(0);
  294. LaneSection * pLS = pRoad->GetLaneSection(0);
  295. pLS->AddLane(0,0,"none",false);
  296. // Lane * pcenterlane = pLS->GetLastAddedLane();
  297. // pcenterlane->AddRoadMarkRecord(0,"solid","standard","yellow",0.15,"none");
  298. pLS->AddLane(-1,-1,"driving",false,true);
  299. Lane * pnewlane = pLS->GetLastAddedLane();
  300. pnewlane->AddWidthRecord(0,flanewidth,0,0,0);
  301. }
  302. double fleftx[4],flefty[4],flefthdg[4];
  303. fleftx[0] = flinelen;flefty[0] = 0;flefthdg[0] = 0;
  304. fleftx[1] = fRoadLen*0.5;flefty[1] = finsectlen*(-0.5);flefthdg[1] = M_PI/2.0;
  305. fleftx[2] = flinelen+finsectlen;flefty[2] = 0;flefthdg[2] = M_PI;
  306. fleftx[3] = fRoadLen*0.5;flefty[3] = finsectlen*0.5;flefthdg[3] = 3.0*M_PI/2.0;
  307. for(i=0;i<4;i++)
  308. {
  309. double fleftlinelen = 0.5*finsectlen - fdefradius;
  310. double fleftarcx = fleftx[i] + fleftlinelen * cos(flefthdg[i]);
  311. double fleftarcy = flefty[i] + fleftlinelen * sin(flefthdg[i]);
  312. double fleftarchdg = flefthdg[i];
  313. char strroadid[100];
  314. snprintf(strroadid,100,"%d",i+9);
  315. pxodr->AddRoad("zl",fleftlinelen*2.0+fdefradius*M_PI/2.0,strroadid,"-1");
  316. Road * pRoad = pxodr->GetLastAddedRoad();
  317. GeometryBlock * pgeob;
  318. if(fleftlinelen >0.00000000001)
  319. {
  320. pRoad->AddGeometryBlock();
  321. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  322. pgeob->AddGeometryLine(0,fleftx[i],flefty[i],flefthdg[i],fleftlinelen);
  323. }
  324. pRoad->AddGeometryBlock();
  325. pgeob= pRoad->GetLastAddedGeometryBlock();
  326. pgeob->AddGeometryArc(fleftlinelen,fleftarcx,fleftarcy,fleftarchdg,fdefradius*M_PI/2.0,1.0/fdefradius);
  327. if(fleftlinelen >0.00000000001)
  328. {
  329. pRoad->AddGeometryBlock();
  330. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  331. pgeob->AddGeometryLine(fleftlinelen + fdefradius*M_PI/2.0,fleftarcx + fdefradius*cos(flefthdg[i]) + fdefradius*cos(flefthdg[i] + M_PI/2.0) ,
  332. fleftarcy + fdefradius*sin(flefthdg[i]) + fdefradius*sin(flefthdg[i] + M_PI/2.0),flefthdg[i] +M_PI/2.0,fleftlinelen);
  333. }
  334. pRoad->AddLaneSection(0);
  335. LaneSection * pLS = pRoad->GetLaneSection(0);
  336. pLS->AddLane(0,0,"none",false);
  337. // Lane * pcenterlane = pLS->GetLastAddedLane();
  338. // pcenterlane->AddRoadMarkRecord(0,"solid","standard","yellow",0.15,"none");
  339. pLS->AddLane(-1,-1,"driving",false,true);
  340. Lane * pnewlane = pLS->GetLastAddedLane();
  341. pnewlane->AddWidthRecord(0,flanewidth,0,0,0);
  342. }
  343. double finlinex[4],finliney[4],finlinehdg[4];
  344. finlinex[0] = flinelen;finliney[0] = 0;finlinehdg[0] = 0;
  345. finlinex[1] = fRoadLen*0.5;finliney[1] = finsectlen*(-0.5);finlinehdg[1] = M_PI/2.0;
  346. finlinex[2] = flinelen+finsectlen;finliney[2] = 0;finlinehdg[2] = M_PI;
  347. finlinex[3] = fRoadLen*0.5;finliney[3] = finsectlen*0.5;finlinehdg[3] = 3.0*M_PI/2.0;
  348. for(i=0;i<4;i++)
  349. {
  350. char strroadid[100];
  351. snprintf(strroadid,100,"%d",i+13);
  352. pxodr->AddRoad("zl",flinelen,strroadid,"-1");
  353. Road * pRoad = pxodr->GetLastAddedRoad();
  354. pRoad->AddGeometryBlock();
  355. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  356. pgeob->AddGeometryLine(0,finlinex[i],finliney[i],finlinehdg[i],finsectlen);
  357. pRoad->AddLaneSection(0);
  358. LaneSection * pLS = pRoad->GetLaneSection(0);
  359. pLS->AddLane(0,0,"none",false);
  360. // Lane * pcenterlane = pLS->GetLastAddedLane();
  361. // pcenterlane->AddRoadMarkRecord(0,"solid solid","standard","yellow",0.15,"none");
  362. int j;
  363. for(j=0;j<nlanecount;j++)
  364. {
  365. pLS->AddLane(-1,(j+1)*(-1),"driving",false,true);
  366. Lane * pnewlane = pLS->GetLastAddedLane();
  367. pnewlane->AddWidthRecord(0,flanewidth,0,0,0);
  368. // if(j == (nlanecount -1))
  369. // {
  370. // pnewlane->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"none");
  371. // }
  372. // else
  373. // pnewlane->AddRoadMarkRecord(0,"broken","standard","standard",0.15,"none");
  374. pLS->AddLane(1,(j+1)*(1),"driving",false,true);
  375. pnewlane = pLS->GetLastAddedLane();
  376. pnewlane->AddWidthRecord(0,flanewidth,0,0,0);
  377. // if(j == (nlanecount -1))
  378. // {
  379. // pnewlane->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"none");
  380. // }
  381. // else
  382. // pnewlane->AddRoadMarkRecord(0,"broken","standard","standard",0.15,"none");
  383. }
  384. }
  385. return 0;
  386. }
  387. int CDAProc::ProcArcRoad(OpenDrive * pxodr, std::string strtype,std::string strradius,std::string strroadlen,std::string strlanewidth,
  388. std::string strlannecount,std::string strlanetype,std::string strlanemarkcolor,std::string strlanemarktype)
  389. {
  390. double fRoadLen = atof(strroadlen.data());
  391. double fRadius = atof(strradius.data());
  392. if(fabs(fRadius) < 0.000000000000001)return -5;
  393. pxodr->AddRoad("wd",fRoadLen,"1","-1");
  394. Road * pRoad = pxodr->GetLastAddedRoad();
  395. double fArcLen = fabs(fRadius) * M_PI/2.0;
  396. bool bHaveLine = false;
  397. double fxline,fyline,fhdgline,flinelen;
  398. if(fArcLen>=fRoadLen)
  399. {
  400. fArcLen = fRoadLen;
  401. }
  402. else
  403. {
  404. bHaveLine = true;
  405. flinelen = fRoadLen - fArcLen;
  406. fxline = fabs(fRadius);
  407. fyline = fRadius;
  408. fhdgline = (fyline/fxline)*(M_PI/2.0);
  409. }
  410. pRoad->AddGeometryBlock();
  411. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  412. pgeob->AddGeometryArc(0,0,0,0,fArcLen,1.0/fRadius);
  413. if(bHaveLine == true)
  414. {
  415. pRoad->AddGeometryBlock();
  416. pgeob = pRoad->GetLastAddedGeometryBlock();
  417. pgeob->AddGeometryLine(fArcLen,fxline,fyline,fhdgline,flinelen);
  418. }
  419. pRoad->AddLaneSection(0);
  420. LaneSection * pLS = pRoad->GetLaneSection(0);
  421. pLS->AddLane(0,0,"none",false);
  422. Lane * pcenterlane = pLS->GetLastAddedLane();
  423. pcenterlane->AddRoadMarkRecord(0,"solid","standard","yellow",0.15,"none");
  424. int nlanecount = atoi(strlannecount.data());
  425. double flanewidth = atof(strlanewidth.data());
  426. int i;
  427. for(i=0;i<nlanecount;i++)
  428. {
  429. pLS->AddLane(-1,(i+1)*(-1),"driving",false,true);
  430. Lane * pnewlane = pLS->GetLastAddedLane();
  431. pnewlane->AddWidthRecord(0,flanewidth,0,0,0);
  432. if(i == (nlanecount -1))
  433. {
  434. pnewlane->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"none");
  435. }
  436. else
  437. {
  438. std::string type = "broken";
  439. if(strlanemarktype == "实线")type = "solid";
  440. std::string color = "standard";
  441. if(strlanemarkcolor == "黄色")color = "yellow";
  442. pnewlane->AddRoadMarkRecord(0,type,"standard",color,0.15,"none");
  443. // pnewlane->AddRoadMarkRecord(0,"broken","standard","standard",0.15,"none");
  444. }
  445. }
  446. return 0;
  447. }
  448. int CDAProc::ProcLineRoad(OpenDrive * pxodr, std::string strtype,std::string strradius,std::string strroadlen,std::string strlanewidth,
  449. std::string strlannecount,std::string strlanetype,std::string strlanemarkcolor,std::string strlanemarktype)
  450. {
  451. pxodr->AddRoad("zl",atof(strroadlen.data()),"1","-1");
  452. Road * pRoad = pxodr->GetLastAddedRoad();
  453. pRoad->AddGeometryBlock();
  454. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  455. pgeob->AddGeometryLine(0,0,0,0,atof(strroadlen.data()));
  456. pRoad->AddLaneSection(0);
  457. LaneSection * pLS = pRoad->GetLaneSection(0);
  458. pLS->AddLane(0,0,"none",false);
  459. Lane * pcenterlane = pLS->GetLastAddedLane();
  460. pcenterlane->AddRoadMarkRecord(0,"solid","standard","yellow",0.15,"none");
  461. int nlanecount = atoi(strlannecount.data());
  462. double flanewidth = atof(strlanewidth.data());
  463. int i;
  464. for(i=0;i<nlanecount;i++)
  465. {
  466. pLS->AddLane(-1,(i+1)*(-1),"driving",false,true);
  467. Lane * pnewlane = pLS->GetLastAddedLane();
  468. pnewlane->AddWidthRecord(0,flanewidth,0,0,0);
  469. if(i == (nlanecount -1))
  470. {
  471. pnewlane->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"none");
  472. }
  473. else
  474. {
  475. std::string type = "broken";
  476. if(strlanemarktype == "实线")type = "solid";
  477. std::string color = "standard";
  478. if(strlanemarkcolor == "黄色")color = "yellow";
  479. pnewlane->AddRoadMarkRecord(0,type,"standard",color,0.15,"none");
  480. // pnewlane->AddRoadMarkRecord(0,"broken","standard","standard",0.15,"none");
  481. }
  482. }
  483. return 0;
  484. }
  485. int CDAProc::ProcRoad(OpenDrive * pxodr, std::string strtype,std::string strradius,std::string strroadlen,std::string strlanewidth,
  486. std::string strlannecount,std::string strlanetype,std::string strlanemarkcolor,std::string strlanemarktype)
  487. {
  488. if(atof(strroadlen.data())<0.00000001)
  489. {
  490. return -2;
  491. }
  492. if(atof(strlanewidth.data())<0.00000001)
  493. {
  494. return -3;
  495. }
  496. if(atoi(strlannecount.data())<1)
  497. {
  498. return -4;
  499. }
  500. if(strtype == "直路" )
  501. {
  502. std::cout<<" is zl . "<<std::endl;
  503. return ProcLineRoad(pxodr,strtype,strradius,strroadlen,strlanewidth,strlannecount,strlanetype,strlanemarkcolor,strlanemarktype);
  504. }
  505. if(strtype == "弯路" )
  506. {
  507. std::cout<<" is wl . "<<std::endl;
  508. return ProcArcRoad(pxodr,strtype,strradius,strroadlen,strlanewidth,strlannecount,strlanetype,strlanemarkcolor,strlanemarktype);
  509. }
  510. if(strtype == "路口" )
  511. {
  512. std::cout<<" is lk . "<<std::endl;
  513. return ProcIntersectionRoad(pxodr,strtype,strradius,strroadlen,strlanewidth,strlannecount,strlanetype,strlanemarkcolor,strlanemarktype);
  514. }
  515. return -1;
  516. }
  517. int CDAProc::Proc(std::string strxlsxpath,OpenDrive * pxodr)
  518. {
  519. void * pexcel = ServiceExcelAPI.Openxlsx(strxlsxpath);
  520. std::string strtype;
  521. std::string strradius;
  522. std::string strroadlen;
  523. std::string strlanewidth;
  524. std::string strlannecount;
  525. std::string strlanetype;
  526. std::string strlanemarkcolor;
  527. std::string strlanemarktype;
  528. ServiceExcelAPI.getcellvalue(pexcel,119,4,strtype);
  529. ServiceExcelAPI.getcellvalue(pexcel,120,4,strradius);
  530. ServiceExcelAPI.getcellvalue(pexcel,121,4,strroadlen);
  531. ServiceExcelAPI.getcellvalue(pexcel,122,4,strlanewidth);
  532. ServiceExcelAPI.getcellvalue(pexcel,123,4,strlannecount);
  533. // ServiceExcelAPI.getcellvalue(pexcel,124,4,strlanetype);
  534. ServiceExcelAPI.getcellvalue(pexcel,124,4,strlanemarkcolor);
  535. ServiceExcelAPI.getcellvalue(pexcel,125,4,strlanemarktype);
  536. std::cout<<"type : "<<strtype<<std::endl;
  537. ServiceExcelAPI.Closexlsx(pexcel);
  538. return ProcRoad(pxodr,strtype,strradius,strroadlen,strlanewidth,strlannecount,strlanemarktype,strlanemarkcolor,strlanemarktype);
  539. }
  540. #include <QDateTime>
  541. #include <OpenDrive/OpenDriveXmlWriter.h>
  542. int CDAProc::ProcRoads(std::string strxlsxpath,std::string stroutpath)
  543. {
  544. void * pexcel = ServiceExcelAPI.Openxlsx(strxlsxpath);
  545. std::string strtype;
  546. std::string strradius;
  547. std::string strroadlen;
  548. std::string strlanewidth;
  549. std::string strlannecount;
  550. std::string strlanetype;
  551. std::string strlanemarkcolor;
  552. std::string strlanemarktype;
  553. std::string strname;
  554. bool bComplete = false;
  555. int i = 4;
  556. int nr = 0;
  557. while(bComplete == false)
  558. {
  559. strtype = "";
  560. strname = "";
  561. ServiceExcelAPI.getcellvalue(pexcel,26,i,strname);
  562. ServiceExcelAPI.getcellvalue(pexcel,119,i,strtype);
  563. ServiceExcelAPI.getcellvalue(pexcel,120,i,strradius);
  564. ServiceExcelAPI.getcellvalue(pexcel,121,i,strroadlen);
  565. ServiceExcelAPI.getcellvalue(pexcel,122,i,strlanewidth);
  566. ServiceExcelAPI.getcellvalue(pexcel,123,i,strlannecount);
  567. // ServiceExcelAPI.getcellvalue(pexcel,124,4,strlanetype);
  568. ServiceExcelAPI.getcellvalue(pexcel,124,i,strlanemarkcolor);
  569. ServiceExcelAPI.getcellvalue(pexcel,125,i,strlanemarktype);
  570. if((strtype == "")||(strname == ""))
  571. {
  572. bComplete = true;
  573. }
  574. else
  575. {
  576. std::cout<<" name : "<<strname<<" type: "<<strtype<<std::endl;
  577. OpenDrive xxodr;
  578. int nrtn = ProcRoad(&xxodr,strtype,strradius,strroadlen,strlanewidth,strlannecount,strlanemarktype,strlanemarkcolor,strlanemarktype);
  579. if(nrtn == 0)
  580. {
  581. if(xxodr.GetHeader() == NULL)
  582. {
  583. xxodr.SetHeader(1,1,"adcmap",1.1,QDateTime::currentDateTime().toString("yyyy-MM-dd").toLatin1().data(),0,0,0,0,39,117,0);
  584. xxodr.GetHeader()->SetVendor("adc");
  585. }
  586. else
  587. {
  588. xxodr.GetHeader()->SetVendor("adc");
  589. }
  590. OpenDriveXmlWriter x(&xxodr);
  591. std::string strfilepath = stroutpath + "/"+ strname+".xodr";
  592. x.WriteFile(strfilepath);
  593. }
  594. else
  595. {
  596. nr = nr + nrtn;
  597. std::cout<<" Convert row "<<i<<" name: "<<strname<<" fail. fail code : "<<nrtn<<std::endl;
  598. }
  599. }
  600. i++;
  601. }
  602. ServiceExcelAPI.Closexlsx(pexcel);
  603. return nr;
  604. }
  605. int CDAProc::ProcCDA(iv::map::cdadraw & xcdadraw,OpenDrive * pxodr)
  606. {
  607. if(xcdadraw.mgeos_size() == 0)
  608. {
  609. std::cout<<" no geo. "<<std::endl;
  610. return -1;
  611. }
  612. int i;
  613. double xnow,ynow,hdgnow;
  614. xnow = 0;
  615. ynow = 0;
  616. hdgnow = 0;
  617. int nroadid = 0;
  618. for(i=0;i<xcdadraw.mgeos_size();i++)
  619. {
  620. iv::map::cdageo * pgeo = xcdadraw.mutable_mgeos(i);
  621. if(pgeo->geotype() == 0)
  622. {
  623. nroadid++;
  624. char strroadid[256];
  625. snprintf(strroadid,256,"%d",nroadid);
  626. pxodr->AddRoad("zl",pgeo->geolen(),strroadid,"-1");
  627. Road * pRoad = pxodr->GetLastAddedRoad();
  628. pRoad->AddGeometryBlock();
  629. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  630. pgeob->AddGeometryLine(0,xnow,ynow,hdgnow,pgeo->geolen());
  631. pRoad->GetGeometryCoords(pgeo->geolen(),xnow,ynow,hdgnow);
  632. pRoad->AddLaneSection(0);
  633. LaneSection * pLS = pRoad->GetLaneSection(0);
  634. pLS->AddLane(0,0,"none",false);
  635. Lane * pcenterlane = pLS->GetLastAddedLane();
  636. pcenterlane->AddRoadMarkRecord(0,"solid solid","standard","yellow",0.15,"none");
  637. int j;
  638. iv::map::cdadraw * pcdadraw = &xcdadraw;
  639. int nlanecount = pcdadraw->mlanes_size();
  640. for(j=0;j<nlanecount;j++)
  641. {
  642. iv::map::cdalane * pcdalane = pcdadraw->mutable_mlanes(j);
  643. pLS->AddLane(-1,(j+1)*(-1),cda_lanetype_sel[pcdalane->lanetype()],false,true);
  644. Lane * pnewlane = pLS->GetLastAddedLane();
  645. pnewlane->AddWidthRecord(0,pcdalane->lanewidth(),0,0,0);
  646. pnewlane->AddRoadMarkRecord(0,cda_lanemarktype_sel[pcdalane->lanemarktype()],"standard",cda_lanemarkcolor_sel[pcdalane->lanemarkcolor()],pcdalane->lanemarkwidth(),"none");
  647. pLS->AddLane(1,(j+1)*(1),cda_lanetype_sel[pcdalane->lanetype()],false,true);
  648. pnewlane = pLS->GetLastAddedLane();
  649. pnewlane->AddWidthRecord(0,pcdalane->lanewidth(),0,0,0);
  650. pnewlane->AddRoadMarkRecord(0,cda_lanemarktype_sel[pcdalane->lanemarktype()],"standard",cda_lanemarkcolor_sel[pcdalane->lanemarkcolor()],pcdalane->lanemarkwidth(),"none");
  651. }
  652. }
  653. if(pgeo->geotype() == 1)
  654. {
  655. nroadid++;
  656. char strroadid[256];
  657. snprintf(strroadid,256,"%d",nroadid);
  658. pxodr->AddRoad("wd",pgeo->geolen(),strroadid,"-1");
  659. Road * pRoad = pxodr->GetLastAddedRoad();
  660. pRoad->AddGeometryBlock();
  661. GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
  662. pgeob->AddGeometryArc(0,xnow,ynow,hdgnow,pgeo->geolen(),1.0/pgeo->georadius());
  663. pRoad->GetGeometryCoords(pgeo->geolen(),xnow,ynow,hdgnow);
  664. pRoad->AddLaneSection(0);
  665. LaneSection * pLS = pRoad->GetLaneSection(0);
  666. pLS->AddLane(0,0,"none",false);
  667. Lane * pcenterlane = pLS->GetLastAddedLane();
  668. pcenterlane->AddRoadMarkRecord(0,"solid solid","standard","yellow",0.15,"none");
  669. int j;
  670. iv::map::cdadraw * pcdadraw = &xcdadraw;
  671. int nlanecount = pcdadraw->mlanes_size();
  672. for(j=0;j<nlanecount;j++)
  673. {
  674. iv::map::cdalane * pcdalane = pcdadraw->mutable_mlanes(j);
  675. pLS->AddLane(-1,(j+1)*(-1),cda_lanetype_sel[pcdalane->lanetype()],false,true);
  676. Lane * pnewlane = pLS->GetLastAddedLane();
  677. pnewlane->AddWidthRecord(0,pcdalane->lanewidth(),0,0,0);
  678. pnewlane->AddRoadMarkRecord(0,cda_lanemarktype_sel[pcdalane->lanemarktype()],"standard",cda_lanemarkcolor_sel[pcdalane->lanemarkcolor()],pcdalane->lanemarkwidth(),"none");
  679. pLS->AddLane(1,(j+1)*(1),cda_lanetype_sel[pcdalane->lanetype()],false,true);
  680. pnewlane = pLS->GetLastAddedLane();
  681. pnewlane->AddWidthRecord(0,pcdalane->lanewidth(),0,0,0);
  682. pnewlane->AddRoadMarkRecord(0,cda_lanemarktype_sel[pcdalane->lanemarktype()],"standard",cda_lanemarkcolor_sel[pcdalane->lanemarkcolor()],pcdalane->lanemarkwidth(),"none");
  683. }
  684. }
  685. if(pgeo->geotype() == 2)
  686. {
  687. ProcIntersectionRoad(pxodr,&xcdadraw,i,nroadid,xnow,ynow,hdgnow);
  688. }
  689. }
  690. // for(i=0;i<pxodr->GetRoadCount();i++)
  691. // {
  692. // Road * pRoad = pxodr->GetRoad(i);
  693. // pRoad->AddLaneSection(0);
  694. // LaneSection * pLS = pRoad->GetLaneSection(0);
  695. // pLS->AddLane(0,0,"none",false);
  696. // Lane * pcenterlane = pLS->GetLastAddedLane();
  697. // pcenterlane->AddRoadMarkRecord(0,"solid","standard","yellow",0.15,"none");
  698. // int i;
  699. // for(i=0;i<2;i++)
  700. // {
  701. // pLS->AddLane(-1,(i+1)*(-1),"driving",false,true);
  702. // Lane * pnewlane = pLS->GetLastAddedLane();
  703. // pnewlane->AddWidthRecord(0,3.5,0,0,0);
  704. // pnewlane->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"none");
  705. // }
  706. // }
  707. return 0;
  708. }