Browse Source

change tool/map_lanetoxodr. add road type speed.

yuchuli 3 years ago
parent
commit
f50f6829f8

+ 30 - 0
src/tool/map_lanetoxodr/OpenDrive/OpenDrive.cpp

@@ -305,3 +305,33 @@ void Header::GetLat0Lon0(double &lat0, double &lon0)
     lat0 = mLat0;
     lon0 = mLon0;
 }
+
+void Header::GetVendor(std::string &strvendor)
+{
+    strvendor = mVendor;
+}
+
+void Header::SetVendor(std::string strvendor)
+{
+    mVendor = strvendor;
+}
+
+void Header::GetgeoReference(std::string &strgeoReference)
+{
+     strgeoReference = mgeoReference;
+}
+
+void Header::GetuserData(std::string &struserData)
+{
+    struserData = muserData;
+}
+
+void Header::SetgeoReference(std::string strgeoReference)
+{
+    mgeoReference = strgeoReference;
+}
+
+void Header::SetuserData(std::string struserData)
+{
+    muserData = struserData;
+}

+ 11 - 1
src/tool/map_lanetoxodr/OpenDrive/OpenDrive.h

@@ -128,7 +128,6 @@ public:
 };
 
 
-
 /**
  * Class used to store the heading details of the OpenDrive file
  */
@@ -147,12 +146,16 @@ private:
 	double mSouth;
 	double mEast;
 	double mWest;
+    string mVendor;
 
     //Added by Yuchuli,2019.11.04
     double mLat0;
     double mLon0;
     double mHdg0;
 
