xodrdijkstra.cpp 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993
  1. #include "xodrdijkstra.h"
  2. #include <qdebug.h>
  3. #include <iostream>
  4. #include <memory>
  5. extern iv::Ivlog *givlog;
  6. extern iv::Ivfault *gfault;
  7. namespace iv {
  8. struct xodrtreeunit
  9. {
  10. double mlen;
  11. iv::xodrtreeunit * mparent;
  12. int nroad;
  13. iv::xodrtreeunit * mpchild;
  14. iv::xodrtreeunit * mpnextbro;
  15. };
  16. }
  17. namespace iv {
  18. struct vertexsame
  19. {
  20. vertexsame(int a,int b) {ma=a; mb =b;}
  21. int ma;
  22. int mb;
  23. };
  24. }
  25. namespace iv {
  26. struct vertexsamearray
  27. {
  28. std::vector<int> mvertexarray;
  29. vertexsamearray(int a,int b) {mvertexarray.push_back(a);mvertexarray.push_back(b);}
  30. bool isinarray(int x)
  31. {
  32. int i;
  33. for(i=0;i<mvertexarray.size();i++)
  34. {
  35. if(x == mvertexarray[i])return true;
  36. }
  37. return false;
  38. }
  39. void print()
  40. {
  41. char strout[10000];
  42. char strtem[30];
  43. int i;
  44. snprintf(strout,10000,"");
  45. for(i=0;i<mvertexarray.size();i++)
  46. {
  47. snprintf(strtem,30,"%d ",mvertexarray[i]);
  48. strncat(strout,strtem,10000);
  49. }
  50. qDebug(strout);
  51. }
  52. void sort()
  53. {
  54. int i;
  55. for(i=1;i<mvertexarray.size();i++)
  56. {
  57. if(mvertexarray[i]<mvertexarray[0])
  58. {
  59. int a = mvertexarray[0];
  60. mvertexarray[0] = mvertexarray[i];
  61. mvertexarray[i] = a;
  62. }
  63. }
  64. }
  65. };
  66. }
  67. Road * xodrdijkstra::GetRoadByID(int nRoadID)
  68. {
  69. OpenDrive * pxodr = mpxodr;
  70. int i;
  71. int nsize = pxodr->GetRoadCount();
  72. for(i=0;i<nsize;i++)
  73. {
  74. Road * pRoad = pxodr->GetRoad(i);
  75. if(atoi(pRoad->GetRoadId().data()) == nRoadID)
  76. {
  77. return pRoad;
  78. }
  79. }
  80. std::cout<<"xodrdijkstra::GetRoadByID "<<nRoadID<<" Fail."<<std::endl;
  81. return 0;
  82. }
  83. /**
  84. * @brief xodrdijkstra::xodrdijkstra
  85. * opendrive to directed graph ,so can use dijkstra
  86. * 1.将OpenDrive的Road转换为边,双行路转换为两条边,单行路转换为一条边,每条边包含两个顶点。
  87. * 2.寻找相同顶点,首先从Junction里寻找有连接关系的作为相同顶点插入到相同顶点表;然后从Road的Link关系里寻找相同顶点,第一种是Road不是Junction的,如果他的前面道路或后继道路是Road的,作为相同顶点关系插入到相同顶点表,第二种Road属于Junction的,如果他的后继道路是Road的,作为相同顶点插入到相同顶点表。
  88. * 3.根据相同顶点表,将相同顶点合并成相同顶点数组(比如(1,3) (2,3)合并为(1,3,2)),随后进行排序(比如(1,2,3)),然后对每条边的顶点重新设置顶点编号(比如3改为1),形成有向图。
  89. * @param pxodr pointer to a OpenDrive Map
  90. **/
  91. xodrdijkstra::xodrdijkstra(OpenDrive * pxodr)
  92. {
  93. mpxodr = pxodr;
  94. int i;
  95. double nlenth = 0;
  96. int nroadsize = mpxodr->GetRoadCount();
  97. for(i=0;i<nroadsize;i++)
  98. {
  99. Road * px = mpxodr->GetRoad(i);
  100. nlenth = nlenth + px->GetRoadLength();
  101. if(px->GetLaneSectionCount()<1)
  102. {
  103. qDebug("no lanesection");
  104. continue;
  105. }
  106. // qDebug("lane count is %d left %d right %d" ,px->GetLaneSection(0)->GetLaneCount(),px->GetLaneSection(0)->GetLeftLaneCount(),
  107. // px->GetLaneSection(0)->GetRightLaneCount());
  108. int j;
  109. for(j=0;j<px->GetLaneSectionCount();j++)
  110. {
  111. if(px->GetLaneSection(j)->GetLaneCount()<2)
  112. {
  113. givlog->info("no lane");
  114. continue;
  115. }
  116. if(px->GetLaneSection(j)->GetLeftLaneCount()>0)
  117. {
  118. double fseclen = 0;
  119. if(j<(px->GetLaneSectionCount() -1))
  120. {
  121. fseclen = px->GetLaneSection(j+1)->GetS() - px->GetLaneSection(j)->GetS();
  122. }
  123. else
  124. {
  125. fseclen = px->GetRoadLength() - px->GetLaneSection(j)->GetS();
  126. }
  127. roadedge xroad(atoi(px->GetRoadId().data()),atoi(px->GetRoadJunction().data()),fseclen,1,j,px);
  128. // roadedge xroad(atoi(px->GetRoadId().data()),atoi(px->GetRoadJunction().data()),px->GetRoadLength(),1,j,px);
  129. // xroad.mpx = px;
  130. mroadedge.push_back(xroad);
  131. }
  132. if(px->GetLaneSection(j)->GetRightLaneCount()>0)
  133. {
  134. double fseclen = 0;
  135. if(j<(px->GetLaneSectionCount() -1))
  136. {
  137. fseclen = px->GetLaneSection(j+1)->GetS() - px->GetLaneSection(j)->GetS();
  138. }
  139. else
  140. {
  141. fseclen = px->GetRoadLength() - px->GetLaneSection(j)->GetS();
  142. }
  143. // if((px->GetRoadId() == "10019")||(px->GetRoadId() == "10020"))
  144. // {
  145. // int axy = 1;
  146. // }
  147. roadedge xroad(atoi(px->GetRoadId().data()),atoi(px->GetRoadJunction().data()),fseclen,2,j,px);
  148. // roadedge xroad(atoi(px->GetRoadId().data()),atoi(px->GetRoadJunction().data()),px->GetRoadLength(),2,j,px);
  149. // xroad.mpx = px;
  150. mroadedge.push_back(xroad);
  151. }
  152. }
  153. // qDebug("id = %s juncton = %s ",px->GetRoadId().data(),px->GetRoadJunction().data());
  154. }
  155. // givlog->debug("road %d ",mroadedge.size());
  156. std::vector<roadedge> * pxxx = &mroadedge;//10021
  157. if(mroadedge.size()<1)return;
  158. int nvertindex = 0;
  159. mroadedge[0].mvertexstart = 0;
  160. mroadedge[1].mvertexend = 1;
  161. //Init Vertex
  162. for(i=0;i<mroadedge.size();i++)
  163. {
  164. mroadedge[i].mbvertex = true;
  165. mroadedge[i].mvertexstart = 2*i;
  166. mroadedge[i].mvertexend = 2*i + 1;
  167. }
  168. //Find Same Vertex
  169. std::vector<iv::vertexsame> xvertexsame;
  170. std::vector<std::vector<int>> xcommonpoint;
  171. Junction * pj;
  172. for(i=0;i<pxodr->GetJunctionCount();i++)
  173. {
  174. pj = pxodr->GetJunction(i);
  175. int j;
  176. // if(atoi(pj->GetId().data()) == 810009)
  177. // {
  178. // int ggg = 11;
  179. // }
  180. for(j=0;j<pj->GetJunctionConnectionCount();j++)
  181. {
  182. JunctionConnection * pjc = pj->GetJunctionConnection(j);
  183. int road_from = atoi(pjc->GetIncomingRoad().data());
  184. int road_to = atoi(pjc->GetConnectingRoad().data());
  185. Road * pRoad_From = GetRoadByID(road_from);
  186. Road * pRoad_To = GetRoadByID(road_to);
  187. int k;
  188. for(k=0;k<pjc->GetJunctionLaneLinkCount();k++)
  189. {
  190. JunctionLaneLink * pjll = pjc->GetJunctionLaneLink(k);
  191. int lane_from = pjll->GetFrom();
  192. int lane_to = pjll->GetTo();
  193. lanenetunit lnu;
  194. int lr_from,lr_to;
  195. if(pjll->GetFrom()>0)lr_from = 1;
  196. else lr_from = 2;
  197. if(pjll->GetTo() > 0)lr_to = 1;
  198. else lr_to = 2;
  199. int fromedge;
  200. int toedge;
  201. fromedge = getroadedge(road_from,lr_from);
  202. toedge = getroadedge(road_to,lr_to);
  203. // qDebug("from %d %d to %d %d fromedge %d toedge %d %s",road_from, pjll->GetFrom(),
  204. // road_to,pjll->GetTo(),fromedge,toedge,pjc->GetContactPoint().data());
  205. if((fromedge == -1)||(toedge == -1))
  206. {
  207. givlog->debug("from %d %d to %d %d fromedge %d toedge %d %s",road_from, pjll->GetFrom(),
  208. road_to,pjll->GetTo(),fromedge,toedge,pjc->GetContactPoint().data());
  209. continue;
  210. }
  211. int a,b;
  212. if(strncmp(pjc->GetContactPoint().data(),"end",255) == 0)
  213. {
  214. // if(road_from == 30011)
  215. // {
  216. // int xx = 1;
  217. // }
  218. // if(lr_from == 2)
  219. if(lr_to == 1)
  220. {
  221. fromedge = getroadedge(road_from,lr_from,pRoad_From->GetLaneSectionCount() -1);
  222. toedge = getroadedge(road_to,lr_to);
  223. a = mroadedge[fromedge].mvertexend;
  224. b = mroadedge[toedge].mvertexstart;
  225. lnu.mpFromRoad = GetRoadByID(road_from);
  226. lnu.mpToRoad = GetRoadByID(road_to);
  227. lnu.mnFromSection = lnu.mpFromRoad->GetLaneSectionCount() - 1;
  228. lnu.mnToSection = 0;
  229. lnu.mnFromLane = lane_from;
  230. lnu.mnToLane = lane_to;
  231. }
  232. else
  233. {
  234. fromedge = getroadedge(road_from,lr_from);
  235. toedge = getroadedge(road_to,lr_to,pRoad_To->GetLaneSectionCount() -1);
  236. a = mroadedge[fromedge].mvertexstart;
  237. b = mroadedge[toedge].mvertexend;
  238. lnu.mpFromRoad = GetRoadByID(road_to);
  239. lnu.mpToRoad = GetRoadByID(road_from);
  240. lnu.mnFromSection = 0;
  241. lnu.mnToSection = lnu.mpToRoad->GetLaneSectionCount()-1;
  242. lnu.mnFromLane = lane_to;
  243. lnu.mnToLane = lane_from;
  244. }
  245. }
  246. if(strncmp(pjc->GetContactPoint().data(),"start",255) == 0)
  247. {
  248. // if(lr_from == 1)
  249. if(lr_to == 2)
  250. {
  251. fromedge = getroadedge(road_from,lr_from,pRoad_From->GetLaneSectionCount() -1);
  252. toedge = getroadedge(road_to,lr_to);
  253. a = mroadedge[fromedge].mvertexend;
  254. b = mroadedge[toedge].mvertexstart;
  255. lnu.mpFromRoad = GetRoadByID(road_from);
  256. lnu.mpToRoad = GetRoadByID(road_to);
  257. lnu.mnFromSection = lnu.mpFromRoad->GetLaneSectionCount() - 1;
  258. lnu.mnToSection = 0;
  259. lnu.mnFromLane = lane_from;
  260. lnu.mnToLane = lane_to;
  261. }
  262. else
  263. {
  264. fromedge = getroadedge(road_from,lr_from);
  265. toedge = getroadedge(road_to,lr_to,pRoad_To->GetLaneSectionCount() -1);
  266. a = mroadedge[fromedge].mvertexstart;
  267. b = mroadedge[toedge].mvertexend;
  268. lnu.mpFromRoad = GetRoadByID(road_to);
  269. lnu.mpToRoad = GetRoadByID(road_from);
  270. lnu.mnFromSection = 0;
  271. lnu.mnToSection = lnu.mpToRoad->GetLaneSectionCount()-1;
  272. lnu.mnFromLane = lane_to;
  273. lnu.mnToLane = lane_from;
  274. }
  275. mlanenet.push_back(lnu);
  276. iv::vertexsame vx(a,b);
  277. xvertexsame.push_back(vx);
  278. }
  279. }
  280. }
  281. }
  282. givlog->debug("After Junction vertex same is %d ",xvertexsame.size());
  283. for(i=0;i<nroadsize;i++)
  284. {
  285. Road * px = mpxodr->GetRoad(i);
  286. if(px->GetLaneSectionCount() == 1)
  287. {
  288. if(px->GetPredecessor() != 0)
  289. {
  290. if(strncmp(px->GetPredecessor()->GetElementType().data(),"road",255) == 0)
  291. {
  292. int k;
  293. int nroadpre = atoi(px->GetPredecessor()->GetElementId().data());
  294. int nroadcur = atoi(px->GetRoadId().data());
  295. for(k=0;k<px->GetLaneSection(0)->GetLaneCount();k++)
  296. {
  297. Lane * plane = px->GetLaneSection(0)->GetLane(k);
  298. if(plane->GetId() == 0)continue;
  299. if(plane->IsPredecessorSet())
  300. {
  301. int a,b;
  302. int npre = plane->GetPredecessor();
  303. int nid = plane->GetId();
  304. lanenetunit lnu;
  305. lnu.mnFromSection = 0;
  306. lnu.mnToSection = 0;
  307. if(strncmp(px->GetPredecessor()->GetContactPoint().data(),"end",255) == 0)
  308. {
  309. if(npre < 0)
  310. {
  311. int nedgepre = getroadedge(nroadpre,2,GetRoadByID(nroadpre)->GetLaneSectionCount()-1);
  312. lnu.mnFromSection = GetRoadByID(nroadpre)->GetLaneSectionCount()-1;
  313. a = mroadedge[nedgepre].mvertexend;
  314. lnu.mpFromRoad = GetRoadByID(nroadpre);
  315. lnu.mpToRoad = GetRoadByID(nroadcur);
  316. lnu.mnFromLane = npre;
  317. lnu.mnToLane = nid;
  318. }
  319. else
  320. {
  321. int nedgepre = getroadedge(nroadpre,1,GetRoadByID(nroadpre)->GetLaneSectionCount()-1);
  322. lnu.mnToSection = GetRoadByID(nroadpre)->GetLaneSectionCount()-1;
  323. a = mroadedge[nedgepre].mvertexstart;
  324. lnu.mpFromRoad = GetRoadByID(nroadcur);
  325. lnu.mpToRoad = GetRoadByID(nroadpre);
  326. lnu.mnFromLane = nid;
  327. lnu.mnToLane = npre;
  328. }
  329. }
  330. if(strncmp(px->GetPredecessor()->GetContactPoint().data(),"start",255) == 0)
  331. {
  332. if(npre < 0)
  333. {
  334. int nedgepre = getroadedge(nroadpre,2);
  335. a = mroadedge[nedgepre].mvertexstart;
  336. lnu.mpFromRoad = GetRoadByID(nroadcur);
  337. lnu.mpToRoad = GetRoadByID(nroadpre);
  338. lnu.mnFromLane = nid;
  339. lnu.mnToLane = npre;
  340. }
  341. else
  342. {
  343. int nedgepre = getroadedge(nroadpre,1);
  344. a = mroadedge[nedgepre].mvertexend;
  345. lnu.mpFromRoad = GetRoadByID(nroadpre);
  346. lnu.mpToRoad = GetRoadByID(nroadcur);
  347. lnu.mnFromLane = npre;
  348. lnu.mnToLane = nid;
  349. }
  350. }
  351. if(nid < 0)
  352. {
  353. int nedgecur = getroadedge(nroadcur,2);
  354. b = mroadedge[nedgecur].mvertexstart;
  355. }
  356. else
  357. {
  358. int nedgecur = getroadedge(nroadcur,1);
  359. b = mroadedge[nedgecur].mvertexend;
  360. }
  361. mlanenet.push_back(lnu);
  362. iv::vertexsame vx(a,b);
  363. xvertexsame.push_back(vx);
  364. }
  365. if(plane->IsSuccessorSet())
  366. {
  367. }
  368. }
  369. }
  370. }
  371. if(px->GetSuccessor() != 0)
  372. {
  373. if(strncmp(px->GetSuccessor()->GetElementType().data(),"road",255) == 0)
  374. {
  375. int k;
  376. int nroadnext = atoi(px->GetSuccessor()->GetElementId().data());
  377. int nroadcur = atoi(px->GetRoadId().data());
  378. for(k=0;k<px->GetLaneSection(px->GetLaneSectionCount()-1)->GetLaneCount();k++)
  379. {
  380. // if(nroadcur == 30001)
  381. // {
  382. // int xg = 0;
  383. // xg++;
  384. // }
  385. Lane * plane = px->GetLaneSection(px->GetLaneSectionCount()-1)->GetLane(k);
  386. if(plane->GetId() == 0)continue;
  387. if(plane->IsSuccessorSet())
  388. {
  389. int a,b;
  390. int nnext = plane->GetSuccessor();
  391. int nid = plane->GetId();
  392. lanenetunit lnu;
  393. lnu.mnFromSection = 0;
  394. lnu.mnToSection = 0;
  395. if(strncmp(px->GetSuccessor()->GetContactPoint().data(),"end",255) == 0)
  396. {
  397. if(nnext < 0)
  398. {
  399. int nedgenext = getroadedge(nroadnext,2,GetRoadByID(nroadnext)->GetLaneSectionCount()-1);
  400. b = mroadedge[nedgenext].mvertexend;
  401. lnu.mnFromSection = GetRoadByID(nroadnext)->GetLaneSectionCount()-1;
  402. lnu.mpFromRoad = GetRoadByID(nroadnext);
  403. lnu.mpToRoad = GetRoadByID(nroadcur);
  404. lnu.mnFromLane = nnext;
  405. lnu.mnToLane = nid;
  406. }
  407. else
  408. {
  409. int nedgenext = getroadedge(nroadnext,1,GetRoadByID(nroadnext)->GetLaneSectionCount()-1);
  410. b = mroadedge[nedgenext].mvertexstart;
  411. lnu.mpFromRoad = GetRoadByID(nroadcur);
  412. lnu.mnToSection = GetRoadByID(nroadnext)->GetLaneSectionCount()-1;
  413. lnu.mpToRoad = GetRoadByID(nroadnext);
  414. lnu.mnFromLane = nid;
  415. lnu.mnToLane = nnext;
  416. }
  417. }
  418. if(strncmp(px->GetSuccessor()->GetContactPoint().data(),"start",255) == 0)
  419. {
  420. if(nnext < 0)
  421. {
  422. int nedgenext = getroadedge(nroadnext,2);
  423. b = mroadedge[nedgenext].mvertexstart;
  424. lnu.mpFromRoad = GetRoadByID(nroadcur);
  425. lnu.mpToRoad = GetRoadByID(nroadnext);
  426. lnu.mnFromLane = nid;
  427. lnu.mnToLane = nnext;
  428. }
  429. else
  430. {
  431. int nedgenext = getroadedge(nroadnext,1);
  432. b = mroadedge[nedgenext].mvertexend;
  433. lnu.mpFromRoad = GetRoadByID(nroadnext);
  434. lnu.mpToRoad = GetRoadByID(nroadcur);
  435. lnu.mnFromLane = nnext;
  436. lnu.mnToLane = nid;
  437. }
  438. }
  439. if(nid < 0)
  440. {
  441. int nedgecur = getroadedge(nroadcur,2);
  442. a = mroadedge[nedgecur].mvertexend;
  443. }
  444. else
  445. {
  446. int nedgecur = getroadedge(nroadcur,1);
  447. a = mroadedge[nedgecur].mvertexstart;
  448. }
  449. iv::vertexsame vx(a,b);
  450. xvertexsame.push_back(vx);
  451. mlanenet.push_back(lnu);
  452. }
  453. }
  454. }
  455. }
  456. }
  457. else
  458. {
  459. if(px->GetPredecessor() != 0)
  460. {
  461. if(strncmp(px->GetPredecessor()->GetElementType().data(),"road",255) == 0)
  462. {
  463. int k;
  464. int nroadpre = atoi(px->GetPredecessor()->GetElementId().data());
  465. int nroadcur = atoi(px->GetRoadId().data());
  466. Road * pRoad_Pre = GetRoadByID(nroadpre);
  467. if(pRoad_Pre == 0)
  468. {
  469. qDebug("Pre Road Missing.");
  470. continue;
  471. }
  472. // if(nroadcur == 30012)
  473. // {
  474. // int ag;
  475. // ag= 1;
  476. // }
  477. for(k=0;k<px->GetLaneSection(0)->GetLaneCount();k++)
  478. {
  479. Lane * plane = px->GetLaneSection(0)->GetLane(k);
  480. if(plane->GetId() == 0)continue;
  481. if(plane->IsPredecessorSet())
  482. {
  483. int a,b;
  484. int npre = plane->GetPredecessor();
  485. int nid = plane->GetId();
  486. lanenetunit lnu;
  487. if(strncmp(px->GetPredecessor()->GetContactPoint().data(),"end",255) == 0)
  488. {
  489. if(npre < 0)
  490. {
  491. int nedgepre = getroadedge(nroadpre,2,pRoad_Pre->GetLaneSectionCount()-1);
  492. a = mroadedge[nedgepre].mvertexend;
  493. lnu.mpFromRoad = GetRoadByID(nroadpre);
  494. lnu.mpToRoad = GetRoadByID(nroadcur);
  495. lnu.mnFromSection = lnu.mpFromRoad->GetLaneSectionCount() - 1;
  496. lnu.mnToSection = 0;
  497. lnu.mnFromLane = npre;
  498. lnu.mnToLane = nid;
  499. }
  500. else
  501. {
  502. int nedgepre = getroadedge(nroadpre,1,pRoad_Pre->GetLaneSectionCount()-1);
  503. a = mroadedge[nedgepre].mvertexstart;
  504. lnu.mpFromRoad = GetRoadByID(nroadcur);
  505. lnu.mpToRoad = GetRoadByID(nroadpre);
  506. lnu.mnFromSection = 0;
  507. lnu.mnToSection = lnu.mpToRoad->GetLaneSectionCount() -1;
  508. lnu.mnFromLane = nid;
  509. lnu.mnToLane = npre;
  510. }
  511. }
  512. if(strncmp(px->GetPredecessor()->GetContactPoint().data(),"start",255) == 0)
  513. {
  514. if(npre < 0)
  515. {
  516. int nedgepre = getroadedge(nroadpre,2);
  517. a = mroadedge[nedgepre].mvertexstart;
  518. lnu.mpFromRoad = GetRoadByID(nroadcur);
  519. lnu.mpToRoad = GetRoadByID(nroadpre);
  520. lnu.mnFromSection = 0;
  521. lnu.mnToSection = lnu.mpToRoad->GetLaneSectionCount() -1;
  522. lnu.mnFromLane = nid;
  523. lnu.mnToLane = npre;
  524. }
  525. else
  526. {
  527. int nedgepre = getroadedge(nroadpre,1);
  528. a = mroadedge[nedgepre].mvertexend;
  529. lnu.mpFromRoad = GetRoadByID(nroadpre);
  530. lnu.mpToRoad = GetRoadByID(nroadcur);
  531. lnu.mnFromSection = lnu.mpFromRoad->GetLaneSectionCount() - 1;
  532. lnu.mnToSection = 0;
  533. lnu.mnFromLane = npre;
  534. lnu.mnToLane = nid;
  535. }
  536. }
  537. if(nid < 0)
  538. {
  539. int nedgecur = getroadedge(nroadcur,2);
  540. b = mroadedge[nedgecur].mvertexstart;
  541. }
  542. else
  543. {
  544. int nedgecur = getroadedge(nroadcur,1);
  545. b = mroadedge[nedgecur].mvertexend;
  546. }
  547. iv::vertexsame vx(a,b);
  548. xvertexsame.push_back(vx);
  549. mlanenet.push_back(lnu);
  550. }
  551. if(plane->IsSuccessorSet())
  552. {
  553. }
  554. }
  555. }
  556. }
  557. int j;
  558. for(j=1;j<px->GetLaneSectionCount();j++)
  559. {
  560. int k;
  561. int nroadpre = atoi(px->GetRoadId().data());
  562. int nroadcur = atoi(px->GetRoadId().data());
  563. for(k=0;k<px->GetLaneSection(j)->GetLaneCount();k++)
  564. {
  565. Lane * plane = px->GetLaneSection(j)->GetLane(k);
  566. if(plane->GetId() == 0)continue;
  567. if(plane->IsPredecessorSet())
  568. {
  569. int a,b;
  570. int npre = plane->GetPredecessor();
  571. int nid = plane->GetId();
  572. lanenetunit lnu;
  573. lnu.mpFromRoad = GetRoadByID(nroadcur);
  574. lnu.mpToRoad = lnu.mpFromRoad;
  575. if(npre < 0)
  576. {
  577. int nedgepre = getroadedge(nroadpre,2,j-1);
  578. a = mroadedge[nedgepre].mvertexend;
  579. lnu.mnFromSection = j-1;
  580. lnu.mnToSection = j;
  581. lnu.mnFromLane = npre;
  582. lnu.mnToLane = nid;
  583. }
  584. else
  585. {
  586. int nedgepre = getroadedge(nroadpre,1,j-1);
  587. a = mroadedge[nedgepre].mvertexstart;
  588. lnu.mnFromSection = j;
  589. lnu.mnToSection = j-1;
  590. lnu.mnFromLane = nid;
  591. lnu.mnToLane = npre;
  592. }
  593. if(nid < 0)
  594. {
  595. int nedgecur = getroadedge(nroadcur,2,j);
  596. b = mroadedge[nedgecur].mvertexstart;
  597. }
  598. else
  599. {
  600. int nedgecur = getroadedge(nroadcur,1,j);
  601. b = mroadedge[nedgecur].mvertexend;
  602. }
  603. mlanenet.push_back(lnu);
  604. iv::vertexsame vx(a,b);
  605. xvertexsame.push_back(vx);
  606. }
  607. if(plane->IsSuccessorSet())
  608. {
  609. }
  610. }
  611. }
  612. if(px->GetSuccessor() != 0)
  613. {
  614. if(strncmp(px->GetSuccessor()->GetElementType().data(),"road",255) == 0)
  615. {
  616. int k;
  617. int nroadnext = atoi(px->GetSuccessor()->GetElementId().data());
  618. int nroadcur = atoi(px->GetRoadId().data());
  619. if(nroadcur == 116)
  620. {
  621. int xxxxx = 1;
  622. }
  623. for(k=0;k<px->GetLaneSection(px->GetLaneSectionCount()-1)->GetLaneCount();k++)
  624. {
  625. Lane * plane = px->GetLaneSection(px->GetLaneSectionCount()-1)->GetLane(k);
  626. if(plane->GetId() == 0)continue;
  627. if(plane->IsSuccessorSet())
  628. {
  629. int a,b;
  630. int nnext = plane->GetSuccessor();
  631. int nid = plane->GetId();
  632. lanenetunit lnu;
  633. if(strncmp(px->GetSuccessor()->GetContactPoint().data(),"end",255) == 0)
  634. {
  635. if(nnext < 0)
  636. {
  637. int nedgenext = getroadedge(nroadnext,2,GetRoadByID(nroadnext)->GetLaneSectionCount()-1);
  638. b = mroadedge[nedgenext].mvertexend;
  639. lnu.mpFromRoad = GetRoadByID(nroadnext);
  640. lnu.mpToRoad = GetRoadByID(nroadcur);
  641. lnu.mnFromSection = GetRoadByID(nroadnext)->GetLaneSectionCount()-1;
  642. lnu.mnToSection = lnu.mpToRoad->GetLaneSectionCount() - 1;
  643. lnu.mnFromLane = nnext;
  644. lnu.mnToLane = nid;
  645. }
  646. else
  647. {
  648. int nedgenext = getroadedge(nroadnext,1,GetRoadByID(nroadnext)->GetLaneSectionCount()-1);
  649. b = mroadedge[nedgenext].mvertexstart;
  650. lnu.mpFromRoad = GetRoadByID(nroadcur);
  651. lnu.mpToRoad = GetRoadByID(nroadnext);
  652. lnu.mnFromSection = lnu.mpFromRoad->GetLaneSectionCount() -1;
  653. lnu.mnToSection = GetRoadByID(nroadnext)->GetLaneSectionCount()-1;
  654. lnu.mnFromLane = nid;
  655. lnu.mnToLane = nnext;
  656. }
  657. }
  658. if(strncmp(px->GetSuccessor()->GetContactPoint().data(),"start",255) == 0)
  659. {
  660. if(nnext < 0)
  661. {
  662. int nedgenext = getroadedge(nroadnext,2);
  663. b = mroadedge[nedgenext].mvertexstart;
  664. lnu.mpFromRoad = GetRoadByID(nroadcur);
  665. lnu.mpToRoad = GetRoadByID(nroadnext);
  666. lnu.mnFromSection = lnu.mpFromRoad->GetLaneSectionCount() -1;
  667. lnu.mnToSection = 0;
  668. lnu.mnFromLane = nid;
  669. lnu.mnToLane = nnext;
  670. }
  671. else
  672. {
  673. int nedgenext = getroadedge(nroadnext,1);
  674. b = mroadedge[nedgenext].mvertexend;
  675. lnu.mpFromRoad = GetRoadByID(nroadnext);
  676. lnu.mpToRoad = GetRoadByID(nroadcur);
  677. lnu.mnFromSection = 0;
  678. lnu.mnToSection = lnu.mpToRoad->GetLaneSectionCount() - 1;
  679. lnu.mnFromLane = nnext;
  680. lnu.mnToLane = nid;
  681. }
  682. }
  683. if(nid < 0)
  684. {
  685. int nedgecur = getroadedge(nroadcur,2,px->GetLaneSectionCount()-1);
  686. a = mroadedge[nedgecur].mvertexend;
  687. }
  688. else
  689. {
  690. int nedgecur = getroadedge(nroadcur,1,px->GetLaneSectionCount()-1);
  691. a = mroadedge[nedgecur].mvertexstart;
  692. }
  693. iv::vertexsame vx(a,b);
  694. xvertexsame.push_back(vx);
  695. mlanenet.push_back(lnu);
  696. }
  697. }
  698. }
  699. }
  700. }
  701. }
  702. givlog->debug("vertex same is %d ",xvertexsame.size());
  703. for(i=0;i<xvertexsame.size();i++)
  704. {
  705. givlog->debug("%d: %d %d",i,xvertexsame[i].ma,xvertexsame[i].mb);
  706. }
  707. //Merge Same Vertex
  708. std::vector<iv::vertexsamearray> xvertexsamearray;
  709. for(i=0;i<xvertexsame.size();i++)
  710. {
  711. int a,b;
  712. a = xvertexsame[i].ma;
  713. b = xvertexsame[i].mb;
  714. int j;
  715. int napos = -1;
  716. for(j=0;j<xvertexsamearray.size();j++)
  717. {
  718. if(xvertexsamearray[j].isinarray(a))
  719. {
  720. napos = j;
  721. break;
  722. }
  723. }
  724. if(napos >= 0)
  725. {
  726. if(!xvertexsamearray[napos].isinarray(b))
  727. {
  728. xvertexsamearray[napos].mvertexarray.push_back(b);
  729. }
  730. }
  731. else
  732. {
  733. int nbpos = -1;
  734. for(j=0;j<xvertexsamearray.size();j++)
  735. {
  736. if(xvertexsamearray[j].isinarray(b))
  737. {
  738. nbpos = j;
  739. break;
  740. }
  741. }
  742. if(nbpos >= 0)
  743. {
  744. xvertexsamearray[nbpos].mvertexarray.push_back(a);
  745. }
  746. else
  747. {
  748. iv::vertexsamearray va(a,b);
  749. xvertexsamearray.push_back(va);
  750. }
  751. }
  752. }
  753. for(i=0;i<xvertexsamearray.size();i++)
  754. {
  755. xvertexsamearray[i].sort();
  756. // xvertexsamearray[i].print();
  757. }
  758. for(i=0;i<mroadedge.size();i++)
  759. {
  760. int j;
  761. for(j=0;j<xvertexsamearray.size();j++)
  762. {
  763. if(xvertexsamearray[j].isinarray(mroadedge[i].mvertexstart))
  764. {
  765. mroadedge[i].mvertexstart = xvertexsamearray[j].mvertexarray[0];
  766. }
  767. if(xvertexsamearray[j].isinarray(mroadedge[i].mvertexend))
  768. {
  769. mroadedge[i].mvertexend = xvertexsamearray[j].mvertexarray[0];
  770. }
  771. }
  772. }
  773. for(i=0;i<mroadedge.size();i++)
  774. {
  775. givlog->debug("%d %d %d: %d %d",mroadedge[i].mroadid,mroadedge[i].mnleftright,mroadedge[i].mnsectionid, mroadedge[i].mvertexstart,mroadedge[i].mvertexend);
  776. }
  777. int * xset = new int[mroadedge.size()*2];
  778. std::shared_ptr<int> pxset;pxset.reset(xset);
  779. for(i=0;i<(mroadedge.size()*2);i++)
  780. {
  781. xset[i] = -1;
  782. }
  783. int nnow = -1;
  784. std::vector<int > xvalidvertex;
  785. for(i=0;i<(mroadedge.size()*2);i++)
  786. {
  787. bool bfind = false;
  788. int j;
  789. int ntempnow = 0;
  790. for(j=0;j<mroadedge.size();j++)
  791. {
  792. if((mroadedge[j].mvertexstart - nnow)>0)
  793. {
  794. if(bfind == false)
  795. {
  796. ntempnow = mroadedge[j].mvertexstart;
  797. bfind = true;
  798. }
  799. else
  800. {
  801. if(mroadedge[j].mvertexstart<ntempnow)ntempnow = mroadedge[j].mvertexstart;
  802. }
  803. }
  804. if((mroadedge[j].mvertexend - nnow)>0)
  805. {
  806. if(bfind == false)
  807. {
  808. ntempnow = mroadedge[j].mvertexend;
  809. bfind = true;
  810. }
  811. else
  812. {
  813. if(mroadedge[j].mvertexend<ntempnow)ntempnow = mroadedge[j].mvertexend;
  814. }
  815. }
  816. }
  817. if(bfind == false)break;
  818. else
  819. {
  820. nnow = ntempnow;
  821. xvalidvertex.push_back(nnow);
  822. }
  823. }
  824. for(i=0;i<mroadedge.size();i++)
  825. {
  826. int j;
  827. for(j=0;j<xvalidvertex.size();j++)
  828. {
  829. if(mroadedge[i].mvertexstart == xvalidvertex[j])
  830. {
  831. mroadedge[i].mvertexstart = j;
  832. break;
  833. }
  834. }
  835. if(j == xvalidvertex.size())qDebug("not found vertex");
  836. for(j=0;j<xvalidvertex.size();j++)
  837. {
  838. if(mroadedge[i].mvertexend == xvalidvertex[j])
  839. {
  840. mroadedge[i].mvertexend = j;
  841. break;
  842. }
  843. }
  844. if(j == xvalidvertex.size())qDebug("not found vertex");
  845. }
  846. for(i=0;i<mroadedge.size();i++)
  847. {
  848. givlog->debug("%d %d %d: %d %d",mroadedge[i].mroadid,mroadedge[i].mnleftright,mroadedge[i].mnsectionid, mroadedge[i].mvertexstart,mroadedge[i].mvertexend);
  849. }
  850. int nvertexnum = xvalidvertex.size(); //vertex num
  851. mvertexnum = nvertexnum;
  852. mvectorvertexedge.clear();
  853. int nmaxvertex = 0;
  854. for(i=0;i<nvertexnum;i++)
  855. {
  856. if(xvalidvertex[i]>nmaxvertex)nmaxvertex = xvalidvertex[i];
  857. }
  858. // for(i=0;i<mroadedge.size();i++)
  859. // {
  860. // if(mroadedge[i].mvertexstart>nmaxvertex)nmaxvertex = mroadedge[i].mvertexstart;
  861. // }
  862. for(i=0;i<=nmaxvertex;i++)
  863. {
  864. vertexedge x;
  865. mvectorvertexedge.push_back(x);
  866. }
  867. for(i=0;i<mroadedge.size();i++)
  868. {
  869. mvectorvertexedge[mroadedge[i].mvertexstart].mvectorroadedge.push_back(&mroadedge[i]);
  870. }
  871. std::cout<<" max is "<<nmaxvertex<<" num is "<<nvertexnum<<std::endl;
  872. nmaxvertex = nmaxvertex + 0;
  873. }
  874. int xodrdijkstra::getroadedge(int nroad,int leftright,int nsection )
  875. {
  876. int nrtn = -1;
  877. int i;
  878. // for(i=0;i<mroadedge.size();i++)
  879. // {
  880. // if((mroadedge[i].mroadid == nroad) &&(mroadedge[i].mnleftright == leftright) )
  881. // {
  882. // qDebug("equal, road %d edge %d ",nroad,i);
  883. // }
  884. // }
  885. for(i=0;i<mroadedge.size();i++)
  886. {
  887. if((mroadedge[i].mroadid == nroad) &&(mroadedge[i].mnleftright == leftright) &&(nsection == mroadedge[i].mnsectionid))
  888. {
  889. nrtn = i;
  890. return nrtn;
  891. }
  892. }
  893. return nrtn;
  894. }
  895. inline double xodrdijkstra::getedgedis(int vs, int vd)
  896. {
  897. int i;
  898. std::vector<roadedge > * proadedge = &mroadedge;
  899. double dis = std::numeric_limits<double>::max();
  900. for(i=0;i<mvectorvertexedge[vs].mvectorroadedge.size();i++)
  901. {
  902. if((vs == mvectorvertexedge[vs].mvectorroadedge[i]->mvertexstart)&&(vd == mvectorvertexedge[vs].mvectorroadedge[i]->mvertexend))
  903. {
  904. dis = mroadedge[i].mlen;
  905. return dis;
  906. }
  907. }
  908. return dis;
  909. for(i=0;i<mroadedge.size();i++)
  910. {
  911. if((vs == mroadedge[i].mvertexstart)&&(vd == mroadedge[i].mvertexend))
  912. {
  913. dis = mroadedge[i].mlen;
  914. return dis;
  915. }
  916. }
  917. return dis;
  918. }
  919. int xodrdijkstra::GetRoadSectionIndexByS(Road *pRoad, const double s)
  920. {
  921. int nrtn = -1;
  922. if(s<0)return nrtn;
  923. if(s>pRoad->GetRoadLength())return nrtn;
  924. int i;
  925. int nseccount = pRoad->GetLaneSectionCount();
  926. if(nseccount== 1)return 0;
  927. for(i=0;i<(nseccount-1);i++)
  928. {
  929. if(s<(pRoad->GetLaneSection(i+1)->GetS()))
  930. {
  931. break;
  932. }
  933. }
  934. return i;
  935. }
  936. double xodrdijkstra::getpathlength(std::vector<int> xvectorpath)
  937. {
  938. int i;
  939. int nsize = xvectorpath.size();
  940. double flen = 0;
  941. for(i=0;i<nsize;i++)
  942. {
  943. flen = flen + mroadedge[xvectorpath[i]].mlen;
  944. }
  945. return flen;
  946. }
  947. std::vector<int> xodrdijkstra::getpath(int srcroadid, int nsrclr, int dstroadid, int ndstlr,const double s_src ,const double s_obj )
  948. {
  949. std::vector<int> rtnpath;
  950. int nvertexnum = mvertexnum;
  951. int i;
  952. int nsecsrc =0;
  953. int nsecdst =0;
  954. nsecsrc = GetRoadSectionIndexByS(GetRoadByID(srcroadid),s_src);
  955. nsecdst = GetRoadSectionIndexByS(GetRoadByID(dstroadid),s_obj);
  956. if((nsecsrc<0)||(nsecdst<0))
  957. {
  958. qDebug("getpath section error.");
  959. return rtnpath;
  960. }
  961. int srcedge = getroadedge(srcroadid,nsrclr,nsecsrc);
  962. int dstedge = getroadedge(dstroadid,ndstlr,nsecdst);
  963. // roadedge * px1 = &mroadedge[srcedge];
  964. // roadedge * px2 = &mroadedge[dstedge];
  965. if((srcedge == -1)||(dstedge == -1))
  966. {
  967. qDebug("srcedge = %d dstedge = %d ",srcedge,dstedge);
  968. return rtnpath;
  969. }
  970. int * flag = new int[nvertexnum];
  971. int * prev = new int[nvertexnum];
  972. double * dist = new double[nvertexnum];
  973. std::shared_ptr<int> pflag; pflag.reset(flag);
  974. std::shared_ptr<int> pprev; pprev.reset(prev);
  975. std::shared_ptr<double> pdist; pdist.reset(dist);
  976. double min;
  977. int vs = mroadedge[srcedge].mvertexend;
  978. // int dstvertex = mroadedge[dstedge].mvertexend;
  979. int dstvertex = mroadedge[dstedge].mvertexstart;
  980. if(srcedge == dstedge)dstvertex = mroadedge[dstedge].mvertexstart;
  981. givlog->debug("src edge is %d vertex is %d",srcedge,vs);
  982. givlog->debug("dst vertex is %d ",dstvertex);
  983. // 初始化
  984. for (i = 0; i < nvertexnum; i++)
  985. {
  986. flag[i] = 0; // 顶点i的最短路径还没获取到。
  987. prev[i] = vs; // 顶点i的前驱顶点为0。
  988. dist[i] = getedgedis(vs,i);// 顶点i的最短路径为"顶点vs"到"顶点i"的权。
  989. }
  990. // 对"顶点vs"自身进行初始化
  991. flag[vs] = 1;
  992. dist[vs] = 0;
  993. // 遍历G.vexnum-1次;每次找出一个顶点的最短路径。
  994. for (i = 1; i < nvertexnum; i++)
  995. {
  996. // qDebug("i = %d",i);
  997. int k,j;
  998. // 寻找当前最小的路径;
  999. // 即,在未获取最短路径的顶点中,找到离vs最近的顶点(k)。
  1000. k = -1;
  1001. min = std::numeric_limits<double>::max();;
  1002. for (j = 0; j < nvertexnum; j++)
  1003. {
  1004. if (flag[j]==0 && dist[j]<min)
  1005. {
  1006. min = dist[j];
  1007. k = j;
  1008. }
  1009. }
  1010. if(min < 0)
  1011. {
  1012. qDebug("hi");
  1013. }
  1014. if(k == -1)
  1015. {
  1016. givlog->debug("i = %d not found k",i);
  1017. break;
  1018. }
  1019. // 标记"顶点k"为已经获取到最短路径
  1020. flag[k] = 1;
  1021. // 修正当前最短路径和前驱顶点
  1022. // 即,当已经"顶点k的最短路径"之后,更新"未获取最短路径的顶点的最短路径和前驱顶点"。
  1023. for (j = 0; j < nvertexnum; j++)
  1024. {
  1025. double tmp;
  1026. tmp = getedgedis(k,j);
  1027. if(tmp == std::numeric_limits<double>::max())
  1028. {
  1029. }
  1030. else
  1031. {
  1032. tmp = min + tmp;
  1033. }
  1034. // tmp = (G.matrix[k][j]==INF ? INF : (min + G.matrix[k][j])); // 防止溢出
  1035. if (flag[j] == 0 && (tmp < dist[j]) )
  1036. {
  1037. dist[j] = tmp;
  1038. prev[j] = k;
  1039. }
  1040. }
  1041. }
  1042. // for (i = 0; i < nvertexnum; i++)
  1043. // qDebug(" shortest(%d, %d)=%f\n", vs, i, dist[i]);
  1044. for (i = 0; i < nvertexnum; i++)
  1045. givlog->debug(" %d =%d\n", i, prev[i]);
  1046. if(flag[dstvertex] == 1)
  1047. {
  1048. int nstart;
  1049. int nend;
  1050. nend = dstvertex;
  1051. nstart = prev[nend];
  1052. while(nend != vs)
  1053. {
  1054. nstart = prev[nend];
  1055. int nedge = getroadedgefromvertex(nstart,nend);
  1056. if(nedge<0)
  1057. {
  1058. givlog->error("prev path error.");
  1059. break;
  1060. }
  1061. rtnpath.push_back(nedge);
  1062. nend = nstart;
  1063. }
  1064. }
  1065. std::vector<int> rtnpath2;
  1066. rtnpath2.push_back(srcedge);
  1067. for(i=0;i<rtnpath.size();i++)
  1068. {
  1069. givlog->debug("%d %d %d %d",i,mroadedge[rtnpath[rtnpath.size()-1-i]].mroadid,mroadedge[rtnpath[rtnpath.size()-1-i]].mnleftright,
  1070. mroadedge[rtnpath[rtnpath.size()-1-i]].mnsectionid);
  1071. // qDebug("%d %d %d %d",i,mroadedge[rtnpath[rtnpath.size()-1-i]].mroadid,mroadedge[rtnpath[rtnpath.size()-1-i]].mnleftright,
  1072. // mroadedge[rtnpath[rtnpath.size()-1-i]].mnsectionid);
  1073. rtnpath2.push_back(rtnpath[rtnpath.size()-1-i]);
  1074. }
  1075. /* if(srcedge == dstedge)*/rtnpath2.push_back(dstedge);
  1076. givlog->debug("rt = %d ",rtnpath.size());
  1077. //gfault->SetFaultState(0,0,"ok");
  1078. return rtnpath2;
  1079. }
  1080. int xodrdijkstra::getroadedgefromvertex(int nstart, int nend)
  1081. {
  1082. int i;
  1083. int nrtn = -1;
  1084. double flen = -1;
  1085. // int nlast = -1;
  1086. for(i=0;i<mroadedge.size();i++)
  1087. {
  1088. if((nstart == mroadedge[i].mvertexstart)&&(nend == mroadedge[i].mvertexend))
  1089. {
  1090. if(flen >0)
  1091. {
  1092. if(mroadedge[i].mlen < flen)
  1093. {
  1094. flen = mroadedge[i].mlen;
  1095. nrtn = i;
  1096. }
  1097. }
  1098. else
  1099. {
  1100. flen = mroadedge[i].mlen;
  1101. nrtn = i;
  1102. }
  1103. // break;
  1104. }
  1105. }
  1106. return nrtn;
  1107. }
  1108. Junction * xodrdijkstra::GetJunctionByID(string junctionname)
  1109. {
  1110. int i;
  1111. for(i=0;i<mpxodr->GetJunctionCount();i++)
  1112. {
  1113. if(strncmp(mpxodr->GetJunction(i)->GetId().data(),junctionname.data(),255) == 0)
  1114. {
  1115. return mpxodr->GetJunction(i);
  1116. }
  1117. }
  1118. std::cout<<"xodrdijkstra::GetJunctionByID can't find"<<std::endl;
  1119. return 0;
  1120. }
  1121. /**
  1122. * @brief xodrdijkstra::CalcLaneChange
  1123. * Decide Lane Chage,if need.
  1124. * @param p1 pre path
  1125. * @param p2 next path
  1126. **/
  1127. void xodrdijkstra::CalcLaneChange(pathsection *p1, pathsection *p2)
  1128. {
  1129. // int njunctionpos = 1; //if 1 p1 is junction if 2 p2 is junction, in junction from it's start have several road.
  1130. int nlr1,nlr2;
  1131. nlr1 = mroadedge[p1->mnroadedgeid].mnleftright;
  1132. nlr2 = mroadedge[p2->mnroadedgeid].mnleftright;
  1133. std::vector<lanenetunit> xln = GetLaneNet(p1->mpRoad,p1->msectionid,p2->mpRoad,p2->msectionid);
  1134. int i;
  1135. int nsel1 = p1->mainsel;
  1136. int nsel2 = p2->mainsel;
  1137. if(IsInLaneNet(xln,p1->mpRoad,p1->msectionid,p1->mainsel,p2->mpRoad,p2->msectionid,p2->mainsel))
  1138. {
  1139. }
  1140. else
  1141. {
  1142. bool bhave = false;
  1143. for(i=0;i<xln.size();i++)
  1144. {
  1145. if(xln.at(i).mnToLane == nsel2) //Have To Next Lane
  1146. {
  1147. nsel1 = xln.at(i).mnFromLane;
  1148. bhave = true;
  1149. break;
  1150. }
  1151. }
  1152. if(bhave == false)
  1153. {
  1154. bool bhave2 = false;
  1155. for(i=0;i<xln.size();i++)
  1156. {
  1157. if(xln.at(i).mnFromLane == nsel1) //Have from Lane
  1158. {
  1159. nsel2 = xln.at(i).mnToLane;
  1160. bhave2= true;
  1161. break;
  1162. }
  1163. }
  1164. if(bhave2 == false)
  1165. {
  1166. int nseldiff = 100;
  1167. for(i=0;i<xln.size();i++)
  1168. {
  1169. if(abs(xln.at(i).mnFromLane - p1->mainsel)<nseldiff) //Find Change Lane Less Lane
  1170. {
  1171. nsel1 = xln.at(i).mnFromLane;
  1172. nsel2 = xln.at(i).mnToLane;
  1173. nseldiff = abs(xln.at(i).mnFromLane - p1->mainsel);
  1174. }
  1175. }
  1176. }
  1177. }
  1178. }
  1179. p1->mnEndLaneSel = nsel1;
  1180. p2->mnStartLaneSel = nsel2;
  1181. }
  1182. /**
  1183. * @brief getgpspoint
  1184. * get gps trace
  1185. * @param srcroadidr source road id.
  1186. * @param nsrclr source road left or right
  1187. * @param dstroadid destination road id
  1188. * @param ndstlr destination road left or right
  1189. * @param xvectorpath grapth path vector,this path is calculated by getpath
  1190. **/
  1191. std::vector<pathsection> xodrdijkstra::getgpspoint(int srcroadid, int nsrclr, int dstroadid, int ndstlr, std::vector<int> xvectorpath,int nSel)
  1192. {
  1193. // int nSel = 1;
  1194. std::vector<int> nvectorlane1; //Road Start Select Lane
  1195. std::vector<int> nvectorlane2; //Road Center Select Lane;
  1196. std::vector<int> nvectorlane3; //Road End Select Lane
  1197. std::vector<pathsection> xpathsection;
  1198. int nlanecount = mroadedge[getroadedge(srcroadid,nsrclr)].mpx->GetLaneSectionCount();
  1199. std::cout<<" section count is "<<nlanecount<<std::endl;;
  1200. //First Get Every Path's lane section for calculate point.
  1201. int i;
  1202. int nsize = xvectorpath.size();
  1203. for(i=0;i<nsize;i++)
  1204. {
  1205. Road * pRoad = mroadedge[xvectorpath[i]].mpx;
  1206. qDebug("road %d is %s",i,pRoad->GetRoadId().data());
  1207. }
  1208. Road * pLastRoad = mroadedge[xvectorpath[nsize-1]].mpx;
  1209. for(i=0;i<nsize;i++)
  1210. {
  1211. pathsection xps;
  1212. Road * pRoad = mroadedge[xvectorpath[i]].mpx;
  1213. int nsuggest = nSel;
  1214. if(mroadedge[xvectorpath[i]].mnleftright == 2)nsuggest = nsuggest *(-1);
  1215. int nlane = xodrfunc::GetDrivingLane(pRoad,mroadedge[xvectorpath[i]].mnsectionid,nsuggest);
  1216. xps.mainsel = nlane;
  1217. xps.mnStartLaneSel = nlane;
  1218. xps.mnEndLaneSel = nlane;
  1219. xps.mainselindex = 0;//mainselindex;
  1220. xps.mroadid = mroadedge[xvectorpath[i]].mroadid;
  1221. xps.msectionid = mroadedge[xvectorpath[i]].mnsectionid;
  1222. xps.mnroadedgeid = xvectorpath[i];
  1223. xps.mpRoad = pRoad;
  1224. xps.secondsel = xps.mainsel;
  1225. xpathsection.push_back(xps);
  1226. }
  1227. for(i=(nsize-1);i>0;i--)
  1228. {
  1229. int noldmainsel = xpathsection[i-1].mainsel;
  1230. Road * pRoad = mroadedge[xvectorpath[i]].mpx;
  1231. LaneSection * pLS = pRoad->GetLaneSection(mroadedge[xvectorpath[i]].mnsectionid);
  1232. Lane * pLane = xodrfunc::GetLaneByID(pLS,xpathsection[i].mainsel);
  1233. Road * pRoad2 = mroadedge[xvectorpath[i-1]].mpx;
  1234. LaneSection * pLS2 = pRoad2->GetLaneSection(mroadedge[xvectorpath[i-1]].mnsectionid);
  1235. Lane * pLane2 = xodrfunc::GetLaneByID(pLS2,xpathsection[i-1].mainsel);
  1236. int nlr = mroadedge[xvectorpath[i]].mnleftright;
  1237. int nlr2 = mroadedge[xvectorpath[i-1]].mnleftright;
  1238. bool bNeedChangeLane = true;
  1239. if(nlr == 2)
  1240. {
  1241. if((pLane2->IsSuccessorSet()) &&(nlr2 == 2))
  1242. {
  1243. if(pLane2->GetSuccessor() != xpathsection[i].mainsel)
  1244. {
  1245. bool bfindgood = false;
  1246. int ngoodlane = 0;
  1247. int j;
  1248. for(j=0;j<pLS2->GetLaneCount();j++)
  1249. {
  1250. if(pLS2->GetLane(j)->IsSuccessorSet())
  1251. {
  1252. if(pLS2->GetLane(j)->GetSuccessor() == xpathsection[i].mainsel)
  1253. {
  1254. ngoodlane = pLS2->GetLane(j)->GetId();
  1255. bfindgood = true;
  1256. break;
  1257. }
  1258. }
  1259. }
  1260. if(bfindgood)
  1261. {
  1262. xpathsection[i-1].mainsel = ngoodlane;
  1263. xpathsection[i-1].mnStartLaneSel = ngoodlane;
  1264. xpathsection[i-1].mnEndLaneSel = ngoodlane;
  1265. bNeedChangeLane = false;
  1266. }
  1267. }
  1268. else
  1269. {
  1270. bNeedChangeLane = false;
  1271. }
  1272. }
  1273. else
  1274. {
  1275. if((pLane2->IsPredecessorSet()) &&(nlr2 == 1))
  1276. {
  1277. if(pLane2->GetPredecessor() != xpathsection[i].mainsel)
  1278. {
  1279. bool bfindgood = false;
  1280. int ngoodlane = 0;
  1281. int j;
  1282. for(j=0;j<pLS2->GetLaneCount();j++)
  1283. {
  1284. if(pLS2->GetLane(j)->IsPredecessorSet())
  1285. {
  1286. if(pLS2->GetLane(j)->GetPredecessor() == xpathsection[i].mainsel)
  1287. {
  1288. ngoodlane = pLS2->GetLane(j)->GetId();
  1289. bfindgood = true;
  1290. break;
  1291. }
  1292. }
  1293. }
  1294. if(bfindgood)
  1295. {
  1296. xpathsection[i-1].mainsel = ngoodlane;
  1297. xpathsection[i-1].mnStartLaneSel = ngoodlane;
  1298. xpathsection[i-1].mnEndLaneSel = ngoodlane;
  1299. bNeedChangeLane = false;
  1300. }
  1301. }
  1302. else
  1303. {
  1304. bNeedChangeLane = false;
  1305. }
  1306. }
  1307. else
  1308. {
  1309. if(pLane->IsPredecessorSet())
  1310. {
  1311. if(pLane->GetPredecessor() != xpathsection[i-1].mainsel)
  1312. {
  1313. xpathsection[i-1].mainsel = pLane->GetPredecessor();
  1314. xpathsection[i-1].mnStartLaneSel = pLane->GetPredecessor();
  1315. xpathsection[i-1].mnEndLaneSel = pLane->GetPredecessor();
  1316. bNeedChangeLane = false;
  1317. }
  1318. else
  1319. {
  1320. bNeedChangeLane = false;
  1321. }
  1322. }
  1323. }
  1324. }
  1325. }
  1326. else
  1327. {
  1328. if((pLane2->IsPredecessorSet())&&(nlr2 == 1))
  1329. {
  1330. if(pLane2->GetPredecessor() != xpathsection[i].mainsel)
  1331. {
  1332. bool bfindgood = false;
  1333. int ngoodlane = 0;
  1334. int j;
  1335. for(j=0;j<pLS2->GetLaneCount();j++)
  1336. {
  1337. if(pLS2->GetLane(j)->IsPredecessorSet())
  1338. {
  1339. if(pLS2->GetLane(j)->GetPredecessor() == xpathsection[i].mainsel)
  1340. {
  1341. ngoodlane = pLS2->GetLane(j)->GetId();
  1342. bfindgood = true;
  1343. break;
  1344. }
  1345. }
  1346. }
  1347. if(bfindgood)
  1348. {
  1349. xpathsection[i-1].mainsel = ngoodlane;
  1350. xpathsection[i-1].mnStartLaneSel = ngoodlane;
  1351. xpathsection[i-1].mnEndLaneSel = ngoodlane;
  1352. bNeedChangeLane = false;
  1353. }
  1354. }
  1355. else
  1356. {
  1357. bNeedChangeLane = false;
  1358. }
  1359. }
  1360. else
  1361. {
  1362. if((pLane2->IsSuccessorSet())&&(nlr2 == 2))
  1363. {
  1364. if(pLane2->GetSuccessor() != xpathsection[i].mainsel)
  1365. {
  1366. bool bfindgood = false;
  1367. int ngoodlane = 0;
  1368. int j;
  1369. for(j=0;j<pLS2->GetLaneCount();j++)
  1370. {
  1371. if(pLS2->GetLane(j)->IsSuccessorSet())
  1372. {
  1373. if(pLS2->GetLane(j)->GetSuccessor() == xpathsection[i].mainsel)
  1374. {
  1375. ngoodlane = pLS2->GetLane(j)->GetId();
  1376. bfindgood = true;
  1377. break;
  1378. }
  1379. }
  1380. }
  1381. if(bfindgood)
  1382. {
  1383. xpathsection[i-1].mainsel = ngoodlane;
  1384. xpathsection[i-1].mnStartLaneSel = ngoodlane;
  1385. xpathsection[i-1].mnEndLaneSel = ngoodlane;
  1386. bNeedChangeLane = false;
  1387. }
  1388. }
  1389. else
  1390. {
  1391. bNeedChangeLane = false;
  1392. }
  1393. }
  1394. else
  1395. {
  1396. if(nlr == 2)
  1397. {
  1398. if(pLane->IsPredecessorSet())
  1399. {
  1400. if(pLane->GetPredecessor() != xpathsection[i-1].mainsel)
  1401. {
  1402. xpathsection[i-1].mainsel = pLane->GetPredecessor();
  1403. xpathsection[i-1].mnStartLaneSel = pLane->GetPredecessor();
  1404. xpathsection[i-1].mnEndLaneSel = pLane->GetPredecessor();
  1405. bNeedChangeLane = false;
  1406. }
  1407. else
  1408. {
  1409. bNeedChangeLane = false;
  1410. }
  1411. }
  1412. }
  1413. else
  1414. {
  1415. if(pLane->IsSuccessorSet())
  1416. {
  1417. if(pLane->GetSuccessor() != xpathsection[i-1].mainsel)
  1418. {
  1419. xpathsection[i-1].mainsel = pLane->GetSuccessor();
  1420. xpathsection[i-1].mnStartLaneSel = pLane->GetSuccessor();
  1421. xpathsection[i-1].mnEndLaneSel = pLane->GetSuccessor();
  1422. bNeedChangeLane = false;
  1423. }
  1424. else
  1425. {
  1426. bNeedChangeLane = false;
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. if(bNeedChangeLane == true)
  1434. {
  1435. std::cout<<" Road "<<pRoad->GetRoadId()<<" need change lane "<<std::endl;
  1436. if(pRoad == pRoad2)
  1437. {
  1438. std::cout<<" Lane Change in road inter. "<<std::endl;
  1439. }
  1440. else
  1441. {
  1442. if(nlr == 2)
  1443. {
  1444. if(pLane2->IsSuccessorSet())
  1445. {
  1446. xpathsection[i].secondsel = pLane2->GetSuccessor();
  1447. }
  1448. else
  1449. {
  1450. int k;
  1451. int xlanecount = pLS->GetLaneCount();
  1452. for(k=0;k<xlanecount;k++)
  1453. {
  1454. if(pLS->GetLane(k)->IsPredecessorSet())
  1455. {
  1456. if(pLS->GetLane(k)->GetPredecessor() == pLane2->GetSuccessor())
  1457. {
  1458. xpathsection[i].secondsel = k;
  1459. break;
  1460. }
  1461. }
  1462. }
  1463. }
  1464. }
  1465. else
  1466. {
  1467. if(pLane2->IsPredecessorSet())
  1468. {
  1469. xpathsection[i].secondsel = pLane2->GetPredecessor();
  1470. }
  1471. else
  1472. {
  1473. int k;
  1474. int xlanecount = pLS->GetLaneCount();
  1475. for(k=0;k<xlanecount;k++)
  1476. {
  1477. if(pLS->GetLane(k)->IsSuccessorSet())
  1478. {
  1479. if(pLS->GetLane(k)->GetSuccessor() == pLane2->GetPredecessor())
  1480. {
  1481. xpathsection[i].secondsel = k;
  1482. break;
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. int k;
  1490. for(k=(nsize-1);k>i;k--)
  1491. {
  1492. if(xpathsection[k].mpRoad == xpathsection[i].mpRoad)
  1493. {
  1494. xpathsection[k].secondsel = xpathsection[i].secondsel;
  1495. }
  1496. }
  1497. }
  1498. else
  1499. {
  1500. xpathsection[i].secondsel = xpathsection[i].mainsel;
  1501. xpathsection[i-1].secondsel = xpathsection[i-1].mainsel;
  1502. }
  1503. if((noldmainsel * xpathsection[i-1].mainsel)<0)
  1504. {
  1505. std::cout<<" lane change sel error. "<<std::endl;
  1506. xpathsection[i-1].mainsel = noldmainsel;
  1507. xpathsection[i-1].secondsel = noldmainsel;
  1508. }
  1509. }
  1510. for(i=0;i<xpathsection.size();i++)
  1511. {
  1512. std::cout<<"path "<<i<<" road:"<<xpathsection[i].mroadid<<" section "<<xpathsection[i].msectionid
  1513. <<" lane "<<xpathsection[i].mainsel<<" sec lane is "<<xpathsection[i].secondsel<<std::endl;
  1514. }
  1515. return xpathsection;
  1516. // for(i=(nsize-1);i>=0;i--)
  1517. // {
  1518. // Road * pRoad = mroadedge[xvectorpathi]
  1519. // }
  1520. for(i=0;i<nsize;i++)
  1521. {
  1522. Road * pRoad = mroadedge[xvectorpath[i]].mpx;
  1523. int nlr = mroadedge[xvectorpath[i]].mnleftright;
  1524. // int nsectioncount = pRoad->GetLaneSectionCount();
  1525. int j;
  1526. j = mroadedge[xvectorpath[i]].mnsectionid;
  1527. LaneSection * pLaneSection = pRoad->GetLaneSection(j);
  1528. int nlane = nSel;
  1529. if(nlane <= 0)nlane = 10;
  1530. int mainselindex = 0;
  1531. if(nlr == 2)nlane = nlane*(-1);
  1532. int nlanecount = pLaneSection->GetLaneCount();
  1533. int k;
  1534. bool bFind = false;
  1535. while(bFind == false)
  1536. {
  1537. for(k=0;k<nlanecount;k++)
  1538. {
  1539. Lane * pLane = pLaneSection->GetLane(k);
  1540. if((nlane == pLane->GetId())&&(strncmp(pLane->GetType().data(),"driving",255) == 0))
  1541. {
  1542. bFind = true;
  1543. mainselindex = k;
  1544. break;
  1545. }
  1546. }
  1547. if(bFind)continue;
  1548. if(nlr == 1)nlane--;
  1549. else nlane++;
  1550. if(nlane == 0) //Find A can use lane;
  1551. {
  1552. // std::cout<<" Fail. can't find lane"<<std::endl;
  1553. for(k=0;k<nlanecount;k++)
  1554. {
  1555. Lane * pLane = pLaneSection->GetLane(k);
  1556. if(strncmp(pLane->GetType().data(),"driving",255) == 0)
  1557. {
  1558. if(nlr == 1)
  1559. {
  1560. if(pLane->GetId()> 0)
  1561. {
  1562. nlane = pLane->GetId();
  1563. mainselindex = k;
  1564. bFind = true;
  1565. break;
  1566. }
  1567. }
  1568. else
  1569. {
  1570. if(pLane->GetId()<0)
  1571. {
  1572. nlane = pLane->GetId();
  1573. mainselindex = k;
  1574. bFind = true;
  1575. break;
  1576. }
  1577. }
  1578. }
  1579. }
  1580. if(nlane == 0)
  1581. {
  1582. std::cout<<" Fail. can't find lane"<<std::endl;
  1583. }
  1584. break;
  1585. }
  1586. }
  1587. // std::cout<<" select lane is "<<nlane<<std::endl;
  1588. pathsection xps;
  1589. xps.mainsel = nlane;
  1590. xps.mnStartLaneSel = nlane;
  1591. xps.mnEndLaneSel = nlane;
  1592. xps.mainselindex = mainselindex;
  1593. // if((i>0)&&(pRoad->GetRoadLength()<300)) //Use Connection,not use default.
  1594. // {
  1595. // int nlast = xpathsection[i-1].mainselindex;
  1596. // for(k=0;k<nlanecount;k++)
  1597. // {
  1598. // Lane * pLane = pLaneSection->GetLane(k);
  1599. // if(pLane->IsPredecessorSet())
  1600. // {
  1601. // if(nlast == pLane->GetPredecessor())
  1602. // {
  1603. // xps.mainsel = pLane->GetId();
  1604. // break;
  1605. // }
  1606. // }
  1607. // }
  1608. // }
  1609. xps.mroadid = mroadedge[xvectorpath[i]].mroadid;
  1610. xps.msectionid = j;
  1611. xps.mnroadedgeid = xvectorpath[i];
  1612. xps.mpRoad = pRoad;
  1613. xpathsection.push_back(xps);
  1614. }
  1615. int nps = xpathsection.size();
  1616. for(i=0;i<nps;i++)
  1617. {
  1618. std::cout<<xpathsection[i].mroadid<<" "<<xpathsection[i].msectionid<<" "<<xpathsection[i].mainsel<<" "
  1619. <<xpathsection[i].mainselindex<<std::endl;
  1620. }
  1621. for(i=0;i<(nps-1);i++)
  1622. {
  1623. CalcLaneChange(&xpathsection[i],&xpathsection[i+1]);
  1624. }
  1625. for(i=0;i<nps;i++)
  1626. {
  1627. if((xpathsection[i].mnStartLaneSel == xpathsection[i].mnEndLaneSel) &&(xpathsection[i].mainsel != xpathsection[i].mnStartLaneSel))
  1628. {
  1629. xpathsection[i].mainsel = xpathsection[i].mnStartLaneSel;
  1630. }
  1631. if(xpathsection[i].mnStartLaneSel == xpathsection[i].mainsel)
  1632. {
  1633. xpathsection[i].mbStartToMainChange = false;
  1634. }
  1635. else
  1636. {
  1637. xpathsection[i].mbStartToMainChange = true;
  1638. }
  1639. if(xpathsection[i].mnEndLaneSel == xpathsection[i].mainsel)
  1640. {
  1641. xpathsection[i].mbMainToEndChange = false;
  1642. }
  1643. else
  1644. {
  1645. xpathsection[i].mbMainToEndChange = true;
  1646. }
  1647. }
  1648. // CalcLaneChange(&xpathsection[10], &xpathsection[11]);
  1649. // for(i=1;i<nsize;i++)
  1650. // {
  1651. // pathsection * p1 = &xpathsection[i-1];
  1652. // pathsection * p2 = &xpathsection[i];
  1653. // if(xpathsection[i-1].mpRoad != xpathsection[i].mpRoad)
  1654. // {
  1655. // CalcLaneChange(&xpathsection[i-1], &xpathsection[i]);
  1656. // }
  1657. // else
  1658. // {
  1659. // if(p1->mainsel != p2->mainsel)
  1660. // {
  1661. // p1->mbMainToEndChange = true;
  1662. // p1->mnEndLaneSel = p2->mainsel;
  1663. // if(abs(p1->mainsel) > abs(p2->mainsel))
  1664. // {
  1665. // p1->mnMainToEndLeftRight = 1;
  1666. // }
  1667. // else
  1668. // {
  1669. // p1->mnMainToEndLeftRight = 2;
  1670. // }
  1671. // }
  1672. // }
  1673. // }
  1674. for(i=0;i<nsize;i++)
  1675. {
  1676. std::cout<<xpathsection[i].mroadid<<" "<<xpathsection[i].mbStartToMainChange<<" "
  1677. <<xpathsection[i].mbMainToEndChange<<std::endl;
  1678. if(xpathsection[i].mbStartToMainChange == false)
  1679. {
  1680. xpathsection[i].mnStartLaneSel = xpathsection[i].mainsel;
  1681. }
  1682. if(xpathsection[i].mbMainToEndChange == false)
  1683. {
  1684. xpathsection[i].mnEndLaneSel = xpathsection[i].mainsel;
  1685. }
  1686. }
  1687. return xpathsection;
  1688. }
  1689. std::vector<lanenetunit> xodrdijkstra::GetLaneNet(Road *p1, int nsec1, Road *p2, int nsec2)
  1690. {
  1691. int i;
  1692. std::vector<lanenetunit> xln;
  1693. int nsize = mlanenet.size();
  1694. for(i=0;i<nsize;i++)
  1695. {
  1696. if((p1== mlanenet.at(i).mpFromRoad) &&(p2 == mlanenet.at(i).mpToRoad))
  1697. {
  1698. if((nsec1 == mlanenet.at(i).mnFromSection)&&(nsec2 == mlanenet.at(i).mnToSection))
  1699. {
  1700. xln.push_back(mlanenet.at(i));
  1701. }
  1702. }
  1703. }
  1704. return xln;
  1705. }
  1706. bool xodrdijkstra::IsInLaneNet(std::vector<lanenetunit> xln, Road *p1, int nsec1, int nlane1, Road *p2, int nsec2, int nlane2)
  1707. {
  1708. int i;
  1709. int nsize = xln.size();
  1710. for(i=0;i<nsize;i++)
  1711. {
  1712. if((p1== xln.at(i).mpFromRoad) &&(p2 == xln.at(i).mpToRoad))
  1713. {
  1714. if((nsec1 == xln.at(i).mnFromSection)&&(nsec2 == xln.at(i).mnToSection))
  1715. {
  1716. if((nlane1 == xln.at(i).mnFromLane)&&(nlane2 == xln.at(i).mnToLane))
  1717. {
  1718. return true;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. return false;
  1724. }