Ver Fonte

change tool/map_lanetoxodr. complete road type speed.

yuchuli há 3 anos atrás
pai
commit
b3fe85456e

+ 1 - 0
src/tool/map_lanetoxodr/OpenDrive/Lane.h

@@ -36,6 +36,7 @@ private:
 	* Record parameters
 	*/
 	double mS;
+    string msingleSide;
 	vector<Lane> mLaneVector;
 
 	unsigned int mLastAddedLane;

+ 53 - 0
src/tool/map_lanetoxodr/OpenDrive/OpenDriveXmlParser.cpp

@@ -250,6 +250,19 @@ bool  OpenDriveXmlParser::ReadRoadLink (Road* road, TiXmlElement *node, short in
 			return false;
 		}
 		road->SetPredecessor(elementType,elementId,contactPoint);
+
+        RoadLink * pRoadLink = road->GetPredecessor();
+        double elementS;
+        string elementDir;
+        if(node->QueryDoubleAttribute("elementS",&elementS) == TIXML_SUCCESS)
+        {
+            pRoadLink->SetElementS(elementS);
+        }
+        if(node->QueryStringAttribute("elementDir",&elementDir) == TIXML_SUCCESS)
+        {
+            pRoadLink->SetELementDir(elementDir);
+        }
+
 		return true;
 
 	}
@@ -271,6 +284,18 @@ bool  OpenDriveXmlParser::ReadRoadLink (Road* road, TiXmlElement *node, short in
 			return false;
 		}
 		road->SetSuccessor(elementType,elementId,contactPoint);
+
+        RoadLink * pRoadLink = road->GetSuccessor();
+        double elementS;
+        string elementDir;
+        if(node->QueryDoubleAttribute("elementS",&elementS) == TIXML_SUCCESS)
+        {
+            pRoadLink->SetElementS(elementS);
+        }
+        if(node->QueryStringAttribute("elementDir",&elementDir) == TIXML_SUCCESS)
+        {
+            pRoadLink->SetELementDir(elementDir);
+        }
 		return true;
 	}
 
@@ -297,6 +322,25 @@ bool  OpenDriveXmlParser::ReadRoadLink (Road* road, TiXmlElement *node, short in
 	return false;
 		
 }
+
+//--------------
+
+bool OpenDriveXmlParser::ReadRoadTypeSpeed(RoadType *roadtype, TiXmlElement *node)
+{
+    double maxspeed;
+    string unit = "m/s";
+    int checker=TIXML_SUCCESS;
+    checker+=node->QueryDoubleAttribute("max",&maxspeed);
+    node->QueryStringAttribute("unit",&unit);
+    if(checker != TIXML_SUCCESS)
+    {
+        cout<<"Error Parsing Road Type Speed"<<endl;
+        return false;
+    }
+    roadtype->AddRoadTypeSpeed(maxspeed,unit);
+    return true;
+}
+
 //--------------
 
 bool OpenDriveXmlParser::ReadRoadType (Road* road, TiXmlElement *node)
@@ -324,6 +368,15 @@ bool OpenDriveXmlParser::ReadRoadType (Road* road, TiXmlElement *node)
         road->AddRoadType(s,type);
     }
 
+    RoadType * roadtype = road->GetRoadType(0);
+    TiXmlElement * subNode;
+    subNode=node->FirstChildElement("speed");
+    while (subNode)
+    {
+        ReadRoadTypeSpeed(roadtype, subNode);
+        subNode=subNode->NextSiblingElement("speed");
+    }
+
 
 	return true;
 }

+ 2 - 0
src/tool/map_lanetoxodr/OpenDrive/OpenDriveXmlParser.h

@@ -41,6 +41,8 @@ public:
 	bool ReadRoadType (Road* road, TiXmlElement *node);
 	//--------------
 
+    bool ReadRoadTypeSpeed (RoadType * roadtype, TiXmlElement *node);
+
 	bool ReadPlanView(Road* road, TiXmlElement *node);
 	bool ReadGeometryBlock (Road* road, TiXmlElement *&node, short int blockType);
 	bool ReadGeometry(GeometryBlock* geomBlock, TiXmlElement *node, short int geometryType);

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

@@ -193,6 +193,16 @@ bool  OpenDriveXmlWriter::WriteRoadLinks (TiXmlElement *node, Road* road)
 		nodeLinkPredecessor->SetAttribute("elementType", lPredecessor->GetElementType());
 		nodeLinkPredecessor->SetAttribute("elementId", lPredecessor->GetElementId());
 		nodeLinkPredecessor->SetAttribute("contactPoint", lPredecessor->GetContactPoint());
+        if(lPredecessor->GetElementS()>=0)
+        {
+            std::stringstream ss;
+            ss << setprecision(16) << setiosflags (ios_base::scientific) << lPredecessor->GetElementS();
+            nodeLinkPredecessor->SetAttribute("elementS", ss.str());
+        }
+        if(lPredecessor->GetElementDir() != "")
+        {
+            nodeLinkPredecessor->SetAttribute("elementDir",lPredecessor->GetElementDir());
+        }
 	}
 	RoadLink *lSuccessor = road->GetSuccessor();
 	if(lSuccessor)
