Browse Source

Change opendrive, add Junction Surface.

yuchuli 1 year ago
parent
commit
db8a743aa5

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

@@ -521,6 +521,22 @@ void Junction::SetJunctionelevationGrid(JunctionelevationGrid elevationGrid)
     mJunctionelevationGrid.push_back(elevationGrid);
 }
 
+
+int Junction::GetJunctionSurface(Junctionsurface & junctionsurface)
+{
+    if(mJunctionsurface.size() == 0)return 0;
+    junctionsurface = mJunctionsurface[0];
+    return 1;
+}
+
+void Junction::SetJunctionSurface(Junctionsurface junctionsurface)
+{
+    mJunctionsurface.clear();
+    mJunctionsurface.push_back(junctionsurface);
+}
+
+
+
 //--------------
 
 
@@ -1682,3 +1698,266 @@ void JunctionelevationGridelevation::Setright(string right)
     mright.push_back(right);
 }
 
+
+//***********************************************************************************
+//Surface Record
+//***********************************************************************************
+
+Junctionsurface_CRG::Junctionsurface_CRG(std::string file,double sStart,double sEnd,std::string orientation,std::string mode)
+{
+    mfile = file;
+    msStart = sStart;
+    msEnd = sEnd;
+    morientation = orientation;
+    mmode = mode;
+}
+
+std::string Junctionsurface_CRG::Getfile()
+{
+    return mfile;
+}
+
+double Junctionsurface_CRG::GetsStart()
+{
+    return msStart;
+}
+
+double Junctionsurface_CRG::GetsEnd()
+{
+    return msEnd;
+}
+
+std::string Junctionsurface_CRG::Getorientation()
+{
+    return morientation;
+}
+
+std::string Junctionsurface_CRG::Getmode()
+{
+    return mmode;
+}
+
+int Junctionsurface_CRG::Getpurpose(std::string & purpose)
+{
+    if(mpurpose.size() == 0)return  0;
+    purpose = mpurpose[0];
+    return 1;
+}
+
+int Junctionsurface_CRG::GetsOffset(double & sOffset)
+{
+    if(msOffset.size() == 0)return  0;
+    sOffset = msOffset[0];
+    return 1;
+}
+
+int Junctionsurface_CRG::GettOffset(double & tOffset)
+{
+    if(mtOffset.size() == 0)return 0;
+    tOffset = mtOffset[0];
+    return  1;
+}
+
+int Junctionsurface_CRG::GetzOffset(double & zOffset)
+{
+    if(mzOffset.size() == 0)return  0;
+    zOffset = mzOffset[0];
+    return 1;
+}
+
+int Junctionsurface_CRG::GetzScale(double & zScale)
+{
+    if(mzScale.size() == 0)return  0;
+    zScale = mzScale[0];
+    return 1;
+}
+
+int Junctionsurface_CRG::GethOffset(double & hOffset)
+{
+    if(mhOffset.size() == 0)return 0;
+    hOffset = mhOffset[0];
+    return  1;
+}
+
+void Junctionsurface_CRG::Setfile(std::string file)
+{
+    mfile = file;
+}
+
+void Junctionsurface_CRG::SetsStart(double sStart)
+{
+    msStart = sStart;
+}
+
+void Junctionsurface_CRG::SetsEnd(double sEnd)
+{
+    msEnd = sEnd;
+}
+
+void Junctionsurface_CRG::Setorientation(std::string orientation)
+{
+    morientation = orientation;
+}
+
+void Junctionsurface_CRG::Setmode(std::string mode)
+{
+    mmode = mode;
+}
+
+void Junctionsurface_CRG::Setpurpose(std::string purpose)
+{
+    if(mpurpose.size() > 0)mpurpose.clear();
+    mpurpose.push_back(purpose);
+}
+
+void Junctionsurface_CRG::SetsOffset(double sOffset)
+{
+    if(msOffset.size()>0)msOffset.clear();
+    msOffset.push_back(sOffset);
+}
+
+void Junctionsurface_CRG::SettOffset(double tOffset)
+{
+    if(mtOffset.size()>0)mtOffset.clear();
+    mtOffset.push_back(tOffset);
+}
+
+void Junctionsurface_CRG::SetzOffset(double zOffset)
+{
+    if(mzOffset.size()>0)mzOffset.clear();
+    mzOffset.push_back(zOffset);
+}
+
+void Junctionsurface_CRG::SetzScale(double zScale)
+{
+    if(mzScale.size()>0)mzScale.clear();
+    mzScale.push_back(zScale);
+}
+
+void Junctionsurface_CRG::SethOffset(double hOffset)
+{
+    if(mhOffset.size()>0)mhOffset.clear();
+    mhOffset.push_back(hOffset);
+}
+
+void Junctionsurface_CRG::Resetpurpose()
+{
+    if(mpurpose.size()>0)mpurpose.clear();
+}
+
+void Junctionsurface_CRG::ResetsOffset()
+{
+    if(msOffset.size()>0)msOffset.clear();
+}
+
+void Junctionsurface_CRG::ResettOffset()
+{
+    if(mtOffset.size()>0)mtOffset.clear();
+}
+
+void Junctionsurface_CRG::ResetzOffset()
+{
+    if(mzOffset.size()>0)mzOffset.clear();
+}
+
+void Junctionsurface_CRG::ResetzScale()
+{
+    if(mzScale.size()>0)mzScale.clear();
+}
+
+void Junctionsurface_CRG::ResethOffset()
+{
+    if(mhOffset.size()>0)mhOffset.clear();
+}
+
+bool Junctionsurface_CRG::CheckInterval(double s_check)
+{
+    if (s_check>=msStart)
+        return true;
+    else
+        return false;
+}
+
+
+
+Junctionsurface::Junctionsurface()
+{
+
+}
+
+std::vector<Junctionsurface_CRG> * Junctionsurface::GetCRGVector()
+{
+    return &mCRG;
+}
+
+Junctionsurface_CRG* Junctionsurface::GetCRG(unsigned int i)
+{
+    if ((mCRG.size()>0)&&(i<(mCRG.size())))
+        return &(mCRG.at(i));
+    else
+        return NULL;
+}
+
+unsigned int Junctionsurface::GetCRGCount()
+{
+    return static_cast<unsigned int >(mCRG.size()) ;
+}
+
+Junctionsurface_CRG*			Junctionsurface::GetLastCRG()
+{
+    if (mCRG.size()>0)
+        return &mCRG.at(mCRG.size()-1);
+    else
+        return NULL;
+}
+
+Junctionsurface_CRG*			Junctionsurface::GetLastAddedCRG()
+{
+    if(mLastAddedCRG<mCRG.size())
+        return &mCRG.at(mLastAddedCRG);
+    else
+        return NULL;
+}
+
+unsigned int Junctionsurface::AddCRG(std::string file,double sStart,double sEnd,std::string orientation,std::string mode)
+{
+
+    // Check the first method in the group for details
+
+    unsigned int index = static_cast<unsigned int>(CheckCRGInterval(sStart)+1) ;
+    if(index>=GetCRGCount()) mCRG.push_back(Junctionsurface_CRG(file,sStart,sEnd,orientation,mode));
+    else mCRG.insert(mCRG.begin()+index, Junctionsurface_CRG(file,sStart,sEnd,orientation,mode));
+    mLastAddedCRG=index;
+    return index;
+}
+
+unsigned int Junctionsurface::CloneCRG(unsigned int index)
+{
+    if(index<(mCRG.size()-1))
+        mCRG.insert(mCRG.begin()+index+1, mCRG[index]);
+    else if(index==mCRG.size()-1)
+        mCRG.push_back(mCRG[index]);
+    mLastAddedCRG=index+1;
+    return mLastAddedCRG;
+}
+
+void Junctionsurface::DeleteCRG(unsigned int index)
+{
+    mCRG.erase(mCRG.begin()+index);
+}
+
+int Junctionsurface::CheckCRGInterval(double s_check)
+{
+    int res=-1;
+    //Go through all the tunnel records
+    for (unsigned int i=0;i<mCRG.size();i++)
+    {
+        //check if the s_check belongs to the current record
+        if (mCRG.at(i).CheckInterval(s_check))
+            res=static_cast<int>(i);	//assign it to the result id
+        else
+            break;	//if not, break;
+    }
+    return res;		//return the result: 0 to MaxInt as the index to the record containing s_check or -1 if nothing found
+}
+

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

