Browse Source

change opendrive. code for 1.8 standard. add juction elevation grid and boundary.

yuchuli 1 year ago
parent
commit
4a9c2b88e8

+ 140 - 0
src/common/common/xodr/OpenDrive/Junction.cpp

@@ -507,6 +507,20 @@ void Junction::SetJunctionboundary(Junctionboundary boundary)
     mJunctionboundary.clear();
     mJunctionboundary.push_back(boundary);
 }
+
+int Junction::GetJunctionelevationGrid(JunctionelevationGrid & elevationGrid)
+{
+    if(mJunctionelevationGrid.size() == 0)return 0;
+    elevationGrid = mJunctionelevationGrid[0];
+    return 1;
+}
+
+void Junction::SetJunctionelevationGrid(JunctionelevationGrid elevationGrid)
+{
+    mJunctionelevationGrid.clear();
+    mJunctionelevationGrid.push_back(elevationGrid);
+}
+
 //--------------
 
 
@@ -1542,3 +1556,129 @@ Junctionboundarysegmentjoint * Junctionboundary::GetLastAddedJunctionboundaryseg
 
 }
 
+JunctionelevationGrid::JunctionelevationGrid(double gridSpacing, double sStart)
+{
+    mgridSpacing = gridSpacing;
+    msStart = sStart;
+}
+
+JunctionelevationGrid::JunctionelevationGrid()
+{
+
+}
+
+double JunctionelevationGrid::GetgridSpacing()
+{
+    return mgridSpacing;
+}
+
+double JunctionelevationGrid::GetsStart()
+{
+    return msStart;
+}
+
+
+void JunctionelevationGrid::SetgridSpacing(double gridSpacing)
+{
+    mgridSpacing = gridSpacing;
+}
+
+void JunctionelevationGrid::SetsStart(double sStart)
+{
+    msStart = sStart;
+}
+
+unsigned int JunctionelevationGrid::Addelevation(string center)
+{
+    melevationvector.push_back(JunctionelevationGridelevation(center));
+    mLastAddedelevation = melevationvector.size()-1;
+    return mLastAddedelevation;
+}
+
+unsigned int JunctionelevationGrid::Cloneelevation(unsigned int index)
+{
+    if(index<melevationvector.size()-1)
+        melevationvector.insert(melevationvector.begin()+index+1, melevationvector[index]);
+    else if(index==melevationvector.size()-1)
+        melevationvector.push_back(melevationvector[index]);
+    mLastAddedelevation=index+1;
+    return mLastAddedelevation;
+}
+
+void JunctionelevationGrid::Deleteelevation(unsigned int index)
+{
+    melevationvector.erase(melevationvector.begin()+index);
+}
+
+std::vector<JunctionelevationGridelevation>* JunctionelevationGrid::GetelevationVector()
+{
+    return &melevationvector;
+}
+
+unsigned int JunctionelevationGrid::GetelevationCount()
+{
+    return melevationvector.size();
+}
+
+JunctionelevationGridelevation * JunctionelevationGrid::Getelevation(unsigned int i)
+{
+    return &melevationvector.at(i);
+}
+
+JunctionelevationGridelevation * JunctionelevationGrid::GetLastelevation()
+{
+    if(melevationvector.size()>0)
+        return &melevationvector.at(melevationvector.size()-1);
+    else
+        return NULL;
+}
+
+JunctionelevationGridelevation * JunctionelevationGrid::GetLastAddedelevation()
+{
+    if(mLastAddedelevation<melevationvector.size())
+        return &melevationvector.at(mLastAddedelevation);
+    else
+        return NULL;
+}
+
+JunctionelevationGridelevation::JunctionelevationGridelevation(string center)
+{
+    mcenter = center;
+}
+
+string JunctionelevationGridelevation::Getcenter()
+{
+    return mcenter;
+}
+
+void JunctionelevationGridelevation::Setcenter(string center)
+{
+    mcenter = center;
+}
+
+int JunctionelevationGridelevation::Getleft(string & left)
+{
+    if(mleft.size() == 0)return 0;
+    left = mleft[0];
+    return 1;
+}
+
+int JunctionelevationGridelevation::Getright(string & right)
+{
+    if(mright.size() == 0)return 0;
+    right = mright[0];
+    return 1;
+}
+
+void JunctionelevationGridelevation::Setleft(string left)
+{
+    mleft.clear();
+    mleft.push_back(left);
+}
+
+void JunctionelevationGridelevation::Setright(string right)
+{
+    mright.clear();
+    mright.push_back(right);
+}
+

+ 62 - 0
src/common/common/xodr/OpenDrive/Junction.h

