Adapted no rendering to new opendrive

This commit is contained in:
Manish 2019-03-25 20:29:32 +01:00
parent 5c9e317f04
commit ec5a4bc72b
1 changed files with 42 additions and 29 deletions

View File

@ -443,7 +443,8 @@ class MapImage(object):
def draw_lane_marking(surface, points, solid=True):
if solid:
pygame.draw.lines(surface, COLOR_ORANGE_0, False, points, 2)
if len(points) > 1:
pygame.draw.lines(surface, COLOR_ORANGE_0, False, points, 2)
else:
broken_lines = [x for n, x in enumerate(zip(*(iter(points),) * 20)) if n % 3 == 0]
for line in broken_lines:
@ -493,43 +494,55 @@ class MapImage(object):
def does_cross_solid_line(waypoint, shift):
w = carla_map.get_waypoint(lateral_shift(waypoint.transform, shift), project_to_road=False)
if w is None or w.road_id != waypoint.road_id:
if w is None or w.lane_change == carla.LaneChange.None or w.road_id != waypoint.road_id:
return True
else:
return (w.lane_id * waypoint.lane_id < 0) or w.lane_id == waypoint.lane_id
topology = [x[0] for x in carla_map.get_topology()]
topology = sorted(topology, key=lambda w: w.transform.location.z)
def draw_topology (carla_topology, index):
topology = [x[index] for x in carla_topology]
topology = sorted(topology, key=lambda w: w.transform.location.z)
for waypoint in topology:
waypoints = [waypoint]
for waypoint in topology:
waypoints = [waypoint]
nxt = waypoint.next(precision)[0]
while nxt.road_id == waypoint.road_id:
waypoints.append(nxt)
nxt = nxt.next(precision)[0]
nxt = waypoint.next(precision)
if len(nxt) > 0:
nxt = nxt[0]
while nxt.road_id == waypoint.road_id:
waypoints.append(nxt)
nxt = nxt.next(precision)
if len(nxt) > 0:
nxt = nxt[0]
else:
break
left_marking = [lateral_shift(w.transform, -w.lane_width * 0.5) for w in waypoints]
right_marking = [lateral_shift(w.transform, w.lane_width * 0.5) for w in waypoints]
left_marking = [lateral_shift(w.transform, -w.lane_width * 0.5) for w in waypoints]
right_marking = [lateral_shift(w.transform, w.lane_width * 0.5) for w in waypoints]
polygon = left_marking + [x for x in reversed(right_marking)]
polygon = [world_to_pixel(x) for x in polygon]
polygon = left_marking + [x for x in reversed(right_marking)]
polygon = [world_to_pixel(x) for x in polygon]
pygame.draw.polygon(map_surface, COLOR_ALUMINIUM_5, polygon, 10)
pygame.draw.polygon(map_surface, COLOR_ALUMINIUM_5, polygon)
if len(polygon) > 2:
pygame.draw.polygon(map_surface, COLOR_ALUMINIUM_5, polygon, 10)
pygame.draw.polygon(map_surface, COLOR_ALUMINIUM_5, polygon)
if not waypoint.is_intersection:
sample = waypoints[int(len(waypoints) / 2)]
draw_lane_marking(
map_surface,
[world_to_pixel(x) for x in left_marking],
does_cross_solid_line(sample, -sample.lane_width * 1.1))
draw_lane_marking(
map_surface,
[world_to_pixel(x) for x in right_marking],
does_cross_solid_line(sample, sample.lane_width * 1.1))
for n, wp in enumerate(waypoints):
if (n % 400) == 0:
draw_arrow(map_surface, wp.transform)
if not waypoint.is_intersection:
sample = waypoints[int(len(waypoints) / 2)]
draw_lane_marking(
map_surface,
[world_to_pixel(x) for x in left_marking],
does_cross_solid_line(sample, -sample.lane_width * 1.2))
draw_lane_marking(
map_surface,
[world_to_pixel(x) for x in right_marking],
does_cross_solid_line(sample, sample.lane_width * 1.2))
for n, wp in enumerate(waypoints):
if (n % 400) == 0:
draw_arrow(map_surface, wp.transform)
topology = carla_map.get_topology()
draw_topology(topology, 0)
draw_topology(topology, 1)
actors = carla_world.get_actors()
stops_transform = [actor.get_transform() for actor in actors if 'stop' in actor.type_id]