Skip to content

Commit d57e2c2

Browse files
Parse and consider OpenDRIVE geo reference offset
1 parent 06fbda6 commit d57e2c2

6 files changed

Lines changed: 46 additions & 6 deletions

File tree

ad_map_opendrive_reader/include/opendrive/parser/GeoReferenceParser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#pragma once
1414

1515
#include <string>
16+
#include <pugixml.hpp>
17+
1618
#include "opendrive/types.hpp"
1719

1820
namespace opendrive {
@@ -21,7 +23,7 @@ namespace parser {
2123
class GeoReferenceParser
2224
{
2325
public:
24-
static ::opendrive::geom::GeoLocation Parse(const std::string &geo_reference_string);
26+
static ::opendrive::geom::GeoLocation Parse(const std::string &geo_reference_string, const pugi::xml_node &geo_offset = pugi::xml_node());
2527
};
2628

2729
} // namespace parser

ad_map_opendrive_reader/include/opendrive/types.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,11 @@ struct GeoLocation
736736
double altitude{0.};
737737
std::string projection{""};
738738
std::string projectionSetAfterLoad{""};
739+
double offset_x{0.0};
740+
double offset_y{0.0};
741+
double offset_z{0.0};
742+
double offset_hdg_sin{0.0};
743+
double offset_hdg_cos{1.0};
739744
};
740745
} // namespace geom
741746

ad_map_opendrive_reader/src/geometry/GeometryGenerator.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,15 +965,22 @@ bool convertToGeoPoints(opendrive::OpenDriveData &mapData)
965965
}
966966
}
967967

968-
auto convertENUToGeo = [&projPtr](Point &point) {
968+
auto convertENUToGeo = [&projPtr, &mapData](Point &point) {
969969
if (!point.isValid())
970970
{
971971
spdlog::error("ConvertENUToGeo: Input point invalid {}, {}", point.x, point.y);
972972
}
973973
point.ensureValid();
974+
975+
double tx = point.x + mapData.geoReference.offset_x;
976+
double ty = point.y + mapData.geoReference.offset_y;
977+
978+
double x_rot = (tx * mapData.geoReference.offset_hdg_cos) - (ty * mapData.geoReference.offset_hdg_sin);
979+
double y_rot = (tx * mapData.geoReference.offset_hdg_sin) + (ty * mapData.geoReference.offset_hdg_cos);
980+
974981
projXY enuPoint;
975-
enuPoint.u = point.x;
976-
enuPoint.v = point.y;
982+
enuPoint.u = x_rot;
983+
enuPoint.v = y_rot;
977984

978985
auto geoPoint = pj_inv(enuPoint, projPtr);
979986
point.x = geoPoint.u * RAD_TO_DEG;

ad_map_opendrive_reader/src/parser/GeoReferenceParser.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,21 @@
2424
namespace opendrive {
2525
namespace parser {
2626

27-
::opendrive::geom::GeoLocation GeoReferenceParser::Parse(const std::string &geo_reference_string)
27+
double GetAttributeOrDefault(const pugi::xml_node &node, const std::string &attribute, double const defaultValue)
28+
{
29+
auto attr = node.attribute(attribute.c_str());
30+
if (attr.empty())
31+
{
32+
return defaultValue;
33+
}
34+
else
35+
{
36+
return attr.as_double();
37+
}
38+
}
39+
40+
::opendrive::geom::GeoLocation GeoReferenceParser::Parse(const std::string &geo_reference_string,
41+
const pugi::xml_node &geo_offset)
2842
{
2943
::opendrive::geom::GeoLocation result{
3044
std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), 0.0, ""};
@@ -65,6 +79,14 @@ ::opendrive::geom::GeoLocation GeoReferenceParser::Parse(const std::string &geo_
6579
}
6680
}
6781

82+
// parse optional offset
83+
result.offset_x = GetAttributeOrDefault(geo_offset, "x", 0.0);
84+
result.offset_y = GetAttributeOrDefault(geo_offset, "y", 0.0);
85+
result.offset_z = GetAttributeOrDefault(geo_offset, "z", 0.0);
86+
auto offset_hdg = GetAttributeOrDefault(geo_offset, "hdg", 0.0);
87+
result.offset_hdg_sin = std::sin(offset_hdg);
88+
result.offset_hdg_cos = std::cos(offset_hdg);
89+
6890
return result;
6991
}
7092

ad_map_opendrive_reader/src/parser/OpenDriveParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ bool OpenDriveParser::Parse(const char *xml,
135135
}
136136

137137
out_open_drive_data.geoReference
138-
= odp::GeoReferenceParser::Parse(xmlDoc.child("OpenDRIVE").child("header").child_value("geoReference"));
138+
= odp::GeoReferenceParser::Parse(xmlDoc.child("OpenDRIVE").child("header").child_value("geoReference"),
139+
xmlDoc.child("OpenDRIVE").child("header").child("offset"));
139140

140141
auto userData = xmlDoc.child("OpenDRIVE").child("header").child("userData");
141142
if (!userData.empty())

doc/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## Latest changes
2+
#### :rocket: New Features
3+
* Add support for OpenDRIVE offset-tag in header
4+
25
## Release 3.0.0
36
#### :rocket: New Features
47
* Renamed branch: master -> main

0 commit comments

Comments
 (0)