21 #include <unordered_map>
22 #include <unordered_set>
25 #include <boost/geometry.hpp>
26 #include <boost/geometry/geometries/point.hpp>
27 #include <boost/geometry/geometries/box.hpp>
28 #include <boost/geometry/index/rtree.hpp>
44 template<
typename T1,
typename T2>
60 template<
typename value_type,
typename Tfirst>
66 return boost::geometry::equals<Tfirst,Tfirst>(v1.first, v2.first) && v1.second == v2.second;
74 boost::geometry::index::quadratic<16>,
75 boost::geometry::index::indexable<idxCoordinate2Border>,
79 boost::geometry::index::quadratic<16>,
80 boost::geometry::index::indexable<idxRegion2Border>,
156 void rotate(
double psi,
double rot_x=0.0,
double rot_y=0.0)
159 for(
auto it=this->
getAllBorders(); it.first!=it.second; it.first++)
161 auto b =
new Border(*((it.first)->second));
162 b->rotateXY(psi,rot_x,rot_y);
163 newBorders.push_back(b);
166 for(
auto it=newBorders.begin(); it!=newBorders.end(); it++)
171 void translate(
double trans_x,
double trans_y,
double trans_z)
174 for(
auto it=this->
getAllBorders(); it.first!=it.second; it.first++)
176 auto b =
new Border(*((it.first)->second));
177 b->translate(trans_x,trans_y,trans_z);
178 newBorders.push_back(b);
181 for(
auto it=newBorders.begin(); it!=newBorders.end(); it++)
243 m_byRegion.remove(std::make_pair(it->second->getBoostBox(0),it->second));
244 m_byFirstCoord.remove(std::make_pair(it->second->m_id.m_first.getBoostPoint(),it->second));
245 m_byLastCoord.remove(std::make_pair(it->second->m_id.m_last.getBoostPoint(),it->second));
289 delete it.first->second;
311 solvedList.push_back(curID);
314 for(
auto b = targets.begin(); b!=targets.end(); b++)
316 if(curID == (*b)->m_id)
323 if(solvedList.size()>searchDepth)
325 solvedList.pop_back();
332 for(;succs.first!=succs.second;succs.first++)
334 auto border = succs.first->second;
336 if(border->typeIsChangeable() && border->isContinuousSuccessorOf(curBorder))
347 solvedList.pop_back();
407 it.
current()!=it.end();it.current()++)
415 hits.push_back(
right);
450 subset.push_back(it->second);
488 for(
int i=1;i<count;i++)
508 for(
int i=0;i<count;i++)
512 targetSet.push_back(
right);
539 for(
int i=1;i<count;i++)
552 subset_specific.push_back(it.current()->second);
555 return subset_specific;
580 X[0] = px; Y[0] = py;
581 X[1] = px + cpsi*(-b) - spsi*(-w2); Y[1] = py + spsi*(-b) + cpsi*(-w2);
582 X[2] = px + cpsi*(+a) - spsi*(-w2); Y[2] = py + spsi*(+a) + cpsi*(-w2);
583 X[3] = px + cpsi*(+a) - spsi*(+w2); Y[3] = py + spsi*(+a) + cpsi*(+w2);
584 X[4] = px + cpsi*(-b) - spsi*(+w2); Y[4] = py + spsi*(-b) + cpsi*(+w2);
595 for(
auto it = subset.begin();it!=subset.end();it++)
612 buffer.push_back(it.
current()->second);
614 for(
auto it2 = buffer.begin();it2!=buffer.end();it2++)
630 auto it =
m_byID.find(
id);
631 if (it ==
m_byID.end())
return 0;
694 return *(
right->m_path);
720 Border* candidate = it->second;
723 if( candidate!=base && candidate!=
left && candidate!=
right
726 && cleft!=base && cleft!=
right
790 if (candidate==0)
continue;
804 std::vector<BorderOverlap> resultset;
817 for(
auto it = baseset.begin(); it!=baseset.end(); it++ )
831 std::vector<BorderOverlap> resultset;
848 for(
int i=0;i<pred_depth;i++)
853 if(it.current()!=it.end())
855 b = it.current()->second;
856 itinset=(
set.find(b)!=
set.end());
858 split=(it.current()!=it.end());
861 Border* other = it.current()->second;
887 std::vector<Border*>& result,
int pred_depth)
889 std::unordered_set<Border*> visited;
890 std::unordered_set<Border*> exclude;
891 for(
auto it=search_area.begin();it!=search_area.end();it++)
895 exclude.emplace(
right);
898 for(
auto it=search_area.begin();it!=search_area.end();it++)
903 box.min_corner().set<2>(-
m_guard);
904 box.max_corner().set<2>(
m_guard);
906 for(
auto it2 =
m_byRegion.qbegin(boost::geometry::index::intersects(box));
910 auto candidate = it2->second;
912 if(visited.find(candidate)==visited.end() && exclude.find(candidate)==exclude.end())
914 visited.emplace(candidate);
917 if(!
right->isNeighborOf(candidate))
919 result.push_back(candidate);
923 if(candidate_right!=0 && visited.find(candidate_right)==visited.end() )
925 visited.emplace(candidate_right);
926 if( !
right->isNeighborOf(candidate_right)
927 && exclude.find(candidate_right)==exclude.end()
930 result.push_back(candidate_right);
951 int r = std::floor(((
double)(std::rand())/((
double)RAND_MAX)) * ((
double)
m_byID.size()));
954 if(
r==0)
return it.first->second;
968 auto it =
m_byID.find(
id);
969 if (it ==
m_byID.end())
return false;
983 if (it ==
m_byID.end() || it->second->m_type != b->
m_type)
1043 if (b == 0 || potentialPredecessor == 0){
return false;}
1071 if (b == 0 || potentialSuccessor == 0){
return false;}
1099 if (includeStartBorder) result.push_back(b);
1101 double borderLength;
1102 for (
auto it = itp.first; it != itp.second; ++it)
1105 if (b==it->second){
continue;}
1106 if(std::find(result.begin(),result.end(),it->second)!=result.end()){
continue;}
1108 borderLength = it->second->getLength();
1109 if (borderLength < distance)
1113 result.push_back(it->second);
1128 if (includeStartBorder) result.push_back(b);
1130 double borderLength;
1131 for (
auto it = itp.first; it != itp.second; ++it)
1135 borderLength = it->second->getLength();
1136 if (borderLength < distance)
1140 result.push_back(it->second);
1154 Border* start,
Border* end, std::vector<env::BorderBased::Border*>* allowedBorders,
1155 std::vector<double>& distances)
1158 double currentDistance = distances.empty() ? 0.0 : distances.back();
1163 std::vector<env::BorderBased::Border*> newStartBorders;
1164 for (
auto it = allowedBorders->begin(); it != allowedBorders->end();)
1168 newStartBorders.push_back(*it);
1169 it = allowedBorders->erase(it);
1176 if (newStartBorders.empty())
1179 if (!distances.empty())
1181 distances.pop_back();
1186 bool first_successor =
true;
1187 for (
auto it = newStartBorders.begin(); it != newStartBorders.end(); ++it)
1189 if (first_successor && !distances.empty())
1191 distances.back() += (*it)->getLength();
1195 distances.push_back(currentDistance + (*it)->getLength());
1197 first_successor =
false;
1254 if (b->
m_left == 0)
return 0;
1256 if (it ==
m_byID.end())
return 0;
1269 if (b->
m_left == 0)
return false;
1313 while(leftNeighbor!=0 && leftNeighbor->typeIsChangeable())
1315 leftmost = leftNeighbor;
1319 value.push_back(leftmost);
1321 while(rightNeighbor!=0 && rightNeighbor->typeIsChangeable())
1323 value.push_back(rightNeighbor);
1338 std::pair<Border*,Border*> target;
1339 target.first=
nullptr;
1340 target.second=
nullptr;
1344 if(target.second==
nullptr)
1349 if(target.first==
nullptr)
1351 target.second =
nullptr;
1358 if(target.second==
nullptr)
return target;
1359 target.first = current_right;
1362 if(target.first->m_id==target.second->m_id
1363 || target.first->m_id==target.second->m_id.getReverseDirectionID())
1366 target.first=
nullptr;
1367 target.second=
nullptr;
1414 if(it.first==it.second)
1420 border = it.first->second;
1422 if(it.first!=it.second)
1433 if(it.first==it.second)
1439 border = it.first->second;
1441 if(it.first!=it.second)
1521 for(
auto it =
getAllBorders(); it.first!=it.second; it.first++)
efficiently store borders in boost R-tree
Definition: borderset.h:99
void removeBorders(const BorderSubSet &subset)
remove all borders in the given set
Definition: borderset.h:593
void removeBorders(itRegion2Border it)
remove all borders in a set described by a region iterator
Definition: borderset.h:606
void clear()
remove all borders from this, delete object if this is owner
Definition: borderset.h:284
bool isPredecessor(Border *b, Border *potentialPredecessor, bool checkForLeftNeighbor=false)
check whether potentialPredecessor is a predecessor of b
Definition: borderset.h:1041
void rotate(double psi, double rot_x=0.0, double rot_y=0.0)
Definition: borderset.h:156
BorderID2Border m_byID
Definition: borderset.h:109
void getOverlappingBorderCandidates(const std::vector< Border * > &search_area, std::vector< Border * > &result, int pred_depth)
efficient pre-search to determine candidates for border overlap
Definition: borderset.h:886
itCoordinate2Border getSplitNeighbors(Border *b)
returns an iterator pair to all borders, which split at the beginning of b (in this list,...
Definition: borderset.h:1210
Region2BordersRT m_byRegion
Definition: borderset.h:113
adore::mad::LLinearPiecewiseFunctionM< double, 4 > getCenterline(const BorderID &id)
get the linear piecewise description of the centerline:
Definition: borderset.h:647
itRegion2Border getBordersInRegion(double x, double y, double r)
get all borders in this within radius around center point
Definition: borderset.h:385
BorderSubSet getBordersAtPoint(double x, double y, double max_lane_width)
get all borders at the given point
Definition: borderset.h:403
bool addAllowedType(BorderType::TYPE type)
add border type to list of allowed border types
Definition: borderset.h:149
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
void removeAllowedType(BorderType::TYPE type)
remove border type from allowed border types
Definition: borderset.h:192
bool hasAllPredecessorsInSet(Border *border, const std::unordered_set< Border * > &set, int pred_depth)
check whether all predecessors up to a certain number exist within the set
Definition: borderset.h:845
Border * getRightNeighbor(Border *b)
get the right neighbor of a border
Definition: borderset.h:1279
itCoordinate2Border getSuccessors(Border *b)
get an interator pair for all borders which follow after b
Definition: borderset.h:996
bool hasRightNeighbor(Border *b)
checks whether right neighbor exists for a border
Definition: borderset.h:1292
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
void matchLanesInRegion(double *x, double *y, int count, BorderSubSet &targetSet)
get a vector of borders, which describe lanes that match the specified region
Definition: borderset.h:481
BorderIteratorPair2 getAllBorders()
get all borders in this
Definition: borderset.h:356
BorderSubSet getBordersAtPoint(double x, double y)
overload for getBordersAtPoint
Definition: borderset.h:429
Border * getBorder(const BorderID &id) const
retrieve a border by ID
Definition: borderset.h:628
double m_guard
Definition: borderset.h:105
void getDistancesBetweenBordersAlongSuccessors(Border *start, Border *end, std::vector< env::BorderBased::Border * > *allowedBorders, std::vector< double > &distances)
Get distances of all paths that are possible with a given subset of allowed borders between two borde...
Definition: borderset.h:1153
void getAllSuccessorsUpToDistance(Border *b, double distance, std::vector< Border * > &result, bool checkLeftNeighbor=true, bool includeStartBorder=false)
adds all successors existant in BorderSet for a given Border to the vector of borders
Definition: borderset.h:1126
adore::mad::LLinearPiecewiseFunctionM< double, 3 > getCenterlineWithOffset(const BorderID &id, double offset)
gets centerline between border and left neighbor
Definition: borderset.h:681
std::pair< Border *, Border * > getLaneChangeTarget(Border *current_right, bool direction_left)
computes a pair of borders (left,right) suitable for lane-changing from given source lane
Definition: borderset.h:1336
itCoordinate2Border getMergeNeighbors(Border *b)
returns an iterator pair to all borders which merge at the end of b (the list contains b itself)
Definition: borderset.h:1231
std::vector< BorderOverlap > getOverlappingBorders(const std::vector< Border * > &baseset)
retrieves all borders that overlap from the set
Definition: borderset.h:829
bool hasBorder(const BorderID &id) const
check whether a border exists in the set
Definition: borderset.h:966
void getAllPredecessorsUpToDistance(Border *b, double distance, std::vector< Border * > &result, bool checkLeftNeighbor=true, bool includeStartBorder=false)
adds all predecessors existant in BorderSet for a given Border to the vector of borders
Definition: borderset.h:1097
std::vector< BorderOverlap > getOverlappingBorders(Border *base)
retrieves borders that overlap with given border
Definition: borderset.h:802
Border * getRandomBorder()
retrieve a random border from the set
Definition: borderset.h:945
Border * getLeftNeighbor(Border *b)
Get left neighbor of a border.
Definition: borderset.h:1252
void erase_border(const BorderID &oldID)
erase border from this
Definition: borderset.h:269
bool isConnected(const BorderID &a, const BorderID &b)
check whether end of border a is beginning of border b
Definition: borderset.h:1381
Coordinate2BordersRT m_byLastCoord
Definition: borderset.h:112
BorderID2Border m_byLeftID
Definition: borderset.h:110
bool m_isOwner
define whether this Borderset is owner of the borders / manages memory
Definition: borderset.h:116
double m_coord_uncertainty_xy
Definition: borderset.h:103
virtual ~BorderSet()
Destroy the Border Set object.
Definition: borderset.h:136
double m_max_lane_width
Definition: borderset.h:106
void matchLanesInRegion(double px, double py, double psi, double a, double b, double w, BorderSubSet &targetSet)
get a vector of borders, which describe lanes that match the specified region
Definition: borderset.h:572
std::set< BorderType::TYPE > m_allowedBorderTypes
Definition: borderset.h:100
void getOverlappingBorders(Border *base, std::vector< BorderOverlap > &resultset)
computes the set of borders, which overlap with base and are thus potential points of conflict
Definition: borderset.h:710
int size()
number of borders in this
Definition: borderset.h:1497
bool hasLeftNeighbor(Border *b)
checks whether left border exists for a border
Definition: borderset.h:1267
bool isSimilar(const Coordinate &a, const Coordinate &b)
checks whether two coordinates are similar based on certainties of this
Definition: borderset.h:1394
void getOverlappingBorders(const std::vector< Border * > &baseset, std::vector< BorderOverlap > &resultset)
retrieves all borders that overlap with the base set
Definition: borderset.h:815
bool isSuccessor(Border *b, Border *potentialSuccessor, bool checkForLeftNeighbor=false)
check whether potentialSuccessor is a successor of b
Definition: borderset.h:1069
void setIsOwner(bool isOwner)
set whether this owns objects in pointers
Definition: borderset.h:214
double m_coord_uncertainty_z
Definition: borderset.h:104
itCoordinate2Border getPredecessors(Border *b)
get an interator pair for all borders which lead to b
Definition: borderset.h:1017
BorderSet()
Construct a new Border Set object.
Definition: borderset.h:123
longitudinal_iterator_creator move_along_border(Border *b)
get borders along given border
Definition: borderset.h:1490
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 ©)
generate a complete copy including copies of objects the pointers point to
Definition: borderset.h:1507
void translate(double trans_x, double trans_y, double trans_z)
Definition: borderset.h:171
bool hasBorder(const Border *b) const
checks whether border with given ID and type exists in the set
Definition: borderset.h:980
BorderSubSet matchBordersInRegion(double *x, double *y, int count)
find all borders that (even without a left neighbor) within the specified area.
Definition: borderset.h:532
Coordinate2BordersRT m_byFirstCoord
Definition: borderset.h:111
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
bool borderTypeValid(Border *b)
check whether border type is in allowed types of set
Definition: borderset.h:204
itRegion2Border getBordersOutsideRegion(double x0, double x1, double y0, double y1)
get all borders outside of region as iterator pair
Definition: borderset.h:464
TYPE
This enum holds the different types of borders.
Definition: border.h:37
@ DRIVING
Definition: border.h:39
std::list< Border * >::iterator BorderIterator
Definition: borderset.h:86
itpair< Region2BordersRT::const_query_iterator, Region2BordersRT::const_query_iterator > itRegion2Border
Definition: borderset.h:90
std::unordered_map< BorderID, Border *, BorderIDHasher > BorderID2Border
Definition: borderset.h:85
std::vector< Border * > BorderSubSet
Definition: borderset.h:92
std::pair< Coordinate::boost_point, Border * > idxCoordinate2Border
Definition: borderset.h:70
boost::geometry::index::rtree< idxCoordinate2Border, boost::geometry::index::quadratic< 16 >, boost::geometry::index::indexable< idxCoordinate2Border >, my_equal< idxCoordinate2Border, Coordinate::boost_point > > Coordinate2BordersRT
Definition: borderset.h:77
std::pair< BorderIterator, BorderIterator > BorderIteratorPair
Definition: borderset.h:87
std::pair< Border::boost_box, Border * > idxRegion2Border
Definition: borderset.h:71
boost::geometry::index::rtree< idxRegion2Border, boost::geometry::index::quadratic< 16 >, boost::geometry::index::indexable< idxRegion2Border >, my_equal< idxRegion2Border, Border::boost_box > > Region2BordersRT
Definition: borderset.h:82
std::unordered_map< Coordinate, std::list< Border * > *, CoordinateHasher > Coordinate2Borders
Definition: borderset.h:84
std::pair< BorderID2Border::iterator, BorderID2Border::iterator > BorderIteratorPair2
Definition: borderset.h:88
itpair< Coordinate2BordersRT::const_query_iterator, Coordinate2BordersRT::const_query_iterator > itCoordinate2Border
Definition: borderset.h:89
@ right
Definition: indicator_hint.h:36
@ left
Definition: indicator_hint.h:35
interval< T > cos(interval< T > x)
Definition: intervalarithmetic.h:225
int computeLaneWidthAndCenter(const adoreMatrix< double, 0, 0 > &left, const adoreMatrix< double, 0, 0 > &right, adoreMatrix< double, 0, 0 > ¢er)
Definition: centerandlanewidth.h:33
T min(T a, T b, T c, T d)
Definition: adoremath.h:663
void set(T *data, T value, int size)
Definition: adoremath.h:39
interval< T > sin(interval< T > x)
Definition: intervalarithmetic.h:204
int computeCenterline(const adoreMatrix< double, 0, 0 > &left, const adoreMatrix< double, 0, 0 > &right, adoreMatrix< double, 0, 0 > ¢er)
Definition: centerline.h:29
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
z0
Definition: adore_set_goal.py:27
y
Definition: adore_set_goal.py:31
y1
Definition: adore_set_pose.py:29
x1
Definition: adore_set_pose.py:28
z1
Definition: adore_set_pose.py:30
w
Definition: adore_set_pose.py:40
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
Definition: borderoverlap.h:32
bool hasAnyOverlap()
Check for any overlap.
Definition: borderoverlap.h:85
Definition: borderset.h:1476
longitudinal_iterator_creator(BorderSet *obs, Border *border)
Definition: borderset.h:1481
Border * m_border
Definition: borderset.h:1478
longitudinal_iterator end()
Definition: borderset.h:1480
longitudinal_iterator begin()
Definition: borderset.h:1479
BorderSet * m_set
Definition: borderset.h:1477
an iterator, which walks along borders, while there is exactly one successor (forward) or predecessor...
Definition: borderset.h:1406
longitudinal_iterator & operator--()
Definition: borderset.h:1430
longitudinal_iterator & operator++()
Definition: borderset.h:1411
Border * border
Definition: borderset.h:1408
BorderSet * m_set
Definition: borderset.h:1407
longitudinal_iterator & earliest()
Definition: borderset.h:1461
longitudinal_iterator & latest()
Definition: borderset.h:1449
longitudinal_iterator(BorderSet *set, Border *b)
Definition: borderset.h:1409
bool operator==(const longitudinal_iterator &other)
Definition: borderset.h:1410
The border struct contains data of the smallest.
Definition: border.h:62
bool isSplitNeighborOf(Border *other)
Check whether the border and its left neighbor start at the same point as the potential split neighbo...
Definition: border.h:401
bool isContinuousPredecessorOf(Border *other)
Check whether the border is a continuous predecessor of another border.
Definition: border.h:363
boost_box getBoostBox(Border *leftNeighbor)
Get a bounding box for the implicit lane object.
Definition: border.h:603
double getLength()
Get the length of the border.
Definition: border.h:703
BorderType::TYPE m_type
Definition: border.h:71
BorderID m_id
Definition: border.h:68
bool typeIsChangeable()
Check whether type is Changeable.
Definition: border.h:278
bool isContinuousSuccessorOf(Border *parent)
Check whether the border is a continuous successor of another border.
Definition: border.h:348
boost::geometry::model::box< Coordinate::boost_point > boost_box
bounding box
Definition: border.h:66
BorderID * m_left
Definition: border.h:69
bool isNeighborOf(Border *other)
Check whether the border is a neighbor of another border.
Definition: border.h:475
a functor, which hashes a Coordinate object -> std::unordered_set<Coordinate,CoordinateHasher> amap(0...
Definition: coordinate.h:281
This struct represents 3-dimensional coordines.
Definition: coordinate.h:34
double m_Y
Definition: coordinate.h:35
double m_Z
Definition: coordinate.h:35
double m_X
Definition: coordinate.h:35
boost::geometry::model::point< double, 3, boost::geometry::cs::cartesian > boost_point
Definition: coordinate.h:36
boost_point getBoostPoint()
Get a boost_point that has the same coordinates as the Coordinate object.
Definition: coordinate.h:202
pair of iterators to iterate from first iterator till second iterator is reached
Definition: borderset.h:46
T1 & current()
Definition: borderset.h:50
T1 first
Definition: borderset.h:47
T2 & end()
Definition: borderset.h:51
itpair(T1 first, T2 second)
Definition: borderset.h:49
T2 second
Definition: borderset.h:48
custom equal test for iterators
Definition: borderset.h:62
result_type operator()(value_type const &v1, value_type const &v2) const
Definition: borderset.h:64
bool result_type
Definition: borderset.h:63