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
BasicPoint p
BoundingBox2d bbox
Eigen::AlignedBox3d BoundingBox3d
Convenience type for an axis aligned bounding box in 3d.
IfAr< AreaT, BoundingBox2d > boundingBox2d(const AreaT &area)
calculates an up-right 2d bounding box
Optional< double > distance
Axis-Aligned bounding box in 2d.
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > BasicPoint2d
a simple 2d-point
A general rule or limitation for a lanelet (abstract base class)
BoundingBox2d to2D(const BoundingBox3d &primitive)
void applyVisitor(RuleParameterVisitor &visitor) const
applies a visitor to every parameter in the regulatory element
double distance2d(const RegulatoryElement &regElem, const BasicPoint2d &p)
BasicPoint2d pdist
IfAr< AreaT, BoundingBox3d > boundingBox3d(const AreaT &area)
calculates 3d bounding box


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