CARLA
InformationSet.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/NonCopyable.h"
13 
14 #include <vector>
15 #include <memory>
16 
17 namespace carla {
18 namespace road {
19 
21  public:
22 
23  InformationSet() = default;
24 
25  InformationSet(std::vector<std::unique_ptr<element::RoadInfo>> &&vec)
26  : _road_set(std::move(vec)) {}
27 
28  /// Return all infos given a type from the start of the road
29  template <typename T>
30  std::vector<const T *> GetInfos() const {
31  std::vector<const T *> vec;
32  auto it = element::MakeRoadInfoIterator<T>(_road_set.GetAll());
33  for (; !it.IsAtEnd(); ++it) {
34  vec.emplace_back(&*it);
35  }
36  return vec;
37  }
38 
39  /// Returns single info given a type and a distance (s) from
40  /// the start of the road
41  template <typename T>
42  const T *GetInfo(const double s) const {
43  auto it = element::MakeRoadInfoIterator<T>(_road_set.GetReverseSubset(s));
44  return it.IsAtEnd() ? nullptr : &*it;
45  }
46 
47  /// Return all infos given a type in a given range of the road
48  template <typename T>
49  std::vector<const T *> GetInfos(const double min_s, const double max_s) const {
50  std::vector<const T *> vec;
51  if(min_s < max_s) {
52  auto it = element::MakeRoadInfoIterator<T>(
53  _road_set.GetSubsetInRange(min_s, max_s)); //reverse
54  for (; !it.IsAtEnd(); ++it) {
55  vec.emplace_back(&*it);
56  }
57  } else {
58  auto it = element::MakeRoadInfoIterator<T>(
59  _road_set.GetReverseSubsetInRange(max_s, min_s)); //reverse
60  for (; !it.IsAtEnd(); ++it) {
61  vec.emplace_back(&*it);
62  }
63  }
64  return vec;
65  }
66 
67  private:
68 
70  };
71 
72 } // road
73 } // carla
RoadElementSet< std::unique_ptr< element::RoadInfo > > _road_set
std::vector< const T * > GetInfos(const double min_s, const double max_s) const
Return all infos given a type in a given range of the road.
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
A set of elements ordered by its position on the road.
const T * GetInfo(const double s) const
Returns single info given a type and a distance (s) from the start of the road.
Inherit (privately) to suppress copy construction and assignment.
std::vector< const T * > GetInfos() const
Return all infos given a type from the start of the road.
InformationSet(std::vector< std::unique_ptr< element::RoadInfo >> &&vec)