LaneletSequence.h
Go to the documentation of this file.
1 #pragma once
2 #include <utility>
3 
7 
8 namespace lanelet {
9 
22 class LaneletSequenceData : public boost::noncopyable {
23  public:
24  using iterator = // NOLINT
31 
32  const CompoundLineString3d& leftBound() const { return leftBound3d(); }
33  const CompoundLineString3d& leftBound3d() const { return leftBound_; }
35 
36  const CompoundLineString3d& rightBound() const { return rightBound3d(); }
37  const CompoundLineString3d& rightBound3d() const { return rightBound_; }
39  const ConstLanelets& lanelets() const { return lanelets_; }
40 
47 
53  CompoundPolygon3d polygon() const;
54 
55  iterator begin(bool inverted) const noexcept {
56  return inverted ? iterator(lanelets_.rbegin()) : iterator(lanelets_.begin());
57  }
58 
59  iterator end(bool inverted) const noexcept {
60  return inverted ? iterator(lanelets_.rend()) : iterator(lanelets_.end());
61  }
62 
63  private:
64  const ConstLanelets lanelets_; // NOLINT
68  mutable std::shared_ptr<CompoundLineString3d> centerline_;
69  mutable std::shared_ptr<CompoundPolygon3d> polygon_;
70 };
71 
86  public:
88  using TwoDType = void;
89  using ThreeDType = void;
90  using HybridType = void;
92  using MutableType = void;
94 
101  : data_{std::make_shared<LaneletSequenceData>(std::move(ls))} {}
102 
107  explicit LaneletSequence(const LaneletSequences& ls)
108  : LaneletSequence(utils::concatenate(ls, [](const auto& e) { return e.lanelets(); })) {}
109 
110  LaneletSequence(LaneletSequenceDataConstPtr data, bool inverted) : data_{std::move(data)}, inverted_{inverted} {}
111 
120  bool inverted() const { return inverted_; }
121 
123  bool empty() const noexcept { return data_->lanelets().empty(); }
124 
126  size_t size() const noexcept { return data_->lanelets().size(); }
127 
134  LaneletSequence invert() const { return {constData(), !inverted()}; }
135 
141  return inverted() ? constData()->rightBound().invert() : constData()->leftBound();
142  }
143 
150  return inverted() ? constData()->leftBound().invert() : constData()->rightBound();
151  }
152 
154  RegulatoryElementConstPtrs regulatoryElements() const;
155 
160  template <typename RegElemT>
161  std::vector<std::shared_ptr<const RegElemT>> regulatoryElementsAs() const {
162  return utils::concatenate(lanelets(),
163  [](const auto& elem) { return elem.template regulatoryElementsAs<RegElemT>(); });
164  }
165 
180  CompoundLineString3d centerline() const { return centerline3d(); }
182  return inverted() ? constData()->centerline().invert() : constData()->centerline();
183  }
184  CompoundLineString2d centerline2d() const { return utils::to2D(centerline3d()); }
185 
194  CompoundPolygon3d polygon3d() const { return constData()->polygon(); }
195 
200  CompoundPolygon2d polygon2d() const { return CompoundPolygon2d(polygon3d()); }
201 
206  ConstLanelets lanelets() const { return inverted() ? utils::invert(data_->lanelets()) : data_->lanelets(); }
207 
209  iterator begin() const noexcept { return data_->begin(inverted()); }
210 
212  iterator end() const noexcept { return data_->end(inverted()); }
213 
215  const ConstLanelet& operator[](size_t idx) const {
216  assert(idx < data_->lanelets().size());
217  return *std::next(begin(), idx);
218  }
219 
224  Ids ids() const {
225  return utils::transform(lanelets(), [](const auto& ls) { return ls.id(); });
226  }
227 
231  LaneletSequenceDataConstPtr constData() const { return data_; }
232 
238  void resetCache() { data_ = std::make_shared<LaneletSequenceData>(data_->lanelets()); }
239 
240  private:
241  std::shared_ptr<const LaneletSequenceData> data_;
242  bool inverted_{false};
243 };
244 
245 namespace utils {
256 inline bool has(const LaneletSequence& ll, Id id) { return has(ll.leftBound(), id) || has(ll.rightBound(), id); }
257 } // namespace utils
258 
259 inline bool operator==(const LaneletSequence& lhs, const LaneletSequence& rhs) {
260  return lhs.lanelets() == rhs.lanelets();
261 }
262 inline bool operator!=(const LaneletSequence& lhs, const LaneletSequence& rhs) { return !(rhs == lhs); }
263 
264 inline std::ostream& operator<<(std::ostream& stream, const LaneletSequence& obj) {
265  auto ids = obj.ids();
266  stream << "[";
267  if (!ids.empty()) {
268  stream << "ids: ";
269  std::copy(ids.begin(), ids.end(), std::ostream_iterator<Id>(stream, " "));
270  }
271  if (obj.inverted()) {
272  stream << ", inverted";
273  }
274  return stream << "]";
275 }
276 } // namespace lanelet
iterator begin() const noexcept
Returns iterator to the first lanelet (or to the last, if inverted)
CompoundPolygon3d polygon() const
Get the bounding polygon around all lanelets. Result is cached.
const CompoundLineString3d & leftBound() const
LaneletSequenceData(ConstLanelets lanelets)
Constructs a new, valid LaneletData object.
CompoundLineString3d centerline3d() const
std::shared_ptr< const LaneletSequenceData > LaneletSequenceDataConstPtr
Definition: Forward.h:94
void resetCache()
call this function if one of the contained Lanelets was modified to give this object the opportunity ...
Ids ids() const
returns the ids of all lanelets in order
A Compound linestring in 3d (returns Point3d)
CompoundLineString2d rightBound2d() const
get the right bound in 2d. To be used over rightBound where geometric calculations are required...
bool empty() const noexcept
Returns wether this holds any lanelets.
int64_t Id
Definition: Forward.h:198
auto transform(Iterator begin, Iterator end, const Func f)
Definition: Utilities.h:176
std::ostream & operator<<(std::ostream &stream, const Attribute &obj)
Definition: Attribute.h:369
iterator end(bool inverted) const noexcept
std::vector< Id > Ids
Definition: Forward.h:200
VectorT concatenate(ContainerT &&c)
Definition: Utilities.h:63
const ConstLanelet & operator[](size_t idx) const
Access an individual lanelet.
bool operator==(const Attribute &lhs, const Attribute &rhs)
Definition: Attribute.h:179
LaneletSequence(const LaneletSequences &ls)
Create a compound lanelet from other compound lanelets.
iterator end() const noexcept
Returns iterator to the last lanelet (or to the first, if inverted)
std::shared_ptr< const LaneletSequenceData > data_
internal data
LaneletSequence(LaneletSequenceDataConstPtr data, bool inverted)
CompoundLineString3d rightBound3d() const
get the combined right bounds of all lanelets
std::shared_ptr< CompoundLineString3d > centerline_
combined centerline
const ConstLanelets & lanelets() const
CompoundLineString3d centerline() const
computes the centerline. Result is cached
CompoundLineString3d leftBound3d() const
const CompoundLineString3d & rightBound() const
CompoundLineString3d invert() const noexcept
create a new, inverted linestring from this one
bool inverted() const
returns out if this is an inverted lanelets.
size_t size() const noexcept
Returns number of lanelets.
const CompoundLineString3d & leftBound3d() const
bool has(const LaneletSequence &ll, Id id)
returns true if element of a primitive has a matching Id
Combines multiple linestrings to one polygon in 3d.
ConstLanelets lanelets() const
returns the lanelets that are part of this object
bool operator!=(const Attribute &lhs, const Attribute &rhs)
Definition: Attribute.h:180
CompoundLineString2d rightBound2d() const
CompoundPolygon3d polygon3d() const
returns the surface covered by the lanelets as 3-dimensional polygon. The result of the computation i...
CompoundPolygon2d polygon2d() const
returns the surface covered by the lanelets as 2-dimensional polygon.
CompoundLineString3d leftBound() const
get the combined left bounds of all lanelets
A Compound linestring in 2d (returns Point2d)
const CompoundLineString3d & rightBound3d() const
A collection of Lanelets.
const CompoundLineString3d leftBound_
< Cached data
An immutable lanelet.
CompoundLineString2d leftBound2d() const
get the left bound in 2d. To be used over leftBound where geometric calculations are required...
CompoundLineString3d rightBound() const
get the combined right bounds of all lanelets
CompoundLineString2d leftBound2d() const
iterator begin(bool inverted) const noexcept
auto concatenate(ContainerT &&c)
overload assuming that c is a container of containers. The return type will be the type of the inner ...
Definition: Utilities.h:260
Common data management class for LaneletSequences.
LaneletSequenceDataConstPtr constData() const
returns the internal data on the linestrings managed by this object
std::vector< RegulatoryElementConstPtr > RegulatoryElementConstPtrs
Definition: Forward.h:195
std::vector< LaneletSequence > LaneletSequences
Definition: Forward.h:118
Id id
Definition: LaneletMap.cpp:63
const ConstLanelets lanelets_
CompoundLineString3d centerline() const
get the centerline of this lanelet
LaneletSequence invert() const
returns the respective inverted LaneletSequence
BoundingBox2d to2D(const BoundingBox3d &primitive)
std::shared_ptr< CompoundPolygon3d > polygon_
combined polygon
LaneletSequence(ConstLanelets ls=ConstLanelets())
Construct from a vector of ConstLineString3d.
Combines multiple linestrings to one polygon in 2d.
Container invert(const Container &cont)
Definition: Utilities.h:169
internal::ReverseAndForwardIterator< ConstLanelets::const_iterator > iterator
std::vector< std::shared_ptr< const RegElemT > > regulatoryElementsAs() const
get all regulatory elements of type RegElemT
CompoundLineString2d centerline2d() const
const CompoundLineString3d rightBound_
std::vector< ConstLanelet > ConstLanelets
Definition: Forward.h:114


lanelet2_core
Author(s): Fabian Poggenhans
autogenerated on Tue Jun 6 2023 02:23:32