@@ -24,6 +24,9 @@ class JunctionplanView;
 
 class Junctionboundary;
 
+class JunctionelevationGrid;
+class JunctionelevationGridelevation;
+
 /**
  * Junction class. Holds all the junction information
  *
@@ -59,6 +62,8 @@ private:
 
     std::vector<Junctionboundary> mJunctionboundary;
 
+    std::vector<JunctionelevationGrid> mJunctionelevationGrid;
+
 public:
 
 	/**
@@ -289,6 +294,9 @@ public:
     int GetJunctionboundary(Junctionboundary & boundary);
     void SetJunctionboundary(Junctionboundary boundary);
 
+    int GetJunctionelevationGrid(JunctionelevationGrid & elevationGrid);
+    void SetJunctionelevationGrid(JunctionelevationGrid elevationGrid);
+
 
 };
 
@@ -957,6 +965,60 @@ public:
 };
 
 
+class JunctionelevationGrid
+{
+private:
+    double mgridSpacing;
+    double msStart;
+
+    std::vector<JunctionelevationGridelevation> melevationvector;
+    unsigned int mLastAddedelevation;
+
+public:
+    JunctionelevationGrid(double gridSpacing, double sStart);
+    JunctionelevationGrid();
+
+    double GetgridSpacing();
+    double GetsStart();
+
+    void SetgridSpacing(double gridSpacing);
+    void SetsStart(double sStart);
+
+    unsigned int Addelevation(string center);
+    unsigned int Cloneelevation(unsigned int index);
+    void Deleteelevation(unsigned int index);
+    std::vector<JunctionelevationGridelevation>* GetelevationVector();
+    unsigned int GetelevationCount();
+    JunctionelevationGridelevation * Getelevation(unsigned int i);
+    JunctionelevationGridelevation * GetLastelevation();
+    JunctionelevationGridelevation * GetLastAddedelevation();
+
+};
+
+class JunctionelevationGridelevation
+{
+private:
+    std::vector<string> mleft;
+    string mcenter;
+    std::vector<string> mright;
+
+public:
+    JunctionelevationGridelevation(string center);
+
+    string Getcenter();
+    void Setcenter(string center);
+
+    int Getleft(string & left);
+    int Getright(string & right);
+
+    void Setleft(string left);
+    void Setright(string right);
+
+
+
+};
+
+
 
 
 

+ 152 - 21
src/common/common/xodr/OpenDrive/OpenDriveXmlParser.cpp

@@ -3083,6 +3083,21 @@ bool OpenDriveXmlParser::ReadJunction (TiXmlElement *node)
         ReadJunctionplanView(junction,subNode);
     }
 
+    subNode=node->FirstChildElement("boundary");
+
+    if(subNode)
+    {
+        ReadJunctionboundary(junction,subNode);
+    }
+
+    subNode=node->FirstChildElement("elevationGrid");
+
+    if(subNode)
+    {
+        ReadJunctionelevationGrid(junction,subNode);
+    }
+
+
 
 	return true;
 	
@@ -3308,21 +3323,35 @@ bool OpenDriveXmlParser::ReadJunctionplanViewgeometry(JunctionplanView* planView
 
 bool OpenDriveXmlParser::ReadJunctionboundary(Junction* junction, TiXmlElement *node)
 {
-    TiXmlElement *subNode=node->FirstChildElement("boundary");
-
-    if(subNode == NULL)return false;
 
     Junctionboundary boundary;
 
+    ReadJunctionboundarysegment(&boundary,node);
+
+    TiXmlElement *subNode=node->FirstChildElement("segment");
+
+    while(subNode)
+    {
+        ReadJunctionboundarysegment(&boundary,subNode);
+        subNode=node->NextSiblingElement("segment");
+    }
+
+    if((boundary.GetJunctionboundarysegmentjointCount()>0) || (boundary.GetJunctionboundarysegmentlaneCount()>0) )
+    {
+        junction->SetJunctionboundary(boundary);
+    }
+    else
+    {
+        std::cout<<" ReadJunctionboundary, junction boundary no  joint lane."<<std::endl;
+        return false;
+    }
 
 
-    junction->SetJunctionboundary(boundary);
     return true;
 }
 
 bool OpenDriveXmlParser::ReadJunctionboundarysegment(Junctionboundary * junctionboundary, TiXmlElement *node)
 {
-    TiXmlElement *subNode=node->FirstChildElement("segment");
 
     int boundaryLane;
     string roadId;
@@ -3336,32 +3365,134 @@ bool OpenDriveXmlParser::ReadJunctionboundarysegment(Junctionboundary * junction
 
     string type;
 
-    while(subNode)
+
+    if(node->QueryStringAttribute("type",&type) == TIXML_SUCCESS)
     {
-        if(subNode->QueryStringAttribute("type",&type) == TIXML_SUCCESS)
+        if(type == "lane")
         {
-            if(type == "lane")
-            {
-                int checker=TIXML_SUCCESS;
-                checker+=node->QueryIntAttribute("boundaryLane",&boundaryLane);
-                checker+=node->QueryStringAttribute("roadId",&roadId);
-                checker+=node->QueryDoubleAttribute("sEnd",&sEnd);
-                checker+=node->QueryDoubleAttribute("sStart",&sStart);
-                if(checker == TIXML_SUCCESS)
+        int checker=TIXML_SUCCESS;
+        checker+=node->QueryIntAttribute("boundaryLane",&boundaryLane);
+        checker+=node->QueryStringAttribute("roadId",&roadId);
+        checker+=node->QueryDoubleAttribute("sEnd",&sEnd);
+        checker+=node->QueryDoubleAttribute("sStart",&sStart);
+        if(checker == TIXML_SUCCESS)
+        {
+                junctionboundary->AddJunctionboundarysegmentlane(boundaryLane,roadId,sEnd,sStart);
+        }
+        else
+        {
+                std::cout<<" Parse Junction Boundary Lane Fail.  "<<std::endl;
+        }
+        }
+        if(type == "joint")
+        {
+        int checker=TIXML_SUCCESS;
+        checker+=node->QueryStringAttribute("contactPoint",&contactPoint);
+        checker+=node->QueryStringAttribute("roadId",&roadId);
+        if(checker == TIXML_SUCCESS)
+        {
+                junctionboundary->AddJunctionboundarysegmentjoint(contactPoint,roadId);
+
+                Junctionboundarysegmentjoint * pjoint = junctionboundary->GetLastAddedJunctionboundarysegmentjoint();
+
+                if(node->QueryIntAttribute("jointLaneEnd",&jointLaneEnd) == TIXML_SUCCESS)
                 {
-                    junctionboundary->AddJunctionboundarysegmentlane(boundaryLane,roadId,sEnd,sStart);
+                    pjoint->SetjointLaneEnd(jointLaneEnd);
+                }
+                if(node->QueryIntAttribute("jointLaneStart",&jointLaneStart) == TIXML_SUCCESS)
+                {
+                    pjoint->SetjointLaneEnd(jointLaneStart);
+                }
+                if(node->QueryDoubleAttribute("transitionLength",&transitionLength) == TIXML_SUCCESS)
+                {
+                    pjoint->SettransitionLength(transitionLength);
                 }
-            }
-            if(type == "joint")
-            {
 
-            }
         }
+        else
+        {
+                std::cout<<" Parse Junction Boundary joint Fail.  "<<std::endl;
+        }
+        }
+    }
 
-        subNode=node->NextSiblingElement("segment");
+    return true;
+}
+
+bool OpenDriveXmlParser::ReadJunctionelevationGrid(Junction* junction, TiXmlElement *node)
+{
+    double gridSpacing;
+    double sStart;
+
+    int checker=TIXML_SUCCESS;
+    checker+=node->QueryDoubleAttribute("gridSpacing",&gridSpacing);
+    checker+=node->QueryDoubleAttribute("sStart",&sStart);
+
+    if(checker == TIXML_SUCCESS)
+    {
+
+    }
+    else
+    {
+        std::cout<<" Parse ReadJunctionelevationGrid Fail. Junction id: "<<junction->GetId()<<std::endl;
+        return false;
+    }
+
+
+    JunctionelevationGrid elevationGrid(gridSpacing,sStart);
+
+
+    TiXmlElement *subNode=node->FirstChildElement("elevation");
+
+    while(subNode)
+    {
+        ReadJunctionelevationGridelevation(&elevationGrid,subNode);
+        subNode=node->NextSiblingElement("elevation");
+    }
+
+
+    junction->SetJunctionelevationGrid(elevationGrid);
+
+    return true;;
+
+
+}
+
+bool OpenDriveXmlParser::ReadJunctionelevationGridelevation(JunctionelevationGrid * junctionelevationGrid, TiXmlElement *node)
+{
+    string left;
+    string center;
+    string right;
+
+    int checker=TIXML_SUCCESS;
+    checker+=node->QueryStringAttribute("center",&center);
+
+    if(checker == TIXML_SUCCESS)
+    {
+
+    }
+    else
+    {
+        std::cout<<" Parse Junction elevation Grid Fail."<<std::endl;
+        return false;
+    }
+
+    junctionelevationGrid->Addelevation(center);
+
+    JunctionelevationGridelevation * pelevation = junctionelevationGrid->GetLastAddedelevation();
+
+    if(node->QueryStringAttribute("left",&left) == TIXML_SUCCESS)
+    {
+        pelevation->Setleft(left);
+    }
+
+    if(node->QueryStringAttribute("right",&right) == TIXML_SUCCESS)
+    {
+        pelevation->Setright(right);
     }
 
     return true;
+
 }
 
 bool OpenDriveXmlParser::ReadJunctionPriority (Junction* junction, TiXmlElement *node)

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

@@ -138,6 +138,8 @@ public:
     bool ReadJunctionplanViewgeometry(JunctionplanView* planView, TiXmlElement *node);
     bool ReadJunctionboundary(Junction* junction, TiXmlElement *node);
     bool ReadJunctionboundarysegment(Junctionboundary * junctionboundary, TiXmlElement *node);
+    bool ReadJunctionelevationGrid(Junction* junction, TiXmlElement *node);
+    bool ReadJunctionelevationGridelevation(JunctionelevationGrid * junctionelevationGrid, TiXmlElement *node);
 	//--------------
 
 	bool ReadJunctionPriority (Junction* junction, TiXmlElement *node);

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

@@ -2468,6 +2468,10 @@ bool OpenDriveXmlWriter::WriteJunction (TiXmlElement *node, Junction *junction)
 
     WriteJunctionplanView(nodeJunction,junction);
 
+    WriteJunctionboundary(nodeJunction,junction);
+
+    WriteJunctionelevationGrid(nodeJunction,junction);
+
 	return true;
 }
 //--------------
@@ -2810,6 +2814,162 @@ bool OpenDriveXmlWriter::WriteJunctionplanViewgeometry(TiXmlElement *node, Junct
     return true;
 }
 
+bool OpenDriveXmlWriter::WriteJunctionboundary(TiXmlElement *node, Junction *junction)
+{
+    Junctionboundary boundary;
+    int nboundary = junction->GetJunctionboundary(boundary);
+
+    if(nboundary == 0)return true;
+
+    if( ( boundary.GetJunctionboundarysegmentjointCount() == 0 ) && ( boundary.GetJunctionboundarysegmentlaneCount() == 0) )
+    {
+        return true;
+    }
+
+    TiXmlElement *nodeJunctionboundary = new TiXmlElement("boundary");
+    node->LinkEndChild(nodeJunctionboundary);
+
+    WriteJunctionboundarysegment(nodeJunctionboundary,&boundary);
+    return true;
+
+}
+
+bool OpenDriveXmlWriter::WriteJunctionboundarysegment(TiXmlElement *node, Junctionboundary *boundary)
+{
+    int boundaryLane;
+    string roadId;
+    double sEnd;
+    double sStart;
+
+    string contactPoint;
+    int jointLaneEnd;
+    int jointLaneStart;
+    double transitionLength;
+
+    string type;
+
+    unsigned int junctionboundarysegmentjointCount = boundary->GetJunctionboundarysegmentjointCount();
+    for(unsigned int i=0; i<junctionboundarysegmentjointCount; i++)
+    {
+        Junctionboundarysegmentjoint *lJunctionboundarysegmentjoint = boundary->GetJunctionboundarysegmentjoint(i);
+
+        contactPoint = lJunctionboundarysegmentjoint->GetcontactPoint();
+        roadId = lJunctionboundarysegmentjoint->GetroadId();
+
+
+        TiXmlElement *nodeJunctionboundarysegmentjoint = new TiXmlElement("segment");
+        node->LinkEndChild(nodeJunctionboundarysegmentjoint);
+
+        type = "joint";
+        nodeJunctionboundarysegmentjoint->SetAttribute("contactPoint",contactPoint);
+        nodeJunctionboundarysegmentjoint->SetAttribute("roadId",roadId);
+        nodeJunctionboundarysegmentjoint->SetAttribute("type",type);
+
+        if(lJunctionboundarysegmentjoint->GetjointLaneEnd(jointLaneEnd) == 1)
+        {
+            nodeJunctionboundarysegmentjoint->SetAttribute("jointLaneEnd",jointLaneEnd);
+        }
+
+        if(lJunctionboundarysegmentjoint->GetjointLaneStart(jointLaneStart) == 1)
+        {
+            nodeJunctionboundarysegmentjoint->SetAttribute("jointLaneStart",jointLaneStart);
+        }
+
+        if(lJunctionboundarysegmentjoint->GettransitionLength(transitionLength) == 1)
+        {
+            nodeJunctionboundarysegmentjoint->SetAttribute("transitionLength",transitionLength);
+        }
+
+    }
+
+    unsigned int junctionboundarysegmentlaneCount = boundary->GetJunctionboundarysegmentlaneCount();
+    for(unsigned int i=0; i<junctionboundarysegmentlaneCount; i++)
+    {
+        Junctionboundarysegmentlane *lJunctionboundarysegmentlane = boundary->GetJunctionboundarysegmentlane(i);
+
+        boundaryLane = lJunctionboundarysegmentlane->GetboundaryLane();
+        roadId = lJunctionboundarysegmentlane->GetroadId();
+        sEnd = lJunctionboundarysegmentlane->GetsEnd();
+        sStart = lJunctionboundarysegmentlane->GetsStart();
+
+
+        TiXmlElement *nodeJunctionboundarysegmentlane = new TiXmlElement("segment");
+        node->LinkEndChild(nodeJunctionboundarysegmentlane);
+
+        type = "lane";
+        nodeJunctionboundarysegmentlane->SetAttribute("boundaryLane",boundaryLane);
+        nodeJunctionboundarysegmentlane->SetAttribute("roadId",roadId);
+        nodeJunctionboundarysegmentlane->SetAttribute("type",type);
+        nodeJunctionboundarysegmentlane->SetAttribute("sEnd",sEnd);
+        nodeJunctionboundarysegmentlane->SetAttribute("sStart",sStart);
+
+
+
+    }
+
+    return true;
+
+}
+
+bool OpenDriveXmlWriter::WriteJunctionelevationGrid(TiXmlElement *node, Junction *junction)
+{
+    JunctionelevationGrid elevationGrid;
+    int nelevationGrid = junction->GetJunctionelevationGrid(elevationGrid);
+
+    if(nelevationGrid == 0)return false;
+
+
+    TiXmlElement *nodeJunctionelevationGrid = new TiXmlElement("elevationGrid");
+
+    node->LinkEndChild(nodeJunctionelevationGrid);
+
+    double gridSpacing;
+    double sStart;
+
+    gridSpacing = elevationGrid.GetgridSpacing();
+    sStart = elevationGrid.GetsStart();
+
+    nodeJunctionelevationGrid->SetDoubleAttribute("gridSpacing",gridSpacing);
+    nodeJunctionelevationGrid->SetDoubleAttribute("sStart",sStart);
+
+    WriteJunctionelevationGridelevation(nodeJunctionelevationGrid,&elevationGrid);
+    return true;
+}
+
+bool OpenDriveXmlWriter::WriteJunctionelevationGridelevation(TiXmlElement *node, JunctionelevationGrid *elevationGrid)
+{
+    string left;
+    string center;
+    string right;
+
+    unsigned int junctionelevationGridelevationCount = elevationGrid->GetelevationCount();
+    for(unsigned int i=0; i<junctionelevationGridelevationCount; i++)
+    {
+        JunctionelevationGridelevation *lJunctionelevationGridelevation = elevationGrid->Getelevation(i);
+
+        center = lJunctionelevationGridelevation->Getcenter();
+
+        TiXmlElement *nodeJunctionlJunctionelevationGridelevation = new TiXmlElement("elevation");
+        node->LinkEndChild(nodeJunctionlJunctionelevationGridelevation);
+
+        nodeJunctionlJunctionelevationGridelevation->SetAttribute("center",center);
+
+        if(lJunctionelevationGridelevation->Getleft(left) == 1)
+        {
+            nodeJunctionlJunctionelevationGridelevation->SetAttribute("left",left);
+        }
+
+        if(lJunctionelevationGridelevation->Getright(right) == 1)
+        {
+            nodeJunctionlJunctionelevationGridelevation->SetAttribute("right",right);
+        }
+
+    }
+
+    return true;
+
+}
+
 
 //---------------------------------------------------------------------------
 

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

@@ -131,6 +131,10 @@ public:
     bool WriteJunctionCrossingsroadSection(TiXmlElement *node, Junction *junction);
     bool WriteJunctionplanView(TiXmlElement *node,  Junction *junction);
     bool WriteJunctionplanViewgeometry(TiXmlElement *node, JunctionplanView *planView);
+    bool WriteJunctionboundary(TiXmlElement *node, Junction *junction);
+    bool WriteJunctionboundarysegment(TiXmlElement *node, Junctionboundary *boundary);
+    bool WriteJunctionelevationGrid(TiXmlElement *node, Junction *junction);
+    bool WriteJunctionelevationGridelevation(TiXmlElement *node, JunctionelevationGrid *elevationGrid);
 	//--------------
 
 	bool WriteJunctionPriority (TiXmlElement *node, Junction* junction);