24namespace node_creator {
28using ::google::protobuf::RepeatedPtrField;
42double GetLengthbyRate(
double cur_s,
double cur_total_length,
43 double target_length) {
44 double new_length = cur_s / cur_total_length * target_length;
45 return std::min(new_length, target_length);
48double GetLaneLength(
const Lane& lane) {
50 for (
const auto& segment : lane.central_curve().segment()) {
51 length += segment.length();
56void AddOutBoundary(
const LaneBoundary& bound,
double lane_length,
57 RepeatedPtrField<CurveRange>*
const out_range) {
58 for (
int i = 0; i < bound.boundary_type_size(); ++i) {
63 range->mutable_start()->set_s(GetLengthbyRate(bound.
boundary_type(i).
s(),
64 bound.
length(), lane_length));
65 if (i != bound.boundary_type_size() - 1) {
66 range->mutable_end()->set_s(GetLengthbyRate(
69 range->mutable_end()->set_s(lane_length);
74void InitNodeInfo(
const Lane& lane,
const std::string& road_id,
76 double lane_length = GetLaneLength(lane);
77 node->set_lane_id(lane.id().id());
78 node->set_road_id(road_id);
79 AddOutBoundary(lane.left_boundary(), lane_length, node->mutable_left_out());
80 AddOutBoundary(lane.right_boundary(), lane_length, node->mutable_right_out());
81 node->set_length(lane_length);
82 node->mutable_central_curve()->CopyFrom(lane.central_curve());
83 node->set_is_virtual(
true);
84 if (!lane.has_junction_id() ||
85 lane.left_neighbor_forward_lane_id_size() > 0 ||
86 lane.right_neighbor_forward_lane_id_size() > 0) {
87 node->set_is_virtual(
false);
91void InitNodeCost(
const Lane& lane,
const RoutingConfig& routing_config,
93 double lane_length = GetLaneLength(lane);
95 lane.has_speed_limit() ? lane.speed_limit() : routing_config.
base_speed();
96 double ratio = speed_limit >= routing_config.
base_speed()
97 ? std::sqrt(routing_config.
base_speed() / speed_limit)
99 double cost = lane_length * ratio;
100 if (lane.has_turn()) {
101 if (lane.turn() == Lane::LEFT_TURN) {
103 }
else if (lane.turn() == Lane::RIGHT_TURN) {
105 }
else if (lane.turn() == Lane::U_TURN) {
109 node->set_cost(cost);
116 InitNodeInfo(lane, road_id, node);
117 InitNodeCost(lane, routingconfig, node);