RegulatoryElementGeometry.cpp
Go to the documentation of this file.
1 #include <boost/variant.hpp>
2 
9 
10 namespace lanelet {
11 namespace geometry {
12 namespace {
13 using traits::to2D;
14 struct Bbox2dVisitor : public RuleParameterVisitor { // NOLINT
15  void operator()(const ConstPoint3d& p) override { bbox.extend(boundingBox2d(to2D(p))); }
16  void operator()(const ConstLineString3d& l) override { bbox.extend(boundingBox2d(to2D(l))); }
17  void operator()(const ConstPolygon3d& p) override { bbox.extend(boundingBox2d(to2D(p))); }
18  void operator()(const ConstWeakLanelet& ll) override {
19  if (ll.expired()) {
20  return;
21  }
22  bbox.extend(boundingBox2d(ll.lock()));
23  }
24  void operator()(const ConstWeakArea& ar) override {
25  if (ar.expired()) {
26  return;
27  }
28  bbox.extend(boundingBox2d(ar.lock()));
29  }
30  BoundingBox2d bbox{};
31 };
32 struct Bbox3dVisitor : public RuleParameterVisitor { // NOLINT
33  void operator()(const ConstPoint3d& p) override { bbox.extend(boundingBox3d(p)); }
34  void operator()(const ConstLineString3d& l) override { bbox.extend(boundingBox3d(l)); }
35  void operator()(const ConstPolygon3d& p) override { bbox.extend(boundingBox3d(p)); }
36  void operator()(const ConstWeakLanelet& ll) override {
37  if (ll.expired()) {
38  return;
39  }
40  bbox.extend(boundingBox3d(ll.lock()));
41  }
42  void operator()(const ConstWeakArea& ar) override {
43  if (ar.expired()) {
44  return;
45  }
46  bbox.extend(boundingBox3d(ar.lock()));
47  }
49 };
50 
51 struct DistanceVisitor : public RuleParameterVisitor { // NOLINT
52  explicit DistanceVisitor(BasicPoint2d p) : pdist{std::move(p)} {}
53  void operator()(const ConstPoint3d& p) override { d = std::min(d, distance(traits::to2D(p), pdist)); }
54  void operator()(const ConstLineString3d& l) override { d = std::min(d, distance2d(l, pdist)); }
55  void operator()(const ConstPolygon3d& p) override { d = std::min(d, distance2d(p, pdist)); }
56  void operator()(const ConstWeakLanelet& ll) override {
57  if (ll.expired()) {
58  return;
59  }
60  d = std::min(d, distance2d(ll.lock(), pdist));
61  }
62  void operator()(const ConstWeakArea& ar) override {
63  if (ar.expired()) {
64  return;
65  }
66  d = std::min(d, distance2d(ar.lock(), pdist));
67  }
69  double d{std::numeric_limits<double>::infinity()};
70 };
71 } // namespace
72 
74  Bbox2dVisitor visitor;
75  regElem.applyVisitor(visitor);
76  return visitor.bbox;
77 }
78 
80  Bbox3dVisitor visitor;
81  regElem.applyVisitor(visitor);
82  return visitor.bbox;
83 }
84 
85 double distance2d(const RegulatoryElement& regElem, const BasicPoint2d& p) {
86  DistanceVisitor visitor(p);
87  regElem.applyVisitor(visitor);
88  return visitor.d;
89 }
90 
91 } // namespace geometry
92 } // namespace lanelet
lanelet::geometry::boundingBox3d
IfAr< AreaT, BoundingBox3d > boundingBox3d(const AreaT &area)
calculates 3d bounding box
Definition: geometry/impl/Area.h:30
RegulatoryElement.h
lanelet::traits::to2D
BoundingBox2d to2D(const BoundingBox3d &primitive)
Definition: primitives/BoundingBox.h:304
lanelet
Definition: Attribute.h:13
p
BasicPoint p
Definition: LineStringGeometry.cpp:196
lanelet::RegulatoryElement::applyVisitor
void applyVisitor(RuleParameterVisitor &visitor) const
applies a visitor to every parameter in the regulatory element
Definition: RegulatoryElement.cpp:146
lanelet::RegulatoryElement
A general rule or limitation for a lanelet (abstract base class)
Definition: primitives/RegulatoryElement.h:174
lanelet::BoundingBox2d
Axis-Aligned bounding box in 2d.
Definition: primitives/BoundingBox.h:23
LineString.h
Area.h
lanelet::BoundingBox3d
Eigen::AlignedBox3d BoundingBox3d
Convenience type for an axis aligned bounding box in 3d.
Definition: primitives/BoundingBox.h:283
bbox
BoundingBox2d bbox
Definition: RegulatoryElementGeometry.cpp:30
Lanelet.h
BoundingBox.h
lanelet::BasicPoint2d
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > BasicPoint2d
a simple 2d-point
Definition: primitives/Point.h:20
Traits.h
lanelet::geometry::boundingBox2d
IfAr< AreaT, BoundingBox2d > boundingBox2d(const AreaT &area)
calculates an up-right 2d bounding box
Definition: geometry/impl/Area.h:25
pdist
BasicPoint2d pdist
Definition: RegulatoryElementGeometry.cpp:68
distance
Optional< double > distance
Definition: LineStringGeometry.cpp:168
d
double d
Definition: RegulatoryElementGeometry.cpp:69
lanelet::geometry::distance2d
double distance2d(const RegulatoryElement &regElem, const BasicPoint2d &p)
Definition: RegulatoryElementGeometry.cpp:85


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