OpenDriveXmlWriter.cpp 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805
  1. #include "OpenDriveXmlWriter.h"
  2. #include <iostream>
  3. #include <algorithm>
  4. //#include "windows.h"
  5. using std::cout;
  6. using std::endl;
  7. /**
  8. * Constructor which saves a reference to OpenDrive structure
  9. */
  10. OpenDriveXmlWriter::OpenDriveXmlWriter (OpenDrive* openDriveObj)
  11. {
  12. mOpenDrive=openDriveObj;
  13. }
  14. /**
  15. * The following methods are used to create the XML representation of the OpenDrive structure
  16. * Methods follow the same hierarchical structure and are called automatically when WriteFile
  17. * is executed
  18. */
  19. bool OpenDriveXmlWriter::WriteHeader(TiXmlElement *node)
  20. {
  21. //Write the Header
  22. unsigned short int revMajor;
  23. unsigned short int revMinor;
  24. string name;
  25. float version;
  26. string date;
  27. double north;
  28. double south;
  29. double east;
  30. double west;
  31. double lat0;
  32. double lon0;
  33. double hdg0;
  34. string strvendor;
  35. Header *lHeader = mOpenDrive->GetHeader();
  36. lHeader->GetAllParams(revMajor, revMinor, name, version, date, north, south, east, west,lat0,lon0,hdg0);
  37. lHeader->GetVendor(strvendor);
  38. TiXmlElement *nodeHeader = new TiXmlElement("header");
  39. node->LinkEndChild(nodeHeader);
  40. nodeHeader->SetAttribute("revMajor",revMajor);
  41. nodeHeader->SetAttribute("revMinor",revMinor);
  42. nodeHeader->SetAttribute("name",name);
  43. nodeHeader->SetDoubleAttribute("version",version);
  44. nodeHeader->SetAttribute("date",date);
  45. std::stringstream snorth;
  46. snorth << setprecision(16) << setiosflags (ios_base::scientific) << north;
  47. nodeHeader->SetAttribute("north",snorth.str());
  48. std::stringstream ssouth;
  49. ssouth << setprecision(16) << setiosflags (ios_base::scientific) << south;
  50. nodeHeader->SetAttribute("south",ssouth.str());
  51. std::stringstream seast;
  52. seast << setprecision(16) << setiosflags (ios_base::scientific) << east;
  53. nodeHeader->SetAttribute("east",seast.str());
  54. std::stringstream swest;
  55. swest << setprecision(16) << setiosflags (ios_base::scientific) << west;
  56. nodeHeader->SetAttribute("west",swest.str());
  57. std::stringstream slat0;
  58. slat0 << setprecision(16) << setiosflags (ios_base::scientific) << lat0;
  59. nodeHeader->SetAttribute("lat0",slat0.str());
  60. std::stringstream slon0;
  61. slon0 << setprecision(16) << setiosflags (ios_base::scientific) << lon0;
  62. nodeHeader->SetAttribute("lon0",slon0.str());
  63. std::stringstream shdg0;
  64. shdg0 << setprecision(16) << setiosflags (ios_base::scientific) << hdg0;
  65. nodeHeader->SetAttribute("hdg0",shdg0.str());
  66. if(strvendor.size()>0)
  67. nodeHeader->SetAttribute("vendor",strvendor);
  68. else
  69. {
  70. nodeHeader->SetAttribute("vendor","adc");
  71. }
  72. std::string strgeoReference;
  73. std::string struserData;
  74. lHeader->GetgeoReference(strgeoReference);
  75. lHeader->GetuserData(struserData);
  76. if(strgeoReference != "")
  77. {
  78. TiXmlElement * nodegeoReference = new TiXmlElement("geoReference");
  79. nodegeoReference->Parse(strgeoReference.data(),0,TIXML_ENCODING_UTF8);
  80. nodeHeader->LinkEndChild(nodegeoReference);
  81. }
  82. if(struserData != "")
  83. {
  84. TiXmlElement * nodeuserData = new TiXmlElement("userData");
  85. nodeuserData->Parse(struserData.data(),0,TIXML_ENCODING_UTF8);
  86. nodeHeader->LinkEndChild(nodeuserData);
  87. }
  88. return true;
  89. }
  90. //--------------
  91. bool OpenDriveXmlWriter::WriteRoad(TiXmlElement *node, Road *road)
  92. {
  93. //Write road attributes
  94. string name;
  95. double length;
  96. string id;
  97. string junction;
  98. string rule;
  99. name = road->GetRoadName();
  100. length = road->GetRoadLength();
  101. id = road->GetRoadId();
  102. junction = road->GetRoadJunction();
  103. rule = road->GetRoadRule();
  104. TiXmlElement *nodeRoad = new TiXmlElement("road");
  105. node->LinkEndChild(nodeRoad);
  106. nodeRoad->SetAttribute("name",name);
  107. std::stringstream slength;
  108. slength << setprecision(16) << setiosflags (ios_base::scientific) << length;
  109. nodeRoad->SetAttribute("length",slength.str());
  110. nodeRoad->SetAttribute("id",id);
  111. nodeRoad->SetAttribute("junction",junction);
  112. if(rule != "")
  113. {
  114. nodeRoad->SetAttribute("rule",rule);
  115. }
  116. //Fill in
  117. //Links
  118. WriteRoadLinks (nodeRoad,road);
  119. //Types
  120. WriteRoadType(nodeRoad, road);
  121. //PlanView
  122. WritePlanView(nodeRoad, road);
  123. //ElevationProfile
  124. WriteElevationProfile(nodeRoad, road);
  125. //LateralProfile
  126. WriteLateralProfile(nodeRoad, road);
  127. //Proceed to Lanes
  128. WriteLanes(nodeRoad, road);
  129. //Proceed to Objects
  130. WriteObjects(nodeRoad, road);
  131. //Proceed to Signals
  132. WriteSignals(nodeRoad, road);
  133. vector<string> * puserDataVector = road->GetUserData();
  134. unsigned int luserDataCount = puserDataVector->size();
  135. for(unsigned int i=0;i<luserDataCount;i++)
  136. {
  137. TiXmlElement * nodeuserData = new TiXmlElement("userData");
  138. nodeuserData->Parse(puserDataVector->at(i).data(),0,TIXML_ENCODING_UTF8);
  139. nodeRoad->LinkEndChild(nodeuserData);
  140. }
  141. if(road->GetRoadBorrowCount()>0)
  142. {
  143. WriteRoadBorrows(nodeRoad,road);
  144. }
  145. if(road->GetRoadNoavoidCount()>0)
  146. {
  147. WriteRoadNoavoids(nodeRoad,road);
  148. }
  149. /*
  150. //Proceed to Surface
  151. subNode=node->FirstChildElement("surface");
  152. if (subNode)
  153. {
  154. WriteSurface(road, subNode);
  155. }
  156. */
  157. return true;
  158. }
  159. //--------------
  160. bool OpenDriveXmlWriter::WriteRoadLinks (TiXmlElement *node, Road* road)
  161. {
  162. TiXmlElement* nodeLink = new TiXmlElement("link");
  163. node->LinkEndChild(nodeLink);
  164. RoadLink *lPredecessor = road->GetPredecessor();
  165. if(lPredecessor)
  166. {
  167. TiXmlElement* nodeLinkPredecessor = new TiXmlElement("predecessor");
  168. nodeLink->LinkEndChild(nodeLinkPredecessor);
  169. nodeLinkPredecessor->SetAttribute("elementType", lPredecessor->GetElementType());
  170. nodeLinkPredecessor->SetAttribute("elementId", lPredecessor->GetElementId());
  171. nodeLinkPredecessor->SetAttribute("contactPoint", lPredecessor->GetContactPoint());
  172. if(lPredecessor->GetElementS()>=0)
  173. {
  174. std::stringstream ss;
  175. ss << setprecision(16) << setiosflags (ios_base::scientific) << lPredecessor->GetElementS();
  176. nodeLinkPredecessor->SetAttribute("elementS", ss.str());
  177. }
  178. if(lPredecessor->GetElementDir() != "")
  179. {
  180. nodeLinkPredecessor->SetAttribute("elementDir",lPredecessor->GetElementDir());
  181. }
  182. }
  183. RoadLink *lSuccessor = road->GetSuccessor();
  184. if(lSuccessor)
  185. {
  186. TiXmlElement* nodeLinkSuccessor = new TiXmlElement("successor");
  187. nodeLink->LinkEndChild(nodeLinkSuccessor);
  188. nodeLinkSuccessor->SetAttribute("elementType", lSuccessor->GetElementType());
  189. nodeLinkSuccessor->SetAttribute("elementId", lSuccessor->GetElementId());
  190. nodeLinkSuccessor->SetAttribute("contactPoint", lSuccessor->GetContactPoint());
  191. if(lSuccessor->GetElementS()>=0)
  192. {
  193. std::stringstream ss;
  194. ss << setprecision(16) << setiosflags (ios_base::scientific) << lSuccessor->GetElementS();
  195. nodeLinkSuccessor->SetAttribute("elementS", ss.str());
  196. }
  197. if(lSuccessor->GetElementDir() != "")
  198. {
  199. nodeLinkSuccessor->SetAttribute("elementDir",lSuccessor->GetElementDir());
  200. }
  201. }
  202. RoadNeighbor *lNeighbor1 = road->GetNeighbor1();
  203. if(lNeighbor1)
  204. {
  205. TiXmlElement* nodeLinkNeighbor1 = new TiXmlElement("neighbor");
  206. nodeLink->LinkEndChild(nodeLinkNeighbor1);
  207. nodeLinkNeighbor1->SetAttribute("side", lNeighbor1->GetSide());
  208. nodeLinkNeighbor1->SetAttribute("elementId", lNeighbor1->GetElementId());
  209. nodeLinkNeighbor1->SetAttribute("direction", lNeighbor1->GetDirection());
  210. }
  211. RoadNeighbor *lNeighbor2 = road->GetNeighbor2();
  212. if(lNeighbor2)
  213. {
  214. TiXmlElement* nodeLinkNeighbor2 = new TiXmlElement("neighbor");
  215. nodeLink->LinkEndChild(nodeLinkNeighbor2);
  216. nodeLinkNeighbor2->SetAttribute("side", lNeighbor2->GetSide());
  217. nodeLinkNeighbor2->SetAttribute("elementId", lNeighbor2->GetElementId());
  218. nodeLinkNeighbor2->SetAttribute("direction", lNeighbor2->GetDirection());
  219. }
  220. return true;
  221. }
  222. //--------------
  223. bool OpenDriveXmlWriter::WriteRoadTypeSpeed(TiXmlElement *node, RoadType *roadtype)
  224. {
  225. double maxSpeed;
  226. string unit;
  227. unsigned int roadTypeSpeedCount = roadtype->GetRoadTypeSpeedCount();
  228. for(unsigned int i=0;i<roadTypeSpeedCount;i++)
  229. {
  230. RoadTypeSpeed * lRoadTypeSpeed = roadtype->GetRoadTypeSpeed(i);
  231. maxSpeed = lRoadTypeSpeed->GetmaxSpeed();
  232. unit = lRoadTypeSpeed->Getunit();
  233. TiXmlElement * nodeRoadTypeSpeed = new TiXmlElement("speed");
  234. node->LinkEndChild(nodeRoadTypeSpeed);
  235. std::stringstream ss;
  236. ss << setprecision(16) << setiosflags (ios_base::scientific) << maxSpeed;
  237. nodeRoadTypeSpeed->SetAttribute("max",ss.str());
  238. nodeRoadTypeSpeed->SetAttribute("unit",unit);
  239. }
  240. return true;
  241. }
  242. //--------------
  243. bool OpenDriveXmlWriter::WriteRoadType (TiXmlElement *node, Road* road)
  244. {
  245. double s;
  246. string type;
  247. unsigned int roadTypeCount = road->GetRoadTypeCount();
  248. for(unsigned int i=0; i<roadTypeCount; i++)
  249. {
  250. RoadType *lRoadType = road->GetRoadType(i);
  251. s=lRoadType->GetS();
  252. type=lRoadType->GetType();
  253. TiXmlElement *nodeRoadType = new TiXmlElement("type");
  254. node->LinkEndChild(nodeRoadType);
  255. std::stringstream ss;
  256. ss << setprecision(16) << setiosflags (ios_base::scientific) << s;
  257. nodeRoadType->SetAttribute("s",ss.str());
  258. nodeRoadType->SetAttribute("type",type);
  259. WriteRoadTypeSpeed(nodeRoadType,lRoadType);
  260. }
  261. return true;
  262. }
  263. //--------------
  264. bool OpenDriveXmlWriter::WritePlanView(TiXmlElement *node, Road *road)
  265. {
  266. TiXmlElement* nodePlanView = new TiXmlElement("planView");
  267. node->LinkEndChild(nodePlanView);
  268. unsigned int geometryCount = road->GetGeometryBlockCount();
  269. for(unsigned int i=0; i<geometryCount; i++)
  270. {
  271. WriteGeometryBlock(nodePlanView, road->GetGeometryBlock(i));
  272. }
  273. return true;
  274. }
  275. //--------------
  276. bool OpenDriveXmlWriter::WriteGeometryBlock (TiXmlElement *node, GeometryBlock* geometryBlock)
  277. {
  278. if(geometryBlock->CheckIfLine())
  279. {
  280. WriteGeometry(node, geometryBlock->GetGeometryAt(0), geometryBlock->GetGeometryAt(0)->GetGeomType());
  281. }
  282. else
  283. {
  284. WriteGeometry(node, geometryBlock->GetGeometryAt(0), 1);
  285. WriteGeometry(node, geometryBlock->GetGeometryAt(1), 2);
  286. WriteGeometry(node, geometryBlock->GetGeometryAt(2), 1);
  287. }
  288. return true;
  289. }
  290. //--------------
  291. bool OpenDriveXmlWriter::WriteGeometry(TiXmlElement *node, RoadGeometry* roadGeometry, short int geometryType)
  292. {
  293. double s, x, y, hdg, length;
  294. s=roadGeometry->GetS();
  295. x=roadGeometry->GetX();
  296. y=roadGeometry->GetY();
  297. hdg=roadGeometry->GetHdg();
  298. length=roadGeometry->GetLength();
  299. //Write the geometry node
  300. TiXmlElement *nodeGeometry = new TiXmlElement("geometry");
  301. node->LinkEndChild(nodeGeometry);
  302. std::stringstream ss;
  303. ss << setprecision(16) << setiosflags (ios_base::scientific) << s;
  304. nodeGeometry->SetAttribute("s",ss.str());
  305. std::stringstream sx;
  306. sx << setprecision(16) << setiosflags (ios_base::scientific) << x;
  307. nodeGeometry->SetAttribute("x",sx.str());
  308. std::stringstream sy;
  309. sy << setprecision(16) << setiosflags (ios_base::scientific) << y;
  310. nodeGeometry->SetAttribute("y",sy.str());
  311. std::stringstream shdg;
  312. shdg << setprecision(16) << setiosflags (ios_base::scientific) << hdg;
  313. nodeGeometry->SetAttribute("hdg",shdg.str());
  314. std::stringstream slength;
  315. slength << setprecision(16) << setiosflags (ios_base::scientific) << length;
  316. nodeGeometry->SetAttribute("length",slength.str());
  317. //Write the type nodes
  318. switch ( geometryType )
  319. {
  320. case 0:
  321. {
  322. //line
  323. TiXmlElement *nodeLine = new TiXmlElement("line");
  324. nodeGeometry->LinkEndChild(nodeLine);
  325. break;
  326. }
  327. case 1:
  328. {
  329. //spiral
  330. double curvatureStart, curvatureEnd;
  331. GeometrySpiral *lSpiral=static_cast<GeometrySpiral*>(roadGeometry);
  332. curvatureStart=lSpiral->GetCurvatureStart();
  333. curvatureEnd=lSpiral->GetCurvatureEnd();
  334. TiXmlElement *nodeSpiral = new TiXmlElement("spiral");
  335. nodeGeometry->LinkEndChild(nodeSpiral);
  336. std::stringstream scurvatureStart;
  337. scurvatureStart << setprecision(16) << setiosflags (ios_base::scientific) << curvatureStart;
  338. nodeSpiral->SetAttribute("curvStart",scurvatureStart.str());
  339. std::stringstream scurvatureEnd;
  340. scurvatureEnd << setprecision(16) << setiosflags (ios_base::scientific) << curvatureEnd;
  341. nodeSpiral->SetAttribute("curvEnd",scurvatureEnd.str());
  342. break;
  343. }
  344. case 2:
  345. {
  346. //arc
  347. double curvature;
  348. GeometryArc *lArc=static_cast<GeometryArc*>(roadGeometry);
  349. curvature=lArc->GetCurvature();
  350. TiXmlElement *nodeArc = new TiXmlElement("arc");
  351. nodeGeometry->LinkEndChild(nodeArc);
  352. std::stringstream scurvature;
  353. scurvature << setprecision(16) << setiosflags (ios_base::scientific) << curvature;
  354. nodeArc->SetAttribute("curvature",scurvature.str());
  355. break;
  356. }
  357. case 3:
  358. {
  359. double ua,ub,uc,ud;
  360. GeometryPoly3 * lp3 = static_cast<GeometryPoly3 *>(roadGeometry);
  361. ua = lp3->GetA();
  362. ub = lp3->GetB();
  363. uc = lp3->GetC();
  364. ud = lp3->GetD();
  365. TiXmlElement *nodePoly3 = new TiXmlElement("poly3");
  366. nodeGeometry->LinkEndChild(nodePoly3);
  367. nodePoly3->SetDoubleAttribute("a",ua);
  368. nodePoly3->SetDoubleAttribute("b",ub);
  369. nodePoly3->SetDoubleAttribute("c",uc);
  370. nodePoly3->SetDoubleAttribute("d",ud);
  371. //poly3
  372. break;
  373. }
  374. case 4:
  375. { //paramPoly3 add by Yu Chuli. 2019.11.1
  376. double ua,ub,uc,ud,va,vb,vc,vd;
  377. bool bNormal;
  378. GeometryParamPoly3 *lpp3=static_cast<GeometryParamPoly3 *>(roadGeometry);
  379. ua = lpp3->GetuA();
  380. ub = lpp3->GetuB();
  381. uc = lpp3->GetuC();
  382. ud = lpp3->GetuD();
  383. va = lpp3->GetvA();
  384. vb = lpp3->GetvB();
  385. vc = lpp3->GetvC();
  386. vd = lpp3->GetvD();
  387. bNormal = lpp3->GetNormal();
  388. TiXmlElement *nodeParamPoly3 = new TiXmlElement("paramPoly3");
  389. nodeGeometry->LinkEndChild(nodeParamPoly3);
  390. std::stringstream sua;
  391. sua << setprecision(16) << setiosflags (ios_base::scientific) << ua;
  392. nodeParamPoly3->SetAttribute("aU",sua.str());
  393. std::stringstream sub;
  394. sub << setprecision(16) << setiosflags (ios_base::scientific) << ub;
  395. nodeParamPoly3->SetAttribute("bU",sub.str());
  396. std::stringstream suc;
  397. suc << setprecision(16) << setiosflags (ios_base::scientific) << uc;
  398. nodeParamPoly3->SetAttribute("cU",suc.str());
  399. std::stringstream sud;
  400. sud << setprecision(16) << setiosflags (ios_base::scientific) << ud;
  401. nodeParamPoly3->SetAttribute("dU",sud.str());
  402. std::stringstream sva;
  403. sva << setprecision(16) << setiosflags (ios_base::scientific) << va;
  404. nodeParamPoly3->SetAttribute("aV",sva.str());
  405. std::stringstream svb;
  406. svb << setprecision(16) << setiosflags (ios_base::scientific) << vb;
  407. nodeParamPoly3->SetAttribute("bV",svb.str());
  408. std::stringstream svc;
  409. svc << setprecision(16) << setiosflags (ios_base::scientific) << vc;
  410. nodeParamPoly3->SetAttribute("cV",svc.str());
  411. std::stringstream svd;
  412. svd << setprecision(16) << setiosflags (ios_base::scientific) << vd;
  413. nodeParamPoly3->SetAttribute("dV",svd.str());
  414. if(bNormal == false)
  415. {
  416. nodeParamPoly3->SetAttribute("pRange","arcLength");
  417. }
  418. break;
  419. }
  420. }
  421. return true;
  422. }
  423. //--------------
  424. bool OpenDriveXmlWriter::WriteElevationProfile (TiXmlElement *node, Road* road)
  425. {
  426. double s, a, b, c, d;
  427. TiXmlElement* nodeElevationProfile = new TiXmlElement("elevationProfile");
  428. node->LinkEndChild(nodeElevationProfile);
  429. unsigned int lElevationCount = road->GetElevationCount();
  430. for(unsigned int i=0; i<lElevationCount; i++)
  431. {
  432. Elevation *lElevation = road->GetElevation(i);
  433. s=lElevation->GetS();
  434. a=lElevation->GetA();
  435. b=lElevation->GetB();
  436. c=lElevation->GetC();
  437. d=lElevation->GetD();
  438. TiXmlElement *nodeElevation = new TiXmlElement("elevation");
  439. nodeElevationProfile->LinkEndChild(nodeElevation);
  440. std::stringstream ss;
  441. ss << setprecision(16) << setiosflags (ios_base::scientific) << s;
  442. nodeElevation->SetAttribute("s",ss.str());
  443. std::stringstream sa;
  444. sa << setprecision(16) << setiosflags (ios_base::scientific) << a;
  445. nodeElevation->SetAttribute("a",sa.str());
  446. std::stringstream sb;
  447. sb << setprecision(16) << setiosflags (ios_base::scientific) << b;
  448. nodeElevation->SetAttribute("b",sb.str());
  449. std::stringstream sc;
  450. sc << setprecision(16) << setiosflags (ios_base::scientific) << c;
  451. nodeElevation->SetAttribute("c",sc.str());
  452. std::stringstream sd;
  453. sd << setprecision(16) << setiosflags (ios_base::scientific) << d;
  454. nodeElevation->SetAttribute("d",sd.str());
  455. }
  456. return true;
  457. }
  458. //--------------
  459. bool OpenDriveXmlWriter::WriteLateralProfile (TiXmlElement *node, Road* road)
  460. {
  461. double s, a, b, c, d;
  462. string side;
  463. TiXmlElement* nodeLateralProfile = new TiXmlElement("lateralProfile");
  464. node->LinkEndChild(nodeLateralProfile);
  465. unsigned int lSuperElevationCount = road->GetSuperElevationCount();
  466. for(unsigned int i=0; i<lSuperElevationCount; i++)
  467. {
  468. SuperElevation *lSuperElevation = road->GetSuperElevation(i);
  469. s=lSuperElevation->GetS();
  470. a=lSuperElevation->GetA();
  471. b=lSuperElevation->GetB();
  472. c=lSuperElevation->GetC();
  473. d=lSuperElevation->GetD();
  474. TiXmlElement *nodeSuperElevation = new TiXmlElement("superelevation");
  475. nodeLateralProfile->LinkEndChild(nodeSuperElevation);
  476. std::stringstream ss;
  477. ss << setprecision(16) << setiosflags (ios_base::scientific) << s;
  478. nodeSuperElevation->SetAttribute("s",ss.str());
  479. std::stringstream sa;
  480. sa << setprecision(16) << setiosflags (ios_base::scientific) << a;
  481. nodeSuperElevation->SetAttribute("a",sa.str());
  482. std::stringstream sb;
  483. sb << setprecision(16) << setiosflags (ios_base::scientific) << b;
  484. nodeSuperElevation->SetAttribute("b",sb.str());
  485. std::stringstream sc;
  486. sc << setprecision(16) << setiosflags (ios_base::scientific) << c;
  487. nodeSuperElevation->SetAttribute("c",sc.str());
  488. std::stringstream sd;
  489. sd << setprecision(16) << setiosflags (ios_base::scientific) << d;
  490. nodeSuperElevation->SetAttribute("d",sd.str());
  491. }
  492. unsigned int lCrossfallCount = road->GetCrossfallCount();
  493. for(unsigned int i=0; i<lCrossfallCount; i++)
  494. {
  495. Crossfall *lCrossfall = road->GetCrossfall(i);
  496. s=lCrossfall->GetS();
  497. a=lCrossfall->GetA();
  498. b=lCrossfall->GetB();
  499. c=lCrossfall->GetC();
  500. d=lCrossfall->GetD();
  501. side=lCrossfall->GetSide();
  502. TiXmlElement *nodeCrossfall = new TiXmlElement("crossfall");
  503. nodeLateralProfile->LinkEndChild(nodeCrossfall);
  504. nodeCrossfall->SetAttribute("side",side);
  505. std::stringstream ss;
  506. ss << setprecision(16) << setiosflags (ios_base::scientific) << s;
  507. nodeCrossfall->SetAttribute("s",ss.str());
  508. std::stringstream sa;
  509. sa << setprecision(16) << setiosflags (ios_base::scientific) << a;
  510. nodeCrossfall->SetAttribute("a",sa.str());
  511. std::stringstream sb;
  512. sb << setprecision(16) << setiosflags (ios_base::scientific) << b;
  513. nodeCrossfall->SetAttribute("b",sb.str());
  514. std::stringstream sc;
  515. sc << setprecision(16) << setiosflags (ios_base::scientific) << c;
  516. nodeCrossfall->SetAttribute("c",sc.str());
  517. std::stringstream sd;
  518. sd << setprecision(16) << setiosflags (ios_base::scientific) << d;
  519. nodeCrossfall->SetAttribute("d",sd.str());
  520. }
  521. return true;
  522. }
  523. //--------------
  524. bool OpenDriveXmlWriter::WriteLanes (TiXmlElement *node, Road* road)
  525. {
  526. TiXmlElement* nodeLanes = new TiXmlElement("lanes");
  527. node->LinkEndChild(nodeLanes);
  528. unsigned int lLaneSectionCount = road->GetLaneSectionCount();
  529. for(unsigned int i=0; i<lLaneSectionCount; i++)
  530. {
  531. WriteLaneSections(nodeLanes, road->GetLaneSection(i));
  532. }
  533. unsigned int lLaneOffsetCount = road->GetLaneOffsetCount();
  534. for(unsigned int i=0; i<lLaneOffsetCount; i++)
  535. {
  536. WriteLaneOffset(nodeLanes, road->GetLaneOffset(i));
  537. }
  538. return true;
  539. }
  540. //--------------
  541. bool OpenDriveXmlWriter::WriteLaneSections (TiXmlElement *node, LaneSection *laneSection)
  542. {
  543. double s;
  544. s=laneSection->GetS();
  545. TiXmlElement* nodeLaneSection = new TiXmlElement("laneSection");
  546. node->LinkEndChild(nodeLaneSection);
  547. std::stringstream ss;
  548. ss << setprecision(16) << setiosflags (ios_base::scientific) << s;
  549. nodeLaneSection->SetAttribute("s",ss.str());
  550. if(laneSection->GetSingleSide() != "")
  551. {
  552. nodeLaneSection->SetAttribute("singleSide",laneSection->GetSingleSide());
  553. }
  554. //Fill in lane section
  555. short int curType=1;
  556. TiXmlElement* nodeLanesLeft=NULL;
  557. if(laneSection->GetLeftLaneCount()>0)
  558. {
  559. nodeLanesLeft = new TiXmlElement("left");
  560. nodeLaneSection->LinkEndChild(nodeLanesLeft);
  561. }
  562. TiXmlElement* nodeLanesCenter = new TiXmlElement("center");
  563. nodeLaneSection->LinkEndChild(nodeLanesCenter);
  564. TiXmlElement* nodeLanesRight=NULL;
  565. if(laneSection->GetRightLaneCount()>0)
  566. {
  567. nodeLanesRight = new TiXmlElement("right");
  568. nodeLaneSection->LinkEndChild(nodeLanesRight);
  569. }
  570. unsigned int lLaneCount = laneSection->GetLaneCount();
  571. for(unsigned int i=0; i<lLaneCount; i++)
  572. {
  573. Lane *lLane = laneSection->GetLane(i);
  574. short int lType=lLane->GetSide();
  575. if(lType>0 && nodeLanesLeft!=NULL)
  576. {
  577. WriteLane(nodeLanesLeft, lLane);
  578. }
  579. else if(lType==0)
  580. {
  581. WriteLane(nodeLanesCenter, lLane);
  582. }
  583. else if(lType<0 && nodeLanesRight!=NULL)
  584. {
  585. WriteLane(nodeLanesRight, lLane);
  586. }
  587. }
  588. return true;
  589. }
  590. //--------------
  591. bool OpenDriveXmlWriter::WriteLaneOffset(TiXmlElement *node, LaneOffset *laneOffset)
  592. {
  593. double s;
  594. s=laneOffset->GetS();
  595. TiXmlElement* nodeLaneSection = new TiXmlElement("laneOffset");
  596. node->LinkEndChild(nodeLaneSection);
  597. nodeLaneSection->SetDoubleAttribute("s",laneOffset->GetS());
  598. nodeLaneSection->SetDoubleAttribute("a",laneOffset->Geta());
  599. nodeLaneSection->SetDoubleAttribute("b",laneOffset->Getb());
  600. nodeLaneSection->SetDoubleAttribute("c",laneOffset->Getc());
  601. nodeLaneSection->SetDoubleAttribute("d",laneOffset->Getd());
  602. // std::stringstream ss;
  603. // ss << setprecision(16) << setiosflags (ios_base::scientific) << s;
  604. // nodeLaneSection->SetAttribute("s",ss.str());
  605. // ss << setprecision(16) << setiosflags (ios_base::scientific) << laneOffset->Geta();
  606. // nodeLaneSection->SetAttribute("a",ss.str());
  607. // ss << setprecision(16) << setiosflags (ios_base::scientific) << laneOffset->Getb();
  608. // nodeLaneSection->SetAttribute("b",ss.str());
  609. // ss << setprecision(16) << setiosflags (ios_base::scientific) << laneOffset->Getc();
  610. // nodeLaneSection->SetAttribute("c",ss.str());
  611. // ss << setprecision(16) << setiosflags (ios_base::scientific) << laneOffset->Getd();
  612. // nodeLaneSection->SetAttribute("d",ss.str());
  613. return true;
  614. }
  615. //--------------
  616. bool OpenDriveXmlWriter::WriteLane (TiXmlElement *node, Lane* lane)
  617. {
  618. //Write Lane attributes
  619. int id;
  620. string type;
  621. string level;
  622. bool boolLevel;
  623. int predecessor;
  624. int successor;
  625. id=lane->GetId();
  626. type=lane->GetType();
  627. boolLevel=lane->GetLevel();
  628. if(boolLevel) level="true";
  629. else level="false";
  630. predecessor=lane->GetPredecessor();
  631. successor=lane->GetSuccessor();
  632. TiXmlElement* nodeLane = new TiXmlElement("lane");
  633. node->LinkEndChild(nodeLane);
  634. //Attributes
  635. nodeLane->SetAttribute("id",id);
  636. nodeLane->SetAttribute("type",type);
  637. nodeLane->SetAttribute("level",level);
  638. //Links
  639. TiXmlElement* nodeLaneLink = new TiXmlElement("link");
  640. nodeLane->LinkEndChild(nodeLaneLink);
  641. if(lane->IsPredecessorSet())
  642. {
  643. TiXmlElement* nodeLaneLinkPredecessor = new TiXmlElement("predecessor");
  644. nodeLaneLink->LinkEndChild(nodeLaneLinkPredecessor);
  645. nodeLaneLinkPredecessor->SetAttribute("id",predecessor);
  646. }
  647. if(lane->IsSuccessorSet())
  648. {
  649. TiXmlElement* nodeLaneLinkSuccessor = new TiXmlElement("successor");
  650. nodeLaneLink->LinkEndChild(nodeLaneLinkSuccessor);
  651. nodeLaneLinkSuccessor->SetAttribute("id",successor);
  652. }
  653. //Lane Width
  654. unsigned int lLaneWidthCount = lane->GetLaneWidthCount();
  655. for(unsigned int i=0; i<lLaneWidthCount; i++)
  656. {
  657. WriteLaneWidth(nodeLane, lane->GetLaneWidth(i));
  658. }
  659. //Lane Border
  660. unsigned int lLaneBorderCount = lane->GetLaneBorderCount();
  661. for(unsigned int i=0; i<lLaneBorderCount; i++)
  662. {
  663. WriteLaneBorder(nodeLane, lane->GetLaneBorder(i));
  664. }
  665. //Lane Road Mark
  666. unsigned int lLaneRoadMark = lane->GetLaneRoadMarkCount();
  667. for(unsigned int i=0; i<lLaneRoadMark; i++)
  668. {
  669. WriteLaneRoadMark(nodeLane, lane->GetLaneRoadMark(i));
  670. }
  671. //Lane Material
  672. unsigned int lLaneMaterial = lane->GetLaneMaterialCount();
  673. for(unsigned int i=0; i<lLaneMaterial; i++)
  674. {
  675. WriteLaneMaterial(nodeLane, lane->GetLaneMaterial(i));
  676. }
  677. //Lane Visibility
  678. unsigned int lLaneVisibility = lane->GetLaneVisibilityCount();
  679. for(unsigned int i=0; i<lLaneVisibility; i++)
  680. {
  681. WriteLaneVisibility(nodeLane, lane->GetLaneVisibility(i));
  682. }
  683. //Lane speed
  684. unsigned int lLaneSpeed = lane->GetLaneSpeedCount();
  685. for(unsigned int i=0; i<lLaneSpeed; i++)
  686. {
  687. WriteLaneSpeed(nodeLane, lane->GetLaneSpeed(i));
  688. }
  689. //Lane access
  690. unsigned int lLaneAccess = lane->GetLaneAccessCount();
  691. for(unsigned int i=0; i<lLaneAccess; i++)
  692. {
  693. WriteLaneAccess(nodeLane, lane->GetLaneAccess(i));
  694. }
  695. //Lane height
  696. unsigned int lLaneHeight = lane->GetLaneHeightCount();
  697. for(unsigned int i=0; i<lLaneHeight; i++)
  698. {
  699. WriteLaneHeight(nodeLane, lane->GetLaneHeight(i));
  700. }
  701. // string struserData;
  702. vector<string> * puserDataVector = lane->GetUserDataVector();
  703. unsigned int luserDataCount = puserDataVector->size();
  704. for(unsigned int i=0;i<luserDataCount;i++)
  705. {
  706. TiXmlElement * nodeuserData = new TiXmlElement("userData");
  707. nodeuserData->Parse(puserDataVector->at(i).data(),0,TIXML_ENCODING_UTF8);
  708. nodeLane->LinkEndChild(nodeuserData);
  709. }
  710. // lane->GetuserData(struserData);
  711. // if(struserData != "")
  712. // {
  713. // TiXmlElement * nodeuserData = new TiXmlElement("userData");
  714. // nodeuserData->Parse(struserData.data(),0,TIXML_ENCODING_UTF8);
  715. // nodeLane->LinkEndChild(nodeuserData);
  716. // }
  717. return true;
  718. }
  719. //--------------
  720. bool OpenDriveXmlWriter::WriteLaneBorder(TiXmlElement *node, LaneBorder* laneBorder)
  721. {
  722. double sOffset, a, b, c, d;
  723. sOffset=laneBorder->GetS();
  724. a=laneBorder->GetA();
  725. b=laneBorder->GetB();
  726. c=laneBorder->GetC();
  727. d=laneBorder->GetD();
  728. TiXmlElement* nodeLaneBorder = new TiXmlElement("border");
  729. node->LinkEndChild(nodeLaneBorder);
  730. std::stringstream ssOffset;
  731. ssOffset << setprecision(16) << setiosflags (ios_base::scientific) << sOffset;
  732. nodeLaneBorder->SetAttribute("sOffset",ssOffset.str());
  733. std::stringstream sa;
  734. sa << setprecision(16) << setiosflags (ios_base::scientific) << a;
  735. nodeLaneBorder->SetAttribute("a",sa.str());
  736. std::stringstream sb;
  737. sb << setprecision(16) << setiosflags (ios_base::scientific) << b;
  738. nodeLaneBorder->SetAttribute("b",sb.str());
  739. std::stringstream sc;
  740. sc << setprecision(16) << setiosflags (ios_base::scientific) << c;
  741. nodeLaneBorder->SetAttribute("c",sc.str());
  742. std::stringstream sd;
  743. sd << setprecision(16) << setiosflags (ios_base::scientific) << d;
  744. nodeLaneBorder->SetAttribute("d",sd.str());
  745. return true;
  746. }
  747. //--------------
  748. bool OpenDriveXmlWriter::WriteLaneWidth(TiXmlElement *node, LaneWidth* laneWidth)
  749. {
  750. double sOffset, a, b, c, d;
  751. sOffset=laneWidth->GetS();
  752. a=laneWidth->GetA();
  753. b=laneWidth->GetB();
  754. c=laneWidth->GetC();
  755. d=laneWidth->GetD();
  756. TiXmlElement* nodeLaneWidth = new TiXmlElement("width");
  757. node->LinkEndChild(nodeLaneWidth);
  758. std::stringstream ssOffset;
  759. ssOffset << setprecision(16) << setiosflags (ios_base::scientific) << sOffset;
  760. nodeLaneWidth->SetAttribute("sOffset",ssOffset.str());
  761. std::stringstream sa;
  762. sa << setprecision(16) << setiosflags (ios_base::scientific) << a;
  763. nodeLaneWidth->SetAttribute("a",sa.str());
  764. std::stringstream sb;
  765. sb << setprecision(16) << setiosflags (ios_base::scientific) << b;
  766. nodeLaneWidth->SetAttribute("b",sb.str());
  767. std::stringstream sc;
  768. sc << setprecision(16) << setiosflags (ios_base::scientific) << c;
  769. nodeLaneWidth->SetAttribute("c",sc.str());
  770. std::stringstream sd;
  771. sd << setprecision(16) << setiosflags (ios_base::scientific) << d;
  772. nodeLaneWidth->SetAttribute("d",sd.str());
  773. return true;
  774. }
  775. //--------------
  776. bool OpenDriveXmlWriter::WriteLaneRoadMark(TiXmlElement *node, LaneRoadMark* laneRoadMark)
  777. {
  778. double sOffset;
  779. string type;
  780. string weight;
  781. string color;
  782. double width;
  783. string laneChange;
  784. sOffset=laneRoadMark->GetS();
  785. type=laneRoadMark->GetType();
  786. weight=laneRoadMark->GetWeight();
  787. color=laneRoadMark->GetColor();
  788. width=laneRoadMark->GetWidth();
  789. laneChange=laneRoadMark->GetLaneChange();
  790. TiXmlElement* nodeLaneRoadMark = new TiXmlElement("roadMark");
  791. node->LinkEndChild(nodeLaneRoadMark);
  792. std::stringstream ssOffset;
  793. ssOffset << setprecision(16) << setiosflags (ios_base::scientific) << sOffset;
  794. nodeLaneRoadMark->SetAttribute("sOffset",ssOffset.str());
  795. nodeLaneRoadMark->SetAttribute("type",type);
  796. nodeLaneRoadMark->SetAttribute("weight",weight);
  797. nodeLaneRoadMark->SetAttribute("color",color);
  798. std::stringstream swidth;
  799. swidth << setprecision(16) << setiosflags (ios_base::scientific) << width;
  800. nodeLaneRoadMark->SetAttribute("width",swidth.str());
  801. nodeLaneRoadMark->SetAttribute("laneChange",laneChange);
  802. return true;
  803. }
  804. //--------------
  805. bool OpenDriveXmlWriter::WriteLaneMaterial(TiXmlElement *node, LaneMaterial* laneMaterial)
  806. {
  807. double sOffset;
  808. string surface;
  809. double friction;
  810. double roughness;
  811. sOffset=laneMaterial->GetS();
  812. surface=laneMaterial->GetSurface();
  813. friction=laneMaterial->GetFriction();
  814. roughness=laneMaterial->GetRoughness();
  815. TiXmlElement* nodeLaneMaterial = new TiXmlElement("material");
  816. node->LinkEndChild(nodeLaneMaterial);
  817. std::stringstream ssOffset;
  818. ssOffset << setprecision(16) << setiosflags (ios_base::scientific) << sOffset;
  819. nodeLaneMaterial->SetAttribute("sOffset",ssOffset.str());
  820. nodeLaneMaterial->SetAttribute("surface",surface);
  821. std::stringstream sfriction;
  822. sfriction << setprecision(16) << setiosflags (ios_base::scientific) << friction;
  823. nodeLaneMaterial->SetAttribute("friction",sfriction.str());
  824. std::stringstream sroughness;
  825. sroughness << setprecision(16) << setiosflags (ios_base::scientific) << roughness;
  826. nodeLaneMaterial->SetAttribute("roughness",sroughness.str());
  827. return true;
  828. }
  829. //--------------
  830. bool OpenDriveXmlWriter::WriteLaneVisibility(TiXmlElement *node, LaneVisibility* laneVisibility)
  831. {
  832. double sOffset;
  833. double forward;
  834. double back;
  835. double left;
  836. double right;
  837. sOffset=laneVisibility->GetS();
  838. forward=laneVisibility->GetForward();
  839. back=laneVisibility->GetBack();
  840. left=laneVisibility->GetLeft();
  841. right=laneVisibility->GetRight();
  842. TiXmlElement* nodeLaneVisibility = new TiXmlElement("visibility");
  843. node->LinkEndChild(nodeLaneVisibility);
  844. std::stringstream ssOffset;
  845. ssOffset << setprecision(16) << setiosflags (ios_base::scientific) << sOffset;
  846. nodeLaneVisibility->SetAttribute("sOffset",ssOffset.str());
  847. std::stringstream sforward;
  848. sforward << setprecision(16) << setiosflags (ios_base::scientific) << forward;
  849. nodeLaneVisibility->SetAttribute("forward",sforward.str());
  850. std::stringstream sback;
  851. sback << setprecision(16) << setiosflags (ios_base::scientific) << back;
  852. nodeLaneVisibility->SetAttribute("back",sback.str());
  853. std::stringstream sleft;
  854. sleft << setprecision(16) << setiosflags (ios_base::scientific) << left;
  855. nodeLaneVisibility->SetAttribute("left",sleft.str());
  856. std::stringstream sright;
  857. sright << setprecision(16) << setiosflags (ios_base::scientific) << right;
  858. nodeLaneVisibility->SetAttribute("right",sright.str());
  859. return true;
  860. }
  861. //--------------
  862. bool OpenDriveXmlWriter::WriteLaneSpeed(TiXmlElement *node, LaneSpeed* laneSpeed)
  863. {
  864. double sOffset;
  865. double max;
  866. sOffset=laneSpeed->GetS();
  867. max=laneSpeed->GetMax();
  868. TiXmlElement* nodeLaneSpeed = new TiXmlElement("speed");
  869. node->LinkEndChild(nodeLaneSpeed);
  870. std::stringstream ssOffset;
  871. ssOffset << setprecision(16) << setiosflags (ios_base::scientific) << sOffset;
  872. nodeLaneSpeed->SetAttribute("sOffset",ssOffset.str());
  873. std::stringstream smax;
  874. smax << setprecision(16) << setiosflags (ios_base::scientific) << max;
  875. nodeLaneSpeed->SetAttribute("max",smax.str());
  876. return true;
  877. }
  878. //--------------
  879. bool OpenDriveXmlWriter::WriteLaneAccess(TiXmlElement *node, LaneAccess* laneAccess)
  880. {
  881. double sOffset;
  882. string restriction;
  883. sOffset=laneAccess->GetS();
  884. restriction=laneAccess->GetRestriction();
  885. TiXmlElement* nodeLaneAccess = new TiXmlElement("access");
  886. node->LinkEndChild(nodeLaneAccess);
  887. std::stringstream ssOffset;
  888. ssOffset << setprecision(16) << setiosflags (ios_base::scientific) << sOffset;
  889. nodeLaneAccess->SetAttribute("sOffset",ssOffset.str());
  890. nodeLaneAccess->SetAttribute("restriction",restriction);
  891. return true;
  892. }
  893. //--------------
  894. bool OpenDriveXmlWriter::WriteLaneHeight(TiXmlElement *node, LaneHeight* laneHeight)
  895. {
  896. double sOffset;
  897. double inner;
  898. double outer;
  899. sOffset=laneHeight->GetS();
  900. inner=laneHeight->GetInner();
  901. outer=laneHeight->GetOuter();
  902. TiXmlElement* nodeLaneHeight = new TiXmlElement("height");
  903. node->LinkEndChild(nodeLaneHeight);
  904. std::stringstream ssOffset;
  905. ssOffset << setprecision(16) << setiosflags (ios_base::scientific) << sOffset;
  906. nodeLaneHeight->SetAttribute("sOffset",ssOffset.str());
  907. std::stringstream sinner;
  908. sinner << setprecision(16) << setiosflags (ios_base::scientific) << inner;
  909. nodeLaneHeight->SetAttribute("inner",sinner.str());
  910. std::stringstream souter;
  911. souter << setprecision(16) << setiosflags (ios_base::scientific) << outer;
  912. nodeLaneHeight->SetAttribute("outer",souter.str());
  913. return true;
  914. }
  915. //--------------
  916. //--------------
  917. bool OpenDriveXmlWriter::WriteObjects (TiXmlElement *node, Road* road)
  918. {
  919. TiXmlElement* nodeObjects = new TiXmlElement("objects");
  920. node->LinkEndChild(nodeObjects);
  921. unsigned int lObjectCount = road->GetObjectCount();
  922. for(unsigned int i=0; i<lObjectCount; i++)
  923. {
  924. WriteObject(nodeObjects, road->GetObject(i));
  925. }
  926. return true;
  927. }
  928. //--------------
  929. bool OpenDriveXmlWriter::WriteObject(TiXmlElement *node, Object *pObject)
  930. {
  931. TiXmlElement* nodeObject = new TiXmlElement("object");
  932. node->LinkEndChild(nodeObject);
  933. nodeObject->SetDoubleAttribute("t",pObject->Gett());
  934. nodeObject->SetDoubleAttribute("zOffset",pObject->GetzOffset());
  935. if(pObject->Gettype() != "")
  936. {
  937. nodeObject->SetAttribute("type",pObject->Gettype());
  938. }
  939. double validLength;
  940. if(pObject->GetvalidLength(validLength) == 1)
  941. {
  942. nodeObject->SetDoubleAttribute("validLength",validLength);
  943. }
  944. if(pObject->Getorientation() != "")
  945. {
  946. nodeObject->SetAttribute("orientation",pObject->Getorientation());
  947. }
  948. if(pObject->Getsubtype() != "")
  949. {
  950. nodeObject->SetAttribute("subtype",pObject->Getsubtype());
  951. }
  952. if(pObject->Getdynamic() != "")
  953. {
  954. nodeObject->SetAttribute("dynamic",pObject->Getdynamic());
  955. }
  956. double hdg;
  957. if(pObject->Gethdg(hdg) == 1)
  958. {
  959. nodeObject->SetDoubleAttribute("hdg",hdg);
  960. }
  961. if(pObject->Getname() != "")
  962. {
  963. nodeObject->SetAttribute("name",pObject->Getname());
  964. }
  965. double pitch;
  966. if(pObject->Getpitch(pitch) == 1)
  967. {
  968. nodeObject->SetDoubleAttribute("pitch",pitch);
  969. }
  970. nodeObject->SetAttribute("id",pObject->Getid());
  971. double roll;
  972. if(pObject->Getroll(roll) == 1)
  973. {
  974. nodeObject->SetDoubleAttribute("roll",roll);
  975. }
  976. double height;
  977. if(pObject->Getheight(height) == 1)
  978. {
  979. nodeObject->SetDoubleAttribute("height",height);
  980. }
  981. nodeObject->SetDoubleAttribute("s",pObject->Gets());
  982. double length;
  983. if(pObject->Getlength(length) == 1)
  984. {
  985. nodeObject->SetDoubleAttribute("length",length);
  986. }
  987. double width;
  988. if(pObject->Getwidth(width) == 1)
  989. {
  990. nodeObject->SetDoubleAttribute("width",width);
  991. }
  992. double radius;
  993. if(pObject->Getradius(radius) == 1)
  994. {
  995. nodeObject->SetDoubleAttribute("radius",radius);
  996. }
  997. Object_parkingSpace parkingSpace;
  998. if(pObject->GetparkingSpace(parkingSpace) == 1)
  999. {
  1000. WriteObjectParkingSpace(nodeObject,&parkingSpace);
  1001. }
  1002. unsigned int i;
  1003. unsigned nrepeatcount = pObject->GetObjectrepeatCount();
  1004. for(i=0;i<nrepeatcount;i++)
  1005. {
  1006. Object_repeat * pObject_repeat = pObject->GetObjectrepeat(i);
  1007. WriteObjectrepeat(nodeObject,pObject_repeat);
  1008. }
  1009. unsigned nmaterialcount = pObject->GetObjectmaterialCount();
  1010. for(i=0;i<nmaterialcount;i++)
  1011. {
  1012. Object_material * pObject_material = pObject->GetObjectmaterial(i);
  1013. WriteObjectMaterial(nodeObject,pObject_material);
  1014. }
  1015. Object_outlines * pObject_outlines = pObject->Getoutlines();
  1016. if(pObject_outlines != NULL)
  1017. {
  1018. WriteObjectOutlines(nodeObject,pObject_outlines);
  1019. }
  1020. unsigned noutlinecount = pObject->GetObjectoutlineCount();
  1021. for(i=0;i<noutlinecount;i++)
  1022. {
  1023. Object_outlines_outline * pObject_outlines_outline = pObject->GetObjectoutline(i);
  1024. WriteObjectOutlinesOutline(nodeObject,pObject_outlines_outline);
  1025. }
  1026. return true;
  1027. }
  1028. //--------------
  1029. bool OpenDriveXmlWriter::WriteObjectrepeat(TiXmlElement * node,Object_repeat * pObject_repeat)
  1030. {
  1031. double s;
  1032. double length;
  1033. double distance;
  1034. double tStart;
  1035. double tEnd;
  1036. double heightStart;
  1037. double heightEnd;
  1038. double zOffsetStart;
  1039. double zOffsetEnd;
  1040. double widthStart;
  1041. double widthEnd;
  1042. double lengthStart;
  1043. double lengthEnd;
  1044. double radiusStart;
  1045. double radiusEnd;
  1046. s = pObject_repeat->Gets();
  1047. length = pObject_repeat->Getlength();
  1048. distance = pObject_repeat->Getdistance();
  1049. tStart = pObject_repeat->GettStart();
  1050. tEnd = pObject_repeat->GettEnd();
  1051. heightStart = pObject_repeat->GetheightStart();
  1052. heightEnd = pObject_repeat->GetheightEnd();
  1053. zOffsetStart = pObject_repeat->GetzOffsetStart();
  1054. zOffsetEnd = pObject_repeat->GetzOffsetEnd();
  1055. TiXmlElement* nodeObjectRepeat = new TiXmlElement("repeat");
  1056. node->LinkEndChild(nodeObjectRepeat);
  1057. nodeObjectRepeat->SetDoubleAttribute("s",s);
  1058. nodeObjectRepeat->SetDoubleAttribute("length",length);
  1059. nodeObjectRepeat->SetDoubleAttribute("distance",distance);
  1060. nodeObjectRepeat->SetDoubleAttribute("tStart",tStart);
  1061. nodeObjectRepeat->SetDoubleAttribute("tEnd",tEnd);
  1062. nodeObjectRepeat->SetDoubleAttribute("heightStart",heightStart);
  1063. nodeObjectRepeat->SetDoubleAttribute("heightEnd",heightEnd);
  1064. nodeObjectRepeat->SetDoubleAttribute("zOffsetStart",zOffsetStart);
  1065. nodeObjectRepeat->SetDoubleAttribute("zOffsetEnd",zOffsetEnd);
  1066. if(pObject_repeat->GetwidthStart(widthStart) == 1)
  1067. {
  1068. nodeObjectRepeat->SetDoubleAttribute("widthStart",widthStart);
  1069. }
  1070. if(pObject_repeat->GetwidthEnd(widthEnd) == 1)
  1071. {
  1072. nodeObjectRepeat->SetDoubleAttribute("widthEnd",widthEnd);
  1073. }
  1074. if(pObject_repeat->GetlengthStart(lengthStart) == 1)
  1075. {
  1076. nodeObjectRepeat->SetDoubleAttribute("lengthStart",lengthStart);
  1077. }
  1078. if(pObject_repeat->GetlengthEnd(lengthEnd) == 1)
  1079. {
  1080. nodeObjectRepeat->SetDoubleAttribute("lengthEnd",lengthEnd);
  1081. }
  1082. if(pObject_repeat->GetradiusStart(radiusStart) == 1)
  1083. {
  1084. nodeObjectRepeat->SetDoubleAttribute("radiusStart",radiusStart);
  1085. }
  1086. if(pObject_repeat->GetradiusEnd(radiusEnd) == 1)
  1087. {
  1088. nodeObjectRepeat->SetDoubleAttribute("radiusEnd",radiusEnd);
  1089. }
  1090. return true;
  1091. }
  1092. //--------------
  1093. bool OpenDriveXmlWriter::WriteObjectMaterial(TiXmlElement * node,Object_material * pObject_material)
  1094. {
  1095. TiXmlElement* nodeObjectMaterial = new TiXmlElement("material");
  1096. node->LinkEndChild(nodeObjectMaterial);
  1097. string surface;
  1098. double friction;
  1099. double roughness;
  1100. if(pObject_material->Getsurface(surface) == 1)
  1101. {
  1102. nodeObjectMaterial->SetAttribute("surface",surface);
  1103. }
  1104. if(pObject_material->Getfriction(friction) == 1)
  1105. {
  1106. nodeObjectMaterial->SetDoubleAttribute("friction",friction);
  1107. }
  1108. if(pObject_material->Getroughness(roughness) == 1)
  1109. {
  1110. nodeObjectMaterial->SetDoubleAttribute("roughness",roughness);
  1111. }
  1112. return true;
  1113. }
  1114. //--------------
  1115. bool OpenDriveXmlWriter::WriteObjectParkingSpace(TiXmlElement *node, Object_parkingSpace *pObject_parkingSpace)
  1116. {
  1117. TiXmlElement* nodeObjectParkingSpace = new TiXmlElement("parkingSpace");
  1118. node->LinkEndChild(nodeObjectParkingSpace);
  1119. nodeObjectParkingSpace->SetAttribute("access",pObject_parkingSpace->Getaccess());
  1120. if(pObject_parkingSpace->Getrestrictions() != "")
  1121. {
  1122. nodeObjectParkingSpace->SetAttribute("restrictions",pObject_parkingSpace->Getrestrictions());
  1123. }
  1124. return true;
  1125. }
  1126. //--------------
  1127. bool OpenDriveXmlWriter::WriteObjectOutlines(TiXmlElement *node, Object_outlines *pObject_outlines)
  1128. {
  1129. Object_outlines_outline xoutlines_outline;
  1130. if(pObject_outlines->GetObject_outlines_outline(xoutlines_outline) == 1)
  1131. {
  1132. TiXmlElement * nodeObjectOutlines = new TiXmlElement("outlines");
  1133. node->LinkEndChild(nodeObjectOutlines);
  1134. WriteObjectOutlinesOutline(nodeObjectOutlines,&xoutlines_outline);
  1135. return true;
  1136. }
  1137. std::cout<<"outlines not have outline."<<std::endl;
  1138. return false;
  1139. }
  1140. //--------------
  1141. bool OpenDriveXmlWriter::WriteObjectOutlinesOutline(TiXmlElement *node, Object_outlines_outline *pObject_outlines_outline)
  1142. {
  1143. TiXmlElement * nodeObjectOutlinesOutline = new TiXmlElement("outline");
  1144. node->LinkEndChild(nodeObjectOutlinesOutline);
  1145. int id;
  1146. string fillType,strouter,strclosed,laneType;
  1147. bool outer,closed;
  1148. if(pObject_outlines_outline->Getid(id) == 1)
  1149. {
  1150. nodeObjectOutlinesOutline->SetAttribute("id",id);
  1151. }
  1152. if(pObject_outlines_outline->GetfillType(fillType) == 1)
  1153. {
  1154. nodeObjectOutlinesOutline->SetAttribute("fillType",fillType);
  1155. }
  1156. if(pObject_outlines_outline->Getouter(outer) == 1)
  1157. {
  1158. if(outer)
  1159. {
  1160. strouter = "true";
  1161. }
  1162. else
  1163. {
  1164. strouter = "false";
  1165. }
  1166. nodeObjectOutlinesOutline->SetAttribute("outer",strouter);
  1167. }
  1168. if(pObject_outlines_outline->Getclosed(closed) == 1)
  1169. {
  1170. if(closed)
  1171. {
  1172. strclosed = "true";
  1173. }
  1174. else
  1175. {
  1176. strclosed = "false";
  1177. }
  1178. nodeObjectOutlinesOutline->SetAttribute("closed",strclosed);
  1179. }
  1180. if(pObject_outlines_outline->GetlaneType(laneType) == 1)
  1181. {
  1182. nodeObjectOutlinesOutline->SetAttribute("laneType",laneType);
  1183. }
  1184. unsigned int ncornerRoadCount = pObject_outlines_outline->GetcornerRoadCount();
  1185. unsigned int i;
  1186. for(i=0;i<ncornerRoadCount;i++)
  1187. {
  1188. Object_outlines_outline_cornerRoad * pcornerRoad = pObject_outlines_outline->GetcornerRoad(i);
  1189. WriteObjectOutlinesOutlinecornerRoad(nodeObjectOutlinesOutline,pcornerRoad);
  1190. }
  1191. unsigned int ncornerLocalCount = pObject_outlines_outline->GetcornerLocalCount();
  1192. for(i=0;i<ncornerLocalCount;i++)
  1193. {
  1194. Object_outlines_outline_cornerLocal * pcornerLocal = pObject_outlines_outline->GetcornerLocal(i);
  1195. WriteObjectOutlinesOutlinecornerLocal(nodeObjectOutlinesOutline,pcornerLocal);
  1196. }
  1197. return true;
  1198. }
  1199. //--------------
  1200. bool OpenDriveXmlWriter::WriteObjectOutlinesOutlinecornerRoad(TiXmlElement *node, Object_outlines_outline_cornerRoad *pObject_outlines_outline_cornerRoad)
  1201. {
  1202. TiXmlElement* nodecornerRoad = new TiXmlElement("cornerRoad");
  1203. node->LinkEndChild(nodecornerRoad);
  1204. nodecornerRoad->SetDoubleAttribute("s",pObject_outlines_outline_cornerRoad->Gets());
  1205. nodecornerRoad->SetDoubleAttribute("t",pObject_outlines_outline_cornerRoad->Gett());
  1206. nodecornerRoad->SetDoubleAttribute("dz",pObject_outlines_outline_cornerRoad->Getdz());
  1207. nodecornerRoad->SetDoubleAttribute("height",pObject_outlines_outline_cornerRoad->Getheight());
  1208. int id;
  1209. if(pObject_outlines_outline_cornerRoad->Getid(id) == 1)
  1210. {
  1211. nodecornerRoad->SetAttribute("id",id);
  1212. }
  1213. return true;
  1214. }
  1215. //--------------
  1216. bool OpenDriveXmlWriter::WriteObjectOutlinesOutlinecornerLocal(TiXmlElement *node, Object_outlines_outline_cornerLocal *pObject_outlines_outline_cornerLocal)
  1217. {
  1218. TiXmlElement* nodecornerLocal = new TiXmlElement("cornerLocal");
  1219. node->LinkEndChild(nodecornerLocal);
  1220. nodecornerLocal->SetDoubleAttribute("u",pObject_outlines_outline_cornerLocal->Getu());
  1221. nodecornerLocal->SetDoubleAttribute("v",pObject_outlines_outline_cornerLocal->Getv());
  1222. nodecornerLocal->SetDoubleAttribute("z",pObject_outlines_outline_cornerLocal->Getz());
  1223. nodecornerLocal->SetDoubleAttribute("height",pObject_outlines_outline_cornerLocal->Getheight());
  1224. int id;
  1225. if(pObject_outlines_outline_cornerLocal->Getid(id) == 1)
  1226. {
  1227. nodecornerLocal->SetAttribute("id",id);
  1228. }
  1229. return true;
  1230. }
  1231. //--------------
  1232. bool OpenDriveXmlWriter::WriteRoadBorrow(TiXmlElement *node, RoadBorrow *pRoadBorrow)
  1233. {
  1234. TiXmlElement* nodeRoadBorrow = new TiXmlElement("roadborrow");
  1235. node->LinkEndChild(nodeRoadBorrow);
  1236. nodeRoadBorrow->SetDoubleAttribute("sOffset",pRoadBorrow->GetS());
  1237. nodeRoadBorrow->SetDoubleAttribute("length",pRoadBorrow->GetLength());
  1238. nodeRoadBorrow->SetAttribute("mode",pRoadBorrow->GetMode());
  1239. return true;
  1240. }
  1241. //--------------
  1242. bool OpenDriveXmlWriter::WriteRoadBorrows(TiXmlElement *node, Road *road)
  1243. {
  1244. TiXmlElement* nodeRoadBorrows = new TiXmlElement("userData");
  1245. nodeRoadBorrows->SetAttribute("code","roadborrow");
  1246. node->LinkEndChild(nodeRoadBorrows);
  1247. unsigned int lRoadBorrowCount = road->GetRoadBorrowCount();
  1248. for(unsigned int i=0; i<lRoadBorrowCount; i++)
  1249. {
  1250. WriteRoadBorrow(nodeRoadBorrows, road->GetRoadBorrow(i));
  1251. }
  1252. return true;
  1253. }
  1254. //--------------
  1255. bool OpenDriveXmlWriter::WriteRoadNoavoids(TiXmlElement *node, Road* road)
  1256. {
  1257. TiXmlElement* nodeRoadNoavoids = new TiXmlElement("userData");
  1258. nodeRoadNoavoids->SetAttribute("code","roadnoavoid");
  1259. node->LinkEndChild(nodeRoadNoavoids);
  1260. unsigned int lRoadNoavoidCount = road->GetRoadNoavoidCount();
  1261. for(unsigned int i=0; i<lRoadNoavoidCount; i++)
  1262. {
  1263. WriteRoadNoavoid(nodeRoadNoavoids, road->GetRoadNoavoid(i));
  1264. }
  1265. return true;
  1266. }
  1267. //--------------
  1268. bool OpenDriveXmlWriter::WriteRoadNoavoid(TiXmlElement *node,RoadNoavoid * pRoadNoavoid)
  1269. {
  1270. TiXmlElement* nodeRoadNoavoid = new TiXmlElement("roadnoavoid");
  1271. node->LinkEndChild(nodeRoadNoavoid);
  1272. nodeRoadNoavoid->SetDoubleAttribute("sOffset",pRoadNoavoid->GetS());
  1273. nodeRoadNoavoid->SetDoubleAttribute("length",pRoadNoavoid->GetLength());
  1274. return true;
  1275. }
  1276. //--------------
  1277. bool OpenDriveXmlWriter::WriteSignals (TiXmlElement *node, Road* road)
  1278. {
  1279. TiXmlElement* nodeSignals = new TiXmlElement("signals");
  1280. node->LinkEndChild(nodeSignals);
  1281. unsigned int lSignalSectionCount = road->GetSignalCount();
  1282. for(unsigned int i=0; i<lSignalSectionCount; i++)
  1283. {
  1284. WriteSignal(nodeSignals, road->GetSignal(i));
  1285. }
  1286. return true;
  1287. }
  1288. bool OpenDriveXmlWriter::WriteSignal(TiXmlElement *node, Signal * pSignal)
  1289. {
  1290. TiXmlElement* nodeSignal = new TiXmlElement("signal");
  1291. node->LinkEndChild(nodeSignal);
  1292. nodeSignal->SetDoubleAttribute("s",pSignal->Gets());
  1293. nodeSignal->SetDoubleAttribute("t",pSignal->Gett());
  1294. nodeSignal->SetAttribute("id",pSignal->Getid());
  1295. nodeSignal->SetAttribute("name",pSignal->Getname());
  1296. if(pSignal->Getdynamic() == true)
  1297. nodeSignal->SetAttribute("dynamic","yes");
  1298. else
  1299. nodeSignal->SetAttribute("dynamic","no");
  1300. nodeSignal->SetAttribute("orientation",pSignal->Getorientation());
  1301. nodeSignal->SetDoubleAttribute("zOffset",pSignal->GetzOffset());
  1302. nodeSignal->SetAttribute("type",pSignal->Gettype());
  1303. nodeSignal->SetAttribute("country",pSignal->Getcountry());
  1304. nodeSignal->SetAttribute("countryRevision",pSignal->GetcountryRevision());
  1305. nodeSignal->SetAttribute("subtype",pSignal->Getsubtype());
  1306. nodeSignal->SetDoubleAttribute("hOffset",pSignal->GethOffset());
  1307. nodeSignal->SetDoubleAttribute("pitch",pSignal->Getpitch());
  1308. nodeSignal->SetDoubleAttribute("roll",pSignal->Getroll());
  1309. nodeSignal->SetDoubleAttribute("height",pSignal->Getheight());
  1310. nodeSignal->SetDoubleAttribute("width",pSignal->Getwidth());
  1311. signal_laneValidity * psignal_lanevalidity = pSignal->GetlaneValidity();
  1312. if(psignal_lanevalidity != 0)
  1313. {
  1314. WriteSignal_laneValidity(nodeSignal,psignal_lanevalidity);
  1315. }
  1316. signal_positionInertial * psignal_positionInertial = pSignal->GetpositionInertial();
  1317. if(psignal_positionInertial != 0)
  1318. {
  1319. WriteSignal_positionInertial(nodeSignal,psignal_positionInertial);
  1320. }
  1321. return true;
  1322. }
  1323. bool OpenDriveXmlWriter::WriteSignal_positionInertial(TiXmlElement *node, signal_positionInertial *pSignal_positionInertial)
  1324. {
  1325. TiXmlElement* nodepositionInertial = new TiXmlElement("positionInertial");
  1326. node->LinkEndChild(nodepositionInertial);
  1327. nodepositionInertial->SetAttribute("x",pSignal_positionInertial->Getx());
  1328. nodepositionInertial->SetAttribute("y",pSignal_positionInertial->Gety());
  1329. nodepositionInertial->SetAttribute("z",pSignal_positionInertial->Getz());
  1330. nodepositionInertial->SetAttribute("hdg",pSignal_positionInertial->Gethdg());
  1331. nodepositionInertial->SetAttribute("pitch",pSignal_positionInertial->Getpitch());
  1332. nodepositionInertial->SetAttribute("roll",pSignal_positionInertial->Getroll());
  1333. return true;
  1334. }
  1335. bool OpenDriveXmlWriter::WriteSignal_laneValidity(TiXmlElement *node, signal_laneValidity *pSignal_laneValidity)
  1336. {
  1337. TiXmlElement* nodelaneValidity = new TiXmlElement("validity");
  1338. node->LinkEndChild(nodelaneValidity);
  1339. nodelaneValidity->SetAttribute("fromLane",pSignal_laneValidity->GetfromLane());
  1340. nodelaneValidity->SetAttribute("toLane",pSignal_laneValidity->GettoLane());
  1341. return true;
  1342. }
  1343. //--------------
  1344. bool OpenDriveXmlWriter::WriteSurface (TiXmlElement *node, Road* road)
  1345. {
  1346. return true;
  1347. }
  1348. //--------------
  1349. bool OpenDriveXmlWriter::WriteController (TiXmlElement *node)
  1350. { return true; }
  1351. //--------------
  1352. bool OpenDriveXmlWriter::WriteJunction (TiXmlElement *node, Junction *junction)
  1353. {
  1354. string name;
  1355. string id;
  1356. name = junction->GetName();
  1357. id = junction->GetId();
  1358. TiXmlElement *nodeJunction = new TiXmlElement("junction");
  1359. node->LinkEndChild(nodeJunction);
  1360. nodeJunction->SetAttribute("name",name);
  1361. nodeJunction->SetAttribute("id",id);
  1362. //Connections
  1363. WriteJunctionConnection(nodeJunction, junction);
  1364. //Priorities
  1365. WriteJunctionPriority(nodeJunction, junction);
  1366. //Controllers
  1367. WriteJunctionController(nodeJunction, junction);
  1368. return true;
  1369. }
  1370. //--------------
  1371. bool OpenDriveXmlWriter::WriteJunctionConnection (TiXmlElement *node, Junction* junction)
  1372. {
  1373. string id;
  1374. string incomingRoad;
  1375. string connectingRoad;
  1376. string contactPoint;
  1377. unsigned int junctionConnectionCount = junction->GetJunctionConnectionCount();
  1378. for(unsigned int i=0; i<junctionConnectionCount; i++)
  1379. {
  1380. JunctionConnection *lJunctionConnection = junction->GetJunctionConnection(i);
  1381. id = lJunctionConnection->GetId();
  1382. incomingRoad = lJunctionConnection->GetIncomingRoad();
  1383. connectingRoad = lJunctionConnection->GetConnectingRoad();
  1384. contactPoint = lJunctionConnection->GetContactPoint();
  1385. TiXmlElement *nodeJunctionConnection = new TiXmlElement("connection");
  1386. node->LinkEndChild(nodeJunctionConnection);
  1387. nodeJunctionConnection->SetAttribute("id",id);
  1388. nodeJunctionConnection->SetAttribute("incomingRoad",incomingRoad);
  1389. nodeJunctionConnection->SetAttribute("connectingRoad",connectingRoad);
  1390. nodeJunctionConnection->SetAttribute("contactPoint",contactPoint);
  1391. //Lane links
  1392. WriteJunctionConnectionLaneLink(nodeJunctionConnection, lJunctionConnection);
  1393. }
  1394. return true;
  1395. }
  1396. bool OpenDriveXmlWriter::WriteJunctionConnectionLaneLink (TiXmlElement *node, JunctionConnection* junctionConnection)
  1397. {
  1398. int from;
  1399. int to;
  1400. unsigned int junctionLaneLinkCount = junctionConnection->GetJunctionLaneLinkCount();
  1401. for(unsigned int i=0; i<junctionLaneLinkCount; i++)
  1402. {
  1403. JunctionLaneLink *lJunctionLaneLink = junctionConnection->GetJunctionLaneLink(i);
  1404. from = lJunctionLaneLink->GetFrom();
  1405. to = lJunctionLaneLink->GetTo();
  1406. TiXmlElement *nodeJunctionLaneLink = new TiXmlElement("laneLink");
  1407. node->LinkEndChild(nodeJunctionLaneLink);
  1408. nodeJunctionLaneLink->SetAttribute("from",from);
  1409. nodeJunctionLaneLink->SetAttribute("to",to);
  1410. }
  1411. return true;
  1412. }
  1413. bool OpenDriveXmlWriter::WriteJunctionPriority (TiXmlElement *node, Junction* junction)
  1414. {
  1415. string high;
  1416. string low;
  1417. unsigned int junctionPriorityCount = junction->GetJunctionPriorityCount();
  1418. for(unsigned int i=0; i<junctionPriorityCount; i++)
  1419. {
  1420. JunctionPriorityRoad *lJunctionPriority = junction->GetJunctionPriority(i);
  1421. high = lJunctionPriority->GetHigh();
  1422. low = lJunctionPriority->GetLow();
  1423. TiXmlElement *nodeJunctionPriority = new TiXmlElement("priority");
  1424. node->LinkEndChild(nodeJunctionPriority);
  1425. nodeJunctionPriority->SetAttribute("high",high);
  1426. nodeJunctionPriority->SetAttribute("low",low);
  1427. }
  1428. return true;
  1429. }
  1430. bool OpenDriveXmlWriter::WriteJunctionController (TiXmlElement *node, Junction* junction)
  1431. {
  1432. string id;
  1433. string type;
  1434. unsigned int junctionControllerCount = junction->GetJunctionControllerCount();
  1435. for(unsigned int i=0; i<junctionControllerCount; i++)
  1436. {
  1437. JunctionController *lJunctionController = junction->GetJunctionController(i);
  1438. id = lJunctionController->GetId();
  1439. type = lJunctionController->GetType();
  1440. TiXmlElement *nodeJunctionController = new TiXmlElement("controller");
  1441. node->LinkEndChild(nodeJunctionController);
  1442. nodeJunctionController->SetAttribute("id",id);
  1443. nodeJunctionController->SetAttribute("type",type);
  1444. }
  1445. return true;
  1446. }
  1447. //---------------------------------------------------------------------------
  1448. /**
  1449. * Writes the data from the OpenDrive structure to a file
  1450. */
  1451. bool OpenDriveXmlWriter::WriteFile(std::string fileName)
  1452. {
  1453. // XML document
  1454. TiXmlDocument doc;
  1455. TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
  1456. doc.LinkEndChild( decl );
  1457. TiXmlElement *rootNode = new TiXmlElement("OpenDRIVE");
  1458. doc.LinkEndChild(rootNode);
  1459. // Write header
  1460. WriteHeader(rootNode);
  1461. // Write roads
  1462. unsigned int roadCount = mOpenDrive->GetRoadCount();
  1463. for(unsigned int i=0; i<roadCount; i++)
  1464. {
  1465. WriteRoad(rootNode, mOpenDrive->GetRoad(i));
  1466. }
  1467. // Write junctions
  1468. unsigned int junctionCount = mOpenDrive->GetJunctionCount();
  1469. for(unsigned int i=0; i<junctionCount; i++)
  1470. {
  1471. WriteJunction(rootNode, mOpenDrive->GetJunction(i));
  1472. }
  1473. // Saves the XML structure to the file
  1474. doc.SaveFile( fileName );
  1475. return true;
  1476. }
  1477. //--------------