geometry/impl/LaneletMap.h
Go to the documentation of this file.
1 #pragma once
2 #include <boost/geometry/algorithms/buffer.hpp>
3 #include <boost/geometry/algorithms/distance.hpp>
4 
9 
10 namespace lanelet {
11 namespace geometry {
12 
13 template <typename LayerT, typename GeometryT>
14 auto findWithin2d(LayerT& layer, const GeometryT& geometry, double maxDist)
15  -> std::vector<std::pair<double, traits::LayerPrimitiveType<LayerT>>> {
16  static_assert(std::is_same<traits::TwoD<GeometryT>, GeometryT>::value,
17  "Call this function with a 2d type as geometry!");
18  using RetT = std::vector<std::pair<double, traits::LayerPrimitiveType<LayerT>>>;
19 
20  BoundingBox2d boundingBox = boundingBox2d(geometry);
21  if (maxDist > 0.) {
22  boost::geometry::buffer(boundingBox, boundingBox, maxDist);
23  }
24  const auto bboxApproximation = layer.search(boundingBox);
25 
26  auto withinVec = utils::createReserved<RetT>(bboxApproximation.size());
27  for (auto const& elem : bboxApproximation) {
28  const double dist = distance2d(geometry, elem);
29  if (dist <= maxDist) {
30  withinVec.push_back(std::make_pair(dist, elem));
31  }
32  }
33  std::sort(withinVec.begin(), withinVec.end(), [](auto& v1, auto& v2) { return v1.first < v2.first; });
34  return withinVec;
35 }
36 
37 template <typename LayerT, typename GeometryT>
38 auto findWithin3d(LayerT& layer, const GeometryT& geometry, double maxDist)
39  -> std::vector<std::pair<double, traits::LayerPrimitiveType<LayerT>>> {
40  using RetT = std::vector<std::pair<double, traits::LayerPrimitiveType<LayerT>>>;
41 
42  BoundingBox2d boundingBox = boundingBox2d(traits::to2D(geometry));
43  if (maxDist > 0.) {
44  boost::geometry::buffer(boundingBox, boundingBox, maxDist);
45  }
46  const auto bboxApproximation = layer.search(boundingBox);
47 
48  auto withinVec = utils::createReserved<RetT>(bboxApproximation.size());
49  for (auto const& elem : bboxApproximation) {
50  const double dist = distance3d(geometry, elem);
51  if (dist <= maxDist) {
52  withinVec.push_back(std::make_pair(dist, elem));
53  }
54  }
55  std::sort(withinVec.begin(), withinVec.end(), [](auto& v1, auto& v2) { return v1.first < v2.first; });
56  return withinVec;
57 }
58 } // namespace geometry
59 } // namespace lanelet
lanelet::traits::to2D
BoundingBox2d to2D(const BoundingBox3d &primitive)
Definition: primitives/BoundingBox.h:304
lanelet
Definition: Attribute.h:13
lanelet::geometry::findWithin3d
auto findWithin3d(LayerT &layer, const GeometryT &geometry, double maxDist) -> std::vector< std::pair< double, traits::LayerPrimitiveType< LayerT >>>
Returns all elements that are closer than maxDist to a geometry in 3d.
Definition: geometry/impl/LaneletMap.h:38
lanelet::BoundingBox2d
Axis-Aligned bounding box in 2d.
Definition: primitives/BoundingBox.h:23
Utilities.h
LaneletMap.h
lanelet::geometry::findWithin2d
auto findWithin2d(LayerT &layer, const GeometryT &geometry, double maxDist) -> std::vector< std::pair< double, traits::LayerPrimitiveType< LayerT >>>
Returns all elements that are closer than maxDist to a geometry in 2d.
Definition: geometry/impl/LaneletMap.h:14
lanelet::geometry::boundingBox2d
IfAr< AreaT, BoundingBox2d > boundingBox2d(const AreaT &area)
calculates an up-right 2d bounding box
Definition: geometry/impl/Area.h:25
BoundingBox.h
lanelet::geometry::distance3d
IfLS2< LineString3d1T, LineString3d2T, double > distance3d(const LineString3d1T &l1, const LineString3d2T &l2)
Definition: geometry/impl/LineString.h:803
Lanelet.h
lanelet::geometry::distance2d
double distance2d(const RegulatoryElement &regElem, const BasicPoint2d &p)
Definition: RegulatoryElementGeometry.cpp:85
lanelet::traits::TwoD
typename PrimitiveTraits< PrimitiveT >::TwoDType TwoD
Utility for determinig the matching two dimensional type for a primitive.
Definition: Traits.h:88


lanelet2_core
Author(s): Fabian Poggenhans
autogenerated on Thu Mar 6 2025 03:25:52