+    string mgeoReference;
+    string muserData;
+
 public:
 	/**
 	 * Constructor that initializes the base properties
@@ -171,6 +174,10 @@ public:
     void GetAllParams(unsigned short int &revMajor, unsigned short int &revMinor, string &name, float &version, string &date,
         double &north, double &south, double &east,double &west,double &lat0,double &lon0, double & hdg0);
 	void GetXYValues(double &north, double &south, double &east,double &west);
+    void GetVendor(std::string & strvendor);
+
+    void GetgeoReference(std::string & strgeoReference);
+    void GetuserData(std::string & struserData);
 	
 	/**
 	 * Setter for all properties
@@ -181,6 +188,9 @@ public:
 
     void SetAllParams(unsigned short int revMajor, unsigned short int revMinor, string name, float version, string date,
         double north, double south, double east,double west,double lat0,double lon0,double hdg0);
+    void SetVendor(std::string strvendor);
+    void SetgeoReference(std::string strgeoReference);
+    void SetuserData(std::string struserData);
 
 
     void GetLat0Lon0(double & lat0,double & lon0);

+ 37 - 1
src/tool/map_lanetoxodr/OpenDrive/OpenDriveXmlParser.cpp

@@ -30,6 +30,7 @@ bool OpenDriveXmlParser::ReadHeader(TiXmlElement *node)
 	double south;
 	double east;
 	double west;
+    string strvendor;
 
     //Added By Yuchuli,2019.11.04
     double lat0;
@@ -54,12 +55,37 @@ bool OpenDriveXmlParser::ReadHeader(TiXmlElement *node)
 		return false;
 	}
 
+
     checker+=node->QueryDoubleAttribute("lat0",&lat0);
     checker+=node->QueryDoubleAttribute("lon0",&lon0);
     checker+=node->QueryDoubleAttribute("hdg0",&hdg0);
 
     mOpenDrive->SetHeader(revMajor, revMinor, name, version, date, north, south, east, west,lat0,lon0,hdg0);
 
+    if(node->QueryStringAttribute("vendor",&strvendor) == TIXML_SUCCESS)
+    {
+        mOpenDrive->GetHeader()->SetVendor(strvendor);
+    }
+
+    TiXmlElement *nodegeo=node->FirstChildElement("geoReference");
+    if(nodegeo != NULL)
+    {
+
+        TiXmlPrinter *printer = new TiXmlPrinter();
+        nodegeo->Accept(printer );//保存该节点及其子节点到字符串
+        std::string str = printer->Str();
+        mOpenDrive->GetHeader()->SetgeoReference(str);
+    }
+
+    TiXmlElement *nodeuserData=node->FirstChildElement("userData");
+    if(nodeuserData != NULL)
+    {
+
+        TiXmlPrinter *printer = new TiXmlPrinter();
+        nodeuserData->Accept(printer );//保存该节点及其子节点到字符串
+        std::string str = printer->Str();
+        mOpenDrive->GetHeader()->SetuserData(str);
+    }
 	return true;
 
 }
@@ -277,6 +303,7 @@ bool OpenDriveXmlParser::ReadRoadType (Road* road, TiXmlElement *node)
 {
 	double s;
 	string type;
+    string country;
 
 	int checker=TIXML_SUCCESS;
 	checker+=node->QueryDoubleAttribute("s",&s);
@@ -288,7 +315,16 @@ bool OpenDriveXmlParser::ReadRoadType (Road* road, TiXmlElement *node)
 		return false;
 	}
 
-	road->AddRoadType(s,type);
+    if(node->QueryStringAttribute("country",&country) == TIXML_SUCCESS)
+    {
+        road->AddRoadType(s,type,country);
+    }
+    else
+    {
+        road->AddRoadType(s,type);
+    }
+
+
 	return true;
 }
 //--------------

+ 32 - 0
src/tool/map_lanetoxodr/OpenDrive/OpenDriveXmlWriter.cpp

@@ -34,9 +34,11 @@ bool OpenDriveXmlWriter::WriteHeader(TiXmlElement *node)
     double lat0;
     double lon0;
     double hdg0;
+    string strvendor;
 
 	Header *lHeader = mOpenDrive->GetHeader();
     lHeader->GetAllParams(revMajor, revMinor, name, version, date, north, south, east, west,lat0,lon0,hdg0);
+    lHeader->GetVendor(strvendor);
 
 	TiXmlElement *nodeHeader = new TiXmlElement("header");
 	node->LinkEndChild(nodeHeader);
@@ -75,6 +77,36 @@ bool OpenDriveXmlWriter::WriteHeader(TiXmlElement *node)
     shdg0 << setprecision(16) << setiosflags (ios_base::scientific) << hdg0;
     nodeHeader->SetAttribute("hdg0",shdg0.str());
 
+    if(strvendor.size()>0)
+        nodeHeader->SetAttribute("vendor",strvendor);
+    else
+    {
+        nodeHeader->SetAttribute("vendor","adc");
+    }
+
+    std::string strgeoReference;
+    std::string struserData;
+    lHeader->GetgeoReference(strgeoReference);
+    lHeader->GetuserData(struserData);
+
+    if(strgeoReference != "")
+    {
+        TiXmlElement * nodegeoReference = new TiXmlElement("geoReference");
+        nodegeoReference->Parse(strgeoReference.data(),0,TIXML_ENCODING_UTF8);
+        nodeHeader->LinkEndChild(nodegeoReference);
+
+    }
+
+    if(struserData != "")
+    {
+        TiXmlElement * nodeuserData = new TiXmlElement("userData");
+        nodeuserData->Parse(struserData.data(),0,TIXML_ENCODING_UTF8);
+        nodeHeader->LinkEndChild(nodeuserData);
+
+    }
+
+
+
 
 	return true;
 }

+ 87 - 5
src/tool/map_lanetoxodr/OpenDrive/Road.cpp

@@ -560,14 +560,14 @@ void Road::RemoveNeighbor2()
 /**
  * Methods used to add child records to the respective vectors
  */
