test_lanelet_sequence.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include <iostream>
4 
10 
11 using namespace std::literals;
12 using namespace lanelet;
13 
14 class LaneletSequenceTest : public ::testing::Test {
15  protected:
16  void SetUp() override {
17  id = 0;
18  p1 = Point3d(++id, 0., 1., 1.);
19  p2 = Point3d(++id, 1., 1., 1.);
20  p3 = Point3d(++id, 2., 1., 1.);
21  p4 = Point3d(++id, 0., 0., 0.);
22  p5 = Point3d(++id, 0.5, 0., 0.);
23  p6 = Point3d(++id, 1, 0., 0.);
24  p7 = Point3d(++id, 2., 0., 0.);
25  left1 = LineString3d(++id, Points3d{p1, p2});
26  right1 = LineString3d(++id, Points3d{p4, p5, p6});
27  left2 = LineString3d(++id, Points3d{p2, p3});
28  right2 = LineString3d(++id, Points3d{p6, p7});
29 
30  ll1 = Lanelet(++id, left1, right1);
31  ll2 = Lanelet(++id, left2, right2);
32  cll = LaneletSequence({ll1, ll2});
33  }
34 
35  public:
36  Id id{1};
37  Point3d p1, p2, p3, p4, p5, p6, p7;
39  LineString3d left1, right1, left2, right2;
40  Lanelet ll1, ll2;
42 };
43 
44 TEST_F(LaneletSequenceTest, LeftBoundHasNoDuplicates) { // NOLINT
45  EXPECT_EQ(cll.leftBound(), ConstPoints3d({p1, p2, p3}));
46 }
47 
48 TEST_F(LaneletSequenceTest, RightBoundHasNoDuplicates) { // NOLINT
49  auto rb = cll.rightBound();
50  EXPECT_EQ(rb, ConstPoints3d({p4, p5, p6, p7}));
51 }
52 
53 TEST_F(LaneletSequenceTest, PolygonHasNoDuplicates) { // NOLINT
54  EXPECT_EQ(cll.polygon3d().basicPolygon(), BasicPolygon3d({p1, p2, p3, p7, p6, p5, p4}));
55 }
56 
57 TEST_F(LaneletSequenceTest, AppendsCenterline) { // NOLINT
58  auto cl = cll.centerline();
59  BasicLineString3d clExpect{BasicPoint3d(0, 0.5, 0.5), BasicPoint3d(0.5, 0.5, 0.5), BasicPoint3d(2, 0.5, 0.5)};
60  for (const auto& p : clExpect) {
61  EXPECT_FLOAT_EQ(geometry::distance(p, cl), 0.f);
62  }
63 }
64 
65 TEST_F(LaneletSequenceTest, InvertIteratesInReverseOrder) { // NOLINT
66  EXPECT_EQ(cll.invert().rightBound(), ConstPoints3d({p3, p2, p1}));
67 }
68 
69 TEST_F(LaneletSequenceTest, LaneletsAreOk) { // NOLINT
70  EXPECT_EQ(cll.lanelets(), ConstLanelets({ll1, ll2}));
71 }
72 
73 TEST_F(LaneletSequenceTest, ConstructFromLaneletSequences) { // NOLINT
74  LaneletSequence cl1{{ll1}};
75  LaneletSequence cl2{{ll2}};
76  LaneletSequence ccl{{cl1, cl2}};
77  EXPECT_EQ(ccl, cll);
78 }
79 
80 TEST_F(LaneletSequenceTest, RegulatoryElementExtraction) { // NOLINT
81  auto tl = TrafficLight::make(++id, AttributeMap(), LineStringsOrPolygons3d({left1, right1}), left1);
82  auto ts = TrafficSign::make(++id, AttributeMap(), {{left2}, "de205"}, {}, {right2});
83  ll1.addRegulatoryElement(tl);
84  ll2.addRegulatoryElement(ts);
85  EXPECT_EQ(1ul, cll.regulatoryElementsAs<TrafficLight>().size());
86  EXPECT_EQ(1ul, cll.regulatoryElementsAs<TrafficSign>().size());
87  EXPECT_TRUE(cll.regulatoryElementsAs<RightOfWay>().empty());
88 }
LaneletSequenceTest::pointsInOrder
Points3d pointsInOrder
Definition: test_lanelet_sequence.cpp:38
RegulatoryElement.h
lanelet
Definition: Attribute.h:13
lanelet::RegulatoryElement::empty
bool empty() const
returns true if this object contains no parameters
Definition: primitives/RegulatoryElement.h:233
LaneletSequenceTest::SetUp
void SetUp() override
Definition: test_lanelet_sequence.cpp:16
lanelet::BasicPoint3d
Eigen::Vector3d BasicPoint3d
a simple 3d-point
Definition: primitives/Point.h:19
lanelet::LaneletSequence
A collection of Lanelets.
Definition: LaneletSequence.h:85
p2
BasicPoint p2
Definition: LineStringGeometry.cpp:167
lanelet::AttributeMap
HybridMap< Attribute, decltype(AttributeNamesString::Map)&, AttributeNamesString::Map > AttributeMap
Definition: Attribute.h:371
p
BasicPoint p
Definition: LineStringGeometry.cpp:196
lanelet::Id
int64_t Id
Definition: Forward.h:198
lanelet::RegulatoryElement::size
size_t size() const
get the number of roles in this regulatoryElement
Definition: primitives/RegulatoryElement.h:236
lanelet::TrafficSign
Expresses a generic traffic sign rule.
Definition: BasicRegulatoryElements.h:230
LaneletSequenceTest::p7
Point3d p7
Definition: test_lanelet_sequence.cpp:37
LineString.h
lanelet::RightOfWay
Defines right of way restrictions.
Definition: BasicRegulatoryElements.h:87
lanelet::Lanelet
The famous (mutable) lanelet class.
Definition: primitives/Lanelet.h:221
lanelet::TrafficLight
Represents a traffic light restriction on the lanelet.
Definition: BasicRegulatoryElements.h:17
lanelet::Points3d
std::vector< Point3d > Points3d
Definition: Forward.h:34
lanelet::LineStringsOrPolygons3d
std::vector< LineStringOrPolygon3d > LineStringsOrPolygons3d
Definition: LineStringOrPolygon.h:132
lanelet::BasicPolygon3d
Primitive 3d polygon with basic points.
Definition: primitives/Polygon.h:38
TEST_F
TEST_F(LaneletSequenceTest, LeftBoundHasNoDuplicates)
Definition: test_lanelet_sequence.cpp:44
p1
BasicPoint p1
Definition: LineStringGeometry.cpp:166
BasicRegulatoryElements.h
LaneletSequenceTest::ll2
Lanelet ll2
Definition: test_lanelet_sequence.cpp:40
Utilities.h
lanelet::Point3d
A mutable 3d point.
Definition: primitives/Point.h:271
LaneletSequenceTest
Definition: test_lanelet_sequence.cpp:14
LaneletSequence.h
LaneletSequenceTest::cll
LaneletSequence cll
Definition: test_lanelet_sequence.cpp:41
lanelet::ConstPoints3d
std::vector< ConstPoint3d > ConstPoints3d
Definition: Forward.h:35
distance
Optional< double > distance
Definition: LineStringGeometry.cpp:168
lanelet::LineString3d
A normal 3d linestring with mutable data.
Definition: primitives/LineString.h:538
LaneletSequenceTest::right2
LineString3d right2
Definition: test_lanelet_sequence.cpp:39
lanelet::ConstLanelets
std::vector< ConstLanelet > ConstLanelets
Definition: Forward.h:114
lanelet::BasicLineString3d
BasicPoints3d BasicLineString3d
Definition: primitives/LineString.h:15


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