@@ -3,6 +3,8 @@
 
 #include <string>
 #include <vector>
+
+
 using std::string;
 
 //Prototypes
@@ -27,6 +29,9 @@ class Junctionboundary;
 class JunctionelevationGrid;
 class JunctionelevationGridelevation;
 
+class Junctionsurface_CRG;
+class Junctionsurface;
+
 /**
  * Junction class. Holds all the junction information
  *
@@ -64,6 +69,9 @@ private:
 
     std::vector<JunctionelevationGrid> mJunctionelevationGrid;
 
+    std::vector<Junctionsurface> mJunctionsurface;
+
+
 public:
 
 	/**
@@ -298,6 +306,11 @@ public:
     void SetJunctionelevationGrid(JunctionelevationGrid elevationGrid);
 
 
+    int GetJunctionSurface(Junctionsurface & junctionsurface);
+    void SetJunctionSurface(Junctionsurface junctionsurface);
+
+
+
 };
 
 
@@ -1019,6 +1032,88 @@ public:
 };
 
 
+class Junctionsurface_CRG
+{
+private:
+    std::string mfile;
+    double msStart;
+    double msEnd;
+    std::string morientation;
+    std::string mmode;
+    std::vector<std::string> mpurpose;
+    std::vector<double> msOffset;
+    std::vector<double> mtOffset;
+    std::vector<double> mzOffset;
+    std::vector<double> mzScale;
+    std::vector<double> mhOffset;
+
+public:
+    Junctionsurface_CRG(std::string file,double sStart,double sEnd,std::string orientation,std::string mode);
+
+    std::string Getfile();
+    double GetsStart();
+    double GetsEnd();
+    std::string Getorientation();
+    std::string Getmode();
+    int Getpurpose(std::string & purpose);
+    int GetsOffset(double & sOffset);
+    int GettOffset(double & tOffset);
+    int GetzOffset(double & zOffset);
+    int GetzScale(double & zScale);
+    int GethOffset(double & hOffset);
+
+    void Setfile(std::string file);
+    void SetsStart(double sStart);
+    void SetsEnd(double sEnd);
+    void Setorientation(std::string orientation);
+    void Setmode(std::string mode);
+    void Setpurpose(std::string purpose);
+    void SetsOffset(double sOffset);
+    void SettOffset(double tOffset);
+    void SetzOffset(double zOffset);
+    void SetzScale(double zScale);
+    void SethOffset(double hOffset);
+
+    void Resetpurpose();
+    void ResetsOffset();
+    void ResettOffset();
+    void ResetzOffset();
+    void ResetzScale();
+    void ResethOffset();
+
+    bool CheckInterval(double s_check);
+
+};
+
+//----------------------------------------------------------------------------------
+
+class Junctionsurface
+{
+private:
+    std::vector<Junctionsurface_CRG> mCRG;
+    unsigned int mLastAddedCRG;
+
+public:
+    Junctionsurface();
+
+    std::vector<Junctionsurface_CRG> * GetCRGVector();
+    Junctionsurface_CRG* GetCRG(unsigned int i);
+    unsigned int GetCRGCount();
+    Junctionsurface_CRG*			GetLastCRG();
+    Junctionsurface_CRG*			GetLastAddedCRG();
+    unsigned int AddCRG(std::string file,double sStart,double sEnd,std::string orientation,std::string mode);
+    unsigned int CloneCRG(unsigned int index);
+    void DeleteCRG(unsigned int index);
+
+    int CheckCRGInterval(double s_check);
+
+
+
+
+};
+
+
+
 
 
 

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

@@ -3636,6 +3636,82 @@ bool OpenDriveXmlParser::ReadJunctionCrossPassEndLaneLink(JunctionCrossPathEndLa
 }
 
 
+bool OpenDriveXmlParser::ReadJunctionSurface(Junction * junction, TiXmlElement *node)
+{
+    Junctionsurface junctionsurface;
+    TiXmlElement *subNode = node->FirstChildElement("CRG");
+
+
+    while (subNode)
+    {
+        ReadJunctionSurfaceCRG(&junctionsurface, subNode);
+        subNode=subNode->NextSiblingElement("CRG");
+    }
+
+    if(junctionsurface.GetCRGCount()>0)
+    {
+        junction->SetJunctionSurface(junctionsurface);
+    }
+
+    return true;
+}
+
+bool OpenDriveXmlParser::ReadJunctionSurfaceCRG(Junctionsurface * junctionsurface, TiXmlElement *node)
+{
+    std::string file,orientation,mode;
+    double sStart,sEnd;
+
+    int checker=TIXML_SUCCESS;
+
+    checker+=node->QueryStringAttribute("file",&file);
+    checker+=node->QueryDoubleAttribute("file",&sStart);
+    checker+=node->QueryDoubleAttribute("file",&sEnd);
+    checker+=node->QueryStringAttribute("orientation",&orientation);
+    checker+=node->QueryStringAttribute("mode",&mode);
+
+    if (checker!=TIXML_SUCCESS)
+    {
+        cout<<"Error parsing Junction Surface CRG attributes"<<endl;
+        return false;
+    }
+
+
+    junctionsurface->AddCRG(file,sStart,sEnd,orientation,mode);
+
+    Junctionsurface_CRG * pCRG = junctionsurface->GetLastAddedCRG();
+
+    std::string purpose;
+    if(node->QueryStringAttribute("purpose",&purpose) == TIXML_SUCCESS)
+    {
+        pCRG->Setpurpose(purpose);
+    }
+
+    double sOffset,tOffset,zOffset,zScale,hOffset;
+    if(node->QueryDoubleAttribute("sOffset",&sOffset))
+    {
+        pCRG->SetsOffset(sOffset);
+    }
+    if(node->QueryDoubleAttribute("tOffset",&tOffset))
+    {
+        pCRG->SetsOffset(tOffset);
+    }
+    if(node->QueryDoubleAttribute("zOffset",&zOffset))
+    {
+        pCRG->SetsOffset(zOffset);
+    }
+    if(node->QueryDoubleAttribute("zScale",&zScale))
+    {
+        pCRG->SetsOffset(zScale);
+    }
+    if(node->QueryDoubleAttribute("hOffset",&hOffset))
+    {
+        pCRG->SetsOffset(hOffset);
+    }
+
+    return true;
+}
+
+
 //---------------------------------------------------------------------------
 /**
  * Reads the data from the OpenDrive structure to a file

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

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