From 6e240acaf8039c45c1f8d7a6cf92a1266e0abe1d Mon Sep 17 00:00:00 2001 From: Sergi Hernandez Juan <shernand@iri.upc.edu> Date: Thu, 17 Dec 2020 18:33:33 +0100 Subject: [PATCH] Fused the next and previous road segments to a single vector (connecting roads). --- include/opendrive_road_segment.h | 9 ++-- src/opendrive_road_segment.cpp | 88 +++++++++++--------------------- 2 files changed, 34 insertions(+), 63 deletions(-) diff --git a/include/opendrive_road_segment.h b/include/opendrive_road_segment.h index 712f1ee..fd83131 100644 --- a/include/opendrive_road_segment.h +++ b/include/opendrive_road_segment.h @@ -23,8 +23,7 @@ class COpendriveRoadSegment int num_left_lanes; std::vector<COpendriveSignal *> signals; std::vector<COpendriveObject *> objects; - std::vector<COpendriveRoadSegment *> next; - std::vector<COpendriveRoadSegment *> prev; + std::vector<COpendriveRoadSegment *> connecting; std::string name; unsigned int id; protected: @@ -51,10 +50,8 @@ class COpendriveRoadSegment const COpendriveSignal &get_signal(unsigned int index) const; unsigned int get_num_obstacles(void) const; const COpendriveObject &get_object(unsigned int index) const; - unsigned int get_num_previous(void) const; - const COpendriveRoadSegment &get_previous(unsigned int index) const; - unsigned int get_num_next(void) const; - const COpendriveRoadSegment &get_next(unsigned int index) const; + unsigned int get_num_connecting(void) const; + const COpendriveRoadSegment &get_connecting(unsigned int index) const; void operator=(const COpendriveRoadSegment &object); friend std::ostream& operator<<(std::ostream& out, COpendriveRoadSegment &segment); ~COpendriveRoadSegment(); diff --git a/src/opendrive_road_segment.cpp b/src/opendrive_road_segment.cpp index 9fc73a2..8f64af0 100644 --- a/src/opendrive_road_segment.cpp +++ b/src/opendrive_road_segment.cpp @@ -10,8 +10,7 @@ COpendriveRoadSegment::COpendriveRoadSegment() this->num_right_lanes=0; this->signals.clear(); this->objects.clear(); - this->next.clear(); - this->prev.clear(); + this->connecting.clear(); this->min_road_length=DEFAULT_MIN_ROAD_LENGTH; this->resolution=DEFAULT_RESOLUTION; this->scale_factor=DEFAULT_SCALE_FACTOR; @@ -44,12 +43,9 @@ COpendriveRoadSegment::COpendriveRoadSegment(const COpendriveRoadSegment &object new_object=new COpendriveObject(*object.objects[i]); this->objects.push_back(new_object); } - this->next.resize(object.next.size()); - for(unsigned int i=0;i<object.next.size();i++) - this->next[i]=object.next[i]; - this->next.resize(object.prev.size()); - for(unsigned int i=0;i<object.prev.size();i++) - this->prev[i]=object.prev[i]; + this->connecting.resize(object.connecting.size()); + for(unsigned int i=0;i<object.connecting.size();i++) + this->connecting[i]=object.connecting[i]; this->resolution=object.resolution; this->scale_factor=object.scale_factor; this->min_road_length=object.min_road_length; @@ -77,8 +73,7 @@ void COpendriveRoadSegment::free(void) this->objects[i]=NULL; } this->objects.clear(); - this->next.clear(); - this->prev.clear(); + this->connecting.clear(); } void COpendriveRoadSegment::set_resolution(double res) @@ -108,10 +103,8 @@ void COpendriveRoadSegment::set_min_road_length(double length) void COpendriveRoadSegment::update_references(std::map<COpendriveRoadSegment *,COpendriveRoadSegment *> refs) { - for(unsigned int i=0;i<this->next.size();i++) - this->next[i]=refs[this->next[i]]; - for(unsigned int i=0;i<this->prev.size();i++) - this->prev[i]=refs[this->prev[i]]; + for(unsigned int i=0;i<this->connecting.size();i++) + this->connecting[i]=refs[this->connecting[i]]; for(unsigned int i=0;i<this->lanes.size();i++) this->lanes[i]->update_references(refs); @@ -271,14 +264,14 @@ void COpendriveRoadSegment::link_neightbour_lanes(lanes::laneSection_type &lane_ void COpendriveRoadSegment::link_segment(COpendriveRoadSegment &segment) { - for(unsigned int i=0;i<this->next.size();i++) - if(this->next[i]->get_id()==segment.get_id())// the segment is already included + for(unsigned int i=0;i<this->connecting.size();i++) + if(this->connecting[i]->get_id()==segment.get_id())// the segment is already included return; - for(unsigned int i=0;i<segment.prev.size();i++) - if(segment.prev[i]->get_id()==this->id) + for(unsigned int i=0;i<segment.connecting.size();i++) + if(segment.connecting[i]->get_id()==this->id) return; - this->next.push_back(&segment); - segment.prev.push_back(this); + this->connecting.push_back(&segment); + segment.connecting.push_back(this); // link lanes for(int i=-this->num_right_lanes;i<0;i++) { @@ -314,14 +307,14 @@ void COpendriveRoadSegment::link_segment(COpendriveRoadSegment &segment) void COpendriveRoadSegment::link_segment(COpendriveRoadSegment &segment,int from, int to) { - for(unsigned int i=0;i<this->next.size();i++) - if(this->next[i]->get_id()==segment.get_id())// the segment is already included + for(unsigned int i=0;i<this->connecting.size();i++) + if(this->connecting[i]->get_id()==segment.get_id())// the segment is already included return; - for(unsigned int i=0;i<segment.prev.size();i++) - if(segment.prev[i]->get_id()==this->id) + for(unsigned int i=0;i<segment.connecting.size();i++) + if(segment.connecting[i]->get_id()==this->id) return; - this->next.push_back(&segment); - segment.prev.push_back(this); + this->connecting.push_back(&segment); + segment.connecting.push_back(this); // link lanes if(this->lanes.find(from)!=this->lanes.end() && segment.lanes.find(to)!=segment.lanes.end()) this->lanes[from]->link_lane(segment.lanes[to],OD_MARK_NONE); @@ -433,30 +426,17 @@ const COpendriveObject &COpendriveRoadSegment::get_object(unsigned int index) co throw CException(_HERE_,"Invalid object index"); } -unsigned int COpendriveRoadSegment::get_num_previous(void) const +unsigned int COpendriveRoadSegment::get_num_connecting(void) const { - return this->prev.size(); + return this->connecting.size(); } -const COpendriveRoadSegment &COpendriveRoadSegment::get_previous(unsigned int index) const +const COpendriveRoadSegment &COpendriveRoadSegment::get_connecting(unsigned int index) const { - if(index>=0 && index<this->prev.size()) - return *this->prev[index]; + if(index>=0 && index<this->connecting.size()) + return *this->connecting[index]; else - throw CException(_HERE_,"Invalid previous segment index"); -} - -unsigned int COpendriveRoadSegment::get_num_next(void) const -{ - return this->next.size(); -} - -const COpendriveRoadSegment &COpendriveRoadSegment::get_next(unsigned int index) const -{ - if(index>=0 && index<this->next.size()) - return *this->next[index]; - else - throw CException(_HERE_,"Invalid next segment index"); + throw CException(_HERE_,"Invalid connecting segment index"); } void COpendriveRoadSegment::operator=(const COpendriveRoadSegment &object) @@ -484,12 +464,9 @@ void COpendriveRoadSegment::operator=(const COpendriveRoadSegment &object) new_object=new COpendriveObject(*object.objects[i]); this->objects.push_back(new_object); } - this->next.resize(object.next.size()); - for(unsigned int i=0;i<object.next.size();i++) - this->next[i]=object.next[i]; - this->next.resize(object.prev.size()); - for(unsigned int i=0;i<object.prev.size();i++) - this->prev[i]=object.prev[i]; + this->connecting.resize(object.connecting.size()); + for(unsigned int i=0;i<object.connecting.size();i++) + this->connecting[i]=object.connecting[i]; this->resolution=object.resolution; this->scale_factor=object.scale_factor; this->min_road_length=object.min_road_length; @@ -498,12 +475,9 @@ void COpendriveRoadSegment::operator=(const COpendriveRoadSegment &object) std::ostream& operator<<(std::ostream& out, COpendriveRoadSegment &segment) { out << "Road " << segment.get_name() << " (" << segment.get_id() << ")" << std::endl; - out << " Previous road segments: " << segment.prev.size() << std::endl; - for(unsigned int i=0;i<segment.prev.size();i++) - out << " " << segment.prev[i]->get_name() << std::endl; - out << " Next road segments: " << segment.next.size() << std::endl; - for(unsigned int i=0;i<segment.next.size();i++) - out << " " << segment.next[i]->get_name() << std::endl; + out << " Connecting road segments: " << segment.connecting.size() << std::endl; + for(unsigned int i=0;i<segment.connecting.size();i++) + out << " " << segment.connecting[i]->get_name() << std::endl; out << " Number of right lanes: " << segment.num_right_lanes << std::endl; for(int i=-1;i>=-segment.num_right_lanes;i--) out << *segment.lanes[i]; -- GitLab