Browse Source

change opendrive, add junction group, not complete.

yuchuli 1 year ago
parent
commit
2e5cc436ef

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

@@ -71,6 +71,15 @@ unsigned int OpenDrive::AddController(string id)
     return index;
 }
 
+unsigned int OpenDrive::AddJunctionGroup(std::string id, std::string type)
+{
+    unsigned int index=GetJunctionGroupCount();
+    mJunctionGroupVector.push_back(JunctionGroup(id,type));
+    mLastAddedJunctionGroup=index;
+    return index;
+}
+
+
 /**
  * Methods used to delete records from the respective vectors
  */
@@ -86,6 +95,10 @@ void OpenDrive::DeleteController(unsigned int index)
 {
     mControllerVector.erase(mControllerVector.begin()+index);
 }
+void OpenDrive::DeleteJunctionGroup(unsigned int index)
+{
+    mJunctionGroupVector.erase(mJunctionGroupVector.begin()+index);
+}
 
 
 //-------------------------------------------------
@@ -114,6 +127,13 @@ Controller* OpenDrive::GetLastController()
     else
         return NULL;
 }
+JunctionGroup* OpenDrive::GetLastJunctionGroup()
+{
+    if (mJunctionGroupVector.size()>0)
+        return &(mJunctionGroupVector.at(mJunctionGroupVector.size()-1));
+    else
+        return NULL;
+}
 
 /**
  * Getters for the last added records in their respective vectors
@@ -134,6 +154,22 @@ Controller* OpenDrive::GetLastAddedController()
         return NULL;
 }
 
+Junction* OpenDrive::GetLastAddedJunction()
+{
+    if(mLastAddedJunction<mJunctionVector.size())
+        return &mJunctionVector.at(mLastAddedJunction);
+    else
+        return NULL;
+}
+
+JunctionGroup* OpenDrive::GetLastAddedJunctionGroup()
+{
+    if(mLastAddedJunctionGroup<mJunctionGroupVector.size())
+        return &mJunctionGroupVector.at(mLastAddedJunctionGroup);
+    else
+        return NULL;
+}
+
 /**
  * Getter for the OpenDrive header
  */
@@ -192,6 +228,23 @@ unsigned int OpenDrive::GetControllerCount()
 {
     return  static_cast<unsigned int >(mControllerVector.size());
 }
+
+//Junction Group records
+vector<JunctionGroup> * OpenDrive::GetJunctionGroupVector()
+{
+    return &mJunctionGroupVector;
+}
+JunctionGroup* OpenDrive::GetJunctionGroup(unsigned int i)
+{
+    if (i < mJunctionGroupVector.size())
+            return &(mJunctionGroupVector.at(i));
+    else
+            return NULL;
+}
+unsigned int OpenDrive::GetJunctionGroupCount()
+{
+    return  static_cast<unsigned int >(mJunctionGroupVector.size());
+}
 //-------------------------------------------------
 
 /**
@@ -223,7 +276,7 @@ OpenDrive::OpenDrive (const OpenDrive& openDrive)
     }
     else
     {
-        mHeader == NULL;
+        mHeader = NULL;
     }
 }
 
@@ -246,7 +299,7 @@ const OpenDrive& OpenDrive::operator=(const OpenDrive& rhs)
     }
     else
     {
-        mHeader == NULL;
+        mHeader = NULL;
     }
 }
 

+ 12 - 0
src/common/common/xodr/OpenDrive/OpenDrive.h

@@ -6,6 +6,7 @@
 
 #include "Road.h"
 #include "controller.h"
+#include "junctiongroup.h"
 //--Prototypes--
 //main
 class Header;
@@ -37,6 +38,7 @@ private:
 	vector<Road> mRoadVector;
 	vector<Junction> mJunctionVector;
     vector<Controller> mControllerVector;
+    vector<JunctionGroup> mJunctionGroupVector;
 	
 	/**
 	 * Indices of the last added records
@@ -44,6 +46,7 @@ private:
 	unsigned int mLastAddedRoad;
 	unsigned int mLastAddedJunction;
     unsigned int mLastAddedController;
+    unsigned int mLastAddedJunctionGroup;
 
 //	//-------------------------------------------------
 
@@ -81,6 +84,7 @@ public:
 	unsigned int AddRoad(string name, double length, string id, string junction);
 	unsigned int AddJunction(string name, string id);
     unsigned int AddController(string id);
+    unsigned int AddJunctionGroup(std::string id, std::string type);
 
 	/**
 	 * Methods used to delete records from the respective vectors
@@ -88,6 +92,7 @@ public:
 	void DeleteRoad(unsigned int index);
 	void DeleteJunction(unsigned int index);
     void DeleteController(unsigned int index);
+    void DeleteJunctionGroup(unsigned int index);
 
 	//-------------------------------------------------
 
@@ -97,12 +102,15 @@ public:
 	Road* GetLastRoad();
 	Junction* GetLastJunction();
     Controller* GetLastController();
+    JunctionGroup* GetLastJunctionGroup();
 
 	/**
 	 * Getters for the last added records in their respective vectors
 	 */
 	Road* GetLastAddedRoad();
     Controller* GetLastAddedController();
