From f060610790c07f9db40d5da1be756e24f53d9631 Mon Sep 17 00:00:00 2001 From: Sergi Hernandez Juan <shernand@iri.upc.edu> Date: Wed, 23 Aug 2023 18:10:56 +0200 Subject: [PATCH] Added functions to add junction segments with incomming, outgoing or both points not belonging to a road. --- include/junction.h | 3 ++ src/junction.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/include/junction.h b/include/junction.h index 9ddbda4..d7c7cc2 100644 --- a/include/junction.h +++ b/include/junction.h @@ -39,6 +39,9 @@ class CJunction void link_roads_by_index(unsigned int incomming_road,unsigned int outgoing_road); void unlink_roads_by_index(unsigned int incomming_road,unsigned int outgoing_road); bool are_roads_linked_by_index(unsigned int incomming_road,unsigned int outgoing_road); + CRoadSegment *link_road_to_point(unsigned int incomming_road,TPoint &outgoing_point,unsigned int outgoing_num_lanes); + CRoadSegment *link_point_to_road(TPoint &incomming_point,unsigned int incomming_num_lanes,unsigned int outgoing_road); + CRoadSegment *link_point_to_point(TPoint &incomming_point,unsigned int incomming_num_lanes,TPoint &outgoing_point,unsigned int outgoing_num_lanes); void link_lanes_by_index(unsigned int incomming_road,unsigned int lane_in,unsigned int outgoing_road,unsigned int lane_out); void unlink_lanes_by_index(unsigned int incomming_road,unsigned int lane_in,unsigned int outgoing_road,unsigned int lane_out); bool are_lanes_linked_by_index(unsigned int incomming_road,unsigned int lane_in,unsigned int outgoing_road,unsigned int lane_out); diff --git a/src/junction.cpp b/src/junction.cpp index be2db05..dff89aa 100644 --- a/src/junction.cpp +++ b/src/junction.cpp @@ -339,6 +339,81 @@ bool CJunction::are_roads_linked_by_id(unsigned int incomming_road,unsigned int return this->are_roads_linked_by_index(incomming_index,outgoing_index); } +CRoadSegment *CJunction::link_road_to_point(unsigned int incomming_road,TPoint &outgoing_point,unsigned int outgoing_num_lanes) +{ + CRoadSegment *new_segment,*in_last_segment; + TPoint start_point,end_point; + unsigned int incomming_index; + + incomming_index=CRoad::get_index_by_id(this->incomming_roads,incomming_road); + if(incomming_index<0 || incomming_index >= this->incomming_roads.size()) + throw CException(_HERE_,"Invalid incomming road index"); + /* connectivity not updated */ + /* create a new road segment */ + in_last_segment=this->incomming_roads[incomming_index]->get_last_segment(); + in_last_segment->get_end_point(start_point); + end_point=outgoing_point; + new_segment=new CRoadSegment(this->incomming_roads[incomming_index]->get_num_lanes(),outgoing_num_lanes); + new_segment->set_resolution(this->resolution); + new_segment->set_parent_junction(this); + new_segment->set_geometry(start_point,end_point); + in_last_segment->add_next_segment(new_segment); + new_segment->add_prev_segment(in_last_segment); + if(this->parent_roadmap!=NULL) + new_segment->id=this->parent_roadmap->get_next_segment_id(); + this->segments.push_back(new_segment); + + return new_segment; +} + +CRoadSegment *CJunction::link_point_to_road(TPoint &incomming_point,unsigned int incomming_num_lanes,unsigned int outgoing_road) +{ + CRoadSegment *new_segment,*out_first_segment; + TPoint start_point,end_point; + unsigned int outgoing_index; + + outgoing_index=CRoad::get_index_by_id(this->outgoing_roads,outgoing_road); + if(outgoing_index<0 || outgoing_index >= this->outgoing_roads.size()) + throw CException(_HERE_,"Invalid outgoing road index"); + /* connectivity not updated */ + /* create a new road segment */ + out_first_segment=this->outgoing_roads[outgoing_index]->get_first_segment(); + start_point=incomming_point; + out_first_segment->get_start_point(end_point); + new_segment=new CRoadSegment(incomming_num_lanes,this->outgoing_roads[outgoing_index]->get_num_lanes()); + new_segment->set_resolution(this->resolution); + new_segment->set_parent_junction(this); + new_segment->set_geometry(start_point,end_point); + new_segment->add_next_segment(out_first_segment); + out_first_segment->add_prev_segment(new_segment); + if(this->parent_roadmap!=NULL) + new_segment->id=this->parent_roadmap->get_next_segment_id(); + this->segments.push_back(new_segment); + + return new_segment; +} + +CRoadSegment *CJunction::link_point_to_point(TPoint &incomming_point,unsigned int incomming_num_lanes,TPoint &outgoing_point,unsigned int outgoing_num_lanes) +{ + CRoadSegment *new_segment; + TPoint start_point,end_point; + + /* connectivity not updated */ + /* create a new road segment */ + start_point=incomming_point; + end_point=outgoing_point; + new_segment=new CRoadSegment(incomming_num_lanes,outgoing_num_lanes); + new_segment->set_resolution(this->resolution); + new_segment->set_parent_junction(this); + new_segment->set_geometry(start_point,end_point); + if(this->parent_roadmap!=NULL) + new_segment->id=this->parent_roadmap->get_next_segment_id(); + this->segments.push_back(new_segment); + + return new_segment; +} + + void CJunction::link_lanes_by_index(unsigned int incomming_road,unsigned int lane_in,unsigned int outgoing_road,unsigned int lane_out) { CRoadSegment *segment; -- GitLab