Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Flatland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
yoogottamk
Flatland
Commits
55eb9c51
Commit
55eb9c51
authored
5 years ago
by
hagrid67
Browse files
Options
Downloads
Patches
Plain Diff
added render show_debug to show agent index - issue 146
parent
fc34b470
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/flatland.rst
+10
-10
10 additions, 10 deletions
docs/flatland.rst
flatland/utils/graphics_pil.py
+21
-5
21 additions, 5 deletions
flatland/utils/graphics_pil.py
flatland/utils/rendertools.py
+9
-5
9 additions, 5 deletions
flatland/utils/rendertools.py
with
40 additions
and
20 deletions
docs/flatland.rst
+
10
−
10
View file @
55eb9c51
...
...
@@ -6,10 +6,10 @@ Subpackages
.. toctree::
flatland.core
flatland.envs
flatland.evaluators
flatland.utils
flatland.core
flatland.envs
flatland.evaluators
flatland.utils
Submodules
----------
...
...
@@ -18,15 +18,15 @@ flatland.cli module
-------------------
.. automodule:: flatland.cli
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: flatland
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
This diff is collapsed.
Click to expand it.
flatland/utils/graphics_pil.py
+
21
−
5
View file @
55eb9c51
...
...
@@ -4,7 +4,7 @@ import time
import
tkinter
as
tk
import
numpy
as
np
from
PIL
import
Image
,
ImageDraw
,
ImageTk
#
, ImageFont
from
PIL
import
Image
,
ImageDraw
,
ImageTk
,
ImageFont
from
numpy
import
array
from
pkg_resources
import
resource_string
as
resource_bytes
...
...
@@ -90,6 +90,8 @@ class PILGL(GraphicsLayer):
self
.
old_background_image
=
(
None
,
None
,
None
)
self
.
create_layers
()
self
.
font
=
ImageFont
.
load_default
()
def
build_background_map
(
self
,
dTargets
):
x
=
self
.
old_background_image
rebuild
=
False
...
...
@@ -167,8 +169,14 @@ class PILGL(GraphicsLayer):
# quit but not destroy!
self
.
__class__
.
window
.
quit
()
def
text
(
self
,
*
args
,
**
kwargs
):
pass
def
text
(
self
,
xPx
,
yPx
,
strText
,
layer
=
RAIL_LAYER
):
xyPixLeftTop
=
(
xPx
,
yPx
)
self
.
draws
[
layer
].
text
(
xyPixLeftTop
,
strText
,
font
=
self
.
font
,
fill
=
(
0
,
0
,
0
,
255
))
def
text_rowcol
(
self
,
rcTopLeft
,
strText
,
layer
=
AGENT_LAYER
):
print
(
"
Text:
"
,
"
rc:
"
,
rcTopLeft
,
"
text:
"
,
strText
,
"
layer:
"
,
layer
)
xyPixLeftTop
=
tuple
((
array
(
rcTopLeft
)
*
self
.
nPixCell
)[[
1
,
0
]])
self
.
text
(
*
xyPixLeftTop
,
strText
,
layer
)
def
prettify
(
self
,
*
args
,
**
kwargs
):
pass
...
...
@@ -492,13 +500,17 @@ class PILSVG(PILGL):
False
)[
0
]
self
.
draw_image_row_col
(
colored_rail
,
(
row
,
col
),
layer
=
PILGL
.
PREDICTION_PATH_LAYER
)
def
set_rail_at
(
self
,
row
,
col
,
binary_trans
,
target
=
None
,
is_selected
=
False
,
rail_grid
=
None
):
def
set_rail_at
(
self
,
row
,
col
,
binary_trans
,
target
=
None
,
is_selected
=
False
,
rail_grid
=
None
,
show_debug
=
True
):
if
binary_trans
in
self
.
pil_rail
:
pil_track
=
self
.
pil_rail
[
binary_trans
]
if
target
is
not
None
:
target_img
=
self
.
station_colors
[
target
%
len
(
self
.
station_colors
)]
target_img
=
Image
.
alpha_composite
(
pil_track
,
target_img
)
self
.
draw_image_row_col
(
target_img
,
(
row
,
col
),
layer
=
PILGL
.
TARGET_LAYER
)
if
show_debug
:
self
.
text_rowcol
((
row
+
0.8
,
col
+
0.0
),
strText
=
str
(
target
),
layer
=
PILGL
.
TARGET_LAYER
)
if
binary_trans
==
0
:
if
self
.
background_grid
[
col
][
row
]
<=
4
:
...
...
@@ -579,7 +591,7 @@ class PILSVG(PILGL):
for
color_idx
,
pil_zug_3
in
enumerate
(
pils
):
self
.
pil_zug
[(
in_direction_2
,
out_direction_2
,
color_idx
)]
=
pils
[
color_idx
]
def
set_agent_at
(
self
,
agent_idx
,
row
,
col
,
in_direction
,
out_direction
,
is_selected
):
def
set_agent_at
(
self
,
agent_idx
,
row
,
col
,
in_direction
,
out_direction
,
is_selected
,
show_debug
=
False
):
delta_dir
=
(
out_direction
-
in_direction
)
%
4
color_idx
=
agent_idx
%
self
.
n_agent_colors
# when flipping direction at a dead end, use the "out_direction" direction.
...
...
@@ -593,6 +605,10 @@ class PILSVG(PILGL):
self
.
clear_layer
(
PILGL
.
SELECTED_AGENT_LAYER
,
0
)
self
.
draw_image_row_col
(
bg_svg
,
(
row
,
col
),
layer
=
PILGL
.
SELECTED_AGENT_LAYER
)
if
show_debug
:
print
(
"
Call text:
"
)
self
.
text_rowcol
((
row
+
0.2
,
col
+
0.2
,),
str
(
agent_idx
))
def
set_cell_occupied
(
self
,
agent_idx
,
row
,
col
):
occupied_im
=
self
.
cell_occupied
[
agent_idx
%
len
(
self
.
cell_occupied
)]
self
.
draw_image_row_col
(
occupied_im
,
(
row
,
col
),
1
)
...
...
This diff is collapsed.
Click to expand it.
flatland/utils/rendertools.py
+
9
−
5
View file @
55eb9c51
...
...
@@ -39,7 +39,9 @@ class RenderTool(object):
theta
=
np
.
linspace
(
0
,
np
.
pi
/
2
,
5
)
arc
=
array
([
np
.
cos
(
theta
),
np
.
sin
(
theta
)]).
T
# from [1,0] to [0,1]
def
__init__
(
self
,
env
,
gl
=
"
PILSVG
"
,
jupyter
=
False
,
agent_render_variant
=
AgentRenderVariant
.
ONE_STEP_BEHIND
):
def
__init__
(
self
,
env
,
gl
=
"
PILSVG
"
,
jupyter
=
False
,
agent_render_variant
=
AgentRenderVariant
.
ONE_STEP_BEHIND
,
show_debug
=
True
):
self
.
env
=
env
self
.
frame_nr
=
0
self
.
start_time
=
time
.
time
()
...
...
@@ -56,6 +58,7 @@ class RenderTool(object):
self
.
gl
=
PILSVG
(
env
.
width
,
env
.
height
,
jupyter
)
self
.
new_rail
=
True
self
.
show_debug
=
show_debug
self
.
update_background
()
def
reset
(
self
):
...
...
@@ -282,7 +285,7 @@ class RenderTool(object):
if
len
(
observation_dict
)
<
1
:
warnings
.
warn
(
"
Predictor did not provide any predicted cells to render.
\
Observa
i
ton builder needs to populate: env.dev_obs_dict
"
)
Observat
i
on builder needs to populate: env.dev_obs_dict
"
)
else
:
for
agent
in
agent_handles
:
color
=
self
.
gl
.
get_agent_color
(
agent
)
...
...
@@ -525,7 +528,7 @@ class RenderTool(object):
is_selected
=
False
self
.
gl
.
set_rail_at
(
r
,
c
,
transitions
,
target
=
target
,
is_selected
=
is_selected
,
rail_grid
=
env
.
rail
.
grid
)
rail_grid
=
env
.
rail
.
grid
,
show_debug
=
self
.
show_debug
)
self
.
gl
.
build_background_map
(
targets
)
...
...
@@ -550,7 +553,8 @@ class RenderTool(object):
# set_agent_at uses the agent index for the color
if
self
.
agent_render_variant
==
AgentRenderVariant
.
ONE_STEP_BEHIND_AND_BOX
:
self
.
gl
.
set_cell_occupied
(
agent_idx
,
*
(
agent
.
position
))
self
.
gl
.
set_agent_at
(
agent_idx
,
*
position
,
old_direction
,
direction
,
selected_agent
==
agent_idx
)
self
.
gl
.
set_agent_at
(
agent_idx
,
*
position
,
old_direction
,
direction
,
selected_agent
==
agent_idx
,
show_debug
=
self
.
show_debug
)
else
:
position
=
agent
.
position
direction
=
agent
.
direction
...
...
@@ -562,7 +566,7 @@ class RenderTool(object):
# set_agent_at uses the agent index for the color
self
.
gl
.
set_agent_at
(
agent_idx
,
*
position
,
agent
.
direction
,
direction
,
selected_agent
==
agent_idx
)
selected_agent
==
agent_idx
,
show_debug
=
self
.
show_debug
)
# set_agent_at uses the agent index for the color
if
self
.
agent_render_variant
==
AgentRenderVariant
.
AGENT_SHOWS_OPTIONS_AND_BOX
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment