From 87b0acff13e719090cb2d2a8188a3b9a656beb12 Mon Sep 17 00:00:00 2001 From: Sergi Hernandez Juan <shernand@iri.upc.edu> Date: Fri, 26 Jan 2024 12:01:14 +0100 Subject: [PATCH] Added an external parameter to set the default lane width. --- include/osm/osm_common.h | 2 +- include/osm/osm_map.h | 1 + include/osm/osm_way.h | 1 + src/examples/osm_import_test.cpp | 2 ++ src/osm/osm_map.cpp | 10 ++++++++++ src/osm/osm_way.cpp | 11 ++++++++--- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/osm/osm_common.h b/include/osm/osm_common.h index dcbf364..5059365 100644 --- a/include/osm/osm_common.h +++ b/include/osm/osm_common.h @@ -1,7 +1,6 @@ #ifndef _OSM_COMMON_H #define _OSM_COMMON_H -#define DEFAULT_LANE_WIDTH 4.0 #define DEFAULT_MIN_TURN_RADIUS 5.0 #define DEFAULT_MIN_ROAD_LENGTH 0.5 @@ -14,6 +13,7 @@ typedef struct{ std::vector<std::string> keys; double min_turn_radius; double min_road_length; + double default_lane_width; bool use_default_lane_width; bool force_two_ways; }TOSMPathData; diff --git a/include/osm/osm_map.h b/include/osm/osm_map.h index c019d18..b425121 100644 --- a/include/osm/osm_map.h +++ b/include/osm/osm_map.h @@ -54,6 +54,7 @@ class COSMMap : public osmium::handler::Handler bool add_path_type(TOSMPathData &path_data); double get_min_turn_radius(std::string &path_type); double get_min_road_length(std::string &path_type); + double get_default_lane_width(std::string &path_type); bool use_default_lane_width(std::string &path_type); bool force_two_ways(std::string &path_type); void node(const osmium::Node& node); diff --git a/include/osm/osm_way.h b/include/osm/osm_way.h index 54d928f..f3f2745 100644 --- a/include/osm/osm_way.h +++ b/include/osm/osm_way.h @@ -65,6 +65,7 @@ class COSMWay std::string get_type(void); double get_min_turn_radius(void); double get_min_road_length(void); + double get_default_lane_width(void); bool use_default_lane_width(void); bool force_two_ways(void); unsigned int get_num_nodes(void); diff --git a/src/examples/osm_import_test.cpp b/src/examples/osm_import_test.cpp index b7ba71a..d88250e 100644 --- a/src/examples/osm_import_test.cpp +++ b/src/examples/osm_import_test.cpp @@ -20,6 +20,7 @@ int main(int argc, char *argv[]) osm_paths[0].name="roads"; osm_paths[0].min_turn_radius=DEFAULT_MIN_TURN_RADIUS; osm_paths[0].min_road_length=DEFAULT_MIN_ROAD_LENGTH; + osm_paths[0].default_lane_width=4.0; osm_paths[0].use_default_lane_width=true; osm_paths[0].force_two_ways=false; osm_paths[0].highways.push_back("motorway"); @@ -41,6 +42,7 @@ int main(int argc, char *argv[]) osm_paths[1].min_turn_radius=DEFAULT_MIN_TURN_RADIUS; osm_paths[1].min_road_length=DEFAULT_MIN_ROAD_LENGTH; osm_paths[1].use_default_lane_width=true; + osm_paths[1].default_lane_width=0.1; osm_paths[1].force_two_ways=true; osm_paths[1].highways.push_back("pedestrian"); map.load_osm(osm_file,osm_paths); diff --git a/src/osm/osm_map.cpp b/src/osm/osm_map.cpp index ed0872d..be755bd 100644 --- a/src/osm/osm_map.cpp +++ b/src/osm/osm_map.cpp @@ -289,6 +289,7 @@ bool COSMMap::add_path_type(TOSMPathData &path_data) new_path_type.data.min_turn_radius=path_data.min_turn_radius; new_path_type.data.min_road_length=path_data.min_road_length; new_path_type.data.use_default_lane_width=path_data.use_default_lane_width; + new_path_type.data.default_lane_width=path_data.default_lane_width; new_path_type.data.force_two_ways=path_data.force_two_ways; for(unsigned int i=0;i<path_data.highways.size();i++) { @@ -348,6 +349,15 @@ double COSMMap::get_min_road_length(std::string &path_type) throw CException(_HERE_,"The given path type does not exist"); } +double COSMMap::get_default_lane_width(std::string &path_type) +{ + for(unsigned int i=0;i<this->path_types.size();i++) + if(this->path_types[i].data.name==path_type) + return this->path_types[i].data.default_lane_width; + + throw CException(_HERE_,"The given path type does not exist"); +} + bool COSMMap::use_default_lane_width(std::string &path_type) { for(unsigned int i=0;i<this->path_types.size();i++) diff --git a/src/osm/osm_way.cpp b/src/osm/osm_way.cpp index 91cceca..603e408 100644 --- a/src/osm/osm_way.cpp +++ b/src/osm/osm_way.cpp @@ -93,12 +93,12 @@ COSMWay::COSMWay(const osmium::Way &way,COSMMap *parent,std::string &type) } // get the road width if(parent->use_default_lane_width(type)) - this->lane_width=DEFAULT_LANE_WIDTH; + this->lane_width=parent->get_default_lane_width(type); else { value=way.get_value_by_key("width"); if(value==NULL) - this->lane_width=DEFAULT_LANE_WIDTH; + this->lane_width=parent->get_default_lane_width(type); else this->lane_width=std::stof(std::string(value))/(this->num_forward_lanes+this->num_backward_lanes); } @@ -542,6 +542,11 @@ double COSMWay::get_min_road_length(void) return this->parent->get_min_road_length(this->type); } +double COSMWay::get_default_lane_width(void) +{ + return this->parent->get_default_lane_width(this->type); +} + bool COSMWay::use_default_lane_width(void) { return this->parent->use_default_lane_width(this->type); @@ -804,7 +809,7 @@ lane_restrictions_t COSMWay::get_lane_restriction(unsigned int index) double COSMWay::get_lane_width(void) { if(this->lane_width==-1.0) - return DEFAULT_LANE_WIDTH; + return this->get_default_lane_width(); else return this->lane_width; } -- GitLab