Skip to content
Snippets Groups Projects
Commit 39ea1654 authored by hagrid67's avatar hagrid67
Browse files

Merge branch 'rendering' into 'master'

Rendering test updates - more test images

See merge request flatland/flatland!5
parents 9687611d 0be0e27f
No related branches found
No related tags found
No related merge requests found
...@@ -52,5 +52,6 @@ Authors ...@@ -52,5 +52,6 @@ Authors
* Sharada Mohanty <mohanty@aicrowd.com> * Sharada Mohanty <mohanty@aicrowd.com>
* Giacomo Spigler <giacomo.spigler@gmail.com> * Giacomo Spigler <giacomo.spigler@gmail.com>
* Mattias Ljungström <ml@mljx.io> * Mattias Ljungström <ml@mljx.io>
* Jeremy Watson
<please fill yourself in> <please fill yourself in>
...@@ -125,7 +125,7 @@ class RenderTool(object): ...@@ -125,7 +125,7 @@ class RenderTool(object):
else: else:
return gTransRCAg return gTransRCAg
def plotAgent(self, rcPos, iDir, sColor): def plotAgent(self, rcPos, iDir, sColor="r"):
""" """
Plot a simple agent. Plot a simple agent.
Assumes a working matplotlib context. Assumes a working matplotlib context.
...@@ -278,14 +278,22 @@ class RenderTool(object): ...@@ -278,14 +278,22 @@ class RenderTool(object):
visit = visitDest visit = visitDest
xyPrev = None xyPrev = None
while visit.prev is not None: while visit.prev is not None:
# rDist = np.linalg.norm(array(visit.xy) - array(xyTarg))
# xLoc = rDist + visit.iDir / 4
# print (visit.xy)
xy = np.matmul(visit.rc, rt.grc2xy) + rt.xyHalf xy = np.matmul(visit.rc, rt.grc2xy) + rt.xyHalf
if xyPrev is not None: if xyPrev is not None:
plt.plot([xy[0], xyPrev[0]], dx, dy = (xyPrev - xy) / 20
[xy[1], xyPrev[1]], xyLine = array([xy, xyPrev]) + array([dy, dx])
color="r", alpha=0.5, lw=3)
plt.plot(*xyLine.T, color="r", alpha=0.5, lw=1)
xyMid = np.sum(xyLine * [[1/4], [3/4]], axis=0)
xyArrow = array([
xyMid + [-dx-dy, +dx-dy],
xyMid,
xyMid + [-dx+dy, -dx-dy]
])
plt.plot(*xyArrow.T, color="r")
visit = visit.prev visit = visit.prev
xyPrev = xy xyPrev = xy
...@@ -411,10 +419,13 @@ class RenderTool(object): ...@@ -411,10 +419,13 @@ class RenderTool(object):
plt.xlim([0, env.width * cell_size]) plt.xlim([0, env.width * cell_size])
plt.ylim([-env.height * cell_size, 0]) plt.ylim([-env.height * cell_size, 0])
plt.xticks(np.linspace(0, env.width * cell_size, env.width+1)) gTicks = (np.arange(0, env.height) + 0.5) * cell_size
plt.yticks(np.linspace(-env.height * cell_size, 0, env.height+1), gLabels = np.arange(0, env.height)
np.abs(np.linspace(-env.height * cell_size, plt.xticks(gTicks, gLabels)
0, env.height+1)))
gTicks = np.arange(-env.height * cell_size, 0) + cell_size/2
gLabels = np.arange(env.height, 0, -1)
plt.yticks(gTicks, gLabels)
plt.xlim([0, env.width * cell_size]) plt.xlim([0, env.width * cell_size])
plt.ylim([-env.height * cell_size, 0]) plt.ylim([-env.height * cell_size, 0])
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -28,7 +28,8 @@ import flatland.utils.rendertools as rt ...@@ -28,7 +28,8 @@ import flatland.utils.rendertools as rt
def checkFrozenImage(sFileImage): def checkFrozenImage(sFileImage):
sTmpFileImage = "images/test/" + sFileImage sDirRoot = "."
sTmpFileImage = sDirRoot + "/images/test/" + sFileImage
if os.path.exists(sTmpFileImage): if os.path.exists(sTmpFileImage):
os.remove(sTmpFileImage) os.remove(sTmpFileImage)
...@@ -36,8 +37,8 @@ def checkFrozenImage(sFileImage): ...@@ -36,8 +37,8 @@ def checkFrozenImage(sFileImage):
plt.savefig(sTmpFileImage) plt.savefig(sTmpFileImage)
bytesFrozenImage = None bytesFrozenImage = None
for sDir in [ "images/", "images/test/" ]: for sDir in [ "/images/", "/images/test/" ]:
sfPath = sDir + sFileImage sfPath = sDirRoot + sDir + sFileImage
with open(sfPath, "rb") as fIn: with open(sfPath, "rb") as fIn:
bytesImage = fIn.read() bytesImage = fIn.read()
if bytesFrozenImage == None: if bytesFrozenImage == None:
...@@ -58,5 +59,26 @@ def test_render_env(): ...@@ -58,5 +59,26 @@ def test_render_env():
checkFrozenImage("basic-env.png") checkFrozenImage("basic-env.png")
plt.figure(figsize=(10,10))
oRT.renderEnv()
lVisits = oRT.plotTreeOnRail(
oEnv.agents_position[0],
oEnv.agents_direction[0],
nDepth=17)
checkFrozenImage("env-tree-spatial.png")
plt.figure(figsize=(8,8))
xyTarg = oRT.env.agents_target[0]
visitDest = oRT.plotTree(lVisits, xyTarg)
checkFrozenImage("env-tree-graph.png")
oFig = plt.figure(figsize=(10,10))
oRT.renderEnv()
oRT.plotPath(visitDest)
checkFrozenImage("env-path.png")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment