Skip to content

Commit 86fcfe5

Browse files
Fix problems of lanemarking generation and tree generation (#7006)
Co-authored-by: xiaofei <13319202082@163.com>
1 parent 60af913 commit 86fcfe5

3 files changed

Lines changed: 56 additions & 67 deletions

File tree

LibCarla/source/carla/road/Map.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ namespace road {
12321232
while(s_current < s_end){
12331233
if(lane->GetWidth(s_current) != 0.0f){
12341234
const auto edges = lane->GetCornerPositions(s_current, 0);
1235+
if (edges.first == edges.second) continue;
12351236
geom::Vector3D director = edges.second - edges.first;
12361237
geom::Vector3D treeposition = edges.first - director.MakeUnitVector() * distancefromdrivinglineborder;
12371238
geom::Transform lanetransform = lane->ComputeTransform(s_current);

LibCarla/source/carla/road/MeshFactory.cpp

Lines changed: 46 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,11 @@ std::map<road::Lane::LaneType , std::vector<std::unique_ptr<Mesh>>> MeshFactory:
761761
case carla::road::element::LaneMarking::Type::Solid: {
762762
size_t currentIndex = out_mesh.GetVertices().size() + 1;
763763

764-
std::pair<geom::Vector3D, geom::Vector3D> edges = lane.GetCornerPositions(s_current, 0);
765-
766-
geom::Vector3D director = edges.second - edges.first;
767-
director /= director.Length();
768-
geom::Vector3D endmarking = edges.first + director * lane_mark_info.width;
764+
std::pair<geom::Vector3D, geom::Vector3D> edges =
765+
ComputeEdgesForLanemark(lane_section, lane, s_current, lane_mark_info.width);
769766

770767
out_mesh.AddVertex(edges.first);
771-
out_mesh.AddVertex(endmarking);
768+
out_mesh.AddVertex(edges.second);
772769

773770
out_mesh.AddIndex(currentIndex);
774771
out_mesh.AddIndex(currentIndex + 1);
@@ -784,30 +781,23 @@ std::map<road::Lane::LaneType , std::vector<std::unique_ptr<Mesh>>> MeshFactory:
784781
case carla::road::element::LaneMarking::Type::Broken: {
785782
size_t currentIndex = out_mesh.GetVertices().size() + 1;
786783

787-
std::pair<geom::Vector3D, geom::Vector3D> edges =
788-
lane.GetCornerPositions(s_current, road_param.extra_lane_width);
789-
790-
geom::Vector3D director = edges.second - edges.first;
791-
director /= director.Length();
792-
geom::Vector3D endmarking = edges.first + director * lane_mark_info.width;
784+
std::pair<geom::Vector3D, geom::Vector3D> edges =
785+
ComputeEdgesForLanemark(lane_section, lane, s_current, lane_mark_info.width);
793786

794787
out_mesh.AddVertex(edges.first);
795-
out_mesh.AddVertex(endmarking);
788+
out_mesh.AddVertex(edges.second);
796789

797790
s_current += road_param.resolution * 3;
798791
if (s_current > s_end)
799792
{
800793
s_current = s_end;
801794
}
802-
edges = lane.GetCornerPositions(s_current, road_param.extra_lane_width);
803795

804-
director = edges.second - edges.first;
805-
director /= director.Length();
806-
endmarking = edges.first + director * lane_mark_info.width;
796+
edges = ComputeEdgesForLanemark(lane_section, lane, s_current, lane_mark_info.width);
807797

808798
out_mesh.AddVertex(edges.first);
809-
out_mesh.AddVertex(endmarking);
810-
799+
out_mesh.AddVertex(edges.second);
800+
811801
out_mesh.AddIndex(currentIndex);
812802
out_mesh.AddIndex(currentIndex + 1);
813803
out_mesh.AddIndex(currentIndex + 2);
@@ -864,13 +854,12 @@ std::map<road::Lane::LaneType , std::vector<std::unique_ptr<Mesh>>> MeshFactory:
864854
const carla::road::element::RoadInfoMarkRecord* road_info_mark = lane.GetInfo<carla::road::element::RoadInfoMarkRecord>(s_current);
865855
if (road_info_mark != nullptr) {
866856
carla::road::element::LaneMarking lane_mark_info(*road_info_mark);
867-
std::pair<geom::Vector3D, geom::Vector3D> edges = lane.GetCornerPositions(s_end, 0);
868-
geom::Vector3D director = edges.second - edges.first;
869-
director /= director.Length();
870-
geom::Vector3D endmarking = edges.first + director * lane_mark_info.width;
857+
858+
std::pair<geom::Vector3D, geom::Vector3D> edges =
859+
ComputeEdgesForLanemark(lane_section, lane, s_end, lane_mark_info.width);
871860

872861
out_mesh.AddVertex(edges.first);
873-
out_mesh.AddVertex(endmarking);
862+
out_mesh.AddVertex(edges.second);
874863
}
875864
inout.push_back(std::make_unique<Mesh>(out_mesh));
876865
}
@@ -927,58 +916,21 @@ std::map<road::Lane::LaneType , std::vector<std::unique_ptr<Mesh>>> MeshFactory:
927916
case carla::road::element::LaneMarking::Type::Broken: {
928917
size_t currentIndex = out_mesh.GetVertices().size() + 1;
929918

930-
std::pair<geom::Vector3D, geom::Vector3D> edges =
931-
lane.GetCornerPositions(s_current, road_param.extra_lane_width);
932-
933-
geom::Vector3D director;
934-
if (lane.GetWidth(s_current) != 0) {
935-
director = edges.second - edges.first;
936-
director /= director.Length();
937-
} else {
938-
const std::map<road::LaneId, road::Lane> & lanes = lane_section.GetLanes();
939-
for (const auto& lane_pair : lanes) {
940-
if (lane_pair.second.GetWidth(s_current) != 0) {
941-
std::pair<geom::Vector3D, geom::Vector3D> another_edge =
942-
lane_pair.second.GetCornerPositions(s_current, road_param.extra_lane_width);
943-
director = another_edge.second - another_edge.first;
944-
director /= director.Length();
945-
break;
946-
}
947-
}
948-
}
949-
950-
geom::Vector3D endmarking = edges.first + director * lane_mark_info.width;
951-
919+
std::pair<geom::Vector3D, geom::Vector3D> edges =
920+
ComputeEdgesForLanemark(lane_section, lane, s_current, lane_mark_info.width);
921+
952922
out_mesh.AddVertex(edges.first);
953-
out_mesh.AddVertex(endmarking);
923+
out_mesh.AddVertex(edges.second);
954924

955925
s_current += road_param.resolution * 3;
956926
if (s_current > s_end) {
957927
s_current = s_end;
958928
}
959929

960-
edges = lane.GetCornerPositions(s_current, road_param.extra_lane_width);
961-
962-
if (lane.GetWidth(s_current) != 0) {
963-
director = edges.second - edges.first;
964-
director /= director.Length();
965-
} else {
966-
const std::map<road::LaneId, road::Lane> & lanes = lane_section.GetLanes();
967-
for (const auto& lane_pair : lanes) {
968-
if (lane_pair.second.GetWidth(s_current) != 0) {
969-
std::pair<geom::Vector3D, geom::Vector3D> another_edge =
970-
lane_pair.second.GetCornerPositions(s_current, road_param.extra_lane_width);
971-
director = another_edge.second - another_edge.first;
972-
director /= director.Length();
973-
break;
974-
}
975-
}
976-
}
977-
978-
endmarking = edges.first + director * lane_mark_info.width;
930+
edges = ComputeEdgesForLanemark(lane_section, lane, s_current, lane_mark_info.width);
979931

980932
out_mesh.AddVertex(edges.first);
981-
out_mesh.AddVertex(endmarking);
933+
out_mesh.AddVertex(edges.second);
982934

983935
out_mesh.AddIndex(currentIndex);
984936
out_mesh.AddIndex(currentIndex + 1);
@@ -1179,6 +1131,33 @@ std::map<road::Lane::LaneType , std::vector<std::unique_ptr<Mesh>>> MeshFactory:
11791131
return std::make_unique<Mesh>(out_mesh);
11801132
}
11811133

1134+
std::pair<geom::Vector3D, geom::Vector3D> MeshFactory::ComputeEdgesForLanemark(
1135+
const road::LaneSection& lane_section,
1136+
const road::Lane& lane,
1137+
const double s_current,
1138+
const double lanemark_width) const {
1139+
std::pair<geom::Vector3D, geom::Vector3D> edges =
1140+
lane.GetCornerPositions(s_current, road_param.extra_lane_width);
1141+
1142+
geom::Vector3D director;
1143+
if (edges.first != edges.second) {
1144+
director = edges.second - edges.first;
1145+
director /= director.Length();
1146+
} else {
1147+
const std::map<road::LaneId, road::Lane> & lanes = lane_section.GetLanes();
1148+
for (const auto& lane_pair : lanes) {
1149+
std::pair<geom::Vector3D, geom::Vector3D> another_edge =
1150+
lane_pair.second.GetCornerPositions(s_current, road_param.extra_lane_width);
1151+
if (another_edge.first != another_edge.second) {
1152+
director = another_edge.second - another_edge.first;
1153+
director /= director.Length();
1154+
break;
1155+
}
1156+
}
1157+
}
1158+
geom::Vector3D endmarking = edges.first + director * lanemark_width;
1159+
return std::make_pair(edges.first, endmarking);
1160+
}
11821161

11831162
} // namespace geom
11841163
} // namespace carla

LibCarla/source/carla/road/MeshFactory.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ namespace geom {
148148

149149
RoadParameters road_param;
150150

151+
private:
152+
153+
// Calculate the points on both sides of the lane mark for the specified s_current
154+
std::pair<geom::Vector3D, geom::Vector3D> ComputeEdgesForLanemark(
155+
const road::LaneSection& lane_section,
156+
const road::Lane& lane,
157+
const double s_current,
158+
const double lanemark_width) const;
159+
151160
};
152161

153162
} // namespace geom

0 commit comments

Comments
 (0)