ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
xodr2borderbased.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Daniel Heß - initial API and implementation
13  * Robert Markowski - initial API and implementation
14  ********************************************************************************/
15 
16 #pragma once
17 
18 #include <OpenDRIVE_1.4H.h>
19 #include <iostream>
20 #include <algorithm>
21 #include <string>
22 #include <vector>
23 #include <unordered_map>
24 #include <set>
30 #include <adore/env/tcd/tcdset.h>
31 #include "idtranslation.h"
32 
33 
34 namespace adore
35 {
36  namespace if_xodr
37  {
43  {
44  private:
45 
46  static const char *XODR_SIGNALTYPE_STOPLINE;
47 
51  typedef std::map<int,std::pair<TBorderFun*,adore::env::BorderBased::BorderType::TYPE>> TSectionBorderSet;
53  typedef std::vector<TSectionBorderSet*> TSectionSet;
55 
61 
62  typedef std::unordered_map<adore::env::BorderBased::Border*,std::string> Border2RoadID;
63 
64  public:
69  struct{
70  double emax;
71  double edes;
72  double xmin;
73  double xmax;
74  double xstart;
77 
78  //map origin
79  double m_x0;
80  double m_y0;
81  public:
82 
88  {
89  sampling.emax = 0.05;
90  sampling.edes = 0.03;
91  sampling.xmin = 0.5;
92  sampling.xmax = 4.0;
93  sampling.xstart = 1;
94  sampling.numberOfPointsPerBorder = 128;
95  m_x0 = 0.0;
96  m_y0 = 0.0;
97  }
103  {
104  public:
107  {
108  return m_pos;
109  }
110  std::string type;
111  std::string id;
112  std::string orientation;
113  int road_id;
114  double s;
115  double t;
116  int fromLane;
117  int toLane;
118  double value;
119  std::list<std::string> dependency;
120  friend bool operator<(const XODR_Signal& l, const XODR_Signal& r)
121  {
122  return l.s<r.s;
123  }
124  };
125  typedef std::unordered_map<std::string,XODR_Signal> SignalByID;
126 
127  public:
128 
141  void convert(
142  const char* filename,
144  adore::env::TCDSet* tcdSet,
147  BorderIDTranslation* idTranslation,
148  double* x0, double* y0,bool transform=false);
149 
160  void convert(
161  const char* filename,
163  adore::env::TCDSet* tcdSet,
166  bool transform);
167 
174  void convert(
175  const char* filename,
184  void convert(
185  const char* filename,
187  bool transform);
188 
197  void convert(const char* filename,
199  bool transform,
200  BorderIDTranslation* idTranslation);
201 
202 
203  private:
211  {
212  using namespace adore::env::BorderBased::BorderType;
213  if(strcmp(xodrType.c_str(),"driving")==0)
214  {
215  return DRIVING;
216  }
217  if(strcmp(xodrType.c_str(),"special1")==0)
218  {
219  return EMERGENCY;
220  }
221  return OTHER;
222  }
223 
237  void extractRoadCenterLine_Spiral(TRoadCenterFun& center,TRoadCenterHeadingFun& center_heading,double s0,double ds,double x0,double y0,double psi0,double kappa0,double kappa1)
238  {
239  TSpiral* spiral = new TSpiral(ds,x0,y0,psi0,kappa0,kappa1,sampling.emax);
240  center.appendHi_shifted(spiral);
241  center_heading.appendHi_shifted(spiral->create_heading());
242  }
243 
255  void extractRoadCenterLine_Line(TRoadCenterFun& center,TRoadCenterHeadingFun& center_heading,double s0,double ds,double x0,double y0,double psi0)
256  {
257  adoreMatrix<double,2,1> p0,dp;
258  p0 = x0,y0;
259  dp = cos(psi0),sin(psi0);
260  TLine* line = new TLine(0,ds,p0,dp);
261  center.appendHi_shifted(line);
262  center_heading.appendHi_shifted( new adore::mad::LConstFun<double,double>(psi0,0,ds) );
263  }
264 
280  void extractRoadCenterLine_Poly3(TRoadCenterFun& center,TRoadCenterHeadingFun& center_heading,double s0,double ds,double x0,double y0,double psi0,double a,double b,double c,double d)
281  {
283  //adoreMatrix<double,2,1> p0;
284  //p0 = x0,y0;
285  //adoreMatrix<double,1,4> params;
286  //params = a,b,c,d;
287  //TPoly3u* ufun = new TPoly3u(0,ds,0,ds);
288  //TPoly3v* vfun = new TPoly3v(params,0,ds);
289  //auto poly3 = adore::mad::funop::add(
290  // adore::mad::funop::rotate(
291  // new adore::mad::LConstFun<double,double>(psi0,0.0,ds),
292  // adore::mad::funop::stack(ufun,vfun)
293  // ),
294  // new adore::mad::LConstFun<double,adoreMatrix<double,2,1>>(p0,0.0,ds)
295  // );
296  //center.appendHi_shifted(poly3);
299  throw("not implemented");
300  }
301 
322  void extractRoadCenterLine_ParamPoly3(TRoadCenterFun& center,TRoadCenterHeadingFun& center_heading, double s0,double ds,double x0,double y0,double psi0, pRange parameterRange, double au,double bu,double cu,double du,double av,double bv,double cv,double dv)
323  {
324  // u = au + bus + cu s� + du s�
325  // v = av + bvs + cv s� + dv s�
326  adoreMatrix<double,2,1> p0;
327  p0 = x0,y0;
328  adoreMatrix<double,0,0> params(2,4);
329  params(0,0) = au;
330  params(0,1) = bu;
331  params(0,2) = cu;
332  params(0,3) = du;
333  params(1,0) = av;
334  params(1,1) = bv;
335  params(1,2) = cv;
336  params(1,3) = dv;
337  //pRange parameterRange = geo->paramPoly3()->pRange().get();
338  TParamPoly3* parampoly;
339  switch(parameterRange)
340  {
341  case pRange::arcLength:
342  {
343  parampoly = new TParamPoly3(params,0,ds);
344  }
345  break;
346  case pRange::normalized:
347  {
348  parampoly = new TParamPoly3(adore::mad::stretch_poly_parameters<double,2,3>(params,0,1,0,ds),0,ds);
349  }
350  break;
351  }
352  parampoly->multiply(adore::mad::rotationMatrix<double,2>(psi0),0,1);
353  parampoly->add(p0,0,1);
354  auto heading = adore::mad::funop::heading<double>((adore::mad::LPolynomialM<double,2,3>*)parampoly->create_derivative());
355  center.appendHi_shifted(parampoly);
356  center_heading.appendHi_shifted(heading);
357  }
358 
367  void extractRoadCenterLine(const OpenDRIVE::road_type& road,TRoadCenterFun& center,TRoadCenterHeadingFun& center_heading, TOffsetFun &offsetFun)
368  {
370  for( auto geo = road.planView().geometry().begin(); geo!= road.planView().geometry().end(); geo++ )
371  {
372  double s0 = geo->s().get();
373  double ds = geo->length().get();//length
374  if(ds < sampling.emax) {continue;}
375  double x0 = geo->x().get();
376  double y0 = geo->y().get();
377  double psi0 = geo->hdg().get();
378  if( geo->arc().present() )
379  {
380  double kappa = geo->arc()->curvature().get();
381  extractRoadCenterLine_Spiral(center,center_heading,s0,ds,x0,y0,psi0,kappa,kappa);
382  }
383  else
384  {
385  if( geo->line().present() )
386  {
387  extractRoadCenterLine_Line(center,center_heading,s0,ds,x0,y0,psi0);
388  }
389  else
390  {
391  if( geo->poly3().present() )
392  {
393  extractRoadCenterLine_Poly3(center,center_heading,s0,ds,x0,y0,psi0,
394  geo->poly3()->a().get(),
395  geo->poly3()->b().get(),
396  geo->poly3()->c().get(),
397  geo->poly3()->d().get());
398  }
399  else
400  {
401  if( geo->paramPoly3().present() )
402  {
403  if(geo->paramPoly3()->pRange().present())
404  {
405  extractRoadCenterLine_ParamPoly3(center,center_heading,s0,ds,x0,y0,psi0,
406  geo->paramPoly3()->pRange().get(),
407  geo->paramPoly3()->aU().get(),
408  geo->paramPoly3()->bU().get(),
409  geo->paramPoly3()->cU().get(),
410  geo->paramPoly3()->dU().get(),
411  geo->paramPoly3()->aV().get(),
412  geo->paramPoly3()->bV().get(),
413  geo->paramPoly3()->cV().get(),
414  geo->paramPoly3()->dV().get());
415  }
416  else
417  {
418  extractRoadCenterLine_ParamPoly3(center,center_heading,s0,ds,x0,y0,psi0,
419  pRange::normalized,
420  geo->paramPoly3()->aU().get(),
421  geo->paramPoly3()->bU().get(),
422  geo->paramPoly3()->cU().get(),
423  geo->paramPoly3()->dU().get(),
424  geo->paramPoly3()->aV().get(),
425  geo->paramPoly3()->bV().get(),
426  geo->paramPoly3()->cV().get(),
427  geo->paramPoly3()->dV().get());
428  }
429  }
430  else
431  {
432  if( geo->spiral().present() )
433  {
434  double kappa0 = geo->spiral()->curvStart().get();
435  double kappa1 = geo->spiral()->curvEnd().get();
436  extractRoadCenterLine_Spiral(center,center_heading,s0,ds,x0,y0,psi0,kappa0,kappa1);
437  }
438  }
439 
440  }
441  }
442  }
443  }
444  if(road.lanes().laneOffset().begin() == road.lanes().laneOffset().end())
445  {
446  offsetFun.appendHi(new adore::mad::LConstFun<double,double>(0,0,road.length().get()));
447  }
448  else
449  {
450  bool first_run = true;
451  for( auto lo = road.lanes().laneOffset().begin(); lo != road.lanes().laneOffset().end(); lo++)
452  {
453  double a = lo->a().get();
454  double b = lo->b().get();
455  double c = lo->c().get();
456  double d = lo->d().get();
457  adoreMatrix<double,1,4> params;
458  params = a, b, c, d;
459  double loStart = lo->s().get();
460  double loEnd = 0;
461  auto nextLo = lo;
462  nextLo++;
463  if(nextLo==road.lanes().laneOffset().end())
464  {
465  loEnd= road.length().get();
466  }
467  else
468  {
469  loEnd = nextLo->s().get();
470  }
471  auto poly = new adore::mad::LPolynomialS<double,3>(params,0,loEnd-loStart);
472  if(nextLo!=road.lanes().laneOffset().end())
473  {
474  double diff = std::abs(poly->f(loEnd-loStart)-nextLo->a().get());
475  if( diff > 0.01)
476  {
477  std::cerr<<"There is a laneOffset jump of "<<std::abs(poly->f(loEnd-loStart)-nextLo->a().get())
478  <<" within road "<<road.id().get()
479  <<"."<<std::endl;
480  }
481  }
482  if(first_run)
483  {
484  first_run = false;
485  }
486  else
487  {
488  double diff = std::abs(poly->f(0)-offsetFun.f(offsetFun.limitHi()));
489  if(diff > 0.01)
490  {
491  std::cerr<<"There is a laneOffset jump of "<<diff
492  <<" in road "<<road.id().get()<<"."<<std::endl;
493  }
494  }
495  offsetFun.appendHi_shifted(poly);
496  }
497  }
498  }
499 
510  void extractLanes_width(int& left_count, int& right_count, double s0, double s1, const lanes::laneSection_type& section, std::map<int,std::pair<adore::mad::LPiecewiseFunction<double,double>*,adore::env::BorderBased::BorderType::TYPE>>& width_record)
511  {
512  if(section.right().present())
513  {
514  int sign = -1;
515  for(auto lane = section.right()->lane().begin();lane!=section.right()->lane().end();lane++)
516  {
517  int width_fun_entry_count = 0;
519  for(auto width = lane->width().begin();width!=lane->width().end();width ++)
520  {
521  /* again, length is determined by the start of the next width entry and there might be multiple width entries */
522  double ws0 = width->sOffset().get() + s0;
523  double ws1;
524  auto nextWidth = width;
525  nextWidth++;
526  if(nextWidth==lane->width().end())
527  {
528  ws1 = s1;
529  }
530  else
531  {
532  ws1 = nextWidth->sOffset().get() + s0;
533  }
534 
535  /* some maps contain erroneous entries for width, e.g. not monotonously increasing s entries.
536  The following lines handle the error cases*/
537  if(ws1<=ws0)continue;
538  if(width_fun_entry_count>0 && width_fun->limitHi()>ws0)continue;
539 
540  /* width entries are alsways polynoms, sign to get them to the right side of the road */
541  adoreMatrix<double,1,4> param;
542  param = width->a().get(),width->b().get(),width->c().get(),width->d().get();
543  param = param * sign;
544  width_fun->appendHi(new adore::mad::LPolynomialS<double,3>(adore::mad::stretch_poly_parameters<double,1,3>(param,0,ws1-ws0,ws0,ws1),ws0,ws1));
545  width_fun_entry_count ++;
546  }
547 
548  /* save width function and LaneType to width record */
549  width_record[lane->id().get()].first = width_fun;
550  width_record[lane->id().get()].second = convertLaneType(lane->type().get());
551  right_count ++;
552  }
553  }
554  /* end right */
555 
556  /* width of the left side */
557  /* width is relative to neighbor lane so far with centerline being the baseline */
558  if(section.left().present())
559  {
560  /* @TODO not sure why this is here, consistent number count from +X to -X, including 0? */
561  width_record[0].first=0;
562 
563  int sign = 1;
564  for(auto lane = section.left()->lane().begin();lane!=section.left()->lane().end();lane++)
565  {
566  int width_fun_entry_count = 0;
568  for(auto width = lane->width().begin();width!=lane->width().end();width ++)
569  {
570  /* again, length is determined by the start of the next width entry and there might be multiple width entries */
571  double ws0 = width->sOffset().get() + s0;
572  double ws1;
573  auto nextWidth = width;
574  nextWidth++;
575  if(nextWidth==lane->width().end())
576  {
577  ws1 = s1;
578  }
579  else
580  {
581  ws1 = nextWidth->sOffset().get() + s0;
582  }
583 
584  /* some maps contain erroneous entries for width, e.g. not monotonously increasing s entries.
585  The following lines handle the error cases*/
586  if(ws1<=ws0)continue;
587  if(width_fun_entry_count>0 && width_fun->limitHi()>ws0)continue;
588 
589  /* width entries are alsways polynoms, sign to get them to the right side of the road */
590  adoreMatrix<double,1,4> param;
591  param = width->a().get(),width->b().get(),width->c().get(),width->d().get();
592  param = param * sign;
593  width_fun->appendHi(new adore::mad::LPolynomialS<double,3>(adore::mad::stretch_poly_parameters<double,1,3>(param,0,ws1-ws0,ws0,ws1),ws0,ws1));
594  }
595 
596  /* save width function and LaneType to width record */
597  width_record[lane->id().get()].first = width_fun;
598  width_record[lane->id().get()].second = convertLaneType(lane->type().get());
599  left_count ++;
600  }
601  }
602  /* end left */
603  }
604 
615  void extractLanes_border(int& left_count, int& right_count, double s0, double s1, const lanes::laneSection_type& section, std::map<int,std::pair<adore::mad::LPiecewiseFunction<double,double>*,adore::env::BorderBased::BorderType::TYPE>>& width_record)
616  {
617  if(section.right().present())
618  {
619  int sign = -1;
620  for(auto lane = section.right()->lane().begin();lane!=section.right()->lane().end();lane++)
621  {
622  int width_fun_entry_count = 0;
624  for(auto width = lane->border().begin();width!=lane->border().end();width ++)
625  {
626  /* again, length is determined by the start of the next width entry and there might be multiple width entries */
627  double ws0 = width->sOffset().get() + s0;
628  double ws1;
629  auto nextWidth = width;
630  nextWidth++;
631  if(nextWidth==lane->border().end())
632  {
633  ws1 = s1;
634  }
635  else
636  {
637  ws1 = nextWidth->sOffset().get() + s0;
638  }
639 
640  /* some maps contain erroneous entries for width, e.g. not monotonously increasing s entries.
641  The following lines handle the error cases*/
642  if(ws1<=ws0)continue;
643  if(width_fun_entry_count>0 && width_fun->limitHi()>ws0)continue;
644 
645  /* width entries are alsways polynoms, sign to get them to the right side of the road */
646  adoreMatrix<double,1,4> param;
647  param = width->a().get(),width->b().get(),width->c().get(),width->d().get();
648  param = param * sign;
649  width_fun->appendHi(new adore::mad::LPolynomialS<double,3>(adore::mad::stretch_poly_parameters<double,1,3>(param,0,ws1-ws0,ws0,ws1),ws0,ws1));
650  width_fun_entry_count ++;
651  }
652 
653  /* save width function and LaneType to width record */
654  width_record[lane->id().get()].first = width_fun;
655  width_record[lane->id().get()].second = convertLaneType(lane->type().get());
656  right_count ++;
657  }
658  }
659  /* end right */
660 
661  /* width of the left side */
662  /* width is relative to neighbor lane so far with centerline being the baseline */
663  if(section.left().present())
664  {
665  /* @TODO not sure why this is here, consistent number count from +X to -X, including 0? */
666  width_record[0].first=0;
667 
668  int sign = 1;
669  for(auto lane = section.left()->lane().begin();lane!=section.left()->lane().end();lane++)
670  {
671  int width_fun_entry_count = 0;
673  for(auto width = lane->border().begin();width!=lane->border().end();width ++)
674  {
675  /* again, length is determined by the start of the next width entry and there might be multiple width entries */
676  double ws0 = width->sOffset().get() + s0;
677  double ws1;
678  auto nextWidth = width;
679  nextWidth++;
680  if(nextWidth==lane->border().end())
681  {
682  ws1 = s1;
683  }
684  else
685  {
686  ws1 = nextWidth->sOffset().get() + s0;
687  }
688 
689  /* some maps contain erroneous entries for width, e.g. not monotonously increasing s entries.
690  The following lines handle the error cases*/
691  if(ws1<=ws0)continue;
692  if(width_fun_entry_count>0 && width_fun->limitHi()>ws0)continue;
693 
694  /* width entries are alsways polynoms, sign to get them to the right side of the road */
695  adoreMatrix<double,1,4> param;
696  param = width->a().get(),width->b().get(),width->c().get(),width->d().get();
697  param = param * sign;
698  width_fun->appendHi(new adore::mad::LPolynomialS<double,3>(adore::mad::stretch_poly_parameters<double,1,3>(param,0,ws1-ws0,ws0,ws1),ws0,ws1));
699  }
700 
701  /* save width function and LaneType to width record */
702  width_record[lane->id().get()].first = width_fun;
703  width_record[lane->id().get()].second = convertLaneType(lane->type().get());
704  left_count ++;
705  }
706  }
707  /* end left */
708  }
709 
710 
723  void extractRoadSection(const lanes::laneSection_type& section,TRoadCenterFun& center,TRoadCenterHeadingFun& center_heading, TOffsetFun &center_offset, double s0, double s1, TSectionMap& sectionMap,TSectionSet& sectionSet)
724  {
725  /* create a new set for the borders in this section */
726  TSectionBorderSet* borderSet = new TSectionBorderSet();
727 
728  /* push the pointer into the set of all sections of this road */
729  sectionSet.push_back(borderSet);
730 
731  /* make an entry in sectionMap, at which position in the section set the s range is covered */
732  sectionMap.appendHi(new adore::mad::LConstFun<double,int>(sectionSet.size()-1,s0,s1));
733 
734  /* width record stores width function in .first and LaneType in .second */
735  std::map<int,std::pair<adore::mad::LPiecewiseFunction<double,double>*,adore::env::BorderBased::BorderType::TYPE>> width_record;
736  int left_count = 0;
737  int right_count = 0;
738  bool usingWidthRepresentation = true;
739 
740  /* FILL WIDTH RECORD */
741  /* width is relative to neighbor lane so far with centerline being the baseline */
742  /* switching between border and width is not possible, when both exist, width prevails according to documentation */
743  if(
744  // right exisitiert
745  // lane->width().begin()!=lane->width().end()
746  // lane->border().begin()!=lane->border().end()
747  (section.right().present() && section.right()->lane().begin()!= section.right()->lane().end() && !section.right()->lane().begin()->width().empty())
748  ||
749  (section.left().present() && section.left()->lane().begin()!= section.left()->lane().end() && !section.left()->lane().begin()->width().empty())
750  )
751  {
752  extractLanes_width(left_count, right_count, s0, s1, section, width_record);
753  }
754  else if(
755  (section.right().present() && section.right()->lane().begin()!= section.right()->lane().end() && !section.right()->lane().begin()->border().empty())
756  ||
757  (section.left().present() && section.left()->lane().begin()!= section.left()->lane().end() && !section.left()->lane().begin()->border().empty())
758  )
759  {
760  extractLanes_border(left_count, right_count, s0, s1, section, width_record);
761  usingWidthRepresentation = false;
762  }
763 
764 
765  /* TRANSLATE FUNCTIONS FROM RELATIVE OFFSET TO ABSOLUTE OFFSET */
766  std::map<int,std::pair<adore::mad::ALFunction<double,double>*,adore::env::BorderBased::BorderType::TYPE>> offset_record;
767 
768  /* @TODO there might be an offset function for the centerline/baseline, this would come in here */
769  /* center_offset only in interval section_start - section_end
770  *
771  */
772 
773  //offset_record[0].first = new adore::mad::LConstFun<double,double>(0,s0,s1);
774 
775  TOffsetFun * local_center_offset = new TOffsetFun();
776  local_center_offset = (TOffsetFun*) center_offset.clone();
777  local_center_offset->setLimits(s0,s1);
778  offset_record[0].first = local_center_offset;
779  //offset_record[0].first = adore::mad::funop::minus<double, double, double, double>(local_center_offset);
780 
781  //offset_record[0].first = new adore::mad::LConstFun<double,double>(0,s0,s1);
782 
783  offset_record[0].second = env::BorderBased::BorderType::OTHER;
784  width_record[0].first=0;
785  /* first absolute offset is equal to relative offset @TODO might change when there is an offset in the centerline/baseline */
786  if(left_count>0)
787  {
788  //offset_record[1].first = width_record[1].first->clone();
789  offset_record[1].first = adore::mad::funop::add(adore::mad::funop::minus<double,double,double,double>(offset_record[0].first->clone()),width_record[1].first->clone());
790  offset_record[1].second = width_record[1].second;
791  }
792  if(right_count>0)
793  {
794  //offset_record[-1].first = width_record[-1].first->clone();
795  offset_record[-1].first = adore::mad::funop::add(offset_record[0].first->clone(),width_record[-1].first->clone());
796  offset_record[-1].second = width_record[-1].second;
797  }
798 
799  /* for all entries beyond the first, the absolute width is the sum of all relative widths up to this point */
800  /* sum over left */
801  for(int i=1;i<=left_count;i++)
802  {
803  if(usingWidthRepresentation)
804  {
805  // width_record[0] is 0, why not use offset_record[0]?
806  offset_record[i].first = adore::mad::funop::add(offset_record[i-1].first->clone(),width_record[i].first->clone());
807  }
808  else // using border representation -> absolute width from center line
809  {
810  offset_record[i].first = width_record[i].first->clone();
811  }
812  offset_record[i].second = width_record[i].second;
813  }
814  /* sum over right */
815  for(int i=1;i<=right_count;i++)
816  {
817  if(usingWidthRepresentation)
818  {
819  offset_record[-i].first = adore::mad::funop::add(offset_record[-i+1].first->clone(),width_record[-i].first->clone());
820  }
821  else // using border representation -> absolute width from center line
822  {
823  offset_record[-i].first = width_record[-i].first->clone();
824  }
825  offset_record[-i].second = width_record[-i].second;
826  }
827 
828  /* create border representation of lane section, no maximum point number, save to border set, also remember LaneType */
829  for(auto it = offset_record.begin();it!=offset_record.end();it++)
830  {
831  //adore::mad::ALFunction<double,double>* offset = it->second;
832  adore::mad::ALFunction<double,double>* offset = it->second.first;
833  auto lane_border = adore::mad::create_normalOffset<double>(center.clone(),center_heading.clone(),offset->clone());
834  auto lane_border_derivative = lane_border->create_derivative();
835  (*borderSet)[it->first].first = adore::mad::sample_adaptive<double,2>(lane_border,lane_border_derivative,sampling.edes,sampling.emax,sampling.xmin,sampling.xmax,sampling.xstart);
836  (*borderSet)[it->first].second = it->second.second;
837  delete lane_border;
838  delete lane_border_derivative;
839  }
840 
841  for(auto it = width_record.begin();it!=width_record.end();it++)
842  {
843  if(it->second.first!=0)delete it->second.first;
844  }
845  for(auto it = offset_record.begin();it!=offset_record.end();it++)
846  {
847  if(it->second.first!=0)delete it->second.first;
848  }
849  }
850 
858  {
859  /*
860  * currently the only traffic light type that's parsed by DynamicObjectSimulation
861  * other traffic light types include 1000009, 1000010, 1000011, 1000012
862  * see OpenDRIVE specifications (6.11 Signal Types) for further information
863  * for traffic signs see https://de.wikipedia.org/wiki/Bildtafeln_der_Verkehrszeichen_in_Deutschland
864  */
865  if(strcmp("1000001",xodrtype.c_str())==0)
866  {
868  }
869  else if(strcmp("206",xodrtype.c_str())==0) // stop SIGN
870  {
872  }
873  else if(strcmp(XODR_SIGNALTYPE_STOPLINE,xodrtype.c_str())==0) // stop LINE
874  {
876  }
877  else if(strcmp("306",xodrtype.c_str())==0)
878  {
880  }
881  else if(strcmp("27430",xodrtype.c_str())==0)
882  {
884  }
885  else if(strcmp("27450",xodrtype.c_str())==0)
886  {
888  }
889  else if(strcmp("27480",xodrtype.c_str())==0)
890  {
892  }
893 
895  }
896 
906  void convertBorders(const TSectionSet& sectionSet, const TSectionMap& sectionMap,adore::env::BorderBased::BorderSet* targetSet,const std::vector<XODR_Signal>& ordered_signal_set, adore::env::BorderBased::LanePositionedObjectSet* stoplineSet,Border2RoadID* border2roadID,const std::string& id)
907  {
908  /*@TODO reintroduce LanePositionedObjectList for Stoplines*/
909  double s = 0;
910  double s_cut = 0;
911  double s_max = 0;
912  auto signal_it = ordered_signal_set.begin();
913 
914  /* CONVERT FUNCTIONS TO BORDERS */
915 
916  /* iterate over sections */
917  for(auto it_section = sectionSet.begin();it_section!=sectionSet.end();it_section++)
918  {
919  int i_min = 1e9;
920  int i_max = -1e9;
921  TSectionBorderSet* borders = *it_section;
922 
923  /* repeat till whole section is converted (check break condition at end of loop) */
924  for(;;)
925  {
926  /* find the cut distance - smallest distance of all lanes in the section */
927  s_cut = 1e10;
928  for(auto it_border = borders->begin();it_border!=borders->end();it_border++)
929  {
930  TBorderFun* border = it_border->second.first;
931  i_min = (std::min)(i_min,it_border->first);
932  i_max = (std::max)(i_max,it_border->first);
933  s_cut = (std::min)(s_cut,border->getXAfterNPoints(s,sampling.numberOfPointsPerBorder-2));
934  s_max = (std::max)(s_max,border->limitHi());
935  }
936 
937  /* creating a point buffer */
938  adoreMatrix<double,0,0> m;
939  m = dlib::zeros_matrix<double>(4,sampling.numberOfPointsPerBorder);
940 
941  /* converting center line */
942  int points = (*borders)[0].first->export_points(m,s,s_cut,1e-10);
943  adoreMatrix<double,4,0> data = colm(m,dlib::range(0,points-1));
944 
945 
946  auto centerFun = new adore::mad::LLinearPiecewiseFunctionM<double,3>(data);
947  auto centerFunInverted = new adore::mad::LLinearPiecewiseFunctionM<double,3>(data);
948  centerFunInverted->invertDomain();
949 
950  adore::env::BorderBased::Border* center = new adore::env::BorderBased::Border(centerFun,(*borders)[0].second);
951  adore::env::BorderBased::Border* center_inverted = new adore::env::BorderBased::Border(centerFunInverted,(*borders)[0].second);
952 
953  targetSet->insert_border(center_inverted);
954  targetSet->insert_border(center);
955 
956  /* export border snippets - left */
957  adore::env::BorderBased::Border* previous = center_inverted;
958  for(int i = 1;i<=i_max;i++)
959  {
960  /* export points */
961  points = (*borders)[i].first->export_points(m,s,s_cut,1e-10);
962  auto function = new adore::mad::LLinearPiecewiseFunctionM<double,3>(dlib::colm(m,dlib::range(0,points-1)));
963 
964  /* adjust points for needs - invert direction, start at 0m */
965  function->invertDomain();
966  function->startDomainAtZero();
967 
968  /* create border */
969  adore::env::BorderBased::Border* current = new adore::env::BorderBased::Border(function,(*borders)[i].second);
970  current->m_left = new adore::env::BorderBased::BorderID(previous->m_id);
971  previous = current;
972 
973  targetSet->insert_border(current);
974  }
975 
976  /* export border snippets - right */
977  previous = center;
978  for(int i=-1;i>=i_min;i--)
979  {
980  /* export points */
981  points = (*borders)[i].first->export_points(m,s,s_cut,1e-10);
982  auto function = new adore::mad::LLinearPiecewiseFunctionM<double,3>(dlib::colm(m,dlib::range(0,points-1)));
983 
984  /* adjust points for needs - invert direction, start at 0m */
985  function->startDomainAtZero();
986 
987  /* create border */
988  adore::env::BorderBased::Border* current = new adore::env::BorderBased::Border(function,(*borders)[i].second);
989  current->m_left = new adore::env::BorderBased::BorderID(previous->m_id);
990  previous = current;
991 
992  /* insert if relevant for driving */
993  targetSet->insert_border(current);
994 
995  /* map with road id*/
996  border2roadID->emplace(std::make_pair(current, id));
997  }
998 
999  /* EXPORT STOPLINES */
1000  while(signal_it!=ordered_signal_set.end() && signal_it->s<s)signal_it++;
1001  for(;signal_it!=ordered_signal_set.end() && signal_it->s<=s_cut;signal_it ++)
1002  {
1003  /* only convert stoplines from odered_signal_set */
1004  if(!strcmp(signal_it->type.c_str(),XODR_SIGNALTYPE_STOPLINE)==0)
1005  {
1006  continue;
1007  }
1008 
1009  int i_start = (std::max)(i_min,signal_it->fromLane);
1010  int i_end = (std::min)(i_max,signal_it->toLane);
1012 
1013  /* create a stopline on each lane */
1014  for(int i = i_start;i<=i_end;i++)
1015  {
1016  //@TODO are there stop lines on emergency lanes?
1017  if(i!=0 && (*borders)[i].second == adore::env::BorderBased::BorderType::DRIVING)
1018  {
1019  /* getting the lanePosition with coordinates of first and last border point (= borderID) and progress */
1020  adoreMatrix<double,2,1> p0 = (*borders)[i].first->f_bounded(s);
1021  adoreMatrix<double,2,1> p1 = (*borders)[i].first->f_bounded(s_cut);
1022  if(i<0)
1023  {
1025  pos.m_rightID.m_first.m_X = p0(0);
1026  pos.m_rightID.m_first.m_Y = p0(1);
1027  pos.m_rightID.m_first.m_Z = 0;
1028  pos.m_rightID.m_last.m_X = p1(0);
1029  pos.m_rightID.m_last.m_Y = p1(1);
1030  pos.m_rightID.m_last.m_Z = 0;
1031  pos.m_progress = signal_it->s-s;
1032  }
1033  else
1034  {
1036  pos.m_rightID.m_first.m_X = p1(0);
1037  pos.m_rightID.m_first.m_Y = p1(1);
1038  pos.m_rightID.m_first.m_Z = 0;
1039  pos.m_rightID.m_last.m_X = p0(0);
1040  pos.m_rightID.m_last.m_Y = p0(1);
1041  pos.m_rightID.m_last.m_Z = 0;
1042  pos.m_progress = s_cut - signal_it->s;
1043  }
1044 
1046  stoplineSet->insert_object(stopLine);
1047  }
1048  }
1049  }
1050 
1051  s = s_cut;
1052  if(s_max-s_cut<sampling.emax)break;
1053  }
1054  }
1055  }
1056 
1063  std::vector<XODR2BorderBasedConverter::XODR_Signal> extractSignals(const OpenDRIVE::road_type& road)
1064  {
1065  std::vector<XODR_Signal> orderedSignalSet;
1066  if(road.signals().present())
1067  {
1068  for(auto signal = road.signals().get().t_signal().begin();signal!=road.signals().get().t_signal().end();signal++)
1069  {
1070  XODR_Signal xs;
1071  xs.s = signal->s().get();
1072  xs.t = signal->t().get();
1073  xs.id = signal->id().get();
1074  xs.orientation = signal->orientation().get();
1075  xs.type = signal->type().get();
1076  xs.value = signal->value().get();
1077 
1079  if(signal->validity().begin()!=signal->validity().end())
1080  {
1081  int from = signal->validity().begin()->fromLane().get();
1082  int to = signal->validity().begin()->toLane().get();
1083  xs.fromLane = (std::min)(from,to);
1084  xs.toLane = (std::max)(from,to);
1085  }
1086  else
1087  {
1088  if(strcmp(xs.orientation.c_str(),"+")==0)
1089  {
1091  xs.fromLane = -1000;
1092  xs.toLane = 0;
1093  }
1094  else if(strcmp(xs.orientation.c_str(),"-")==0)
1095  {
1097  xs.fromLane = 0;
1098  xs.toLane = 1000;
1099  }
1100  else if(strcmp(xs.orientation.c_str(),"none")==0)
1101  {
1103  xs.fromLane = -1000;
1104  xs.toLane = 1000;
1105  }
1107  for(auto depIt = signal->dependency().begin(); depIt != signal->dependency().end(); depIt++)
1108  {
1109  if(strcmp(depIt->type().get().c_str(), "limitline")==0)
1110  {
1111  xs.dependency.push_back(depIt->id().get());
1112  }
1113  }
1114  }
1115  orderedSignalSet.push_back(xs);
1116  }
1117  }
1118  return orderedSignalSet;
1119  }
1120 
1129  void convertNonStoplineSignals(TRoadCenterFun &center, TRoadCenterHeadingFun &centerHeading, std::vector<XODR_Signal> &orderedSignalSet, adore::env::TCDSet* tcdSet)
1130  {
1131  for(auto signalIt = orderedSignalSet.begin(); signalIt != orderedSignalSet.end(); signalIt++)
1132  {
1133 
1134  if(!strcmp((signalIt->type).c_str(), XODR_SIGNALTYPE_STOPLINE)==0)
1135  {
1136  // convert from s/t to x/y
1137  double s = signalIt->s;
1138  s = adore::mad::bound(center.limitLo(),s,center.limitHi());
1139  if(s<center.limitLo()||s>center.limitHi())continue;
1140  double t = signalIt->t;
1141  auto p = center.f(s);
1142  double psi = centerHeading(s);
1143  double x = p(0) - std::sin(psi)*t;
1144  double y = p(1) + std::cos(psi)*t;
1145  int toLane = signalIt->toLane;
1146 
1147  if(toLane > 0 )
1148  {
1149  psi += 3.14159;
1150  if( psi > (2 * 3.14159))
1151  {
1152  psi -= (2*3.14159);
1153  }
1154  }
1155 
1156  // create TrafficControlDevice, set values, add to tcdSet
1158  //@TODO add z coordinate
1160  tcd->setID(std::stoi(signalIt->id));
1161  tcd->setOrientation(psi);
1162  tcd->setType(convertTCDType(signalIt->type));
1163  tcdSet->insertTCD(tcd);
1164  }
1165  }
1166  }
1167 
1177  void convertRoad(const OpenDRIVE::road_type& road,adore::env::BorderBased::BorderSet* targetSet, adore::env::TCDSet* tcdSet, adore::env::BorderBased::LanePositionedObjectSet* stoplineSet, adore::env::BorderBased::ParkingSpotSet* parkingSpotSet, Border2RoadID* idTranslation)
1178  {
1179  //the road id
1180  std::string id = road.id().get();
1181 
1182  /* EXTRACT ROAD CENTERLINE */
1183  /* it's the basis for all the lane geometries */
1184  TRoadCenterFun center;
1185  TRoadCenterHeadingFun center_heading;
1186  TOffsetFun center_offset;
1187  extractRoadCenterLine(road,center,center_heading, center_offset);
1188 
1189  /* EXTRACT ROAD SECTIONS AS FUNCTIONS */
1190  TSectionMap sectionMap;
1191  TSectionSet sectionSet;
1192  for(auto section = road.lanes().laneSection().begin(); section!=road.lanes().laneSection().end(); section++)
1193  {
1194  /* determine length of current section, it's determined by the start of the next section */
1195  double s0 = section->s().get();
1196  double s1;
1197  auto nextLaneSection = section;
1198  nextLaneSection++;
1199  if(nextLaneSection==road.lanes().laneSection().end())
1200  {
1201  s1 = road.length().get();
1202  }
1203  else
1204  {
1205  s1 = nextLaneSection->s().get();
1206  }
1207 
1208  if(s1-s0>1e-3)//hess_da, 13.08.2018: Problem with some maps (9032_...tostmannplatz): Road sections with length smaller than 1e-8: could not be converted
1209  {
1210  /* EXTRACT ROAD SECTION */
1211  /* extract geometries of sections as functions, save to sectionMap and sectionSet */
1212  extractRoadSection(*section,center,center_heading, center_offset,s0,s1,sectionMap,sectionSet);
1213  }
1214  }
1215 
1216  /* EXTRACT SIGNALS (TRAFFICCONTROLDEVICES AND STOPLIENS) */
1217  std::vector<XODR_Signal> orderedSignalSet = extractSignals(road);
1218 
1219  /* EXTRACT PARKINGSPTS */
1220  if(road.objects().present())
1221  {
1222  for(auto obj = road.objects().get().object().begin(); obj != road.objects().get().object().end(); obj++)
1223  {
1224  if(obj->type().present() && strcmp(obj->type().get().c_str(),"parkingSpace")==0)
1225  {
1226  double s0_obj = obj->s().get();
1227  double t0_obj = obj->t().get();
1228  double hdg_obj = obj->hdg().get();
1229  /* is parking space object, check for repeat */
1230  if(obj->repeat().size()>0)
1231  {
1232  /* there can be multiple repeat clauses for an object */
1233  for(auto it = obj->repeat().begin(); it != obj->repeat().end(); it++)
1234  {
1235  double s0_repeat = it->s().get();
1236  double length = it->length().get();
1237  double distance = it->distance().get();
1238  double t0_repeat = it->tStart().get();
1239  double t_repeat_changeRate = (it->tEnd().get()-t0_repeat)/length;
1240  double s_repeat = 0;
1241  /* repeat while objects still within range */
1242  do
1243  {
1244  double s = s0_repeat + s_repeat;
1245  double t = t0_repeat + s*t_repeat_changeRate;
1246  double psi = center_heading.f(s);
1247  double hdg = hdg_obj + psi;
1248  auto point = center.f(s);
1249  double x = point(0) - std::sin(psi)*t;
1250  double y = point(1) + std::cos(psi)*t;
1251  //adore::env::BorderBased::ParkingSpot* ps = new adore::env::BorderBased::ParkingSpot(adore::env::BorderBased::Coordinate(x,y,0),hdg);
1253  s_repeat = s_repeat + distance;
1254  } while(s_repeat <= length);
1255 
1256  }
1257  }
1258  else
1259  { /* single object */
1260  auto point = center.f(s0_obj);
1261  auto psi = center_heading.f(s0_obj);
1262  double hdg = hdg_obj + psi;
1263  double x = point(0) - std::sin(psi)*t0_obj;
1264  double y = point(1) + std::cos(psi)*t0_obj;
1266  }
1267  }
1268  }
1269  }
1270 
1271  /* CONVERT ALL NON-STOPLINE SIGNALS */
1272  convertNonStoplineSignals(center, center_heading, orderedSignalSet, tcdSet);
1273 
1274  /* convert functions to borderbased::Border and xodr-stoplines to borderbased::LanePositionedObjects */
1275  convertBorders(sectionSet,sectionMap,targetSet,orderedSignalSet,stoplineSet,idTranslation,id);
1276  }
1277 
1284  void addMovementIdAndJunctionId(const std::unique_ptr<OpenDRIVE> op, adore::env::TCDSet* tcdSet)
1285  {
1286  for(auto it = op->controller().begin(); it!=op->controller().end(); it++)
1287  {
1288  if(!it->id().present())
1289  {
1290  continue;
1291  }
1292  auto ctrlId = it->id().get();
1293  for(auto it2 = it->control().begin(); it2!=it->control().end(); it2++)
1294  {
1295  if(it2->signalId().present())
1296  {
1297  tcdSet->setMovementId(atoi(it2->signalId().get().c_str()), atoi(ctrlId.c_str()));
1298  }
1299  }
1300  }
1301  for(auto it = op->junction().begin(); it!= op->junction().end(); it++)
1302  {
1303  if(!it->id().present())
1304  {
1305  continue;
1306  }
1307  auto junctionId = it->id().get();
1308  for(auto it2 = it->controller().begin(); it2!= it->controller().end(); it2++)
1309  {
1310  if(it2->id().present())
1311  {
1312  tcdSet->setJunctionId(atoi(it2->id().get().c_str()), atoi(junctionId.c_str()));
1313  }
1314  }
1315  }
1316  }
1317 
1330  void do_convert(const char* filename,
1332  adore::env::TCDSet* tcdSet,
1335  BorderIDTranslation* idTranslation,
1336  double* x0, double* y0,
1337  bool relative_coordinates,
1338  double x_r, double y_r, double angle)
1339  {
1340  std::unique_ptr<OpenDRIVE> op = OpenDRIVE_(filename, xml_schema::flags::keep_dom | xml_schema::flags::dont_validate);
1341  if(relative_coordinates && op->header().south().present() && op->header().west().present())
1342  {
1343  m_x0 = op->header().west().get();
1344  m_y0 = op->header().south().get();
1345  }
1346  else
1347  {
1348  m_x0 = 0.0;
1349  m_y0 = 0.0;
1350  }
1351  *x0 = m_x0;
1352  *y0 = m_y0;
1353 
1355  adore::env::TCDSet tmpTCDSet;
1357  adore::env::BorderBased::ParkingSpotSet tmpParkingSpotSet;
1358  Border2RoadID border2RoadID;
1359 
1360  /*
1361  * iterate over roads
1362  * convert road geometries to functions and sample these into borders
1363  * convert stoplines and traffic control devices belonging to this road
1364  */
1365  for( auto road = op->road().begin(); road!=op->road().end(); road++ )
1366  {
1367  convertRoad(*road,&tmpBorderSet,&tmpTCDSet,&tmpStoplineSet,&tmpParkingSpotSet,&border2RoadID);
1368  }
1369  /*
1370  * extract junction information
1371  */
1372  for( auto junction = op->junction().begin(); junction!=op->junction().end(); junction++)
1373  {
1374  std::string junctionID = junction->id().get();
1375  for( auto connection = junction->connection().begin(); connection!= junction->connection().end(); connection++ )
1376  {
1377  std::string connectingRoadID = connection->connectingRoad().get();
1378  idTranslation->insert(junctionID,connectingRoadID);
1379  }
1380  }
1381 
1382  addMovementIdAndJunctionId(std::move(op), &tmpTCDSet);
1383 
1388  translate_and_rotate_map(m_x0,m_y0,0.0, x_r, y_r, angle,
1389  &tmpBorderSet,&tmpTCDSet,&tmpStoplineSet,&tmpParkingSpotSet,
1390  targetSet,tcdSet,stoplineSet,parkingSpotSet,&border2RoadID,idTranslation);
1391 
1392 
1393  }
1394 
1410  void translate_and_rotate_map(double dx,double dy, double dz, double x_r, double y_r, double angle,
1411  adore::env::BorderBased::BorderSet* sourceBorderSet,
1412  adore::env::TCDSet* sourceTcdSet,
1414  adore::env::BorderBased::ParkingSpotSet* sourceParkingSpotSet,
1415  adore::env::BorderBased::BorderSet* targetBorderSet,
1416  adore::env::TCDSet* targetTcdSet,
1418  adore::env::BorderBased::ParkingSpotSet* targetParkingSpotSet,
1419  Border2RoadID* border2RoadID,
1420  BorderIDTranslation* idTranslation)
1421  {
1422  if(targetBorderSet!=nullptr)
1423  {
1424  for(auto it = sourceBorderSet->getAllBorders();it.first!=it.second;it.first++)
1425  {
1426  adore::env::BorderBased::Border* sourceBorder = it.first->second;
1427  adore::env::BorderBased::Border* newBorder = new adore::env::BorderBased::Border(*sourceBorder);
1428  // newBorder->rotateXY(angle, x_r, y_r);
1429  newBorder->translate(dx,dy,dz);
1430  targetBorderSet->insert_border(newBorder);
1431  idTranslation->insert(newBorder->m_id,(*border2RoadID)[sourceBorder]);
1432  }
1433  }
1434 
1435  if(targetTcdSet!=nullptr)
1436  {
1437  for(auto it = sourceTcdSet->getAllTCDs();it.first!=it.second;it.first++)
1438  {
1439  adore::env::TrafficControlDevice* sourceTCD = it.first->second;
1441  // newTCD->rotate(angle, x_r, y_r);
1442  newTCD->translate(dx,dy,dz);
1443  targetTcdSet->insertTCD(newTCD);
1445  {
1446  adore::env::TTCDTrafficLightTuple tlt = sourceTcdSet->getTCDTrafficLight(sourceTCD->getID());
1447  targetTcdSet->setMovementId(sourceTCD->getID(), std::get<1>(tlt));
1448  targetTcdSet->setJunctionId(std::get<1>(tlt),std::get<2>(tlt));
1449  }
1450  }
1451  }
1452 
1453  if(targetStoplineSet!=nullptr)
1454  {
1455  for(auto it = sourceStoplineSet->getAllObjects();it.first!=it.second;it.first++)
1456  {
1459  // newSL->rotate(angle, x_r, y_r);
1460  newSL->translate(dx,dy,dz);
1461  targetStoplineSet->insert_object(newSL);
1462  }
1463  }
1464  if(targetParkingSpotSet!=nullptr)
1465  {
1466  for(auto it = sourceParkingSpotSet->getAllParkingSpots();it.first!=it.second;it.first++)
1467  {
1468  auto ps = it.first;
1469  auto x = ps->first.get<0>();
1470  auto y = ps->first.get<1>();
1471  auto z = ps->first.get<2>();
1473  // c.rotate(angle, x_r, y_r);
1474  c.translate(dx,dy,dz);
1475  targetParkingSpotSet->insertParkingSpot(adore::env::BorderBased::ParkingSpot(c,ps->second));
1476  }
1477  }
1478  }
1479  };
1480  }
1481 }
Abstract class for Objects that are positioned by a connection to a certain lane.
Definition: alanepositionedobject.h:28
efficiently store borders in boost R-tree
Definition: borderset.h:99
void insert_border(Border *b, bool force_insert=false)
insert new border into this
Definition: borderset.h:225
BorderIteratorPair2 getAllBorders()
get all borders in this
Definition: borderset.h:356
This class represents a set of objects that are positioned by LanePosition.
Definition: lanepositionedobjectset.h:34
ObjectIteratorPair getAllObjects()
Get the begin()- and end()-iterator for the whole set.
Definition: lanepositionedobjectset.h:224
void insert_object(object *obj, bool remove_duplicates=false, double precision=0.5)
Insert a new object.
Definition: lanepositionedobjectset.h:147
Definition: parkingspotset.h:39
bool insertParkingSpot(ParkingSpot parkingSpot)
Definition: parkingspotset.h:135
ItPairCoordinate2heading getAllParkingSpots()
Definition: parkingspotset.h:181
This class definition is to represent parking spots.
Definition: parkingspot.h:31
This class provide information about stoplines.
Definition: stopline.h:31
void translate(double dx, double dy, double dz)
Translate the stop line.
Definition: stopline.h:115
Definition: tcdset.h:34
bool insertTCD(env::TrafficControlDevice *tcd)
Definition: tcdset.h:128
void setMovementId(int tcdId, int movementId)
Definition: tcdset.h:149
void setJunctionId(int movementId, int junctionId)
Definition: tcdset.h:154
TCDIteratorPair getAllTCDs()
Definition: tcdset.h:205
env::TTCDTrafficLightTuple getTCDTrafficLight(int tcdID)
Definition: tcdset.h:273
Definition: trafficcontroldevice.h:24
void translate(double dx, double dy, double dz)
Definition: trafficcontroldevice.h:137
void setType(TCDType type)
Definition: trafficcontroldevice.h:150
void setCoordinate(BorderBased::Coordinate coordinate)
Definition: trafficcontroldevice.h:170
void setID(int id)
Definition: trafficcontroldevice.h:148
int getID() const
Definition: trafficcontroldevice.h:146
void setOrientation(double orientation)
Definition: trafficcontroldevice.h:160
TCDType getType() const
Definition: trafficcontroldevice.h:155
TCDType
Definition: trafficcontroldevice.h:28
@ STOP_SIGN
Definition: trafficcontroldevice.h:32
@ UNKNOWN
Definition: trafficcontroldevice.h:48
@ RIGHT_OF_WAY
Definition: trafficcontroldevice.h:31
@ TRAFFIC_LIGHT
Definition: trafficcontroldevice.h:29
@ SPEED_LIMIT_30
Definition: trafficcontroldevice.h:35
@ SPEED_LIMIT_80
Definition: trafficcontroldevice.h:40
@ SPEED_LIMIT_50
Definition: trafficcontroldevice.h:37
BorderIDTranslation is a set of translation tables, which keeps track of road ids,...
Definition: idtranslation.h:32
void insert(const BorderID &borderID, TID roadID)
Definition: idtranslation.h:57
internal signal representation for conversion
Definition: xodr2borderbased.h:103
std::list< std::string > dependency
Definition: xodr2borderbased.h:119
adore::env::BorderBased::LanePosition m_pos
Definition: xodr2borderbased.h:105
int road_id
Definition: xodr2borderbased.h:113
friend bool operator<(const XODR_Signal &l, const XODR_Signal &r)
Definition: xodr2borderbased.h:120
double t
Definition: xodr2borderbased.h:115
virtual const adore::env::BorderBased::LanePosition & getLanePosition()
Get the LanePosition of the Object.
Definition: xodr2borderbased.h:106
int toLane
Definition: xodr2borderbased.h:117
double value
Definition: xodr2borderbased.h:118
std::string type
Definition: xodr2borderbased.h:110
double s
Definition: xodr2borderbased.h:114
std::string id
Definition: xodr2borderbased.h:111
std::string orientation
Definition: xodr2borderbased.h:112
int fromLane
Definition: xodr2borderbased.h:116
OpenDRIVE converter from file to object sets.
Definition: xodr2borderbased.h:43
adore::mad::LLinearFunction< double, double > TPoly3u
Definition: xodr2borderbased.h:59
void extractRoadCenterLine_Spiral(TRoadCenterFun &center, TRoadCenterHeadingFun &center_heading, double s0, double ds, double x0, double y0, double psi0, double kappa0, double kappa1)
extract spiral geometry of road center line
Definition: xodr2borderbased.h:237
void extractLanes_width(int &left_count, int &right_count, double s0, double s1, const lanes::laneSection_type &section, std::map< int, std::pair< adore::mad::LPiecewiseFunction< double, double > *, adore::env::BorderBased::BorderType::TYPE >> &width_record)
extract lanes with width entries
Definition: xodr2borderbased.h:510
std::vector< TSectionBorderSet * > TSectionSet
Definition: xodr2borderbased.h:53
struct adore::if_xodr::XODR2BorderBasedConverter::@1 sampling
sampling configuration object
adore::mad::LPiecewiseFunction< double, adoreMatrix< double, 2, 1 > > TRoadCenterFun
Definition: xodr2borderbased.h:48
adore::mad::LLinearFunction< double, adoreMatrix< double, 2, 1 > > TLine
Definition: xodr2borderbased.h:57
adore::mad::LLinearPiecewiseFunctionM< double, 2 > TBorderFun
Definition: xodr2borderbased.h:50
adore::mad::LSpiralFunction< double, 1 > TSpiral
Definition: xodr2borderbased.h:56
double emax
Definition: xodr2borderbased.h:70
double xstart
Definition: xodr2borderbased.h:74
double numberOfPointsPerBorder
Definition: xodr2borderbased.h:75
XODR2BorderBasedConverter()
Construct a new XODR2BorderBasedConverter object.
Definition: xodr2borderbased.h:87
void extractRoadCenterLine(const OpenDRIVE::road_type &road, TRoadCenterFun &center, TRoadCenterHeadingFun &center_heading, TOffsetFun &offsetFun)
extract road center line geometry to center and center heading functions
Definition: xodr2borderbased.h:367
void extractRoadCenterLine_ParamPoly3(TRoadCenterFun &center, TRoadCenterHeadingFun &center_heading, double s0, double ds, double x0, double y0, double psi0, pRange parameterRange, double au, double bu, double cu, double du, double av, double bv, double cv, double dv)
extract parampoly3 geometry of road center line
Definition: xodr2borderbased.h:322
void do_convert(const char *filename, adore::env::BorderBased::BorderSet *targetSet, adore::env::TCDSet *tcdSet, adore::env::BorderBased::LanePositionedObjectSet *stoplineSet, adore::env::BorderBased::ParkingSpotSet *parkingSpotSet, BorderIDTranslation *idTranslation, double *x0, double *y0, bool relative_coordinates, double x_r, double y_r, double angle)
Fills data sets of BorderBased map data representation with data from openDrive xml file.
Definition: xodr2borderbased.h:1330
std::unordered_map< adore::env::BorderBased::Border *, std::string > Border2RoadID
Definition: xodr2borderbased.h:62
double xmax
Definition: xodr2borderbased.h:73
void convertRoad(const OpenDRIVE::road_type &road, adore::env::BorderBased::BorderSet *targetSet, adore::env::TCDSet *tcdSet, adore::env::BorderBased::LanePositionedObjectSet *stoplineSet, adore::env::BorderBased::ParkingSpotSet *parkingSpotSet, Border2RoadID *idTranslation)
convert road geometry to borders and also extract traffic control devices and stop lines
Definition: xodr2borderbased.h:1177
adore::mad::LPiecewiseFunction< double, double > TOffsetFun
Definition: xodr2borderbased.h:54
double m_x0
Definition: xodr2borderbased.h:79
std::vector< XODR2BorderBasedConverter::XODR_Signal > extractSignals(const OpenDRIVE::road_type &road)
save signals from OpenDRIVE to XODR_Signal for later processing
Definition: xodr2borderbased.h:1063
adore::env::BorderBased::BorderType::TYPE convertLaneType(std::string xodrType)
convert xodr lane type to border type
Definition: xodr2borderbased.h:210
double edes
Definition: xodr2borderbased.h:71
adore::mad::LPolynomialM< double, 2, 3 > TParamPoly3
Definition: xodr2borderbased.h:60
adore::env::TrafficControlDevice::TCDType convertTCDType(std::string xodrtype)
convert OpenDRIVE signal type to traffic control device type
Definition: xodr2borderbased.h:857
void extractLanes_border(int &left_count, int &right_count, double s0, double s1, const lanes::laneSection_type &section, std::map< int, std::pair< adore::mad::LPiecewiseFunction< double, double > *, adore::env::BorderBased::BorderType::TYPE >> &width_record)
extract lanes with border entries
Definition: xodr2borderbased.h:615
std::unordered_map< std::string, XODR_Signal > SignalByID
Definition: xodr2borderbased.h:125
void extractRoadSection(const lanes::laneSection_type &section, TRoadCenterFun &center, TRoadCenterHeadingFun &center_heading, TOffsetFun &center_offset, double s0, double s1, TSectionMap &sectionMap, TSectionSet &sectionSet)
combine lanes and center line to function representation of road section
Definition: xodr2borderbased.h:723
void extractRoadCenterLine_Line(TRoadCenterFun &center, TRoadCenterHeadingFun &center_heading, double s0, double ds, double x0, double y0, double psi0)
extract line geometry of road center line
Definition: xodr2borderbased.h:255
void translate_and_rotate_map(double dx, double dy, double dz, double x_r, double y_r, double angle, adore::env::BorderBased::BorderSet *sourceBorderSet, adore::env::TCDSet *sourceTcdSet, adore::env::BorderBased::LanePositionedObjectSet *sourceStoplineSet, adore::env::BorderBased::ParkingSpotSet *sourceParkingSpotSet, adore::env::BorderBased::BorderSet *targetBorderSet, adore::env::TCDSet *targetTcdSet, adore::env::BorderBased::LanePositionedObjectSet *targetStoplineSet, adore::env::BorderBased::ParkingSpotSet *targetParkingSpotSet, Border2RoadID *border2RoadID, BorderIDTranslation *idTranslation)
change position of all objects via translation
Definition: xodr2borderbased.h:1410
void convertBorders(const TSectionSet &sectionSet, const TSectionMap &sectionMap, adore::env::BorderBased::BorderSet *targetSet, const std::vector< XODR_Signal > &ordered_signal_set, adore::env::BorderBased::LanePositionedObjectSet *stoplineSet, Border2RoadID *border2roadID, const std::string &id)
convert function representation of road to border representation, determine absolute stop line positi...
Definition: xodr2borderbased.h:906
std::map< int, std::pair< TBorderFun *, adore::env::BorderBased::BorderType::TYPE > > TSectionBorderSet
Definition: xodr2borderbased.h:51
void convertNonStoplineSignals(TRoadCenterFun &center, TRoadCenterHeadingFun &centerHeading, std::vector< XODR_Signal > &orderedSignalSet, adore::env::TCDSet *tcdSet)
determine absolute coordinate and heading of non stop line headings
Definition: xodr2borderbased.h:1129
adore::mad::LPiecewiseFunction< double, double > TRoadCenterHeadingFun
Definition: xodr2borderbased.h:49
double m_y0
Definition: xodr2borderbased.h:80
void addMovementIdAndJunctionId(const std::unique_ptr< OpenDRIVE > op, adore::env::TCDSet *tcdSet)
determine controller and junction id of traffic lights
Definition: xodr2borderbased.h:1284
double xmin
Definition: xodr2borderbased.h:72
void extractRoadCenterLine_Poly3(TRoadCenterFun &center, TRoadCenterHeadingFun &center_heading, double s0, double ds, double x0, double y0, double psi0, double a, double b, double c, double d)
extract poly3 geometry of road center line
Definition: xodr2borderbased.h:280
static const char * XODR_SIGNALTYPE_STOPLINE
Definition: xodr2borderbased.h:46
void convert(const char *filename, adore::env::BorderBased::BorderSet *target_set, adore::env::TCDSet *tcdSet, adore::env::BorderBased::LanePositionedObjectSet *stoplineSet, adore::env::BorderBased::ParkingSpotSet *parkingSpotSet, BorderIDTranslation *idTranslation, double *x0, double *y0, bool transform=false)
full conversion of OpenDRIVE map to object representations
Definition: xodr2borderbased.cpp:26
adore::mad::LPiecewiseFunction< double, int > TSectionMap
Definition: xodr2borderbased.h:52
adore::mad::LPolynomialS< double, 3 > TPoly3v
Definition: xodr2borderbased.h:58
Definition: alfunction.h:74
virtual ALFunction< DT, CT > * clone()=0
Definition: alfunction.h:287
Definition: alfunction.h:307
T getXAfterNPoints(T xstart, int N)
Definition: llinearpiecewisefunction.h:1113
virtual DT limitHi() const override
Definition: llinearpiecewisefunction.h:259
Definition: lpiecewisefunction.h:30
virtual void setLimits(DT lo, DT hi) override
Definition: lpiecewisefunction.h:125
virtual DT limitHi() const override
Definition: lpiecewisefunction.h:114
virtual DT limitLo() const override
Definition: lpiecewisefunction.h:119
virtual ALFunction< DT, CT > * clone() override
Definition: lpiecewisefunction.h:189
void appendHi(ALFunction< DT, CT > *newfun)
Definition: lpiecewisefunction.h:82
virtual CT f(DT x) const override
Definition: lpiecewisefunction.h:109
void appendHi_shifted(ALFunction< DT, CT > *newfun)
Definition: lpiecewisefunction.h:95
Definition: lpolynomial.h:202
virtual void multiply(adoreMatrix< T, 0, 0 > A, int rowi, int rowj) override
Definition: lpolynomial.h:307
virtual ALFunction< DT, CT > * create_derivative() override
Definition: lpolynomial.h:243
virtual void add(adoreMatrix< T, 0, 1 > b, int rowi, int rowj) override
Definition: lpolynomial.h:311
Definition: lpolynomial.h:140
Definition: lspiralfunction.h:38
virtual ALFunction< T, T > * create_heading()
Definition: lspiralfunction.h:138
TYPE
This enum holds the different types of borders.
Definition: border.h:37
@ OTHER
Definition: border.h:38
@ EMERGENCY
Definition: border.h:41
@ DRIVING
Definition: border.h:39
std::tuple< TrafficControlDevice *, int, int > TTCDTrafficLightTuple
Definition: tcdtrafficlightset.h:25
ALFunction< T, T > * heading(AScalarToN< T, 2 > *df)
Definition: heading.h:114
ALFunction< DT, CT > * add(ALFunction< DT, CT > *a, ALFunction< DT, CT > *b)
Definition: alfunction.h:742
interval< T > cos(interval< T > x)
Definition: intervalarithmetic.h:225
T bound(T lb, T value, T ub)
Definition: adoremath.h:569
T min(T a, T b, T c, T d)
Definition: adoremath.h:663
interval< T > sin(interval< T > x)
Definition: intervalarithmetic.h:204
adoreMatrix< T, N, M > max(adoreMatrix< T, N, M > a, const adoreMatrix< T, N, M > &b)
Definition: adoremath.h:686
x0
Definition: adore_set_goal.py:25
x
Definition: adore_set_goal.py:30
y0
Definition: adore_set_goal.py:26
y
Definition: adore_set_goal.py:31
z
Definition: adore_set_goal.py:32
p0
Definition: adore_set_pose.py:32
r
Definition: adore_suppress_lanechanges.py:209
Definition: areaofeffectconverter.h:20
This struct identifies a Border by the coordinates of the starting and the end point.
Definition: borderid.h:31
Coordinate m_last
Definition: borderid.h:32
Coordinate m_first
Definition: borderid.h:32
The border struct contains data of the smallest.
Definition: border.h:62
BorderID m_id
Definition: border.h:68
void translate(double dx, double dy, double dz)
Translate the border.
Definition: border.h:289
BorderID * m_left
Definition: border.h:69
This struct represents 3-dimensional coordines.
Definition: coordinate.h:34
void translate(double dx, double dy, double dz)
Translate a coordinate object.
Definition: coordinate.h:87
double m_Y
Definition: coordinate.h:35
double m_Z
Definition: coordinate.h:35
double m_X
Definition: coordinate.h:35
This is a struct that contains a position defined by a BorderID and a progress on that border.
Definition: laneposition.h:30
double m_progress
Definition: laneposition.h:32
BorderID m_rightID
Definition: laneposition.h:31
T1 first
Definition: parkingspotset.h:47