Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
IndexedDistanceMap.hpp
Go to the documentation of this file.
1#pragma once
2
3/*
4 * Copyright (C) 2022 LEIDOS.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18
19#include <vector>
20#include <tuple>
21#include <utility>
22#include <lanelet2_core/primitives/LineString.h>
23#include <lanelet2_core/geometry/Point.h>
24#include <unordered_map>
25#include <math.h>
26
27namespace carma_wm
28{
43{
44private:
45 // Distance storage structure
46 // A vector of tuples where the first vector is indexed by line segment and the second vector is index by point index
47 // on that line segment. The double value in the tuple stores the total along-line distance to the start of that line
48 // segment from the first point on the first line segment The double value inside the interior vector store the
49 // along-line distance of the point from the start of its line segment
50 std::vector<std::tuple<std::vector<double>, double>> accum_lengths;
51
52 // Id mapping structure
53 // Sores the linestring and point index's as values with their lanelet Ids as the key
54 std::unordered_map<lanelet::Id, std::pair<size_t, size_t>> id_index_map;
55
56public:
65 void pushBack(const lanelet::LineString2d& ls);
66
76 double elementLength(size_t index) const;
77
87 double distanceToElement(size_t index) const;
88
100 double distanceBetween(size_t index, size_t p1_index, size_t p2_index) const;
101
112 double distanceToPointAlongElement(size_t index, size_t point_index) const;
113
119 double totalLength() const;
120
131 std::pair<size_t, size_t> getIndexFromId(const lanelet::Id& id) const;
132
138 size_t size() const;
139
145 size_t size(size_t index) const;
146
162 std::pair<size_t, size_t> getElementIndexByDistance(double distance, bool get_point=true) const;
163};
164} //namespace carma_wm
O(1) distance lookup structure for quickly accessing route distance information. NOTE: This structure...
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.