31 #include <lanelet2_io/Io.h> 32 #include <lanelet2_projection/UTM.h> 37 #include "gtest/gtest.h" 42 template <
typename MatchVectorT>
43 std::string toString(
const MatchVectorT& matchVector) {
45 for (
auto& match : matchVector) {
46 out += std::to_string(match.lanelet.id());
47 if (match.lanelet.inverted()) {
57 hullPoints.reserve(relativeHull.size());
58 for (
const auto& hullPt : relativeHull) {
59 hullPoints.push_back(pose * hullPt);
87 map = std::make_shared<LaneletMap>();
94 lanelet::Point3d p1{1, 0, 0},
p2{2, 2, 0}, p3{3, 0, 2}, p4{4, 2, 2};
95 lanelet::Point3d p5{1, 100, 0}, p6{2, 102, 0}, p7{3, 100, 2}, p8{4, 102, 2};
96 lanelet::LineString3d ls11{11, {
p1,
p2}}, ls12{12, {p3, p4}}, ls13{13, {
p1, p3}}, ls14{14, {p2, p4}};
105 EXPECT_TRUE(map->laneletLayer.exists(21));
106 EXPECT_TRUE(map->laneletLayer.exists(22));
107 EXPECT_TRUE(map->laneletLayer.exists(23));
108 EXPECT_EQ(3ul, map->laneletLayer.size());
115 obj.
pose.linear() = Eigen::Rotation2D<double>(-1.5 * M_PI).matrix();
129 obj.
pose.linear() = Eigen::Rotation2D<double>(150. / 180. * M_PI).matrix();
137 std::vector<std::pair<double, Lanelet>> laneletsWithDistance =
140 EXPECT_EQ(3ul, laneletsWithDistance.size());
146 obj.
pose.linear() = Eigen::Rotation2D<double>(1. / 180. * M_PI).matrix();
151 using namespace matching::utils;
154 <<
"should throw on covariance = zero";
158 <<
"should throw on determinant = zero";
164 EXPECT_NEAR(0.011, mahaDist21, 10e-2);
167 EXPECT_NEAR(320.411, mahaDist21inv, 10e-2);
174 obj.pose.linear() = Eigen::Rotation2D<double>(90.1 / 180. * M_PI).matrix();
175 obj.absoluteHull = absoluteHull(
178 obj.positionCovariance = matching::PositionCovariance2d::Identity() * 2.;
179 obj.vonMisesKappa = 1. / (10. / 180. * M_PI);
187 for (
size_t i = 1; i < matches.size(); i++) {
188 EXPECT_TRUE(matches.at(i).distance >= matches.at(i - 1).distance)
189 <<
"Not sorted: at i=" << i - 1 <<
" dist = " << matches.at(i - 1).distance <<
"at i=" << i
190 <<
" dist = " << matches.at(i).distance;
192 EXPECT_EQ(4ul, matches.size());
193 EXPECT_NEAR(0., matches.at(0).distance, 0.1);
200 EXPECT_EQ(4ul, matches.size());
207 for (
size_t i = 1; i < matches.size(); i++) {
208 EXPECT_TRUE(matches.at(i).mahalanobisDistSq >= matches.at(i - 1).mahalanobisDistSq) <<
"Not sorted at i=" << i;
210 EXPECT_NEAR(0.0, matches.at(0).mahalanobisDistSq, 0.001);
211 EXPECT_EQ(22, matches.at(0).lanelet.id());
212 EXPECT_FALSE(matches.at(0).lanelet.inverted()) <<
"best match must be non inverted 21";
213 EXPECT_EQ(4ul, matches.size());
220 EXPECT_EQ(4ul, matches.size());
227 EXPECT_TRUE(
isCloseTo(map->laneletLayer, obj, 4.));
228 EXPECT_FALSE(
isCloseTo(emptyLayer, obj, 4.));
230 EXPECT_TRUE(
isWithin(map->laneletLayer, obj));
231 EXPECT_FALSE(
isWithin(emptyLayer, obj));
234 objWithEmptyHull.
pose.translation() = obj.pose.translation();
241 EXPECT_EQ(4ul, matches.size());
242 EXPECT_EQ(
"22 21inv 21 22inv ", toString(matches));
247 EXPECT_EQ(1ul, compliantMatches.size()) <<
"should exclude pedestrian lanelets and inverted one-way lanelets";
248 EXPECT_EQ(
"21 ", toString(compliantMatches));
254 EXPECT_EQ(4ul, matches.size());
259 EXPECT_EQ(1ul, compliantMatches.size()) <<
"filterNonCompliantProbabilistic for details";
static constexpr char Germany[]
Hull2d absoluteHull
Hull of the object in map coordinates, position is used for matching when hull is empty...
std::vector< LaneletMatchProbabilistic > getProbabilisticMatches(LaneletMap &map, const ObjectWithCovariance2d &obj, double maxDist)
get probabilistic lanelet matches of an object with a maximum deterministic euler distance of maxDist...
static constexpr const char Road[]
static constexpr const char Vehicle[]
static constexpr const char Location[]
std::shared_ptr< LaneletMap > LaneletMapPtr
matching::ObjectWithCovariance2d obj
static constexpr const char Walkway[]
Pose2d pose
Pose of the object in map coordinates.
double getMahalanobisDistSq(const ConstLanelet &lanelet, const ObjectWithCovariance2d &obj)
Compute squared mahalanobis distance based on pose and covariance, hull is not used.
Eigen::Transform< double, 2, Eigen::Isometry, Eigen::DontAlign > Pose2d
a 2d pose
MatchVectorT removeNonRuleCompliantMatches(const MatchVectorT &matches, const lanelet::traffic_rules::TrafficRulesPtr &trafficRulesPtr)
Remove non traffic rule compliant probabilistic lanelet matches.
static TrafficRulesUPtr create(const std::string &location, const std::string &participant, TrafficRules::Configuration configuration=TrafficRules::Configuration())
Thrown when matching is not possible.
TEST_F(MatchingUtilitiesBase, fixtureSetupSuccessful)
double vonMisesKappa
kappa as defined in https://en.wikipedia.org/wiki/Von_Mises_distribution
static constexpr const char Urban[]
std::vector< LaneletMatch > getDeterministicMatches(LaneletMap &map, const Object2d &obj, double maxDist)
get deterministic lanelet matches of an object with a maximum distance of maxDist, sorted ascending by distance
auto findWithin(LayerT &map, const Object2d &obj, double maxDist) -> std::vector< std::pair< double, traits::LayerPrimitiveType< LayerT >>>
Find all primitives as close as or closer than maxDist to an object.
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > BasicPoint2d
static constexpr const char Subtype[]
PositionCovariance2d positionCovariance
bool isCloseTo(const LayerT &map, const Object2d &obj, double maxDist)
Determine whether an object is within a maximum distance to any primitive of the layer.
bool isWithin(const LayerT &map, const Object2d &obj)
Determine whether an object is (at least partially) within any primitive of the layer.
std::shared_ptr< TrafficRules > TrafficRulesPtr