ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
map_border_management.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  ********************************************************************************/
13 
14 #pragma once
15 
17 #include "map_auxiliary.h"
18 
19 #include <vector>
20 #include <queue>
21 
22 namespace adore
23 {
24  namespace env
25  {
27  {
30  std::vector<BorderBased::BorderType::TYPE> borderTypeProfile;
31  };
37  {
38  // base set that should not be altered
40 
41  // global set from which borders can be removed
43 
44  // local set that represents local map, borders can be removed and added
46 
47  // update queue - all borders that are changed
48  std::queue<adore::env::BorderBased::BorderID> m_updateQueue;
49 
50 
56  {
58  }
59 
66  {
67  baseSet->deepBorderCopy(m_baseSet);
68  initGlobalSet();
69  }
70 
71  // returns vector newBorders with borders that newly appear on the local map and vector outdatedBorders that references all borders that are out of sight
72  void do_run(double x, double y, double r, std::vector<adore::env::BorderBased::Border*> &newBorders, std::vector<adore::env::BorderBased::BorderID> &outdatedBorders, std::vector<adore::env::BorderBased::BorderID> &updatedBorders, int MAX_SEND_NUMBER = 40)
73  {
74  static int MIN_DELETE_NUMBER = 5;
75  newBorders.clear();
76  outdatedBorders.clear();
77  updatedBorders.clear();
78  auto corners = MAP_AUX::getCornerPoints(x,y,r);
79 
80  // collect borders that will be removed
81  auto invisible = m_localSet.getBorderSetOutsideRegion(corners.at(0),corners.at(1),corners.at(2),corners.at(3));
82  for(auto it = invisible.begin(); it!=invisible.end(); it++)
83  {
84  outdatedBorders.push_back((*it)->m_id);
85  m_localSet.erase_border((*it)->m_id);
86  }
87 
88  // collect new borders
89  int newCount = 0;
90  for(auto visible = m_globalSet.getBordersInRegion(corners.at(0),corners.at(1),corners.at(2),corners.at(3));visible.first!=visible.second;visible.first++)
91  {
92  adore::env::BorderBased::Border* border = visible.first->second;
93  // border type sensitive hasBorder()
94  if(!m_localSet.hasBorder(border) && border->m_path!=0)
95  {
96  newBorders.push_back(border);
98  newCount++;
99  // if there are no borders to delete, use full buffer, otherwise leave at least MIN_DELETE_NUMBER for deleting borders
100  if(newCount >= MAX_SEND_NUMBER - MIN_DELETE_NUMBER)
101  {
102  if(!m_updateQueue.empty())
103  {
104  break;
105  }
106  else if(newCount >= MAX_SEND_NUMBER)
107  {
108  break;
109  }
110  }
111  }
112  }
113 
114  // collect updated borders
115  for(int i = 0; i < MAX_SEND_NUMBER - newCount ;i++)
116  {
117  if(m_updateQueue.empty())
118  {
119  break;
120  }
122  updatedBorders.push_back(m_updateQueue.front());
123  m_updateQueue.pop();
124  }
125  }
126 
127  public:
133  {
134  }
135 
143  {
144  return m_globalSet.getSuccessors(b);
145  }
146 
155  {
157  }
158 
165  {
166  initBaseSet(baseSet);
167  }
168 
176  {
177  return m_globalSet.getBorder(bId);
178  }
179 
185  {
186  m_localSet.clear();
187  }
188 
193  void reset()
194  {
195  std::queue<adore::env::BorderBased::BorderID>().swap(m_updateQueue);
196  auto its = m_baseSet.getAllBorders();
197  for(;its.first!=its.second;its.first++)
198  {
199  auto b = its.first->second;
200  if(!m_globalSet.hasBorder(b))
201  {
202  m_updateQueue.push(b->m_id);
203  }
204  }
205  m_globalSet.clear();
206  m_localSet.clear();
207  initGlobalSet();
208  }
209 
211  {
212  return &m_globalSet;
213  }
214 
223  void deleteBordersInRegion(double x0, double x1, double y0, double y1)
224  {
225  auto itpair = m_baseSet.getBordersInRegion(x0,x1,y0,y1);
226  for(;itpair.first!=itpair.second;itpair.first++)
227  {
228  auto border = itpair.first->second;
229  if(!border->typeIsChangeable()) continue;
230 
231  auto b = itpair.first->second->m_id;
232  if(m_localSet.hasBorder(b))
233  {
235  auto newB = new adore::env::BorderBased::Border(*border);
236  newB->deleteType();
238  }
239  if(m_globalSet.hasBorder(b))
240  {
242  auto newB = new adore::env::BorderBased::Border(*border);
243  newB->deleteType();
245  // erase ALL deleted borders via feed
246  m_updateQueue.push(b);
247  }
248  }
249  }
250 
259  void addBordersInRegion(double x0, double x1, double y0, double y1)
260  {
261  auto itpair = m_baseSet.getBordersInRegion(x0,x1,y0,y1);
262  for(;itpair.first!=itpair.second;itpair.first++)
263  {
264  auto b = itpair.first->second;
265  auto newB = new adore::env::BorderBased::Border(*b);
266  m_globalSet.insert_border(newB,true);
267  m_updateQueue.push((*b).m_id);
268  }
269  }
270 
271  // full run method, return new borders, old borders and deleted borders
272  void run(double x, double y, double r, std::vector<adore::env::BorderBased::Border*> &newBorders, std::vector<adore::env::BorderBased::BorderID> &outdatedBorders, std::vector<adore::env::BorderBased::BorderID> &updatedBorders, int MAX_SEND_NUMBER = 40)
273  {
274  do_run(x, y, r, newBorders, outdatedBorders, updatedBorders, MAX_SEND_NUMBER);
275  }
276 
287  void run(double x, double y, double r, std::vector<adore::env::BorderBased::Border*> &newBorders, std::vector<adore::env::BorderBased::BorderID> &outdatedBorders, int MAX_SEND_NUMBER = 40)
288  {
289  std::vector<adore::env::BorderBased::BorderID> dummyDelete;
290  do_run(x, y, r, newBorders, outdatedBorders, dummyDelete, MAX_SEND_NUMBER);
291  }
292 
301  {
302  auto vec = m_globalSet.getBordersAtPoint(x,y);
303  for(auto b = vec.begin(); b!= vec.end(); b++)
304  {
305  if((*b)->typeIsChangeable())
306  {
307  (*b)->m_type = t;
308  m_updateQueue.push((*b)->m_id);
309  }
310  }
311 
312  }
313 
321  {
323  {
324  m_globalSet.getBorder(id)->m_type = t;
325  m_updateQueue.push(id);
326  LOG_T("Update queue: %i", m_updateQueue.size());
327  }
328  }
329 
339  void changeBorderType(adore::env::BorderBased::BorderType::TYPE t, double x0, double x1, double y0, double y1)
340  {
341  auto itpair = m_globalSet.getBordersInRegion(x0,x1,y0,y1);
342  for(;itpair.first!=itpair.second;itpair.first++)
343  {
344  if(itpair.first->second->typeIsChangeable())
345  {
346  itpair.first->second->m_type = t;
347  m_updateQueue.push(itpair.first->second->m_id);
348  }
349  }
350  }
351 
356  {
357  LOG_T("Enter function.");
358  // profiles are ordered from leftmost to rightmost
359  BorderBased::BorderSubSet startingProfile, endingProfile;
360 
361  // find starting profile, ordered from left to right
362  auto startingBorders = m_globalSet.getBordersAtPoint(btcp.start.m_X, btcp.start.m_Y);
363  for(auto b = startingBorders.begin(); b!=startingBorders.end(); b++)
364  {
365  if((*b)->typeIsChangeable())
366  {
367  startingProfile = m_globalSet.getIndexableNeighbors((*b));
368  break;
369  }
370  }
371  // find ending profile, ordered from left to right
372  auto endingBorders = m_globalSet.getBordersAtPoint(btcp.end.m_X, btcp.end.m_Y);
373  for(auto b = endingBorders.begin(); b!=endingBorders.end(); b++)
374  {
375  if((*b)->typeIsChangeable())
376  {
377  endingProfile = m_globalSet.getIndexableNeighbors((*b));
378  break;
379  }
380  }
381  LOG_T("Border Sizes: %i, %i", startingProfile.size(), endingProfile.size());
382  // check for inconsistencies
383  if(startingProfile.size()==0 or endingProfile.size()==0 or startingProfile.size()!=endingProfile.size() or btcp.borderTypeProfile.size()<startingProfile.size())
384  {
385  LOG_E("BorderTypeChangeProfile is inconsistent.");
386  return;
387  }
388  // find path per border in profile
389  for(int i=0; i<startingProfile.size(); i++)
390  {
391  auto startingBorder = startingProfile.at(i);
392  auto endingBorder = endingProfile.at(i);
393  BorderBased::BorderSubSet targetBorder;
394  targetBorder.push_back(endingBorder);
395  std::deque<BorderBased::BorderID> path;
396  m_globalSet.findPathBetweenBorders(startingBorder->m_id,path,targetBorder);
397  if(path.size()==0)
398  {
399  LOG_W("BorderTypeChangeProfile path between borders was not found.");
400  }
401  LOG_T("Path size: %i", path.size());
402  // change border type of path
403  for(auto id=path.begin(); id!=path.end(); id++)
404  {
405  // border type profile is also ordered from left to right
406  this->changeBorderType(*id,btcp.borderTypeProfile.at(i));
407  LOG_T("%s\ttype:", (*id).toString().c_str(), static_cast<int>(btcp.borderTypeProfile.at(i)));
408  }
409  }
410  }
411  };
412  }
413 }
efficiently store borders in boost R-tree
Definition: borderset.h:99
void clear()
remove all borders from this, delete object if this is owner
Definition: borderset.h:284
BorderSubSet getBordersAtPoint(double x, double y, double max_lane_width)
get all borders at the given point
Definition: borderset.h:403
bool findPathBetweenBorders(BorderID curID, std::deque< BorderID > &solvedList, std::vector< Border * > targets, size_t searchDepth=10)
find path between a starting border and a list of possible target borders in a recursive manner
Definition: borderset.h:308
itCoordinate2Border getSuccessors(Border *b)
get an interator pair for all borders which follow after b
Definition: borderset.h:996
void insert_border(Border *b, bool force_insert=false)
insert new border into this
Definition: borderset.h:225
itRegion2Border getBordersInRegion(double x0, double x1, double y0, double y1)
get all borders in this within region
Definition: borderset.h:370
BorderIteratorPair2 getAllBorders()
get all borders in this
Definition: borderset.h:356
Border * getBorder(const BorderID &id) const
retrieve a border by ID
Definition: borderset.h:628
bool hasBorder(const BorderID &id) const
check whether a border exists in the set
Definition: borderset.h:966
void erase_border(const BorderID &oldID)
erase border from this
Definition: borderset.h:269
BorderSubSet getBorderSetOutsideRegion(double x0, double x1, double y0, double y1)
get all borders outside of region in BorderSubSet
Definition: borderset.h:443
void deepBorderCopy(BorderSet &copy)
generate a complete copy including copies of objects the pointers point to
Definition: borderset.h:1507
BorderSubSet getIndexableNeighbors(Border *b)
returns the given border and all parallel borders with a changeable type, ordered from leftmost to ri...
Definition: borderset.h:1303
Automatically manage local map and necessary updates based on vehicle position and last state of obje...
Definition: map_border_management.h:37
void deleteBordersInRegion(double x0, double x1, double y0, double y1)
removes borders in region from global and local map
Definition: map_border_management.h:223
void init(adore::env::BorderBased::BorderSet *baseSet)
initialization routine with base map
Definition: map_border_management.h:164
std::queue< adore::env::BorderBased::BorderID > m_updateQueue
Definition: map_border_management.h:48
void initBaseSet(adore::env::BorderBased::BorderSet *baseSet)
initialization of internal sets
Definition: map_border_management.h:65
adore::env::BorderBased::Border * getBorder(adore::env::BorderBased::BorderID &bId)
Direct access to border in global map for auxiliary uses like plotting.
Definition: map_border_management.h:175
void changeBorderType(adore::env::BorderBased::BorderType::TYPE t, double x0, double x1, double y0, double y1)
change border type of borders in region to given type
Definition: map_border_management.h:339
env::BorderBased::BorderSubSet getBordersAtPoint(double x, double y)
Get borders at given point.
Definition: map_border_management.h:154
adore::env::BorderBased::BorderSet m_localSet
Definition: map_border_management.h:45
void changeBorderType(adore::env::BorderBased::BorderType::TYPE t, double x, double y)
change border type of border at exactly the given position
Definition: map_border_management.h:300
MapBorderManagement()
Construct a new Map Border Management object.
Definition: map_border_management.h:132
adore::env::BorderBased::BorderSet m_baseSet
Definition: map_border_management.h:39
void changeBorderType(adore::env::BorderBased::BorderID id, adore::env::BorderBased::BorderType::TYPE t)
change border type of border identified by id
Definition: map_border_management.h:320
env::BorderBased::itCoordinate2Border getSuccessors(env::BorderBased::Border *b)
Get successors of a given border from global set.
Definition: map_border_management.h:142
void changeBorderType(BorderTypeChangeProfile btcp)
change border type based on BorderTypeChangeProfile struct
Definition: map_border_management.h:355
void reset()
undo all changes to global map and clears local map
Definition: map_border_management.h:193
void addBordersInRegion(double x0, double x1, double y0, double y1)
add formerly deleted borders in a given region into global map from base map
Definition: map_border_management.h:259
void initGlobalSet()
initialization of global set
Definition: map_border_management.h:55
void clearLocalMap()
clear local map
Definition: map_border_management.h:184
adore::env::BorderBased::BorderSet m_globalSet
Definition: map_border_management.h:42
void do_run(double x, double y, double r, std::vector< adore::env::BorderBased::Border * > &newBorders, std::vector< adore::env::BorderBased::BorderID > &outdatedBorders, std::vector< adore::env::BorderBased::BorderID > &updatedBorders, int MAX_SEND_NUMBER=40)
Definition: map_border_management.h:72
adore::env::BorderBased::BorderSet * getGlobalMap()
Definition: map_border_management.h:210
void run(double x, double y, double r, std::vector< adore::env::BorderBased::Border * > &newBorders, std::vector< adore::env::BorderBased::BorderID > &outdatedBorders, int MAX_SEND_NUMBER=40)
reduced run method, receive new visible borders and now outdated borders
Definition: map_border_management.h:287
void run(double x, double y, double r, std::vector< adore::env::BorderBased::Border * > &newBorders, std::vector< adore::env::BorderBased::BorderID > &outdatedBorders, std::vector< adore::env::BorderBased::BorderID > &updatedBorders, int MAX_SEND_NUMBER=40)
Definition: map_border_management.h:272
#define LOG_T(...)
log on trace level
Definition: csvlog.h:28
#define LOG_W(...)
log on warning level
Definition: csvlog.h:46
#define LOG_E(...)
log on error level
Definition: csvlog.h:55
TYPE
This enum holds the different types of borders.
Definition: border.h:37
std::vector< Border * > BorderSubSet
Definition: borderset.h:92
std::vector< double > getCornerPoints(double x, double y, double r)
Get corner points vector from center point and radius.
Definition: map_auxiliary.h:34
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
y1
Definition: adore_set_pose.py:29
x1
Definition: adore_set_pose.py:28
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
The border struct contains data of the smallest.
Definition: border.h:62
Tborderpath * m_path
Definition: border.h:70
BorderType::TYPE m_type
Definition: border.h:71
bool typeIsChangeable()
Check whether type is Changeable.
Definition: border.h:278
This struct represents 3-dimensional coordines.
Definition: coordinate.h:34
double m_Y
Definition: coordinate.h:35
double m_X
Definition: coordinate.h:35
T1 first
Definition: borderset.h:47
Definition: map_border_management.h:27
std::vector< BorderBased::BorderType::TYPE > borderTypeProfile
Definition: map_border_management.h:30
BorderBased::Coordinate end
Definition: map_border_management.h:29
BorderBased::Coordinate start
Definition: map_border_management.h:28