+    Junction* GetLastAddedJunction();
+    JunctionGroup* GetLastAddedJunctionGroup();
 
 	/**
 	 * Getter for the OpenDrive header
@@ -124,6 +132,10 @@ public:
     vector<Controller> * GetControllerVector();
     Controller* GetController(unsigned int i);
     unsigned int GetControllerCount();
+    //Junction Group records
+    vector<JunctionGroup> * GetJunctionGroupVector();
+    JunctionGroup* GetJunctionGroup(unsigned int i);
+    unsigned int GetJunctionGroupCount();
 	
 	//-------------------------------------------------
 

+ 2 - 0
src/common/common/xodr/OpenDrive/OpenDrive.pri

@@ -9,6 +9,7 @@ HEADERS += \
     $$PWD/Road.h \
     $$PWD/RoadGeometry.h \
     $$PWD/controller.h \
+    $$PWD/junctiongroup.h \
     $$PWD/userData.h
 
 SOURCES += \
@@ -22,4 +23,5 @@ SOURCES += \
     $$PWD/Road.cpp \
     $$PWD/RoadGeometry.cpp \
     $$PWD/controller.cpp \
+    $$PWD/junctiongroup.cpp \
     $$PWD/userData.cpp

+ 74 - 1
src/common/common/xodr/OpenDrive/OpenDriveXmlParser.cpp

@@ -3097,6 +3097,12 @@ bool OpenDriveXmlParser::ReadJunction (TiXmlElement *node)
         ReadJunctionelevationGrid(junction,subNode);
     }
 
+    subNode = node->FirstChildElement("surface");
+
+    if(subNode)
+    {
+        ReadJunctionSurface(junction,subNode);
+    }
 
 
 	return true;
@@ -3712,6 +3718,65 @@ bool OpenDriveXmlParser::ReadJunctionSurfaceCRG(Junctionsurface * junctionsurfac
 }
 
 
+bool OpenDriveXmlParser::ReadJunctionGroup(TiXmlElement *node)
+{
+    std::string id,type,name;
+
+    int checker=TIXML_SUCCESS;
+
+    checker+=node->QueryStringAttribute("id",&id);
+    checker+=node->QueryStringAttribute("type",&type);
+
+
+    if(checker != TIXML_SUCCESS)
+    {
+        std::cout<<"Parse Junction Group Fail."<<std::endl;
+        return false;
+    }
+
+    mOpenDrive->AddJunctionGroup(id,type);
+
+    JunctionGroup * junctionGroup = mOpenDrive->GetLastAddedJunctionGroup();
+
+    if(node->QueryStringAttribute("name",&name) == TIXML_SUCCESS)
+    {
+        junctionGroup->Setname(name);
+    }
+
+
+    TiXmlElement *subNode = node->FirstChildElement("junctionReference");
+
+    while (subNode)
+    {
+        ReadJunctionGroupReference(junctionGroup, subNode);
+        subNode=subNode->NextSiblingElement("junctionReference");
+    }
+
+    return true;
+
+}
+
+bool OpenDriveXmlParser::ReadJunctionGroupReference(JunctionGroup* junctionGroup, TiXmlElement *node)
+{
+
+    std::string junction;
+
+    int checker=TIXML_SUCCESS;
+
+    checker+=node->QueryStringAttribute("junction",&junction);
+
+    if(checker != TIXML_SUCCESS)
+    {
+        std::cout<<" Parse Junction Group Reference Fail."<<std::endl;
+        return false;
+    }
+
+    junctionGroup->AddjunctionReference(junction);
+
+    return true;
+}
+
+
 //---------------------------------------------------------------------------
 /**
  * Reads the data from the OpenDrive structure to a file
@@ -3745,7 +3810,7 @@ bool OpenDriveXmlParser::ReadFile(std::string fileName)
 			node=node->NextSiblingElement("controller");
 		}
 
-		//read junctions
+        //read junctions
 		node=rootNode->FirstChildElement("junction");
 		while (node!=0)
 		{
@@ -3753,6 +3818,14 @@ bool OpenDriveXmlParser::ReadFile(std::string fileName)
 			node=node->NextSiblingElement("junction");
 		}
 
+        //read junctionGroups
+        node=rootNode->FirstChildElement("junctionGroup");
+        while (node!=0)
+        {
+            ReadJunctionGroup(node);
+            node=node->NextSiblingElement("junctionGroup");
+        }
+
 		return true;
 	}
 	

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

@@ -152,6 +152,9 @@ public:
 
 	//--------------
 
+    bool ReadJunctionGroup(TiXmlElement *node);
+    bool ReadJunctionGroupReference(JunctionGroup* junctionGroup, TiXmlElement *node);
+
     bool ParseGeoReferenceLon0Lat0(std::string strgr, double & lon0,double & lat0);
 };
 

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

@@ -2472,6 +2472,8 @@ bool OpenDriveXmlWriter::WriteJunction (TiXmlElement *node, Junction *junction)
 
     WriteJunctionelevationGrid(nodeJunction,junction);
 
+    WriteJunctionsurface(nodeJunction,junction);
+
 	return true;
 }
 //--------------
@@ -2971,6 +2973,80 @@ bool OpenDriveXmlWriter::WriteJunctionelevationGridelevation(TiXmlElement *node,
 }
 
 
+bool OpenDriveXmlWriter::WriteJunctionsurface(TiXmlElement *node, Junction *junction)
+{
+    Junctionsurface surface;
+    int nsurface = junction->GetJunctionSurface(surface);
+
+    if(nsurface == 0)return false;
+
+    TiXmlElement *nodeJunctionsurface = new TiXmlElement("surface");
+
+    node->LinkEndChild(nodeJunctionsurface);
+
+    WriteJunctionsurfaceCRG(nodeJunctionsurface,&surface);
+    return true;
+}
+
+bool OpenDriveXmlWriter::WriteJunctionsurfaceCRG(TiXmlElement *node, Junctionsurface *junctionsurface)
+{
+    unsigned int surfaceCRGCount = junctionsurface->GetCRGCount();
+    for(unsigned int i=0;i<surfaceCRGCount;i++)
+    {
+        TiXmlElement * nodeSurfaceCRG = new TiXmlElement("CRG");
+        node->LinkEndChild(nodeSurfaceCRG);
+
+        Junctionsurface_CRG * psurfaceCRG = junctionsurface->GetCRG(i);
+
+        nodeSurfaceCRG->SetAttribute("file",psurfaceCRG->Getfile());
+        nodeSurfaceCRG->SetDoubleAttribute("sStart",psurfaceCRG->GetsStart());
+        nodeSurfaceCRG->SetDoubleAttribute("sEnd",psurfaceCRG->GetsEnd());
+        nodeSurfaceCRG->SetAttribute("orientation",psurfaceCRG->Getorientation());
+        nodeSurfaceCRG->SetAttribute("mode",psurfaceCRG->Getmode());
+
+        std::string purpose;
+        if(psurfaceCRG->Getpurpose(purpose) == 1)
+        {
+            nodeSurfaceCRG->SetAttribute("purpose",purpose);
+        }
+
+        double sOffset,tOffset,zOffset,zScale,hOffset;
+        if(psurfaceCRG->GetsOffset(sOffset) == 1)
+        {
+            nodeSurfaceCRG->SetDoubleAttribute("sOffset",sOffset);
+        }
+        if(psurfaceCRG->GettOffset(tOffset) == 1)
+        {
+            nodeSurfaceCRG->SetDoubleAttribute("tOffset",tOffset);
+        }
+        if(psurfaceCRG->GetzOffset(zOffset) == 1)
+        {
+            nodeSurfaceCRG->SetDoubleAttribute("zOffset",zOffset);
+        }
+        if(psurfaceCRG->GetzScale(zScale) == 1)
+        {
+            nodeSurfaceCRG->SetDoubleAttribute("zScale",zScale);
+        }
+        if(psurfaceCRG->GethOffset(hOffset) == 1)
+        {
+            nodeSurfaceCRG->SetDoubleAttribute("hOffset",hOffset);
+        }
+    }
+
+    return true;
+}
+
+
+bool OpenDriveXmlWriter::WriteJunctionGroup(TiXmlElement *node, JunctionGroup *junctionGroup)
+{
+
+}
+
+bool OpenDriveXmlWriter::WriteJunctionGroupReference(TiXmlElement *node, JunctionGroupReference *junctionGroupReference)
+{
+
+}
+
 //---------------------------------------------------------------------------
 
 /**
@@ -3017,4 +3093,7 @@ bool OpenDriveXmlWriter::WriteFile(std::string fileName)
 //	return true;
 
 }
+
+
+
 //--------------

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

@@ -135,6 +135,8 @@ public:
     bool WriteJunctionboundarysegment(TiXmlElement *node, Junctionboundary *boundary);
     bool WriteJunctionelevationGrid(TiXmlElement *node, Junction *junction);
     bool WriteJunctionelevationGridelevation(TiXmlElement *node, JunctionelevationGrid *elevationGrid);
+    bool WriteJunctionsurface(TiXmlElement *node, Junction *junction);
+    bool WriteJunctionsurfaceCRG(TiXmlElement *node, Junctionsurface *junctionsurface);
 	//--------------
 
 	bool WriteJunctionPriority (TiXmlElement *node, Junction* junction);
@@ -143,6 +145,10 @@ public:
     bool WriteJunctionCrossPassStartLaneLink(TiXmlElement *node, JunctionCrossPath* junctionCrossPass);
     bool WriteJunctionCrossPassEndLaneLink(TiXmlElement *node, JunctionCrossPath* junctionCrossPass);
 	//--------------
+
+    bool WriteJunctionGroup(TiXmlElement *node, JunctionGroup *junctionGroup);
+    bool WriteJunctionGroupReference(TiXmlElement *node, JunctionGroupReference *junctionGroupReference);
+
 };
 
 

+ 122 - 0
src/common/common/xodr/OpenDrive/junctiongroup.cpp

@@ -0,0 +1,122 @@
+#include "junctiongroup.h"
+
+JunctionGroup::JunctionGroup()
+{
+
+}
+
+JunctionGroup::JunctionGroup(std::string id, std::string type)
+{
+    mid = id;
+    mtype = type;
+    mname.clear();
+    mReferenceVector.clear();
+}
+
+
+unsigned int JunctionGroup::AddjunctionReference(std::string junctionid)
+{
+    mReferenceVector.push_back(JunctionGroupReference(junctionid));
+    mLastAddedJunctionGroupReference = mReferenceVector.size()-1;
+    return mLastAddedJunctionGroupReference;
+}
+
+unsigned int JunctionGroup::ClonejunctionReference(unsigned int index)
+{
+    if(index<mReferenceVector.size()-1)
+        mReferenceVector.insert(mReferenceVector.begin()+index+1, mReferenceVector[index]);
+    else if(index==mReferenceVector.size()-1)
+        mReferenceVector.push_back(mReferenceVector[index]);
+    mLastAddedJunctionGroupReference=index+1;
+    return mLastAddedJunctionGroupReference;
+}
+
+void JunctionGroup::DeletejunctionReference(unsigned int index)
+{
+    mReferenceVector.erase(mReferenceVector.begin()+index);
+}
+
+std::vector<JunctionGroupReference>* JunctionGroup::GetjunctionReferenceVector()
+{
+    return &mReferenceVector;
+}
+
+unsigned int JunctionGroup::GetjunctionReferenceCount()
+{
+    return mReferenceVector.size();
+}
+
+JunctionGroupReference * JunctionGroup::GetjunctionReference(unsigned int i)
+{
+    return &mReferenceVector.at(i);
+}
+
+JunctionGroupReference * JunctionGroup::GetLastjunctionReference()
+{
+    if(mReferenceVector.size()>0)
+        return &mReferenceVector.at(mReferenceVector.size()-1);
+    else
+        return NULL;
+}
+
+JunctionGroupReference * JunctionGroup::GetLastAddedjunctionReference()
+{
+    if(mLastAddedJunctionGroupReference<mReferenceVector.size())
+        return &mReferenceVector.at(mLastAddedJunctionGroupReference);
+    else
+        return NULL;
+}
+
+
+std::string JunctionGroup::Getid()
+{
+    return mid;
+}
+
+std::string JunctionGroup::Gettype()
+{
+    return mtype;
+}
+
+void JunctionGroup::Setid(std::string id)
+{
+    mid = id;
+}
+
+void JunctionGroup::Settype(std::string type)
+{
+    mtype = type;
+}
+
+int JunctionGroup::Getname(std::string & name)
+{
+    if(mname.size() == 0)return 0;
+    name = mname[0];
+    return 1;
+}
+
+void JunctionGroup::Setname(std::string name)
+{
+    mname.clear();
+    mname.push_back(name);
+}
+
+JunctionGroupReference::JunctionGroupReference()
+{
+
+}
+
+JunctionGroupReference::JunctionGroupReference(std::string junctionid)
+{
+    mjunction = junctionid;
+}
+
+std::string JunctionGroupReference::Getjunction()
+{
+    return mjunction;
+}
+
+void JunctionGroupReference::Setjunction(std::string junctionid)
+{
+    mjunction = junctionid;
+}

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

@@ -0,0 +1,62 @@
+#ifndef JUNCTIONGROUP_H
+#define JUNCTIONGROUP_H
+
+#include <string>
+#include <vector>
+
+class JunctionGroup;
+class JunctionGroupReference;
+
+class JunctionGroup
+{
+private:
+    std::string mid;
+    std::string mtype;
+    std::vector<std::string> mname;
+
+    std::vector<JunctionGroupReference> mReferenceVector;
+
+    unsigned int mLastAddedJunctionGroupReference;
+
+public:
+    JunctionGroup();
+    JunctionGroup(std::string id, std::string type);
+
+    std::string Getid();
+    std::string Gettype();
+
+    void Setid(std::string id);
+    void Settype(std::string type);
+
+    int Getname(std::string & name);
+
+    void Setname(std::string name);
+
+
+    unsigned int AddjunctionReference(std::string junctionid);
+
+    unsigned int ClonejunctionReference(unsigned int index);
+
+    void DeletejunctionReference(unsigned int index);
+
+    std::vector<JunctionGroupReference>* GetjunctionReferenceVector();
+    unsigned int GetjunctionReferenceCount();
+    JunctionGroupReference * GetjunctionReference(unsigned int i);
+    JunctionGroupReference * GetLastjunctionReference();
+    JunctionGroupReference * GetLastAddedjunctionReference();
+
+};
+
+class JunctionGroupReference
+{
+private:
+    std::string mjunction;
+
+public:
+    JunctionGroupReference();
+    JunctionGroupReference(std::string junctionid);
+    std::string Getjunction();
+    void Setjunction(std::string junctionid);
+};
+
+#endif // JUNCTIONGROUP_H