@@ -202,6 +212,16 @@ bool  OpenDriveXmlWriter::WriteRoadLinks (TiXmlElement *node, Road* road)
 		nodeLinkSuccessor->SetAttribute("elementType", lSuccessor->GetElementType());
 		nodeLinkSuccessor->SetAttribute("elementId", lSuccessor->GetElementId());
 		nodeLinkSuccessor->SetAttribute("contactPoint", lSuccessor->GetContactPoint());
+        if(lSuccessor->GetElementS()>=0)
+        {
+            std::stringstream ss;
+            ss << setprecision(16) << setiosflags (ios_base::scientific) << lSuccessor->GetElementS();
+            nodeLinkSuccessor->SetAttribute("elementS", ss.str());
+        }
+        if(lSuccessor->GetElementDir() != "")
+        {
+            nodeLinkSuccessor->SetAttribute("elementDir",lSuccessor->GetElementDir());
+        }
 	}
 	RoadNeighbor *lNeighbor1 = road->GetNeighbor1();
 	if(lNeighbor1)
@@ -224,6 +244,34 @@ bool  OpenDriveXmlWriter::WriteRoadLinks (TiXmlElement *node, Road* road)
 
 	return true;
 }
+
+//--------------
+
+bool OpenDriveXmlWriter::WriteRoadTypeSpeed(TiXmlElement *node, RoadType *roadtype)
+{
+    double maxSpeed;
+    string unit;
+
+    unsigned int roadTypeSpeedCount = roadtype->GetRoadTypeSpeedCount();
+    for(unsigned int i=0;i<roadTypeSpeedCount;i++)
+    {
+        RoadTypeSpeed * lRoadTypeSpeed = roadtype->GetRoadTypeSpeed(i);
+
+        maxSpeed = lRoadTypeSpeed->GetmaxSpeed();
+        unit = lRoadTypeSpeed->Getunit();
+
+        TiXmlElement * nodeRoadTypeSpeed = new TiXmlElement("speed");
+        node->LinkEndChild(nodeRoadTypeSpeed);
+
+        std::stringstream ss;
+        ss << setprecision(16) << setiosflags (ios_base::scientific) << maxSpeed;
+        nodeRoadTypeSpeed->SetAttribute("max",ss.str());
+        nodeRoadTypeSpeed->SetAttribute("unit",unit);
+    }
+
+    return true;
+}
+
 //--------------
 
 bool OpenDriveXmlWriter::WriteRoadType (TiXmlElement *node, Road* road)
@@ -246,6 +294,8 @@ bool OpenDriveXmlWriter::WriteRoadType (TiXmlElement *node, Road* road)
 		ss << setprecision(16) << setiosflags (ios_base::scientific) << s;
 		nodeRoadType->SetAttribute("s",ss.str());
 		nodeRoadType->SetAttribute("type",type);
+
+        WriteRoadTypeSpeed(nodeRoadType,lRoadType);
 	}
 
 	return true;

+ 2 - 0
src/tool/map_lanetoxodr/OpenDrive/OpenDriveXmlWriter.h

@@ -42,6 +42,8 @@ public:
 	bool WriteRoadType (TiXmlElement *node, Road* road);
 	//--------------
 
+    bool WriteRoadTypeSpeed(TiXmlElement * node,RoadType * roadtype);
+
 	bool WritePlanView(TiXmlElement *node, Road* road);
 	bool WriteGeometryBlock (TiXmlElement *node, GeometryBlock *geometryBlock);
 	bool WriteGeometry(TiXmlElement *node, RoadGeometry* roadGeometry, short int geometryType);

+ 16 - 0
src/tool/map_lanetoxodr/OpenDrive/Road.cpp

@@ -1159,6 +1159,14 @@ string RoadLink::GetContactPoint()
 {	
 	return mContactPoint;	
 }
+double RoadLink::GetElementS()
+{
+    return mElementS;
+}
+string RoadLink::GetElementDir()
+{
+    return mElementDir;
+}
 
 /**
  * Setters for the basic properties
@@ -1175,6 +1183,14 @@ void RoadLink::SetContactPoint(string contactPoint)
 {	
 	mContactPoint=contactPoint;	
 }
+void RoadLink::SetElementS(double value)
+{
+    mElementS = value;
+}
+void RoadLink::SetELementDir(std::string elementdir)
+{
+    mElementDir = elementdir;
+}
 
 
 //***********************************************************************************

+ 10 - 0
src/tool/map_lanetoxodr/OpenDrive/Road.h

@@ -335,6 +335,10 @@ private:
 	string mElementType;
 	string mElementId;
 	string mContactPoint;
+
+    double mElementS = -1.0;
+    string mElementDir;
+
 public:
 	/**
 	 * Constructor which intializes the base properties
@@ -347,6 +351,9 @@ public:
 	void SetElementType(string elementType);
 	void SetElementId(string elementId);
 	void SetContactPoint(string contactPoint);
+
+    void SetElementS(double value);
+    void SetELementDir(string elementdir);
 	
 
 	/**
@@ -355,6 +362,9 @@ public:
 	string GetElementType();
 	string GetElementId();
 	string GetContactPoint();
+
+    double GetElementS();
+    string GetElementDir();
 };