Browse Source

change tool/map_lanetoxodr. add lanebore and lane's userData.

yuchuli 3 years ago
parent
commit
16d91f8d7d

+ 143 - 0
src/tool/map_lanetoxodr/OpenDrive/Lane.cpp

@@ -428,7 +428,23 @@ LaneSection::~LaneSection()
 	mLaneVector.clear();
 }
 
+/**
+ * @brief LaneSection::SetSingleSide
+ * @param singleSide
+ */
+void LaneSection::SetSingleSide(std::string singleSide)
+{
+    msingleSide = singleSide;
+}
 
+/**
+ * @brief LaneSection::GetSingleSide
+ * @return singleSide
+ */
+string LaneSection::GetSingleSide()
+{
+    return msingleSide;
+}
 /**
 * Lane Section Sample. Holds all the lane information at a certain S value including lane widths, levels, 
 * heights, etc
@@ -615,6 +631,28 @@ void Lane::RemoveSuccessor()
 {	mSuccessor=0;	mSuccessorExists=false;		}
 
 
+/**
+ * @brief Lane::AddBorderRecord  Add Border Record
+ * @param s
+ * @param a
+ * @param b
+ * @param c
+ * @param d
+ * @return
+ */
+unsigned int Lane::AddBorderRecord(double s, double a, double b, double c, double d)
+{
+    // Gets the index where the record should be inserted in the vector
+    unsigned int index = CheckBorderInterval(s)+1;
+    // If larger than the record count - push to the back
+    if(index>=GetLaneBorderCount()) mLaneBorder.push_back(LaneBorder(s,a,b,c,d));
+    // else insert in the middle
+    else mLaneBorder.insert(mLaneBorder.begin()+index, LaneBorder(s,a,b,c,d));
+    // Save the last added record index
+    mLastAddedLaneBorder=index;
+    return index;
+}
+
 /**
  * Methods used to add child records to the respective vectors
  */
@@ -697,6 +735,24 @@ unsigned int Lane::AddHeightRecord(double sOffset, double inner, double outer)
 	return index;
 }
 
+/**
+ * @brief Lane::CloneLaneBorder
+ * @param index
+ * @return
+ */
+unsigned int Lane::CloneLaneBorder(unsigned int index)
+{
+    // Clone the object and insert it in the middle of the vector
+    if(index<mLaneBorder.size()-1)
+        mLaneBorder.insert(mLaneBorder.begin()+index+1, mLaneBorder[index]);
+    // or just push it to the back
+    else if(index==mLaneBorder.size()-1)
+        mLaneBorder.push_back(mLaneBorder[index]);
+    // Save the last added record index
+    mLastAddedLaneBorder=index+1;
+    return mLastAddedLaneBorder;
+}
+
 /**
  * Methods used to clone child records in the respective vectors
  */
@@ -779,9 +835,16 @@ unsigned int Lane::CloneLaneHeight(unsigned int index)
 	return mLastAddedLaneHeight;
 }
 
+
+
 /**
  * Methods used to delete child records from the respective vectors
  */