-unsigned int Road::AddRoadType(double s, string type)
+unsigned int Road::AddRoadType(double s, string type,string country)
 {	
 	// Gets the index where the record should be inserted in the vector
 	unsigned int index = CheckRoadTypeInterval(s)+1;
 	// If larger than the record count - push to the back
-	if(index>=GetRoadTypeCount()) mRoadTypeVector.push_back(RoadType(s, type));
+    if(index>=GetRoadTypeCount()) mRoadTypeVector.push_back(RoadType(s, type,country));
 	// else insert in the middle
-	else mRoadTypeVector.insert(mRoadTypeVector.begin()+index, RoadType(s, type));
+    else mRoadTypeVector.insert(mRoadTypeVector.begin()+index, RoadType(s, type,country));
 	// Save the last added record index
 	mLastAddedRoadType=index;
 	return index;
@@ -1228,9 +1228,9 @@ void RoadNeighbor::SetDirection(string direction)
 /**
  * Constructor which intializes the basic properties
  */
-RoadType::RoadType (double s, string type)
+RoadType::RoadType (double s, string type,string country)
 {	
-	mS=s; mType=type;	
+    mS=s; mType=type;mCountry = country;
 }
 
 /**
@@ -1244,6 +1244,10 @@ void RoadType::SetType(string type)
 {
 	mType=type;
 }
+void RoadType::SetCountry(std::string country)
+{
+    mCountry = country;
+}
 
 /**
  * Getters for the basic properties
@@ -1256,7 +1260,85 @@ string RoadType::GetType()
 {
 	return mType;
 }
+string RoadType::GetCountry()
+{
+    return mCountry;
+}
+
+vector<RoadTypeSpeed> * RoadType::GetRoadTypeSpeedVector()
+{
+    return &mRoadTypeSpeedVector;
+}
+
+unsigned int RoadType::GetRoadTypeSpeedCount()
+{
+    return mRoadTypeSpeedVector.size();
+}
+
+RoadTypeSpeed * RoadType::GetRoadTypeSpeed(unsigned int i)
+{
+    if ((mRoadTypeSpeedVector.size()>0)&&(i<mRoadTypeSpeedVector.size()))
+        return &mRoadTypeSpeedVector.at(i);
+    else
+        return NULL;
+}
+
+unsigned int RoadType::AddRoadTypeSpeed(double maxSpeed, std::string unit)
+{
+    RoadTypeSpeed rts(maxSpeed,unit);
+    if(mRoadTypeSpeedVector.size()>0)mRoadTypeSpeedVector.clear();
+    mRoadTypeSpeedVector.push_back(rts);
+    return mRoadTypeSpeedVector.size()-1;
+}
+
+void RoadType::DeleteRoadTypeSpeed(unsigned int index)
+{
+    if(index >= 1)
+    {
+        return;
+    }
+    mRoadTypeSpeedVector.clear();
+}
+
+
+
+
+//***********************************************************************************
+//Road Type Speed
+//***********************************************************************************
+/**
+ * Constructor which intializes the basic properties
+ */
+
+RoadTypeSpeed::RoadTypeSpeed(double maxSpeed, std::string unit)
+{
+    mmaxSpeed = maxSpeed;
+    munit = unit;
+}
 
+/**
+ * Setters for the basic properties
+ */
+void RoadTypeSpeed::SetmaxSpeed(double value)
+{
+    mmaxSpeed = value;
+}
+void RoadTypeSpeed::Setunit(std::string unit)
+{
+    munit = unit;
+}
+
+/**
+ * Getters for the basic properties
+ */
+double RoadTypeSpeed::GetmaxSpeed()
+{
+    return mmaxSpeed;
+}
+string RoadTypeSpeed::Getunit()
+{
+    return munit;
+}
 
 
 

+ 54 - 2
src/tool/map_lanetoxodr/OpenDrive/Road.h

@@ -15,6 +15,7 @@
 class Road;
 class RoadLink;
 class RoadNeighbor;
+class RoadTypeSpeed;
 class RoadType;
 class GeometryBlock;
 class Elevation;
@@ -233,7 +234,7 @@ public:
 	/**
 	 * Methods used to add child records to the respective vectors
 	 */
-	unsigned int AddRoadType(double s, string type);
+    unsigned int AddRoadType(double s, string type,string country = "");
 	unsigned int AddGeometryBlock();
 	unsigned int AddElevation(double s, double a, double b, double c, double d);
 	unsigned int AddSuperElevation(double s, double a, double b, double c, double d);
@@ -396,6 +397,42 @@ public:
 	string GetDirection();
 };
 
