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

Scene plotter visualiztion features #134

Merged
Merged
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3f33f59
Added suggested wording updates to BLAME documentation.
Aug 8, 2023
d15c25a
Added the ability to specify face and edge colours for all agents in …
Aug 11, 2023
acb9f6b
Revert "Added suggested wording updates to BLAME documentation."
Aug 11, 2023
a90305a
Add docstrings to public methods of ScenePlotter and parameter valida…
Aug 15, 2023
4e4bcc0
Added OpenDRIVE map variables as kwargs to ScenePlotter.
Aug 15, 2023
ec75d3e
Fixed name error in kwarg validation.
Aug 15, 2023
688e977
Updated documentation and fixed data validation including open_drive …
Aug 23, 2023
d916d07
Added website documentation for Utils, ONLY for the ScenePlotter class.
Aug 23, 2023
2f9ee0c
Changed a few if statements to explicitly reference None case.
Aug 23, 2023
864027f
Merge branch 'develop' into scene_plotter_visualiztion_features
Aug 23, 2023
9ad33bd
Updates to ScenePlotter sphinx documentation.
Aug 23, 2023
4212e01
Updated sphinx documentation.
Aug 23, 2023
8e9d5b2
Further updates to sphinx documentation.
Aug 23, 2023
1705e0d
Changed members field to sphinx documentation.
Aug 23, 2023
54da6d6
Cleaned up the docstrings for ScenePlotter functions.
Aug 23, 2023
928a6da
Updated demos and README.md to use updated ScenePlotter parameters.
Aug 23, 2023
677545a
Fixed numbers parameter data type issue.
Sep 11, 2023
9cd9c22
Added functionality for left-hand coordinate maps as well as fixing d…
Sep 13, 2023
37e916f
Merged develop into branch
Jan 9, 2024
fd06597
Merge develop branch.
Mar 11, 2024
e1635a5
Updated documentation and other examples.
Mar 11, 2024
883630f
Merged in develop and made fixes.
KieranRatcliffeInvertedAI Jul 22, 2024
3bb9f77
Merged in develop branch.
KieranRatcliffeInvertedAI Aug 1, 2024
9ec2ea5
Fixed agent properties addition in scene plotter.
KieranRatcliffeInvertedAI Aug 1, 2024
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
47 changes: 41 additions & 6 deletions invertedai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ def __init__(self, map_image=None, fov=None, xy_offset=None, static_actors=None,

self.numbers = False

self.agent_face_colors = None
self.agent_edge_colors = None

def initialize_recording(self, agent_states, agent_attributes, traffic_light_states=None, conditional_agents=None):
self.agent_states_history = [agent_states]
self.traffic_lights_history = [traffic_light_states]
Expand All @@ -689,6 +692,8 @@ def reset_recording(self):
self.traffic_lights_history = []
self.agent_attributes = None
self.conditional_agents = []
self.agent_face_colors = None #: Optional[Optional[Tuple[float,float,float]]] representing R,G,B values for each agent's main color between [0,1] or None if using the default
self.agent_edge_colors = None #: Optional[Optional[Tuple[float,float,float]]] representing R,G,B values for each agent's border color between [0,1] or None if using the default

def record_step(self, agent_states, traffic_light_states=None):
self.agent_states_history.append(agent_states)
Expand All @@ -713,7 +718,17 @@ def plot_frame(self, idx, ax=None, numbers=False, direction_vec=False,

def animate_scene(self, output_name=None, start_idx=0, end_idx=-1, ax=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to add a docstring and some type hints here.

(I apologize for not doing that when I originally made this, but it's not too late to start :) )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I am going through the attributes and methods making docstrings, I have two questions as of now:

  1. What does open_drive do? It appears to be a flag that enables different behaviour but what is the high level function of these different execution paths?
  2. It seems like there are a lot of parameters from the LocationResponse dataclass are input separately into the class. My question is why is this done separately instead of just inputting the LocationResponse directly? Is there any use case where a user needs to modify these parameters after getting the LocationResponse individually since it is opening this tool up to misuse and seems overall clunky.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I don't know what open_drive does unfortunately. Maybe that's something Alireza added?

  2. If you can refactor that I would say go for it, seems like a sensible thing to do!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was said in-person but for documentation purposes, I will be taking this feedback and doing a larger refactor of ScenePlotter.

numbers=False, direction_vec=True, velocity_vec=False,
plot_frame_number=False):
plot_frame_number=False, agent_face_colors=None,
agent_edge_colors=None):

if (agent_face_colors and self.agent_attributes) and (len(agent_face_colors) != len(self.agent_attributes)):
raise Exception("Number of agent colors does not match number of agents.")
if (agent_edge_colors and self.agent_attributes) and (len(agent_edge_colors) != len(self.agent_attributes)):
raise Exception("Number of agent colors does not match number of agents.")

self.agent_face_colors = agent_face_colors
self.agent_edge_colors = agent_edge_colors

self._initialize_plot(ax=ax, numbers=numbers, direction_vec=direction_vec,
velocity_vec=velocity_vec, plot_frame_number=plot_frame_number)
end_idx = len(self.agent_states_history) if end_idx == -1 else end_idx
Expand Down Expand Up @@ -758,6 +773,19 @@ def _initialize_plot(self, ax=None, numbers=False, direction_vec=True,

self._update_frame_to(0)

def _get_color(self,agent_idx,color_list):
c = None
if color_list and color_list[agent_idx]:
is_good_color_format = isinstance(color_list[agent_idx],tuple)
for pc in color_list[agent_idx]:
is_good_color_format *= isinstance(pc,float) and (0.0 <= pc <= 1.0)

if not is_good_color_format:
raise Exception(f"Expected color format is Tuple[float,float,float] with 0 <= float <= 1 but received {color_list[agent_idx]}.")
c = color_list[agent_idx]

return c

def _update_frame_to(self, frame_idx):
for i, (agent, agent_attribute) in enumerate(zip(self.agent_states_history[frame_idx], self.agent_attributes)):
self._update_agent(i, agent, agent_attribute)
Expand Down Expand Up @@ -812,13 +840,20 @@ def _update_agent(self, agent_idx, agent, agent_attribute):
self.box_labels[agent_idx].set_x(x)
self.box_labels[agent_idx].set_y(y)

if agent_idx in self.conditional_agents:
c = self.cond_c
else:
c = self.agent_c
lw = 1
fc = self._get_color(agent_idx,self.agent_face_colors)
if not fc:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use if fc is None here. Although in this case I think you'd be OK, it is generally not a good idea to check for None as a boolean (the problem is that 0, [] and '' are also False, but they are not None). See: https://peps.python.org/pep-0008/#programming-recommendations

if agent_idx in self.conditional_agents:
fc = self.cond_c
else:
fc = self.agent_c
ec = self._get_color(agent_idx,self.agent_edge_colors)
if not ec:
lw = 0
ec = fc

rect = Rectangle((x - l / 2, y - w / 2), l, w, angle=psi *
180 / np.pi, rotation_point='center', fc=c, lw=0)
180 / np.pi, rotation_point='center', fc=fc, ec=ec, lw=lw)
if agent_idx in self.actor_boxes:
self.actor_boxes[agent_idx].remove()
self.actor_boxes[agent_idx] = rect
Expand Down