Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions python-sdk/nuscenes/map_expansion/map_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from typing import Dict, List, Tuple, Optional, Union

import cv2
import descartes
from matplotlib.path import Path
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
from matplotlib.axes import Axes
from matplotlib.figure import Figure
from matplotlib.patches import Rectangle, Arrow
from matplotlib.patches import PathPatch, Rectangle, Arrow
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
from pyquaternion import Quaternion
from shapely import affinity
Expand All @@ -31,6 +31,31 @@
# Recommended style to use as the plots will show grids.
plt.style.use('seaborn-v0_8-whitegrid')


def polygon_patch(polygon, **kwargs):
"""Create a matplotlib PathPatch from a Shapely polygon.

This replaces descartes.PolygonPatch which is incompatible with Shapely 2.0+.
"""
exterior_coords = np.array(polygon.exterior.coords)
codes = np.full(len(exterior_coords), Path.LINETO, dtype=Path.code_type)
codes[0] = Path.MOVETO
codes[-1] = Path.CLOSEPOLY

all_coords = [exterior_coords]
all_codes = [codes]

for interior in polygon.interiors:
interior_coords = np.array(interior.coords)
interior_codes = np.full(len(interior_coords), Path.LINETO, dtype=Path.code_type)
interior_codes[0] = Path.MOVETO
interior_codes[-1] = Path.CLOSEPOLY
all_coords.append(interior_coords)
all_codes.append(interior_codes)

path = Path(np.concatenate(all_coords), np.concatenate(all_codes))
return PathPatch(path, **kwargs)

# Define a map geometry type for polygons and lines.
Geometry = Union[Polygon, LineString]

Expand Down Expand Up @@ -1186,7 +1211,7 @@ def render_map_in_image(self,
continue

label = layer_name
ax.add_patch(descartes.PolygonPatch(polygon_proj, fc=self.color_map[layer_name], alpha=alpha,
ax.add_patch(polygon_patch(polygon_proj, fc=self.color_map[layer_name], alpha=alpha,
label=label))

# Display the image.
Expand Down Expand Up @@ -1719,7 +1744,7 @@ def _render_polygon_layer(self, ax: Axes, layer_name: str, alpha: float, tokens:
first_time = False
else:
label = None
ax.add_patch(descartes.PolygonPatch(polygon, fc=self.color_map[layer_name], alpha=alpha,
ax.add_patch(polygon_patch(polygon, fc=self.color_map[layer_name], alpha=alpha,
label=label))
else:
for record in records:
Expand All @@ -1731,7 +1756,7 @@ def _render_polygon_layer(self, ax: Axes, layer_name: str, alpha: float, tokens:
else:
label = None

ax.add_patch(descartes.PolygonPatch(polygon, fc=self.color_map[layer_name], alpha=alpha,
ax.add_patch(polygon_patch(polygon, fc=self.color_map[layer_name], alpha=alpha,
label=label))

def _render_line_layer(self, ax: Axes, layer_name: str, alpha: float, tokens: List[str] = None) -> None:
Expand Down
1 change: 0 additions & 1 deletion setup/requirements/requirements_base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cachetools
descartes
fire
matplotlib>=3.6.0
numpy>=1.22.0,<2.0.0
Expand Down
3 changes: 0 additions & 3 deletions setup/requirements_3_12_lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ contourpy==1.3.3
# via matplotlib
cycler==0.12.1
# via matplotlib
descartes==1.1.0
# via -r setup/requirements/requirements_base.txt
filelock==3.19.1
# via torch
fire==0.7.1
Expand All @@ -31,7 +29,6 @@ markupsafe==3.0.2
matplotlib==3.10.5
# via
# -r setup/requirements/requirements_base.txt
# descartes
motmetrics==1.4.0
# via -r setup/requirements/requirements_tracking.txt
mpmath==1.3.0
Expand Down
3 changes: 0 additions & 3 deletions setup/requirements_3_9_lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ contourpy==1.3.0
# via matplotlib
cycler==0.12.1
# via matplotlib
descartes==1.1.0
# via -r setup/requirements/requirements_base.txt
filelock==3.19.1
# via torch
fire==0.7.1
Expand All @@ -35,7 +33,6 @@ markupsafe==3.0.2
matplotlib==3.9.4
# via
# -r setup/requirements/requirements_base.txt
# descartes
motmetrics==1.4.0
# via -r setup/requirements/requirements_tracking.txt
mpmath==1.3.0
Expand Down