From e6ba65db2190856d319491687d549070a87609a3 Mon Sep 17 00:00:00 2001 From: Blyron Date: Thu, 30 May 2024 14:59:57 +0200 Subject: [PATCH] Uses switches depending on line type --- LibCarla/source/carla/road/MeshFactory.cpp | 145 +++++++++++++++------ LibCarla/source/carla/road/MeshFactory.h | 10 +- 2 files changed, 113 insertions(+), 42 deletions(-) diff --git a/LibCarla/source/carla/road/MeshFactory.cpp b/LibCarla/source/carla/road/MeshFactory.cpp index 8d7019ebb..0c2d08515 100644 --- a/LibCarla/source/carla/road/MeshFactory.cpp +++ b/LibCarla/source/carla/road/MeshFactory.cpp @@ -206,23 +206,33 @@ namespace geom { size_t PosToAdd = it - redirections.begin(); Mesh out_mesh; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving ){ - out_mesh += *GenerateTesselated(lane_pair.second); - }else{ - out_mesh += *GenerateSidewalk(lane_pair.second); + switch(lane_pair.second.GetType()) + { + case road::Lane::LaneType::Driving: + case road::Lane::LaneType::Parking: + case road::Lane::LaneType::Bidirectional: + { + out_mesh += *GenerateTesselated(lane_pair.second); + break; + } + case road::Lane::LaneType::Shoulder: + case road::Lane::LaneType::Sidewalk: + case road::Lane::LaneType::Biking: + { + out_mesh += *GenerateSidewalk(lane_pair.second); + break; + } + default: + { + out_mesh += *GenerateTesselated(lane_pair.second); + break; + } } if( result[lane_pair.second.GetType()].size() <= PosToAdd ){ result[lane_pair.second.GetType()].push_back(std::make_unique(out_mesh)); } else { - uint32_t verticesinwidth = 0; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving) { - verticesinwidth = vertices_in_width; - }else if(lane_pair.second.GetType() == road::Lane::LaneType::Sidewalk){ - verticesinwidth = 6; - }else{ - verticesinwidth = 2; - } + uint32_t verticesinwidth = SelectVerticesInWidth(vertices_in_width, lane_pair.second.GetType()); (result[lane_pair.second.GetType()][PosToAdd])->ConcatMesh(out_mesh, verticesinwidth); } } @@ -548,12 +558,28 @@ std::map>> MeshFactory: for (auto &&lane_pair : lane_section.GetLanes()) { Mesh lane_section_mesh; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving ){ - lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_until); - }else{ - lane_section_mesh += *GenerateSidewalk(lane_pair.second, s_current, s_until); + switch(lane_pair.second.GetType()) + { + case road::Lane::LaneType::Driving: + case road::Lane::LaneType::Parking: + case road::Lane::LaneType::Bidirectional: + { + lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_until); + break; + } + case road::Lane::LaneType::Shoulder: + case road::Lane::LaneType::Sidewalk: + case road::Lane::LaneType::Biking: + { + lane_section_mesh += *GenerateSidewalk(lane_pair.second, s_current, s_until); + break; + } + default: + { + lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_until); + break; + } } - auto it = std::find(redirections.begin(), redirections.end(), lane_pair.first); if (it == redirections.end()) { redirections.push_back(lane_pair.first); @@ -564,14 +590,7 @@ std::map>> MeshFactory: if (mesh_uptr_list[lane_pair.second.GetType()].size() <= PosToAdd) { mesh_uptr_list[lane_pair.second.GetType()].push_back(std::make_unique(lane_section_mesh)); } else { - uint32_t verticesinwidth = 0; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving) { - verticesinwidth = vertices_in_width; - }else if(lane_pair.second.GetType() == road::Lane::LaneType::Sidewalk){ - verticesinwidth = 6; - }else{ - verticesinwidth = 2; - } + uint32_t verticesinwidth = SelectVerticesInWidth(vertices_in_width, lane_pair.second.GetType()); (mesh_uptr_list[lane_pair.second.GetType()][PosToAdd])->ConcatMesh(lane_section_mesh, verticesinwidth); } } @@ -580,10 +599,27 @@ std::map>> MeshFactory: if (s_end - s_current > EPSILON) { for (auto &&lane_pair : lane_section.GetLanes()) { Mesh lane_section_mesh; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving ){ - lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_end); - }else{ - lane_section_mesh += *GenerateSidewalk(lane_pair.second, s_current, s_end); + switch(lane_pair.second.GetType()) + { + case road::Lane::LaneType::Driving: + case road::Lane::LaneType::Parking: + case road::Lane::LaneType::Bidirectional: + { + lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_end); + break; + } + case road::Lane::LaneType::Shoulder: + case road::Lane::LaneType::Sidewalk: + case road::Lane::LaneType::Biking: + { + lane_section_mesh += *GenerateSidewalk(lane_pair.second, s_current, s_end); + break; + } + default: + { + lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_end); + break; + } } auto it = std::find(redirections.begin(), redirections.end(), lane_pair.first); @@ -598,13 +634,7 @@ std::map>> MeshFactory: mesh_uptr_list[lane_pair.second.GetType()].push_back(std::make_unique(lane_section_mesh)); } else { uint32_t verticesinwidth = 0; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving) { - verticesinwidth = vertices_in_width; - }else if(lane_pair.second.GetType() == road::Lane::LaneType::Sidewalk){ - verticesinwidth = 6; - }else{ - verticesinwidth = 2; - } + *(mesh_uptr_list[lane_pair.second.GetType()][PosToAdd]) += lane_section_mesh; } } @@ -725,9 +755,20 @@ std::map>> MeshFactory: for (auto&& lane_section : road.GetLaneSections()) { for (auto&& lane : lane_section.GetLanes()) { if (lane.first != 0) { - if(lane.second.GetType() == road::Lane::LaneType::Driving ){ - GenerateLaneMarksForNotCenterLine(lane_section, lane.second, inout, outinfo); - outinfo.push_back("white"); + switch(lane.second.GetType()) + { + case road::Lane::LaneType::Driving: + case road::Lane::LaneType::Parking: + case road::Lane::LaneType::Bidirectional: + { + GenerateLaneMarksForNotCenterLine(lane_section, lane.second, inout, outinfo); + outinfo.push_back("white"); + break; + } + default: + { + break; + } } } else { if(lane.second.GetType() == road::Lane::LaneType::None ){ @@ -1131,6 +1172,32 @@ std::map>> MeshFactory: return std::make_unique(out_mesh); } + uint32_t MeshFactory::SelectVerticesInWidth(uint32_t default_num_vertices, road::Lane::LaneType type) + { + switch(type) + { + case road::Lane::LaneType::Driving: + case road::Lane::LaneType::Parking: + case road::Lane::LaneType::Bidirectional: + { + return default_num_vertices; + break; + } + case road::Lane::LaneType::Shoulder: + case road::Lane::LaneType::Sidewalk: + case road::Lane::LaneType::Biking: + { + return 6; + break; + } + default: + { + return 2; + break; + } + } + } + std::pair MeshFactory::ComputeEdgesForLanemark( const road::LaneSection& lane_section, const road::Lane& lane, diff --git a/LibCarla/source/carla/road/MeshFactory.h b/LibCarla/source/carla/road/MeshFactory.h index 42bc60ea1..00d3a712e 100644 --- a/LibCarla/source/carla/road/MeshFactory.h +++ b/LibCarla/source/carla/road/MeshFactory.h @@ -129,9 +129,7 @@ namespace geom { const road::Lane& lane, std::vector>& inout, std::vector& outinfo ) const; - // ========================================================================= - // -- Generation parameters ------------------------------------------------ - // ========================================================================= + /// Parameters for the road generation struct RoadParameters { @@ -148,6 +146,12 @@ namespace geom { RoadParameters road_param; + + // ========================================================================= + // -- Helper functions ------------------------------------------------ + // ========================================================================= + + static uint32_t SelectVerticesInWidth(uint32_t default_num_vertices, road::Lane::LaneType type); private: // Calculate the points on both sides of the lane mark for the specified s_current