Browse Source

change opendrive, complete crosspass.

yuchuli 1 year ago
parent
commit
428e67c73b

+ 113 - 0
src/common/common/xodr/OpenDrive/OpenDriveXmlParser.cpp

@@ -3033,6 +3033,14 @@ bool OpenDriveXmlParser::ReadJunction (TiXmlElement *node)
 		subNode=subNode->NextSiblingElement("controller");
 	}
 
+    subNode =  node->FirstChildElement("crossPath");
+
+    while(subNode)
+    {
+        ReadJunctionCrossPass(junction,subNode);
+        subNode=subNode->NextSiblingElement("crossPath");
+    }
+
 
 	return true;
 	
@@ -3122,6 +3130,111 @@ bool OpenDriveXmlParser::ReadJunctionController (Junction* junction, TiXmlElemen
 	return true;
 }
 
+bool OpenDriveXmlParser::ReadJunctionCrossPass(Junction * junction, TiXmlElement *node)
+{
+    string strId;
+    string strcrossingRoad;
+    string strroadAtStart;
+    string strroadAtEnd;
+    JunctionCrossPathStartLaneLink startLaneLink;
+    JunctionCrossPathEndLaneLink endLaneLink;
+    int checker=TIXML_SUCCESS;
+    checker+=node->QueryStringAttribute("id",&strId);
+    checker+=node->QueryStringAttribute("crossingRoad",&strcrossingRoad);
+    checker+=node->QueryStringAttribute("roadAtStart",&strroadAtStart);
+    checker+=node->QueryStringAttribute("roadAtEnd",&strroadAtEnd);
+    if (checker!=TIXML_SUCCESS)
+    {
+        cout<<"Error parsing Junction CrossPass attributes"<<endl;
+        return false;
+    }
+
+    TiXmlElement *subNode=node->FirstChildElement("startLaneLink");
+
+    if (subNode)
+    {
+        if(ReadJunctionCrossPassStartLaneLink(startLaneLink,subNode))
+        {
+
+        }
+        else
+        {
+            return false;
+        }
+    }
+    else
+    {
+        cout<<"Error parsing Junction CrossPass, no startlanelink attributes."<<endl;
+    }
+
+    subNode=node->FirstChildElement("endLaneLink");
+
+    if (subNode)
+    {
+        if(ReadJunctionCrossPassEndLaneLink(endLaneLink,subNode))
+        {
+
+        }
+        else
+        {
+            return false;
+        }
+    }
+    else
+    {
+        cout<<"Error parsing Junction CrossPass, no startlanelink attributes."<<endl;
+    }
+
+    junction->AddJunctionCrossPath(strId,strcrossingRoad,strroadAtStart,strroadAtEnd,startLaneLink,endLaneLink);
+
+    return true;
+}
+
+bool OpenDriveXmlParser::ReadJunctionCrossPassStartLaneLink(JunctionCrossPathStartLaneLink & startLaneLink,TiXmlElement * node)
+{
+    double s;
+    int nFrom;
+    int nTo;
+
+    int checker=TIXML_SUCCESS;
+    checker+=node->QueryDoubleAttribute("s",&s);
+    checker+=node->QueryIntAttribute("from",&nFrom);
+    checker+=node->QueryIntAttribute("to",&nTo);
+    if (checker!=TIXML_SUCCESS)
+    {
+        cout<<"Error parsing Junction CrossPass StartLaneLink attributes"<<endl;
+        return false;
+    }
+
+    startLaneLink.SetS(s);
+    startLaneLink.SetFrom(nFrom);
+    startLaneLink.SetTo(nTo);
+    return true;
+
+}
+
+bool OpenDriveXmlParser::ReadJunctionCrossPassEndLaneLink(JunctionCrossPathEndLaneLink & endLaneLink,TiXmlElement * node)
+{
+    double s;
+    int nFrom;
+    int nTo;
+
+    int checker=TIXML_SUCCESS;
+    checker+=node->QueryDoubleAttribute("s",&s);
+    checker+=node->QueryIntAttribute("from",&nFrom);
+    checker+=node->QueryIntAttribute("to",&nTo);
+    if (checker!=TIXML_SUCCESS)
+    {
+        cout<<"Error parsing Junction CrossPass EndLaneLink attributes"<<endl;
+        return false;
+    }
+
+    endLaneLink.SetS(s);
+    endLaneLink.SetFrom(nFrom);
+    endLaneLink.SetTo(nTo);
+    return true;
+}
+
 
 //---------------------------------------------------------------------------
 /**

+ 3 - 0
src/common/common/xodr/OpenDrive/OpenDriveXmlParser.h

@@ -134,6 +134,9 @@ public:
 
 	bool ReadJunctionPriority (Junction* junction, TiXmlElement *node);
 	bool ReadJunctionController (Junction* junction, TiXmlElement *node);
+    bool ReadJunctionCrossPass(Junction * junction, TiXmlElement *node);
+    bool ReadJunctionCrossPassStartLaneLink(JunctionCrossPathStartLaneLink & startLaneLink,TiXmlElement * node);
+    bool ReadJunctionCrossPassEndLaneLink(JunctionCrossPathEndLaneLink & endLaneLink,TiXmlElement * node);
 	//--------------
 
     bool ParseGeoReferenceLon0Lat0(std::string strgr, double & lon0,double & lat0);

+ 82 - 0
src/common/common/xodr/OpenDrive/OpenDriveXmlWriter.cpp

@@ -2434,6 +2434,9 @@ bool OpenDriveXmlWriter::WriteJunction (TiXmlElement *node, Junction *junction)
 	//Controllers
 	WriteJunctionController(nodeJunction, junction);
 
+    //CrossPass
+    WriteJunctionCrossPass(nodeJunction,junction);
+
 	return true;
 }
 //--------------
@@ -2534,6 +2537,85 @@ bool OpenDriveXmlWriter::WriteJunctionController (TiXmlElement *node, Junction*
 	return true;
 }
 
+bool OpenDriveXmlWriter::WriteJunctionCrossPass(TiXmlElement *node, Junction* junction)
+{
+    string strId;
+    string strcrossingRoad;
+    string strroadAtStart;
+    string strroadAtEnd;
+
+
+    unsigned int junctionCrossPassCount = junction->GetJunctionCrossPathCount();
+    for(unsigned i=0;i<junctionCrossPassCount;i++)
+    {
+        JunctionCrossPath *lJunctionCrossPass = junction->GetJunctionCrossPath(i);
+
+        strId = lJunctionCrossPass->GetId();
+        strcrossingRoad = lJunctionCrossPass->GetcrossingRoad();
+        strroadAtStart = lJunctionCrossPass->GetroadAtStart();
+        strroadAtEnd = lJunctionCrossPass->GetroadAtEnd();
+
+        TiXmlElement * nodeJunctionCrossPass = new TiXmlElement("crossPath");
+        node->LinkEndChild(nodeJunctionCrossPass);
+
+        nodeJunctionCrossPass->SetAttribute("id",strId);
+        nodeJunctionCrossPass->SetAttribute("crossingRoad",strcrossingRoad);
+        nodeJunctionCrossPass->SetAttribute("roadAtStart",strroadAtStart);
+        nodeJunctionCrossPass->SetAttribute("roadAtEnd",strroadAtEnd);
+
+        WriteJunctionCrossPassStartLaneLink(nodeJunctionCrossPass,lJunctionCrossPass);
+        WriteJunctionCrossPassEndLaneLink(nodeJunctionCrossPass,lJunctionCrossPass);
+
+    }
+    return true;
+}
+
+bool OpenDriveXmlWriter::WriteJunctionCrossPassStartLaneLink(TiXmlElement *node, JunctionCrossPath* junctionCrossPass)
+{
+    JunctionCrossPathStartLaneLink startLaneLink;
+    startLaneLink = junctionCrossPass->GetstartLaneLink();
+
+    double s;
+    int nFrom;
+    int nTo;
+
+    s = startLaneLink.GetS();
+    nFrom = startLaneLink.GetFrom();
+    nTo = startLaneLink.GetTo();
+
+    TiXmlElement * nodeJunctionCrossPassStartLaneLink = new TiXmlElement("startLaneLink");
+    node->LinkEndChild(nodeJunctionCrossPassStartLaneLink);
+
+    nodeJunctionCrossPassStartLaneLink->SetDoubleAttribute("s",s);
+    nodeJunctionCrossPassStartLaneLink->SetAttribute("from",nFrom);
+    nodeJunctionCrossPassStartLaneLink->SetAttribute("to",nTo);
+
+    return true;
+}
+
+bool OpenDriveXmlWriter::WriteJunctionCrossPassEndLaneLink(TiXmlElement *node, JunctionCrossPath* junctionCrossPass)
+{
+    JunctionCrossPathEndLaneLink endLaneLink;
+    endLaneLink = junctionCrossPass->GetendLaneLink();
+
+    double s;
+    int nFrom;
+    int nTo;
+
+    s = endLaneLink.GetS();
+    nFrom = endLaneLink.GetFrom();
+    nTo = endLaneLink.GetTo();
+
+    TiXmlElement * nodeJunctionCrossPassEndLaneLink = new TiXmlElement("endLaneLink");
+    node->LinkEndChild(nodeJunctionCrossPassEndLaneLink);
+
+    nodeJunctionCrossPassEndLaneLink->SetDoubleAttribute("s",s);
+    nodeJunctionCrossPassEndLaneLink->SetAttribute("from",nFrom);
+    nodeJunctionCrossPassEndLaneLink->SetAttribute("to",nTo);
+
+    return true;
+}
+
 
 //---------------------------------------------------------------------------
 

+ 3 - 0
src/common/common/xodr/OpenDrive/OpenDriveXmlWriter.h

@@ -129,6 +129,9 @@ public:
 
 	bool WriteJunctionPriority (TiXmlElement *node, Junction* junction);
 	bool WriteJunctionController (TiXmlElement *node, Junction* junction);
+    bool WriteJunctionCrossPass(TiXmlElement *node, Junction* junction);
+    bool WriteJunctionCrossPassStartLaneLink(TiXmlElement *node, JunctionCrossPath* junctionCrossPass);
+    bool WriteJunctionCrossPassEndLaneLink(TiXmlElement *node, JunctionCrossPath* junctionCrossPass);
 	//--------------
 };
 

+ 2 - 2
src/common/common/xodr/OpenDrive/Road.cpp

@@ -2474,7 +2474,7 @@ double Road::GetDis(const double x,const double y, const double hdg, double & fR
                     if(fvectorwidth.size()>0)
                     {
                         unsigned int i;
-                        unsigned int nwidthsize = fvectorwidth.size();
+                        unsigned int nwidthsize =  static_cast<unsigned int>(fvectorwidth.size()) ;
                         for(i=0;i<nwidthsize;i++)
                         {
                             frealdis = frealdis - fvectorwidth[i];
@@ -2496,7 +2496,7 @@ double Road::GetDis(const double x,const double y, const double hdg, double & fR
                     if(fvectorwidth.size()>0)
                     {
                         unsigned int i;
-                        unsigned int nwidthsize = fvectorwidth.size();
+                        unsigned int nwidthsize = static_cast<unsigned int>(fvectorwidth.size()) ;
                         for(i=0;i<nwidthsize;i++)
                         {
                             frealdis = frealdis - fvectorwidth[i];