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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
elrichgro
Flatland
Commits
dd3df88b
Commit
dd3df88b
authored
5 years ago
by
hagrid67
Browse files
Options
Downloads
Patches
Plain Diff
rendertools - moved getTreeFromRail out of plotTreeOnRail
parent
39967741
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
flatland/utils/rendertools.py
+16
-10
16 additions, 10 deletions
flatland/utils/rendertools.py
images/env-tree-spatial.png
+0
-0
0 additions, 0 deletions
images/env-tree-spatial.png
tests/test_rendertools.py
+3
-2
3 additions, 2 deletions
tests/test_rendertools.py
with
19 additions
and
12 deletions
flatland/utils/rendertools.py
+
16
−
10
View file @
dd3df88b
...
...
@@ -30,7 +30,8 @@ class RenderTool(object):
def
__init__
(
self
,
env
):
self
.
env
=
env
def
plotTreeOnRail
(
self
,
rcPos
,
iDir
,
nDepth
=
10
):
#def plotTreeOnRail(self, rcPos, iDir, nDepth=10, color="r"):
def
plotTreeOnRail
(
self
,
lVisits
,
color
=
"
r
"
):
"""
Derives and plots a tree of transitions starting at position rcPos
in direction iDir.
...
...
@@ -50,7 +51,7 @@ class RenderTool(object):
self
.
plotAgent
(
rcPos
,
iDir
,
sColor
)
gTransRCAg
=
self
.
getTransRC
(
rcPos
,
iDir
)
self
.
plotTrans
(
rcPos
,
gTransRCAg
)
self
.
plotTrans
(
rcPos
,
gTransRCAg
,
color
=
color
)
if
False
:
# TODO: this was `rcDir' but it was undefined
...
...
@@ -62,13 +63,16 @@ class RenderTool(object):
giTrans
=
np
.
where
(
tbTrans
)[
0
]
# RC list of transitions
gTransRCAg
=
self
.
__class__
.
gTransRC
[
giTrans
]
# rcPos=(6,4)
# iDir=2
gTransRCAg
=
self
.
getTransRC
(
rcPos
,
iDir
)
self
.
plotTrans
(
rcPos
,
gTransRCAg
)
for
visit
in
lVisits
:
# transition for next cell
oTrans
=
self
.
env
.
rail
[
visit
.
rc
]
tbTrans
=
rt
.
RETrans
.
get_transitions
(
oTrans
,
visit
.
iDir
)
giTrans
=
np
.
where
(
tbTrans
)[
0
]
# RC list of transitions
gTransRCAg
=
rt
.
gTransRC
[
giTrans
]
self
.
plotTrans
(
visit
.
rc
,
gTransRCAg
,
depth
=
str
(
visit
.
iDepth
),
color
=
color
)
lVisits
=
self
.
getTreeFromRail
(
rcPos
,
iDir
,
nDepth
=
nDepth
)
return
lVisits
#
lVisits = self.getTreeFromRail(rcPos, iDir, nDepth=nDepth)
#
return lVisits
def
plotAgents
(
self
):
rt
=
self
.
__class__
...
...
@@ -149,12 +153,13 @@ class RenderTool(object):
xyPos
=
np
.
matmul
(
rcPos
,
rt
.
grc2xy
)
+
rt
.
xyHalf
gxyTrans
=
xyPos
+
np
.
matmul
(
gTransRCAg
,
rt
.
grc2xy
/
2.4
)
# print(gxyTrans)
#print(gxyTrans, color)
plt
.
scatter
(
*
gxyTrans
.
T
,
color
=
color
,
marker
=
"
o
"
,
s
=
50
,
alpha
=
0.2
)
if
depth
is
not
None
:
for
x
,
y
in
gxyTrans
:
plt
.
text
(
x
,
y
,
depth
)
def
getTreeFromRail
(
self
,
rcPos
,
iDir
,
nDepth
=
10
,
bBFS
=
True
):
def
getTreeFromRail
(
self
,
rcPos
,
iDir
,
nDepth
=
10
,
bBFS
=
True
,
bPlot
=
False
):
"""
Generate a tree from the env starting at rcPos, iDir.
"""
...
...
@@ -194,7 +199,8 @@ class RenderTool(object):
stack
.
append
(
visitNext
)
# plot the available transitions from this node
self
.
plotTrans
(
visit
.
rc
,
gTransRCAg
,
depth
=
str
(
visit
.
iDepth
))
if
bPlot
:
self
.
plotTrans
(
visit
.
rc
,
gTransRCAg
,
depth
=
str
(
visit
.
iDepth
))
return
lVisits
...
...
This diff is collapsed.
Click to expand it.
images/env-tree-spatial.png
+41 B (+0%)
View file @
dd3df88b
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
This diff is collapsed.
Click to expand it.
tests/test_rendertools.py
+
3
−
2
View file @
dd3df88b
...
...
@@ -61,10 +61,11 @@ def test_render_env():
plt
.
figure
(
figsize
=
(
10
,
10
))
oRT
.
renderEnv
()
lVisits
=
oRT
.
plotTreeOnRail
(
lVisits
=
oRT
.
getTreeFromRail
(
oEnv
.
agents_position
[
0
],
oEnv
.
agents_direction
[
0
],
nDepth
=
17
)
nDepth
=
17
,
bPlot
=
True
)
checkFrozenImage
(
"
env-tree-spatial.png
"
)
...
...
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