From 2ab3c4b0986040c808cb8f1fa82029be9f760070 Mon Sep 17 00:00:00 2001
From: Sergi Hernandez Juan <shernand@iri.upc.edu>
Date: Thu, 17 Dec 2020 18:21:38 +0100
Subject: [PATCH] Added the link to the previous segment.

---
 src/opendrive_road.cpp         | 2 --
 src/opendrive_road_segment.cpp | 8 ++++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/opendrive_road.cpp b/src/opendrive_road.cpp
index ae0ca2e..b0c67e4 100644
--- a/src/opendrive_road.cpp
+++ b/src/opendrive_road.cpp
@@ -137,7 +137,6 @@ void COpendriveRoad::load(const std::string &filename)
       // link segments
       this->link_segments(*open_drive);
       // process junctions
-/*
       for(OpenDRIVE::junction_iterator junction_it(open_drive->junction().begin());junction_it!=open_drive->junction().end();++junction_it)
       {
         for(junction::connection_iterator connection_it(junction_it->connection().begin()); connection_it!=junction_it->connection().end();++connection_it)
@@ -182,7 +181,6 @@ void COpendriveRoad::load(const std::string &filename)
           }
         }
       }
-          */
     }catch (const xml_schema::exception& e){
       std::ostringstream os;
       os << e;
diff --git a/src/opendrive_road_segment.cpp b/src/opendrive_road_segment.cpp
index c021614..9fc73a2 100644
--- a/src/opendrive_road_segment.cpp
+++ b/src/opendrive_road_segment.cpp
@@ -274,7 +274,11 @@ 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
       return;
+  for(unsigned int i=0;i<segment.prev.size();i++)
+    if(segment.prev[i]->get_id()==this->id)
+      return;
   this->next.push_back(&segment);
+  segment.prev.push_back(this);
   // link lanes
   for(int i=-this->num_right_lanes;i<0;i++)
   {
@@ -313,7 +317,11 @@ void COpendriveRoadSegment::link_segment(COpendriveRoadSegment &segment,int from
   for(unsigned int i=0;i<this->next.size();i++)
     if(this->next[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)
+      return;
   this->next.push_back(&segment);
+  segment.prev.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);
-- 
GitLab