From 487d4e678be9ca7d3239eff392fa3e6394f701b5 Mon Sep 17 00:00:00 2001 From: Marc Garcia Puig Date: Fri, 10 Apr 2020 13:01:06 +0200 Subject: [PATCH] Some PR fixes --- LibCarla/source/carla/geom/MeshFactory.cpp | 31 ++++++++++--------- LibCarla/source/carla/geom/MeshFactory.h | 20 +++++++----- .../carla/rpc/OpendriveGenerationParameters.h | 2 +- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/LibCarla/source/carla/geom/MeshFactory.cpp b/LibCarla/source/carla/geom/MeshFactory.cpp index 3cd1ae0e2..1fc649310 100644 --- a/LibCarla/source/carla/geom/MeshFactory.cpp +++ b/LibCarla/source/carla/geom/MeshFactory.cpp @@ -357,35 +357,37 @@ namespace geom { size_t lane_mesh_idx; bool is_static; }; - constexpr double MaxWeightDistance = 5; - constexpr double SameLaneWeightMultiplier = 3; - constexpr double LaneEndsMultiplier = 3; - // Helper gunction to compute the weight of neighboring vertices - VertexWeight ComputeVertexWeight(const VertexInfo& vertex_info, const VertexInfo& neighbor_info) { - double distance3D = geom::Math::Distance(*vertex_info.vertex, *neighbor_info.vertex); + // Helper function to compute the weight of neighboring vertices + static VertexWeight ComputeVertexWeight( + const MeshFactory::RoadParameters &road_param, + const VertexInfo &vertex_info, + const VertexInfo &neighbor_info) { + const float distance3D = geom::Math::Distance(*vertex_info.vertex, *neighbor_info.vertex); // Ignore vertices beyond a certain distance - if(distance3D > MaxWeightDistance) { + if(distance3D > road_param.max_weight_distance) { return {neighbor_info.vertex, 0}; } - if(abs(distance3D) < std::numeric_limits::epsilon()) { + if(abs(distance3D) < EPSILON) { return {neighbor_info.vertex, 0}; } - double weight = geom::Math::Clamp(1.0 / (distance3D), 0.0, 100000.0); + float weight = geom::Math::Clamp(1.0f / distance3D, 0.0f, 100000.0f); // Additional weight to vertices in the same lane if(vertex_info.lane_mesh_idx == neighbor_info.lane_mesh_idx) { - weight *= SameLaneWeightMultiplier; + weight *= road_param.same_lane_weight_multiplier; // Further additional weight for fixed verices if(neighbor_info.is_static) { - weight *= LaneEndsMultiplier; + weight *= road_param.lane_ends_multiplier; } } return {neighbor_info.vertex, weight}; } // Helper function to compute neighborhoord of vertices and their weights - std::vector GetVertexNeighborhoodAndWeights(std::vector> &lane_meshes) { + std::vector GetVertexNeighborhoodAndWeights( + const MeshFactory::RoadParameters &road_param, + std::vector> &lane_meshes) { // Build rtree for neighborhood queries using Rtree = geom::PointCloudRtree; using Point = Rtree::BPoint; @@ -419,7 +421,8 @@ namespace geom { if(&vertex == vertex_info.vertex) { continue; } - auto vertex_weight = ComputeVertexWeight({&vertex, lane_mesh_idx, false}, vertex_info); + auto vertex_weight = ComputeVertexWeight( + road_param, {&vertex, lane_mesh_idx, false}, vertex_info); if(vertex_weight.weight > 0) vertex_neighborhood.neighbors.push_back(vertex_weight); } @@ -433,7 +436,7 @@ namespace geom { std::unique_ptr MeshFactory::MergeAndSmooth(std::vector> &lane_meshes) const { geom::Mesh out_mesh; - auto vertices_neighborhoods = GetVertexNeighborhoodAndWeights(lane_meshes); + auto vertices_neighborhoods = GetVertexNeighborhoodAndWeights(road_param, lane_meshes); // Laplacian function auto Laplacian = [&](const Mesh::vertex_type* vertex, const std::vector &neighbors) -> double { diff --git a/LibCarla/source/carla/geom/MeshFactory.h b/LibCarla/source/carla/geom/MeshFactory.h index 39d72216c..cc45d310e 100644 --- a/LibCarla/source/carla/geom/MeshFactory.h +++ b/LibCarla/source/carla/geom/MeshFactory.h @@ -17,7 +17,7 @@ namespace carla { namespace geom { - /// Mesh helper generator static + /// Mesh helper generator class MeshFactory { public: @@ -58,17 +58,19 @@ namespace geom { // -- Chunked -- - /// Generates list of meshes that defines a single road with a maximum length + /// Generates a list of meshes that defines a road with a maximum length std::vector> GenerateWithMaxLen( const road::Road &road) const; - /// Generates list of meshes that defines a single lane_section with a maximum length + /// Generates a list of meshes that defines a lane_section with a maximum length std::vector> GenerateWithMaxLen( const road::LaneSection &lane_section) const; + /// Generates a list of meshes that defines a road safety wall with a maximum length std::vector> GenerateWallsWithMaxLen( const road::Road &road) const; + /// Generates a list of meshes that defines a lane_section safety wall with a maximum length std::vector> GenerateWallsWithMaxLen( const road::LaneSection &lane_section) const; @@ -86,10 +88,14 @@ namespace geom { /// Parameters for the road generation struct RoadParameters { - float resolution = 2.0f; - float max_road_len = 50.0f; - float extra_lane_width = 1.0f; - float wall_height = 0.6f; + float resolution = 2.0f; + float max_road_len = 50.0f; + float extra_lane_width = 1.0f; + float wall_height = 0.6f; + // Road mesh smoothness: + float max_weight_distance = 5.0f; + float same_lane_weight_multiplier = 2.0f; + float lane_ends_multiplier = 2.0f; }; RoadParameters road_param; diff --git a/LibCarla/source/carla/rpc/OpendriveGenerationParameters.h b/LibCarla/source/carla/rpc/OpendriveGenerationParameters.h index 501091fc9..91277e28f 100644 --- a/LibCarla/source/carla/rpc/OpendriveGenerationParameters.h +++ b/LibCarla/source/carla/rpc/OpendriveGenerationParameters.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma +// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma // de Barcelona (UAB). // // This work is licensed under the terms of the MIT license.