ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
trafficmap.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 implementation and API
13  ********************************************************************************/
14 
15 
16 #pragma once
17 
18 #include <unordered_map>
21 #include <adore/env/afactory.h>
22 #include "participant.h"
23 
24 
25 namespace adore
26 {
27  namespace env
28  {
29  namespace traffic
30  {
35  class TrafficMap
36  {
37  public:
38  typedef std::unordered_multimap<adore::env::BorderBased::BorderID,std::pair<adore::env::BorderBased::BorderPositioning<4>,adore::env::traffic::Participant::TTrackingID>,adore::env::BorderBased::BorderIDHasher> TBorderToParticipant;
39  typedef std::unordered_multimap<adore::env::traffic::Participant::TTrackingID,std::pair<adore::env::BorderBased::BorderID,adore::env::BorderBased::BorderPositioning<4>>> TParticipantToBorder;
40  typedef std::unordered_multimap<adore::env::traffic::Participant::TTrackingID,adore::env::traffic::Participant> TTrackingIDToParticipant;
41  private:
48  public:
55  {
56  return participantSet_;
57  }
64  {
65  return borderSet_;
66  }
73  {
74  return borderToParticipant_;
75  }
82  {
83  return participantToBorder_;
84  }
91  {
93  }
100  {
102  borderSet_ = borderSet;
103  }
111  {
112  if(factory!=nullptr)
113  {
115  }
116  else
117  {
118  tpsetReader_ = nullptr;
119  }
120  borderSet_ = borderSet;
121  }
126  void update()
127  {
128  if(tpsetReader_->hasUpdate())
129  {
130  borderToParticipant_.clear();
131  participantToBorder_.clear();
132  trackingIDToParticipant_.clear();
134  for(auto& participant:participantSet_)
135  {
136  trackingIDToParticipant_.insert(std::make_pair(participant.trackingID_,participant));
137  }
138  matchBorders();
139  }
140  //implement variant where individual participants are re-matched
141  }
147  {
148  double X[4];double Y[4];
149  double ca;
150  double sa;
151  double Xref;
152  double Yref;
153  double a;
154  double b;
155  double w2;
156  double xmin,xmax,ymin,ymax;
157 
158  for(auto& participant:participantSet_)
159  {
160  ca = std::cos(participant.yaw_);
161  sa = std::sin(participant.yaw_);
162  a = participant.length_*0.5;
163  b = -participant.length_*0.5;
164  w2 = participant.width_*0.5;
165  Xref = participant.center_(0);
166  Yref = participant.center_(1);
167  X[0] = Xref+ca*b -sa*(-w2);
168  Y[0] = Yref+sa*b +ca*(-w2);
169  X[1] = Xref+ca*a -sa*(-w2);
170  Y[1] = Yref+sa*a +ca*(-w2);
171  X[2] = Xref+ca*a -sa*(+w2);
172  Y[2] = Yref+sa*a +ca*(+w2);
173  X[3] = Xref+ca*b -sa*(+w2);
174  Y[3] = Yref+sa*b +ca*(+w2);
175  xmin = std::min(std::min(X[0],X[1]),std::min(X[2],X[3]));
176  xmax = std::max(std::min(X[0],X[1]),std::max(X[2],X[3]));
177  ymin = std::min(std::min(Y[0],Y[1]),std::min(Y[2],Y[3]));
178  ymax = std::max(std::min(Y[0],Y[1]),std::max(Y[2],Y[3]));
181 
182  double offset = 5.0;
183  for(auto bit = borderSet_->getBordersInRegion(xmin-offset,xmax+offset,ymin-offset,ymax+offset);
184  bit.first!=bit.second;
185  bit.first++)
186  {
187  auto border = bit.first->second;
188  auto left = borderSet_->getLeftNeighbor(border);
189  if(left!=0)
190  {
191  if(boost::geometry::intersects(border->getBoostBox(left),pbox))
192  {
193  adore::env::BorderBased::BorderPositioning<4> positioning(border,left,Xref,Yref,X,Y);
194  if(positioning.anyInside())
195  {
196  borderToParticipant_.insert(std::make_pair(border->m_id,std::make_pair(positioning,participant.trackingID_)));
197  participantToBorder_.insert(std::make_pair(participant.trackingID_,std::make_pair(border->m_id,positioning)));
198  }
199  }
200  }
201  }
202  }
203  }
204  };
205  }
206  }
207 }
abstract factory for adore::env communication
Definition: afactory.h:41
virtual TParticipantSetReader * getTrafficParticipantSetReader()=0
Definition: lanematchingstrategy.h:350
bool anyInside()
Definition: lanematchingstrategy.h:367
efficiently store borders in boost R-tree
Definition: borderset.h:99
itRegion2Border getBordersInRegion(double x0, double x1, double y0, double y1)
get all borders in this within region
Definition: borderset.h:370
Border * getLeftNeighbor(Border *b)
Get left neighbor of a border.
Definition: borderset.h:1252
static adore::env::AFactory * get()
Definition: afactory.h:236
Definition: trafficmap.h:36
std::unordered_multimap< adore::env::BorderBased::BorderID, std::pair< adore::env::BorderBased::BorderPositioning< 4 >, adore::env::traffic::Participant::TTrackingID >, adore::env::BorderBased::BorderIDHasher > TBorderToParticipant
Definition: trafficmap.h:38
TParticipantSet participantSet_
Definition: trafficmap.h:45
adore::env::AFactory::TParticipantSetReader * tpsetReader_
Definition: trafficmap.h:47
adore::env::BorderBased::BorderSet * getBorderSet()
Get the border set.
Definition: trafficmap.h:63
void update()
Update the TrafficMap.
Definition: trafficmap.h:126
TParticipantToBorder participantToBorder_
Definition: trafficmap.h:43
adore::env::BorderBased::BorderSet * borderSet_
Definition: trafficmap.h:46
TTrackingIDToParticipant trackingIDToParticipant_
Definition: trafficmap.h:44
const TBorderToParticipant & getBorderToParticipant() const
Get the border to participant map.
Definition: trafficmap.h:72
TParticipantSet & getTrafficParticipantSet()
Get the set of traffic participants.
Definition: trafficmap.h:54
TrafficMap(adore::env::BorderBased::BorderSet *borderSet)
Construct a new TrafficMap object.
Definition: trafficmap.h:99
std::unordered_multimap< adore::env::traffic::Participant::TTrackingID, adore::env::traffic::Participant > TTrackingIDToParticipant
Definition: trafficmap.h:40
const TParticipantToBorder & getParticipantToBorder() const
Get the participant to border map.
Definition: trafficmap.h:81
void matchBorders()
Match traffic to borders.
Definition: trafficmap.h:146
TrafficMap(adore::env::BorderBased::BorderSet *borderSet, adore::env::AFactory *factory)
Construct a new TrafficMap object.
Definition: trafficmap.h:110
const TTrackingIDToParticipant & getTrackingIDToParticipant() const
Get the tracking id to participant map.
Definition: trafficmap.h:90
TBorderToParticipant borderToParticipant_
Definition: trafficmap.h:42
std::unordered_multimap< adore::env::traffic::Participant::TTrackingID, std::pair< adore::env::BorderBased::BorderID, adore::env::BorderBased::BorderPositioning< 4 > > > TParticipantToBorder
Definition: trafficmap.h:39
Definition: com_patterns.h:68
virtual void getData(T &value)=0
virtual bool hasUpdate() const =0
std::vector< Participant > TParticipantSet
Definition: participant.h:164
@ left
Definition: indicator_hint.h:35
interval< T > cos(interval< T > x)
Definition: intervalarithmetic.h:225
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
Definition: areaofeffectconverter.h:20
a functor, which hashes a BorderID object -> std::unordered_set<BorderID,BorderIDHasher> amap(0);
Definition: borderid.h:176
boost::geometry::model::box< Coordinate::boost_point > boost_box
bounding box
Definition: border.h:66
boost::geometry::model::point< double, 3, boost::geometry::cs::cartesian > boost_point
Definition: coordinate.h:36
T1 first
Definition: borderset.h:47
int TTrackingID
Definition: participant.h:32