+/**
+ * RoadType class is used to store information about a road type speed record
+ *
+ *
+ *
+ *
+ */
+class RoadTypeSpeed
+{
+private:
+    /**
+     * Base properties of a road type speed
+     */
+    double mmaxSpeed;
+    string munit;
+
+public:
+    /**
+     * Constructor which intializes the base properties
+     */
+    RoadTypeSpeed (double maxSpeed, string unit);
+
+    /**
+     * Setters for the base properties
+     */
+    void SetmaxSpeed(double value);
+    void Setunit(string unit);
+
+    /**
+     * Getters for the base properties
+     */
+    double GetmaxSpeed();
+    string Getunit();
+
+};
+
 //----------------------------------------------------------------------------------
 /**
  * RoadType class is used to store information about a road type record
@@ -412,23 +449,38 @@ private:
 	 */
 	double mS;
 	string mType;
+    string mCountry;
+
+    // Road type vector
+    vector<RoadTypeSpeed> mRoadTypeSpeedVector;
+
 public:
 	/**
 	 * Constructor which intializes the base properties
 	 */
-	RoadType (double s, string type);
+    RoadType (double s, string type,string country="");
 	
 	/**
 	 * Setters for the base properties
 	 */
 	void SetS(double value);
 	void SetType(string type);
+    void SetCountry(string country);
 	
 	/**
 	 * Getters for the base properties
 	 */
 	double GetS();
 	string GetType();
+    string GetCountry();
+
+    // Road type Speed records
+    vector<RoadTypeSpeed> *GetRoadTypeSpeedVector();
+    RoadTypeSpeed * GetRoadTypeSpeed(unsigned int i);
+    unsigned int GetRoadTypeSpeedCount();
+
+    unsigned int AddRoadTypeSpeed(double maxSpeed,string unit);
+    void DeleteRoadTypeSpeed(unsigned int index);
 };
 
 //----------------------------------------------------------------------------------

+ 16 - 1
src/tool/map_lanetoxodr/mainwindow.cpp

@@ -2778,6 +2778,13 @@ void MainWindow::onClickLoad()
     if(pxodr->GetHeader() != 0)
     {
         pxodr->GetHeader()->GetAllParams(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
+//        mxodr.SetHeader(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
+//        std::string strgeoref;
+//        std::string struserData;
+//        pxodr->GetHeader()->GetgeoReference(strgeoref);
+//        pxodr->GetHeader()->GetuserData(struserData);
+//        mxodr.GetHeader()->SetgeoReference(strgeoref);
+//        mxodr.GetHeader()->SetuserData(struserData);
     }
 
     double xMoveX = 0;
@@ -2912,7 +2919,15 @@ void MainWindow::onClickSave()
 
     if(str.indexOf(".xodr")<0)str = str + ".xodr";
 
-    mxodr.SetHeader(1,1,"adcmap",1.1,QDateTime::currentDateTime().toString("yyyy-MM-dd").toLatin1().data(),0,0,0,0,glat0,glon0,ghdg0);
+    if(mxodr.GetHeader() == NULL)
+    {
+        mxodr.SetHeader(1,1,"adcmap",1.1,QDateTime::currentDateTime().toString("yyyy-MM-dd").toLatin1().data(),0,0,0,0,glat0,glon0,ghdg0);
+        mxodr.GetHeader()->SetVendor("adc");
+    }
+    else
+    {
+        mxodr.GetHeader()->SetVendor("adc");
+    }
     OpenDriveXmlWriter x(&mxodr);
     x.WriteFile(str.toStdString());
 }