25 throw std::invalid_argument(
"IndexedDistanceMap already contains this ls");
27 std::vector<double> accumulated_dist;
28 accumulated_dist.reserve(ls.size());
29 accumulated_dist.push_back(0);
32 for (
size_t i = 0;
i < ls.numSegments();
i++)
34 auto segment = ls.segment(
i);
35 double dist = lanelet::geometry::distance2d(segment.first, segment.second);
36 accumulated_dist.push_back(dist + accumulated_dist.back());
37 id_index_map[segment.second.id()] = std::make_pair(ls_i,
i + 1);
39 auto tuple = std::make_tuple(accumulated_dist,
totalLength());
46 throw std::invalid_argument(
"Distance must non-negative: " +
std::to_string(distance));
49 throw std::invalid_argument(
"Distance cannot be greater than distance map length");
52 throw std::invalid_argument(
"No data available in distance map");
56 [](
const std::tuple<std::vector<double>,
double>& a,
const double& b){return std::get<1>(a) < b;});
62 ls_index = std::max(low -
accum_lengths.begin() - 1, (
long int)0);
66 return std::make_pair(ls_index, (
size_t) 0);
71 double relative_dist = distance - dist_to_ls;
73 auto low_point = std::lower_bound (std::get<0>(
accum_lengths[ls_index]).begin(), std::get<0>(
accum_lengths[ls_index]).end(), relative_dist,
74 [](
const double& a,
const double& b){
return a < b; });
76 size_t point_idx = std::max(low_point - std::get<0>(
accum_lengths[ls_index]).begin() - 1, (
long int)0);
77 return std::make_pair(ls_index, point_idx);
std::pair< size_t, size_t > getIndexFromId(const lanelet::Id &id) const
Returns the indexes of the element identified by the provided Id NOTE: It is up to the user to know i...
std::unordered_map< lanelet::Id, std::pair< size_t, size_t > > id_index_map
void pushBack(const lanelet::LineString2d &ls)
Add a linestring to this structure. This function will iterate over the line string to compute distan...
double elementLength(size_t index) const
Get the length of the linestring located at the provided index.
std::vector< std::tuple< std::vector< double >, double > > accum_lengths
std::pair< size_t, size_t > getElementIndexByDistance(double distance, bool get_point=true) const
Returns index of the linestring which the provided distance is within. NOTE: Unlike the rest of this ...
double distanceToPointAlongElement(size_t index, size_t point_index) const
Get the along-line distance to the point on the provided linestring.
double totalLength() const
Returns the total along-line length of this structure.
double distanceToElement(size_t index) const
Get the distance to the start of the linestring at the specified index.
size_t size() const
Returns number of linestrings in this structure.
double distanceBetween(size_t index, size_t p1_index, size_t p2_index) const
Get the distance between two points on the same linestring.
auto to_string(const UtmZone &zone) -> std::string