19.0.0
Description
Important
Right before merging this PR, please change the target branch of #1479 and #1731 to master.
Otherwise those PRs (which are next in line to be merged) will be closed automatically.
Abstract
This PR is a continuation of HdMapUtils refactoring.
For a full overview of changes that all 6 PRs will introduce, please see the Abstract of the first PR.
Generally member functions of HdMapUtils class have been moved to be free functions in traffic_simulator::lanelet_wrapper::distance and traffic_simulator::distance namespaces.
This required some helper functions to be moved from HdMapUtils to appropriate namespaces like for map handling to traffic_simulator::lanelet_wrapper::lanelet_map or traffic_simulator::lanelet_map
For exact details of what this PR introduces see the Details below.
Details
Here all changes in code are explained.
They aim to achieve the goal defined in Abstract.
As refactoring that moves the functions from one file to another can be hard to track on GitHub the list of changes to each function from this PR has been prepared below.
Global changes
Generally in the modified parts of the code some minor improvements were implemented like usage of const & when applicable.
Other changes like removal of unnecessary allocations have been explained below in details.
ActionNode::getOtherEntityStatus
The ActionNode::getOtherEntityStatus was replaced by ActionNode::getOtherEntitiesCanonicalizedLaneletPoses.
First returned entites in the lanelet, second returns canonicalized lanalet poses of all entites.
The change was done so that refactoring of ActionNode::getYieldStopDistance can be achieved.
ActionNode::getYieldStopDistance
Some part of implementation for calculating actual distance between entity and right of way lanelet has been moved to new function traffic_simulator::distance::distanceToYieldStop.
utils distance::distanceToYieldStop
A part of ActionNode::getYieldStopDistance that has been slightly modified.
Instead of getOtherEntityStatus it uses getPosesOnLanelet lambda which instead of filtering entity statuses filters entity positions. These are only needed to determine whether the lanelet is occupied.
Additionally an optimization was added to store only nearest distance instead of all distances when only smallest is returned.
HdMapUtils::getDistanceToTrafficLightStopLine (x4)
4 overloads of HdMapUtils::getDistanceToTrafficLightStopLine have meen moved to lanelet_wrapper::distance::distanceToTrafficLightStopLine.
They are generally the same, but code repetition was removed.
In overloads with waypoints argument which created a spline from the waypoints and performed the same logic as spline overload -- the spline is constructed and spline overload is just called.
Additionally an optimization was added to store only nearest distance instead of all distances when only smallest is returned.
utils distance::distanceToCrosswalk
distance::distanceToCrosswalk implementation has been moved to lanelet_wrapper. In utils there is only a forwarding.
In lanelet_wrapper the function has been divided into two functions where one is an overload for more flexibility.
One additional change is an explicit search_in_backward_direction argumenthas been added to not depend on default values.
Note: Utilizes newly added lanelet_wrapper::lanelet_map::laneletPolygon.
lanelet_wrapper::lanelet_map::laneletIds
Modified to allocate memory once, because we know how many elements there will be.
lanelet_wrapper::lanenet_map::nextLaneletIDs
Modified to allocate memory once, because we know how many elements there will be.
lanelet_wrapper::lanelet_map::laneletPolygon
Copied from HdMapUtils::getLaneletPolygon to use in distance::distanceToCrosswalk.
lanelet_wrapper::lanelet_map::rightOfWayLaneletIds
Copied from HdMapUtils::getRightOfWayLaneletIds.
utils distance::longitudinalDistance
Stores only smallest value rather than all when only smallest is returned.
Caution
The description below is left as a preservation of what this PR once was introducing.
This may be relevant or helpful at some point, so it is intentionally not deleted.
The PR was made smaller by extracting its parts into a new small PRs, but this PR was a base for them and the below description is the overwiev of all changes it originally introduced (before extracting contents into smaller PRs).
Description
Important
Right before merging this PR, please change the target branch of #1479 to master.
Otherwise that PR (which is next in line to be merged) will be closed automatically.
Abstract
This is the second PR of 6 related to the HdMapUtils refactor (for the first one, see #1472).
For a full overview of changes that all 6 PRs will introduce, please see the Abstract of the first PR.
Background
The lanelet_wrapper namespace contains:
LaneletLoaderLaneletWrapperRouteCache,CenterPointsCache,LaneletLengthCacheTrafficRulesWithRoutingGraph- 6 category-specific sub-namespaces
These static methods are used by the sub-namespaces of lanelet_wrapper.
lanelet_wrapper namespace consist of 6 sub-namespaces:
lanelet_wrapper::lanelet_map,lanelet_wrapper::pose,lanelet_wrapper::distance,lanelet_wrapper::route,lanelet_wrapper::lane_change,lanelet_wrapper::traffic_lights.
As a result of the merge of this PR 2/6, the namespaces lanelet_wrapper::lanelet_map, lanelet_wrapper::distance, lanelet_wrapper::route and lanelet_wrapper::traffic_lights were added to the project. But most importantly, the ::distance from utils is adapted for its use.
In addition to this, PR is making several other improvements to the code, see below for details.
Details
The distance namespace in lanelet_wrapper and only the strictly necessary parts of route and traffic_lights are developed.
Important
By moving from HdMapUtils, we mean moving the entire member function to lanelet_wrapper - making it a free function.
This is accessible to traffic_simulator through free functions in utils namespace.
Before these changes the structure looked like this:
<HdMapUtils member function name>
After the changes structure looks like this:
<utils namespace and function name> → <lanelet_wrapper namespace and function name>
Below is the list of moved function (member functions transformed to free functions)
Tip
Most functions that have been removed from HdMapUtils have been renamed in such a way that the get prefix has been removed and thus the first letter of the new function name has been made lower case.
Example of such name change can be the following
HdMapUtils::getLateralDistance → lanelet_wrapper::distance::lateralDistance
| Old name | New name |
|---|---|
HdMapUtils::getLateralDistance |
distance::lateralDistance → lanelet_wrapper::distance::lateralDistance |
HdMapUtils::getLongitudinalDistance |
distance::longitudinalDistance → lanelet_wrapper::distance::longitudinalDistance |
HdMapUtils::getDistanceToStopLine |
distance::distanceToStopLine → lanelet_wrapper::distance::distanceToStopLine |
HdMapUtils::getDistanceToTrafficLightStopLine |
distance::distanceToTrafficLightStopLine → lanelet_wrapper::distance::distanceToTrafficLightStopLine |
HdMapUtils::getDistanceToCrosswalk |
distance::distanceToCrosswalk → lanelet_wrapper::distance::distanceToCrosswalk |
HdMapUtils::getLeftBound |
lanelet_wrapper::lanelet_map::leftBound |
HdMapUtils::getRightBound |
lanelet_wrapper::lanelet_map::rightBound |
HdMapUtils::getLaneletPolygon |
lanelet_wrapper::lanelet_map::laneletPolygon |
HdMapUtils::getStopLinePolygon |
lanelet_wrapper::lanelet_map::stopLinePolygon |
HdMapUtils::toPolygon |
lanelet_wrapper::lanelet_map::toPolygon |
HdMapUtils::getRightOfWayLaneletIds |
lanelet_wrapper::lanelet_map::rightOfWayLaneletIds |
HdMapUtils::getTrafficSignRegulatoryElementsOnPath |
lanelet_wrapper::lanelet_map::trafficSignsOnPath |
HdMapUtils::getStopLinesOnPath |
lanelet_wrapper::lanelet_map::stopLinesOnPath |
HdMapUtils::getStopLineIdsOnPath |
lanelet_wrapper::lanelet_map::stopLineIdsOnPath |
HdMapUtils::getRoute |
route::route → lanelet_wrapper::route::route |
HdMapUtils::getTrafficLightStopLinesPoints |
lanelet_wrapper::traffic_lights::trafficLightStopLinesPoints |
HdMapUtils::getTrafficLightIdsOnPath |
lanelet_wrapper::traffic_lights::trafficLightStopLinesPoints |
HdMapUtils::getTrafficLights |
lanelet_wrapper::traffic_lights::toAutowareTrafficLights |
HdMapUtils::getTrafficLightRegulatoryElementsOnPath |
lanelet_wrapper::traffic_lights::autowareTrafficLightsOnPath |
Additionally, distance::distanceToYieldStop function has been separated from ActionNode::getYieldStopDistance in order to improve readability and to maintain the division of functionality.
Note
Some of the functions copied from HdMapUtils class have been slightly modified. The modifications are small improvements of things like removing storing of unnecessary values.
One such change is in function distanceToStopLine where instead of adding all values to std::set and in the end using the first one, only the smallest value is stored.
Before:
https://github.com/tier4/scenario_simulator_v2/blob/5140e05d3130900184030a59ff959fb98740ded0/simulation/traffic_simulator/src/hdmap_utils/hdmap_utils.cpp#L1504-L1511
After:
https://github.com/tier4/scenario_simulator_v2/blob/1d2453b2ba159f8668c514a36499e9665fcb645c/simulation/traffic_simulator/src/lanelet_wrapper/distance.cpp#L149-L155
Copyright
It has been notices that in some files the copyright date is wrong (other than 2015), thus the date has been fixed both in files added or modified by this PR and any other files where the incorrect copyright date has been noticed.