Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(map_based_prediction): create a fence LineString layer and use rtree query #8406

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <visualization_msgs/msg/marker_array.hpp>

#include <lanelet2_core/Forward.h>
#include <lanelet2_core/LaneletMap.h>
#include <lanelet2_routing/Forward.h>
#include <lanelet2_traffic_rules/TrafficRules.h>

Expand Down Expand Up @@ -178,6 +179,9 @@ class MapBasedPredictionNode : public rclcpp::Node
// Crosswalk Entry Points
lanelet::ConstLanelets crosswalks_;

// Fences
lanelet::LaneletMapUPtr fence_layer_{nullptr};

// Parameters
bool enable_delay_compensation_;
PredictionTimeHorizon prediction_time_horizon_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Tier IV, Inc.

Check notice on line 1 in perception/autoware_map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 1936 to 1944, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.

Check notice on line 1 in perception/autoware_map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 6.56 to 6.58, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -929,6 +929,16 @@
const auto walkways = lanelet::utils::query::walkwayLanelets(all_lanelets);
crosswalks_.insert(crosswalks_.end(), crosswalks.begin(), crosswalks.end());
crosswalks_.insert(crosswalks_.end(), walkways.begin(), walkways.end());

lanelet::LineStrings3d fences;
for (const auto & linestring : lanelet_map_ptr_->lineStringLayer) {
if (const std::string type = linestring.attributeOr(lanelet::AttributeName::Type, "none");
type == "fence") {
fences.push_back(lanelet::LineString3d(
std::const_pointer_cast<lanelet::LineStringData>(linestring.constData())));
}
}
fence_layer_ = lanelet::utils::createMap(fences);
}

void MapBasedPredictionNode::trafficSignalsCallback(
Expand Down Expand Up @@ -1318,10 +1328,9 @@
for (const auto & p : predicted_path.path)
predicted_path_ls.emplace_back(p.position.x, p.position.y);
const auto candidates =
lanelet_map_ptr_->lineStringLayer.search(lanelet::geometry::boundingBox2d(predicted_path_ls));
fence_layer_->lineStringLayer.search(lanelet::geometry::boundingBox2d(predicted_path_ls));
for (const auto & candidate : candidates) {
const std::string type = candidate.attributeOr(lanelet::AttributeName::Type, "none");
if (type == "fence" && doesPathCrossFence(predicted_path, candidate)) {
if (doesPathCrossFence(predicted_path, candidate)) {
return true;
}
}
Expand Down
Loading