+
+void Lane::DeleteLaneBoder(unsigned int index)
+{
+    mLaneBorder.erase(mLaneBorder.begin()+index);
+}
 void Lane::DeleteLaneWidth(unsigned int index)
 {
 	mLaneWidth.erase(mLaneWidth.begin()+index);
@@ -856,6 +919,9 @@ int Lane::GetSuccessor()
 /**
 *	Get pointers to the records vectors
 */
+vector <LaneBorder> *Lane::GetLaneBorderVector()
+{	return &mLaneBorder;	}
+
 vector <LaneWidth> *Lane::GetLaneWidthVector()
 {	return &mLaneWidth;	}
 
@@ -881,6 +947,9 @@ vector <LaneHeight> *Lane::GetLaneHeightVector()
 /**
 *	Get the number of elements in a certain vector
 */
+unsigned int Lane::GetLaneBorderCount()
+{	return mLaneBorder.size();	}
+
 unsigned int Lane::GetLaneWidthCount()
 {	return mLaneWidth.size();	}
 
@@ -905,6 +974,14 @@ unsigned int Lane::GetLaneHeightCount()
 /**
 *	Get the elements of a certain vectors at position i
 */
+LaneBorder* Lane::GetLaneBorder(unsigned int i)
+{
+    if ((mLaneBorder.size()>0)&&(i<mLaneBorder.size()))
+        return &mLaneBorder.at(i);
+    else
+        return NULL;
+}
+
 LaneWidth* Lane::GetLaneWidth(unsigned int i)
 {
 	if ((mLaneWidth.size()>0)&&(i<mLaneWidth.size()))
@@ -965,6 +1042,13 @@ LaneHeight* Lane::GetLaneHeight(unsigned int i)
 /**
 *	Get the last elements of a certain vectors
 */
+LaneBorder* Lane::GetLastLaneBorder()
+{
+    if (mLaneBorder.size()>0)
+        return &mLaneBorder.at(mLaneBorder.size()-1);
+    else
+        return NULL;
+}
 LaneWidth* Lane::GetLastLaneWidth()
 {
 	if (mLaneWidth.size()>0)
@@ -1018,6 +1102,13 @@ LaneHeight* Lane::GetLastLaneHeight()
 /**
 *	Get the last added elements of a certain vectors (their position might not be at the end of the vector)
 */
+LaneBorder* Lane::GetLastAddedLaneBorder()
+{
+    if(mLastAddedLaneBorder<mLaneBorder.size())
+        return &mLaneBorder.at(mLastAddedLaneBorder);
+    else
+        return NULL;
+}
 LaneWidth* Lane::GetLastAddedLaneWidth()
 {
 	if(mLastAddedLaneWidth<mLaneWidth.size())
@@ -1071,6 +1162,21 @@ LaneHeight* Lane::GetLastAddedLaneHeight()
 /**
 *	Check the intervals and return the index of the records that applies to the provided s-offset
 */
+int  Lane::CheckBorderInterval(double s_check)
+{
+
+    int res=-1;
+    //Go through all the width records
+    for (unsigned int i=0;i<mLaneBorder.size();i++)
+    {
+        //check if the s_check belongs to the current record
+        if (s_check >= mLaneBorder.at(i).GetS())
+            res=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
+}
 int  Lane::CheckWidthInterval(double s_check)
 {
 
@@ -1174,6 +1280,18 @@ int Lane::CheckHeightInterval(double s_check)
 /**
 *	Evaluate the record and return the width value
 */
+
+double  Lane::GetBorderValue(double s_check)
+{
+    double retVal=0;
+    //find the record where s_check belongs
+    int index=CheckBorderInterval(s_check);
+    //If found, return the type
+    if (index>=0)
+        retVal= mLaneBorder.at(index).GetValue(s_check);
+    return retVal;
+}
+
 double  Lane::GetWidthValue(double s_check)
 {
 	double retVal=0;
@@ -1203,6 +1321,16 @@ LaneHeight  Lane::GetHeightValue(double s_check)
 }
 
 
+void Lane::SetuserData(std::string struserData)
+{
+    muserData = struserData;
+}
+
+void Lane::GetuserData(std::string &struserData)
+{
+    struserData = muserData;
+}
+
 /**
 *	Evaluate the road marks records and return the road mark object corresponding to the provided s-offset
 */
@@ -1252,8 +1380,23 @@ Lane::~Lane()
 
 	// DELETING LANE HEIGHTS
 	mLaneHeight.clear();
+
+    //DELETE LANE BORDERS
+    mLaneBorder.clear();
 }
 
+
+/**
+ * @brief LaneWidth::LaneWidth
+ * @param s
+ * @param a
+ * @param b
+ * @param c
+ * @param d
+ */
+LaneBorder::LaneBorder(double s, double a, double b, double c, double d):ThirdOrderPolynom(s,a,b,c,d)
+{}
+
 /**
 * Lane width class. Holds all the data that describes a lane width
 *

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

@@ -18,6 +18,7 @@ class LaneVisibility;
 class LaneSpeed;
 class LaneAccess;
 class LaneHeight;
+class LaneBorder;
 
 using std::vector;
 using std::string;
@@ -178,6 +179,9 @@ public:
 	* Destructor. Delete all the members of the vectors: mLeft, mCenter, mRight
 	*/
 	~LaneSection();
+
+    void SetSingleSide(string singleSide);
+    string GetSingleSide();
 };
 
 
@@ -316,6 +320,8 @@ private:
 	vector<LaneAccess> mLaneAccess;
 	//Lane Height
 	vector<LaneHeight> mLaneHeight;
+    //Lane Border
+    vector<LaneBorder> mLaneBorder;
 
 
 	unsigned int mLastAddedLaneWidth;
@@ -325,6 +331,9 @@ private:
 	unsigned int mLastAddedLaneSpeed;
 	unsigned int mLastAddedLaneAccess;
 	unsigned int mLastAddedLaneHeight;
+    unsigned int mLastAddedLaneBorder;
+
+    string muserData;
 
 public:
 	/**
@@ -363,6 +372,7 @@ public:
 	unsigned int AddSpeedRecord(double sOffset, double max);
 	unsigned int AddAccessRecord(double sOffset, string restriction);
 	unsigned int AddHeightRecord(double sOffset, double inner, double outer);
+    unsigned int AddBorderRecord(double s, double a, double b, double c, double d);
 
 	/**
 	 * Methods used to clone child records in the respective vectors
@@ -374,6 +384,7 @@ public:
 	unsigned int CloneLaneSpeed(unsigned int index);
 	unsigned int CloneLaneAccess(unsigned int index);
 	unsigned int CloneLaneHeight(unsigned int index);
+    unsigned int CloneLaneBorder(unsigned int index);
 
 	/**
 	 * Methods used to delete child records from the respective vectors
@@ -385,6 +396,7 @@ public:
 	void DeleteLaneSpeed(unsigned int index);
 	void DeleteLaneAccess(unsigned int index);
 	void DeleteLaneHeight(unsigned int index);
+    void DeleteLaneBoder(unsigned int index);
 
 
 	/**
@@ -413,6 +425,7 @@ public:
 	vector <LaneSpeed> *GetLaneSpeedVector();
 	vector <LaneAccess> *GetLaneAccessVector();
 	vector <LaneHeight> *GetLaneHeightVector();
+    vector <LaneBorder> *GetLaneBorderVector();
 
 
 	/**
@@ -425,6 +438,7 @@ public:
 	unsigned int GetLaneSpeedCount();
 	unsigned int GetLaneAccessCount();
 	unsigned int GetLaneHeightCount();
+    unsigned int GetLaneBorderCount();
 
 
 	/**
@@ -437,6 +451,7 @@ public:
 	LaneSpeed* GetLaneSpeed(unsigned int i);
 	LaneAccess* GetLaneAccess(unsigned int i);
 	LaneHeight* GetLaneHeight(unsigned int i);
+    LaneBorder* GetLaneBorder(unsigned int i);
 
 
 	/**
@@ -449,6 +464,7 @@ public:
 	LaneSpeed* GetLastLaneSpeed();
 	LaneAccess* GetLastLaneAccess();
 	LaneHeight* GetLastLaneHeight();
+    LaneBorder* GetLastLaneBorder();
 
 	/**
 	*	Get the last added elements of a certain vectors (their position might not be at the end of the vector)
@@ -460,6 +476,7 @@ public:
 	LaneSpeed* GetLastAddedLaneSpeed();
 	LaneAccess* GetLastAddedLaneAccess();
 	LaneHeight* GetLastAddedLaneHeight();
+    LaneBorder* GetLastAddedLaneBorder();
 
 	/**
 	*	Check the intervals and return the index of the records that applies to the provided s-offset
@@ -471,8 +488,14 @@ public:
 	int CheckSpeedInterval(double s_check);
 	int CheckAccessInterval(double s_check);
 	int CheckHeightInterval(double s_check);
+    int CheckBorderInterval(double s_check);
+
 
+    void GetuserData(std::string & struserData);
+    void SetuserData(std::string struserData);
 
+
+    double GetBorderValue(double s_check);
 	/**
 	*	Evaluate the record and return the width value
 	*/
@@ -499,6 +522,22 @@ public:
 
 };
 
+
+/**
+ * @brief The LaneBorder class Holds all the data of border
+ */
+class LaneBorder : public ThirdOrderPolynom
+{
+public:
+    /**
+    * Constructor
+    * @param s s-offset of the record starting from the lane section s-offset
+    * @ param a,b,c,d The 4 parameters of the polynomial
+    */
+    LaneBorder(double s, double a, double b, double c, double d);
+};
+
+
 /**
 * Lane width class. Holds all the data that describes a lane width
 *

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

@@ -674,6 +674,7 @@ bool OpenDriveXmlParser::ReadLaneSections (Road* road, TiXmlElement *node)
 
 	int checker=TIXML_SUCCESS;
 	double s;
+    string singleSide;
 	checker+=node->QueryDoubleAttribute("s",&s);
 
 	if (checker!=TIXML_SUCCESS)
@@ -685,6 +686,12 @@ bool OpenDriveXmlParser::ReadLaneSections (Road* road, TiXmlElement *node)
 	
 	road->AddLaneSection(s);
 	LaneSection* laneSection=road->GetLastAddedLaneSection();
+
+    if(node->QueryStringAttribute("singleSide",&singleSide) == TIXML_SUCCESS)
+    {
+        laneSection->SetSingleSide(singleSide);
+    }
+
 	TiXmlElement *subNode=node->FirstChildElement("left");
 	if (subNode)
 	{
@@ -808,6 +815,14 @@ bool OpenDriveXmlParser::ReadLane (LaneSection* laneSection, TiXmlElement *node,
 			}
     }
 
+    //Proceed to the Road border
+    subNode=node->FirstChildElement("border");
+    while (subNode)
+    {
+        ReadLaneBorder(lane, subNode);
+        subNode=subNode->NextSiblingElement("border");
+    }
+
 	//Proceed to the Road width
 	subNode=node->FirstChildElement("width");
 	while (subNode)
@@ -864,11 +879,45 @@ bool OpenDriveXmlParser::ReadLane (LaneSection* laneSection, TiXmlElement *node,
 		subNode=subNode->NextSiblingElement("height");
 	}
 
+    //Proceed to the user Data
+    TiXmlElement *nodeuserData=node->FirstChildElement("userData");
+    if(nodeuserData != NULL)
+    {
+
+        TiXmlPrinter *printer = new TiXmlPrinter();
+        nodeuserData->Accept(printer );//保存该节点及其子节点到字符串
+        std::string str = printer->Str();
+        lane->SetuserData(str);
+    }
+
 	return true;
 }
 //--------------
 
 
+bool OpenDriveXmlParser::ReadLaneBorder(Lane* lane, TiXmlElement *node)
+{
+    double sOffset, a, b, c, d;
+
+    int checker=TIXML_SUCCESS;
+    checker+=node->QueryDoubleAttribute("sOffset",&sOffset);
+    checker+=node->QueryDoubleAttribute("a",&a);
+    checker+=node->QueryDoubleAttribute("b",&b);
+    checker+=node->QueryDoubleAttribute("c",&c);
+    checker+=node->QueryDoubleAttribute("d",&d);
+
+    if (checker!=TIXML_SUCCESS)
+    {
+        cout<<"Error parsing Lane Weight attributes"<<endl;
+        return false;
+    }
+
+    lane->AddBorderRecord(sOffset,a,b,c,d);
+
+    return true;
+}
+//--------------
+
 bool OpenDriveXmlParser::ReadLaneWidth(Lane* lane, TiXmlElement *node)
 {
 	double sOffset, a, b, c, d;

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

@@ -63,6 +63,7 @@ public:
 	bool ReadLaneAccess(Lane* lane, TiXmlElement *node);
 	bool ReadLaneHeight(Lane* lane, TiXmlElement *node);
     bool ReadLaneOffsets(Road * road,TiXmlElement * node);
+    bool ReadLaneBorder(Lane* lane, TiXmlElement *node);
 	//--------------
 
 	bool ReadObjects (Road* road, TiXmlElement *node);

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

@@ -641,6 +641,11 @@ bool OpenDriveXmlWriter::WriteLaneSections (TiXmlElement *node, LaneSection *lan
 	ss << setprecision(16) << setiosflags (ios_base::scientific) << s;
 	nodeLaneSection->SetAttribute("s",ss.str());
 
+    if(laneSection->GetSingleSide() != "")
+    {
+        nodeLaneSection->SetAttribute("singleSide",laneSection->GetSingleSide());
+    }
+
 	//Fill in lane section
 	short int curType=1;
 	TiXmlElement* nodeLanesLeft=NULL;
@@ -761,6 +766,13 @@ bool OpenDriveXmlWriter::WriteLane (TiXmlElement *node, Lane* lane)
 		WriteLaneWidth(nodeLane, lane->GetLaneWidth(i));
 	}
 
+    //Lane Border
+    unsigned int lLaneBorderCount = lane->GetLaneBorderCount();
+    for(unsigned int i=0; i<lLaneBorderCount; i++)
+    {
+        WriteLaneBorder(nodeLane, lane->GetLaneBorder(i));
+    }
+
 	//Lane Road Mark
 	unsigned int lLaneRoadMark = lane->GetLaneRoadMarkCount();
 	for(unsigned int i=0; i<lLaneRoadMark; i++)
@@ -803,10 +815,56 @@ bool OpenDriveXmlWriter::WriteLane (TiXmlElement *node, Lane* lane)
 		WriteLaneHeight(nodeLane, lane->GetLaneHeight(i));
 	}
 
+    string struserData;
+    lane->GetuserData(struserData);
+    if(struserData != "")
+    {
+        TiXmlElement * nodeuserData = new TiXmlElement("userData");
+        nodeuserData->Parse(struserData.data(),0,TIXML_ENCODING_UTF8);
+        nodeLane->LinkEndChild(nodeuserData);
+
+    }
+
 	return true;
 }
 //--------------
 
+bool OpenDriveXmlWriter::WriteLaneBorder(TiXmlElement *node, LaneBorder* laneBorder)
+{
+    double sOffset, a, b, c, d;
+
+    sOffset=laneBorder->GetS();
+    a=laneBorder->GetA();
+    b=laneBorder->GetB();
+    c=laneBorder->GetC();
+    d=laneBorder->GetD();
+
+    TiXmlElement* nodeLaneBorder = new TiXmlElement("border");
+    node->LinkEndChild(nodeLaneBorder);
+
+    std::stringstream ssOffset;
+    ssOffset << setprecision(16) << setiosflags (ios_base::scientific) << sOffset;
+    nodeLaneBorder->SetAttribute("sOffset",ssOffset.str());
+
+    std::stringstream sa;
+    sa << setprecision(16) << setiosflags (ios_base::scientific) << a;
+    nodeLaneBorder->SetAttribute("a",sa.str());
+
+    std::stringstream sb;
+    sb << setprecision(16) << setiosflags (ios_base::scientific) << b;
+    nodeLaneBorder->SetAttribute("b",sb.str());
+
+    std::stringstream sc;
+    sc << setprecision(16) << setiosflags (ios_base::scientific) << c;
+    nodeLaneBorder->SetAttribute("c",sc.str());
+
+    std::stringstream sd;
+    sd << setprecision(16) << setiosflags (ios_base::scientific) << d;
+    nodeLaneBorder->SetAttribute("d",sd.str());
+
+    return true;
+}
+//--------------
 
 bool OpenDriveXmlWriter::WriteLaneWidth(TiXmlElement *node, LaneWidth* laneWidth)
 {

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

@@ -64,6 +64,7 @@ public:
 	bool WriteLaneAccess(TiXmlElement *node, LaneAccess* laneAccess);
 	bool WriteLaneHeight(TiXmlElement *node, LaneHeight* laneHeight);
     bool WriteLaneOffset (TiXmlElement *node, LaneOffset *laneOffset);
+    bool WriteLaneBorder(TiXmlElement *node, LaneBorder* laneWidth);
 	//--------------
 
 	bool WriteObjects (TiXmlElement *node, Road* road);