浏览代码

change map_lanetoxodr, add geely lat0 lon0 support.

yuchuli 2 年之前
父节点
当前提交
72874d80c2

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

@@ -14,6 +14,57 @@ OpenDriveXmlParser::OpenDriveXmlParser (OpenDrive* openDriveObj)
 	mOpenDrive=openDriveObj;	
 }
 
+
+bool OpenDriveXmlParser::ParseGeoReferenceLon0Lat0(std::string strgr, double & lon0,double & lat0)
+{
+    const char * strdata = strgr.data();
+    const char * strlat0 = strstr(strdata,"+lat_0");
+    if(strlat0 != NULL)
+    {
+        strlat0 = strlat0 + 7;
+        int npos = 0;
+        while((strlat0[npos] != ' ')&&(npos<30))
+        {
+            npos++;
+        }
+        int i;
+        char strvalue[100];
+        for(i=0;i<npos;i++)
+        {
+            strvalue[i] = strlat0[i];
+        }
+        strvalue[i] =0;
+        lat0 = atof(strvalue);
+    }
+    else
+    {
+        return false;
+    }
+    const char * strlon0 = strstr(strdata,"+lon_0");
+    if(strlon0 != NULL)
+    {
+        strlon0 = strlon0 + 7;
+        int npos = 0;
+        while((strlon0[npos] != ' ')&&(npos<30))
+        {
+            npos++;
+        }
+        int i;
+        char strvalue[100];
+        for(i=0;i<npos;i++)
+        {
+            strvalue[i] = strlon0[i];
+        }
+        strvalue[i] =0;
+        lon0 = atof(strvalue);
+    }
+    else
+    {
+        return false;
+    }
+    return true;
+}
+
 /**
  * The following methods are used to read the data from the XML file and fill in the the OpenDrive structure
  * Methods follow the hierarchical structure and are called automatically when ReadFile is executed
@@ -66,6 +117,19 @@ bool OpenDriveXmlParser::ReadHeader(TiXmlElement *node)
     }
     checker+=node->QueryDoubleAttribute("hdg0",&hdg0);
 
+    TiXmlElement *nodegeo=node->FirstChildElement("geoReference");
+    if(nodegeo != NULL)
+    {
+
+        TiXmlPrinter *printer = new TiXmlPrinter();
+        nodegeo->Accept(printer );//保存该节点及其子节点到字符串
+        std::string str = printer->Str();
+
+        ParseGeoReferenceLon0Lat0(str,lon0,lat0);
+
+    }
+
+
     mOpenDrive->SetHeader(revMajor, revMinor, name, version, date, north, south, east, west,lat0,lon0,hdg0);
 
     if(node->QueryStringAttribute("vendor",&strvendor) == TIXML_SUCCESS)
@@ -73,7 +137,7 @@ bool OpenDriveXmlParser::ReadHeader(TiXmlElement *node)
         mOpenDrive->GetHeader()->SetVendor(strvendor);
     }
 
-    TiXmlElement *nodegeo=node->FirstChildElement("geoReference");
+    nodegeo=node->FirstChildElement("geoReference");
     if(nodegeo != NULL)
     {
 
@@ -81,8 +145,13 @@ bool OpenDriveXmlParser::ReadHeader(TiXmlElement *node)
         nodegeo->Accept(printer );//保存该节点及其子节点到字符串
         std::string str = printer->Str();
         mOpenDrive->GetHeader()->SetgeoReference(str);
+
+        ParseGeoReferenceLon0Lat0(str,lon0,lat0);
+
     }
 
+
+
     TiXmlElement *nodeuserData=node->FirstChildElement("userData");
     if(nodeuserData != NULL)
     {

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

@@ -132,6 +132,8 @@ public:
 	bool ReadJunctionPriority (Junction* junction, TiXmlElement *node);
 	bool ReadJunctionController (Junction* junction, TiXmlElement *node);
 	//--------------
+
+    bool ParseGeoReferenceLon0Lat0(std::string strgr, double & lon0,double & lat0);
 };