Skip to content
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

Fixed bubble rendering issue, added ConfigurableZone #1693

Merged
merged 13 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions envision/web/src/helpers/state_unpacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const WorldState = Object.freeze({
SCENARIO_ID: 1,
SCENARIO_NAME: 2,
TRAFFIC: 3,
BUBBLES: 4,
SCORES: 5,
EGO_AGENT_IDS: 6,
BUBBLES: 5,
SCORES: 6,
EGO_AGENT_IDS: 7,
});

const Traffic = Object.freeze({
Expand Down
40 changes: 38 additions & 2 deletions smarts/sstudio/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from dataclasses import dataclass, field
from enum import IntEnum
from sys import maxsize
from typing import Any, Callable, Dict, NewType, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Dict, NewType, Optional, Sequence, Tuple, Union, List

import numpy as np
from shapely.affinity import rotate as shapely_rotate
Expand Down Expand Up @@ -653,7 +653,7 @@ class GroupedLapMission:
class Zone:
"""The base for a descriptor that defines a capture area."""

def to_geometry(self, road_map: RoadMap) -> Polygon:
def to_geometry(self, road_map: Optional[RoadMap] = None) -> Polygon:
"""Generates the geometry from this zone."""
raise NotImplementedError

Expand Down Expand Up @@ -813,6 +813,36 @@ def to_geometry(self, road_map: Optional[RoadMap] = None) -> Polygon:
poly = shapely_rotate(poly, self.rotation, use_radians=True)
return shapely_translate(poly, xoff=x, yoff=y)

@dataclass(frozen=True)
class ConfigurableZone(Zone):
"""A descripter that defines a specific configurableZone defined by user"""

ext_coordinates: List[Tuple[float, float]]
"""external coordinates of the polygon"""
rotation: Optional[float] = None
"""The heading direction of the bubble(radians, clock-wise rotation)"""

def to_geometry(self, road_map: Optional[RoadMap] = None) -> Polygon:
"""Generate a polygon according to given coordinates"""
poly = None
if (
len(self.ext_coordinates) == 2
): # if user only specified two points, create a box
x_min = min(self.ext_coordinates[0][0], self.ext_coordinates[1][0])
x_max = max(self.ext_coordinates[0][0], self.ext_coordinates[1][0])
y_min = min(self.ext_coordinates[1][0], self.ext_coordinates[1][1])
y_max = max(self.ext_coordinates[1][0], self.ext_coordinates[1][1])
poly = Polygon(
[(x_min, y_min), (x_max, y_min), (x_max, y_max), (x_min, y_max)],
)

else: # else create a polygon according to the coordinates
poly = Polygon(self.ext_coordinates)

if self.rotation is not None:
poly = shapely_rotate(poly, self.rotation, use_radians=True)
return poly


@dataclass(frozen=True)
class BubbleLimits:
Expand Down Expand Up @@ -890,6 +920,12 @@ def __post_init__(self):
"Only boids can have keep_alive enabled (for persistent boids)"
)

poly = None
if not isinstance(self.zone, MapZone):
poly = self.zone.to_geometry(road_map=None)
if poly is not None and (poly.is_valid == False):
raise ValueError("The Zone Polygon is not a valid closed loop")

@staticmethod
def to_actor_id(actor, mission_group):
"""Mashes the actor id and mission group to create what needs to be a unique id."""
Expand Down