-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xodr offset transformation #217
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,12 +115,23 @@ def parse_lanes_from_lane_sections(self, lanes, lane_section): | |
lane_section["lanes"].append(new_lane) | ||
return lane_section | ||
|
||
def parse_offset(self, header): | ||
# in compiliance with 5.2.2 of specification | ||
offset = {} | ||
offset["x"] = float(header.find("offset").get("x")) | ||
offset["y"] = float(header.find("offset").get("y")) | ||
offset["z"] = float(header.find("offset").get("z")) | ||
offset["hdg"] = float(header.find("offset").get("hdg")) | ||
return offset | ||
|
||
def parse_header(self, header): | ||
new_header = {} | ||
new_header["north"] = header.get("north") | ||
new_header["south"] = header.get("south") | ||
new_header["east"] = header.get("east") | ||
new_header["west"] = header.get("west") | ||
if header.find("offset") is not None: | ||
new_header["offset"] = self.parse_offset(header) | ||
self.python_map["header"] = new_header | ||
|
||
def parse_lane_sections_from_road(self, lane_sections, road): | ||
|
@@ -247,7 +258,8 @@ def print_python_map(self): | |
pp = pprint.PrettyPrinter(indent=2) | ||
pp.pprint(self.python_map) | ||
|
||
def create_cpp_plan_view(self, plan_view): | ||
def create_cpp_plan_view(self, plan_view, header): | ||
|
||
new_plan_view = PlanView() | ||
# create plan view.. | ||
for geometry in plan_view["geometries"]: | ||
|
@@ -267,6 +279,15 @@ def create_cpp_plan_view(self, plan_view): | |
float(geometry["length"]), | ||
float(geometry["geometry"]["curv_start"]), | ||
float(geometry["geometry"]["curv_end"]), 2) # TODO: s_inc | ||
|
||
# now use header/ offset to modify plan view | ||
if "offset" in header: | ||
off_x = header["offset"]["x"] | ||
off_y = header["offset"]["y"] | ||
off_hdg = header["offset"]["hdg"] | ||
print("Transforming PlanView with given offset", header["offset"]) | ||
new_plan_view.apply_offset_transform(off_x, off_y, off_hdg) | ||
|
||
return new_plan_view | ||
|
||
def create_cpp_road_link(self, link): | ||
|
@@ -289,11 +310,11 @@ def create_cpp_road_link(self, link): | |
pass | ||
return new_link | ||
|
||
def create_cpp_road(self, road): | ||
def create_cpp_road(self, road, header): | ||
new_road = Road() | ||
new_road.id = int(road["id"]) | ||
new_road.name = road["name"] | ||
new_road.plan_view = self.create_cpp_plan_view(road["plan_view"]) | ||
new_road.plan_view = self.create_cpp_plan_view(road["plan_view"], header) | ||
new_road = self.create_cpp_lane_section(new_road, road) | ||
new_road.link = self.create_cpp_road_link(road["link"]) | ||
|
||
|
@@ -431,7 +452,7 @@ def convert_to_map(self, python_map): | |
CPP Map -- Map for usage with CPP | ||
""" | ||
for road in self.python_map["roads"]: | ||
new_road = self.create_cpp_road(road) | ||
new_road = self.create_cpp_road(road, self.python_map["header"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if there is no header -- like in many files? |
||
self.map.add_road(new_road) | ||
|
||
for junction in self.python_map["junctions"]: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,14 @@ bool PlanView::add_arc( | |
return true; | ||
} | ||
|
||
bool PlanView::apply_offset_transform(float x, float y, float hdg) { | ||
geometry::Line rotated_line = rotate(reference_line_, hdg); | ||
geometry::Line transformed_line = translate(rotated_line, x, y); | ||
reference_line_ = transformed_line; | ||
Comment on lines
+97
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reference_line_ = translate(rotated_line, x, y); |
||
|
||
return true; | ||
} | ||
|
||
} // namespace opendrive | ||
} // namespace world | ||
} // namespace modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The length(s) should not change due to a rotation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, just wanted to make sure ... I'll remove it