Some PR fixes

This commit is contained in:
Marc Garcia Puig 2020-04-10 13:01:06 +02:00 committed by bernat
parent b28cb75273
commit 487d4e678b
3 changed files with 31 additions and 22 deletions

View File

@ -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<double>::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<float>(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<VertexNeighbors> GetVertexNeighborhoodAndWeights(std::vector<std::unique_ptr<Mesh>> &lane_meshes) {
std::vector<VertexNeighbors> GetVertexNeighborhoodAndWeights(
const MeshFactory::RoadParameters &road_param,
std::vector<std::unique_ptr<Mesh>> &lane_meshes) {
// Build rtree for neighborhood queries
using Rtree = geom::PointCloudRtree<VertexInfo>;
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<Mesh> MeshFactory::MergeAndSmooth(std::vector<std::unique_ptr<Mesh>> &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<VertexWeight> &neighbors) -> double {

View File

@ -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<std::unique_ptr<Mesh>> 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<std::unique_ptr<Mesh>> GenerateWithMaxLen(
const road::LaneSection &lane_section) const;
/// Generates a list of meshes that defines a road safety wall with a maximum length
std::vector<std::unique_ptr<Mesh>> GenerateWallsWithMaxLen(
const road::Road &road) const;
/// Generates a list of meshes that defines a lane_section safety wall with a maximum length
std::vector<std::unique_ptr<Mesh>> 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;

View File

@ -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.