ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
borderoverlap.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  ********************************************************************************/
14 
15 
16 #pragma once
17 #include <algorithm>
19 
20 namespace adore
21 {
22  namespace env
23  {
24  namespace BorderBased
25  {
32  {
33  public:
34  std::pair<double,double> m_intersection_left_left;
35  std::pair<double,double> m_intersection_left_right;
36  std::pair<double,double> m_intersection_right_left;
37  std::pair<double,double> m_intersection_right_right;
46  std::vector<Coordinate> points_;
55  {
56  }
65  BorderOverlap(Border* first_right, Border* first_left,Border* second_right,Border* second_left):
68  {
69  this->m_first_right = first_right;
70  this->m_second_right = second_right;
71  this->m_first_left = first_left;
72  this->m_second_left = second_left;
73 
74  if(first_left!=0 && second_left!=0)m_has_intersection_left_left = first_left->m_path->getFirstIntersection2d(second_left->m_path,m_intersection_left_left);
75  if(first_left!=0 && second_right!=0)m_has_intersection_left_right = first_left->m_path->getFirstIntersection2d(second_right->m_path,m_intersection_left_right);
76  if(first_right!=0 && second_left!=0)m_has_intersection_right_left = first_right->m_path->getFirstIntersection2d(second_left->m_path,m_intersection_right_left);
77  if(first_right!=0 && second_right!=0)m_has_intersection_right_right = first_right->m_path->getFirstIntersection2d(second_right->m_path,m_intersection_right_right);
78  }
86  {
88  }
94  unsigned int getNumberOfIntersections()
95  {
96  return (m_has_intersection_left_left?1u:0u)
100  }
106  std::pair<double,double> getIntersectionIntervalFR()
107  {
108  std::pair<double,double> interval(m_first_right->m_path->limitHi(),m_first_right->m_path->limitLo());
110  {
111  auto point = m_first_left->m_path->f(m_intersection_left_left.first);
112  double s = m_first_right->m_path->getClosestParameter(point(0),point(1),1,2);
113  interval.first = (std::min)(interval.first,s);
114  interval.second = (std::max)(interval.second,s);
115  }
117  {
118  auto point = m_first_left->m_path->f(m_intersection_left_right.first);
119  double s = m_first_right->m_path->getClosestParameter(point(0),point(1),1,2);
120  interval.first = (std::min)(interval.first,s);
121  interval.second = (std::max)(interval.second,s);
122  }
124  {
125  double s = m_intersection_right_right.first;
126  interval.first = (std::min)(interval.first,s);
127  interval.second = (std::max)(interval.second,s);
128  }
130  {
131  double s = m_intersection_right_left.first;
132  interval.first = (std::min)(interval.first,s);
133  interval.second = (std::max)(interval.second,s);
134  }
135  return interval;
136  }
142  std::pair<double,double> getIntersectionIntervalSR()
143  {
144  std::pair<double,double> interval(m_second_right->m_path->limitHi(),m_second_right->m_path->limitLo());
146  {
147  auto point = m_second_left->m_path->f(m_intersection_left_left.second);
148  double s = m_second_right->m_path->getClosestParameter(point(0),point(1),1,2);
149  interval.first = (std::min)(interval.first,s);
150  interval.second = (std::max)(interval.second,s);
151  }
153  {
154  auto point = m_second_left->m_path->f(m_intersection_right_left.second);
155  double s = m_second_right->m_path->getClosestParameter(point(0),point(1),1,2);
156  interval.first = (std::min)(interval.first,s);
157  interval.second = (std::max)(interval.second,s);
158  }
160  {
161  double s = m_intersection_right_right.second;
162  interval.first = (std::min)(interval.first,s);
163  interval.second = (std::max)(interval.second,s);
164  }
166  {
167  double s = m_intersection_left_right.second;
168  interval.first = (std::min)(interval.first,s);
169  interval.second = (std::max)(interval.second,s);
170  }
171  return interval;
172  }
178  adoreMatrix<double,3,4> getCornerPoints()
179  {
180  adoreMatrix<double,3,4> points;
181  int count=0;
182  if(m_has_intersection_left_left)count++;
186 
187  if(count>=2)
188  {
190  {
193  double s0 = (std::min)(sa,sb);
194  double s1 = (std::max)(sa,sb);
195  dlib::set_colm(points,0) = m_first_right->m_path->f(s0);
196  dlib::set_colm(points,1) = m_first_right->m_path->f(s1);
197 
198  if(m_has_intersection_left_left || m_has_intersection_left_right)//second passes through first
199  {
202  s0 = (std::min)(sa,sb);
203  s1 = (std::max)(sa,sb);
204  dlib::set_colm(points,2) = m_first_right->m_path->f(s1);
205  dlib::set_colm(points,3) = m_first_right->m_path->f(s0);
206  }
207  else
208  {
209  if( s0==m_intersection_right_left.first )//second enters first from the right
210  {
211  dlib::set_colm(points,2) = m_second_right->m_path->f(m_second_right->m_path->limitHi());
212  if(m_second_left!=0)
213  {
214  dlib::set_colm(points,3) = m_second_left->m_path->f(m_second_left->m_path->limitHi());
215  }
216  else
217  {
218  dlib::set_colm(points,3) = m_second_right->m_path->f(m_second_right->m_path->limitHi());
219  }
220  }
221  else //second exits from first to the right case
222  {
223  if(m_second_left!=0)
224  {
225  dlib::set_colm(points,2) = m_second_left->m_path->f(m_second_left->m_path->limitLo());
226  }
227  else
228  {
229  dlib::set_colm(points,2) = m_second_right->m_path->f(m_second_right->m_path->limitLo());
230  }
231  dlib::set_colm(points,3) = m_second_right->m_path->f(m_second_right->m_path->limitLo());
232  }
233  }
234  }
235  else
236  {
239  double s0 = (std::min)(sa,sb);
240  double s1 = (std::max)(sa,sb);
241  dlib::set_colm(points,0) = m_first_right->m_path->f(s1);
242  dlib::set_colm(points,1) = m_first_right->m_path->f(s0);
243  if( s0==m_intersection_left_right.first )//second enters first from the left
244  {
245  dlib::set_colm(points,2) = m_second_right->m_path->f(m_second_right->m_path->limitHi());
246  if(m_second_left!=0)
247  {
248  dlib::set_colm(points,3) = m_second_left->m_path->f(m_second_left->m_path->limitHi());
249  }
250  else
251  {
252  dlib::set_colm(points,3) = m_second_right->m_path->f(m_second_right->m_path->limitHi());
253  }
254  }
255  else //second exits from first to the left case
256  {
257  if(m_second_left!=0)
258  {
259  dlib::set_colm(points,2) = m_second_left->m_path->f(m_second_left->m_path->limitLo());
260  }
261  else
262  {
263  dlib::set_colm(points,2) = m_second_right->m_path->f(m_second_right->m_path->limitLo());
264  }
265  dlib::set_colm(points,3) = m_second_right->m_path->f(m_second_right->m_path->limitLo());
266  }
267 
268  }
269  }
270  else//only one intersection point for reference
271  {
272  double s=0;
277  dlib::set_colm(points,0) = m_first_right->m_path->f(adore::mad::bound(m_first_right->m_path->limitLo(),s-0.1,m_first_right->m_path->limitHi()));
278  dlib::set_colm(points,1) = m_first_right->m_path->f(adore::mad::bound(m_first_right->m_path->limitLo(),s+0.1,m_first_right->m_path->limitHi()));
279  if(m_first_left!=0)
280  {
281  dlib::set_colm(points,2) = m_first_left->m_path->f(adore::mad::bound(m_first_left->m_path->limitLo(),s+0.1,m_first_left->m_path->limitHi()));
282  dlib::set_colm(points,3) = m_first_left->m_path->f(adore::mad::bound(m_first_left->m_path->limitLo(),s-0.1,m_first_left->m_path->limitHi()));
283  }
284  else
285  {
286  //this is totally degenerate
287  dlib::set_colm(points,2) = m_first_right->m_path->f(adore::mad::bound(m_first_right->m_path->limitLo(),s+0.1,m_first_right->m_path->limitHi()));
288  dlib::set_colm(points,3) = m_first_right->m_path->f(adore::mad::bound(m_first_right->m_path->limitLo(),s-0.1,m_first_right->m_path->limitHi()));
289  }
290 
291  }
292  return points;
293  }
294  std::vector<Coordinate>* getCornerPointVector()
295  {
296  if(points_.size()==getNumberOfIntersections()) return &points_;
298  {
301  points_.push_back(s0);
302  if (std::sqrt(std::abs(s0(0)-s1(0))*std::abs(s0(0)-s1(0)) +std::abs(s1(1)-s0(1))*std::abs(s1(1)-s0(1)))>0.7)std::cout << " A C H T U N G" << std::endl;
303  }
305  {
308  points_.push_back(s0);
309  if (std::sqrt(std::abs(s0(0)-s1(0))*std::abs(s0(0)-s1(0)) +std::abs(s1(1)-s0(1))*std::abs(s1(1)-s0(1)))>0.7)std::cout << " A C H T U N G" << std::endl;
310  }
312  {
315  points_.push_back(s0);
316  if (std::sqrt(std::abs(s0(0)-s1(0))*std::abs(s0(0)-s1(0)) +std::abs(s1(1)-s0(1))*std::abs(s1(1)-s0(1)))>0.7)std::cout << " A C H T U N G" << std::endl;
317  }
319  {
322  points_.push_back(s0);
323  if (std::sqrt(std::abs(s0(0)-s1(0))*std::abs(s0(0)-s1(0)) +std::abs(s1(1)-s0(1))*std::abs(s1(1)-s0(1)))>0.7)std::cout << " A C H T U N G" << std::endl;
324  }
325  if(points_.size() != getNumberOfIntersections())std::cout << " A C H T U N G" << std::endl;
326  return &points_;
327  }
328  };
334  {
335  public:
336  std::vector<BorderOverlap*> borderoverlaps_; // vector of borderoverlaps within borderoverlapset
337  std::vector<Border*> conflictingBorders_; // borders that intersect
338  std::vector<Border*> conflictingPath_; // conflicting path that leads to overlapset
339  void getCoordinates(std::vector<Coordinate>& result)
340  {
341  for (auto &ol:borderoverlaps_)
342  {
343  auto p = ol->getCornerPointVector();
344  result.insert(result.begin(),p->begin(),p->end());
345  }
346  }
347  };
348 
349  }
350  }
351 }
Set of BorderOverlap objects that are connected, e. g. to form a conflict zone.
Definition: borderoverlap.h:334
std::vector< Border * > conflictingBorders_
Definition: borderoverlap.h:337
std::vector< Border * > conflictingPath_
Definition: borderoverlap.h:338
std::vector< BorderOverlap * > borderoverlaps_
Definition: borderoverlap.h:336
void getCoordinates(std::vector< Coordinate > &result)
Definition: borderoverlap.h:339
virtual CT f(DT x) const override
Definition: llinearpiecewisefunction.h:251
bool getFirstIntersection2d(LLinearPiecewiseFunctionM< T, n > *other, int dim1, int dim2, std::pair< T, T > &result)
Definition: llinearpiecewisefunction.h:664
double getClosestParameter(T px, T py, int d1, int d2, T &n_min) const
Definition: llinearpiecewisefunction.h:1014
virtual DT limitLo() const override
Definition: llinearpiecewisefunction.h:264
virtual DT limitHi() const override
Definition: llinearpiecewisefunction.h:259
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
adoreMatrix< T, N, M > max(adoreMatrix< T, N, M > a, const adoreMatrix< T, N, M > &b)
Definition: adoremath.h:686
Definition: areaofeffectconverter.h:20
Definition: borderoverlap.h:32
std::pair< double, double > m_intersection_left_left
Definition: borderoverlap.h:34
Border * m_second_right
Definition: borderoverlap.h:43
unsigned int getNumberOfIntersections()
Get the number of intersections.
Definition: borderoverlap.h:94
adoreMatrix< double, 3, 4 > getCornerPoints()
Get the corner points of the overlap.
Definition: borderoverlap.h:178
std::vector< Coordinate > points_
Definition: borderoverlap.h:46
bool m_has_intersection_right_right
Definition: borderoverlap.h:41
std::pair< double, double > m_intersection_left_right
Definition: borderoverlap.h:35
std::vector< Coordinate > * getCornerPointVector()
Definition: borderoverlap.h:294
std::pair< double, double > m_intersection_right_left
Definition: borderoverlap.h:36
std::pair< double, double > getIntersectionIntervalSR()
Get the intersection interval of second right border.
Definition: borderoverlap.h:142
Border * m_second_left
Definition: borderoverlap.h:45
bool hasAnyOverlap()
Check for any overlap.
Definition: borderoverlap.h:85
BorderOverlap(Border *first_right, Border *first_left, Border *second_right, Border *second_left)
Construct a new Border Overlap object.
Definition: borderoverlap.h:65
std::pair< double, double > m_intersection_right_right
Definition: borderoverlap.h:37
Border * m_first_right
Definition: borderoverlap.h:42
BorderOverlap()
Construct a new BorderOverlap object.
Definition: borderoverlap.h:51
Border * m_first_left
Definition: borderoverlap.h:44
bool m_has_intersection_right_left
Definition: borderoverlap.h:40
bool m_has_intersection_left_right
Definition: borderoverlap.h:39
std::pair< double, double > getIntersectionIntervalFR()
Get the intersection interval of first right border.
Definition: borderoverlap.h:106
bool m_has_intersection_left_left
Definition: borderoverlap.h:38
The border struct contains data of the smallest.
Definition: border.h:62
Tborderpath * m_path
Definition: border.h:70