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

Merge branch 'rendering' -

moved getTreeFromRail out of plotTreeOnRail
hopefully incorporate Giacomo's changes to the image comparison
parents 989f292f 436fac21
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,7 @@ class RenderTool(object): ...@@ -30,7 +30,7 @@ class RenderTool(object):
def __init__(self, env): def __init__(self, env):
self.env = env self.env = env
def plotTreeOnRail(self, rcPos, iDir, nDepth=10): def plotTreeOnRail(self, lVisits, color="r"):
""" """
Derives and plots a tree of transitions starting at position rcPos Derives and plots a tree of transitions starting at position rcPos
in direction iDir. in direction iDir.
...@@ -50,7 +50,7 @@ class RenderTool(object): ...@@ -50,7 +50,7 @@ class RenderTool(object):
self.plotAgent(rcPos, iDir, sColor) self.plotAgent(rcPos, iDir, sColor)
gTransRCAg = self.getTransRC(rcPos, iDir) gTransRCAg = self.getTransRC(rcPos, iDir)
self.plotTrans(rcPos, gTransRCAg) self.plotTrans(rcPos, gTransRCAg, color=color)
if False: if False:
# TODO: this was `rcDir' but it was undefined # TODO: this was `rcDir' but it was undefined
...@@ -62,13 +62,15 @@ class RenderTool(object): ...@@ -62,13 +62,15 @@ class RenderTool(object):
giTrans = np.where(tbTrans)[0] # RC list of transitions giTrans = np.where(tbTrans)[0] # RC list of transitions
gTransRCAg = self.__class__.gTransRC[giTrans] gTransRCAg = self.__class__.gTransRC[giTrans]
# rcPos=(6,4) for visit in lVisits:
# iDir=2 # transition for next cell
gTransRCAg = self.getTransRC(rcPos, iDir) oTrans = self.env.rail[visit.rc]
self.plotTrans(rcPos, gTransRCAg) tbTrans = rt.RETrans.get_transitions(oTrans, visit.iDir)
giTrans = np.where(tbTrans)[0] # RC list of transitions
lVisits = self.getTreeFromRail(rcPos, iDir, nDepth=nDepth) gTransRCAg = rt.gTransRC[giTrans]
return lVisits self.plotTrans(
visit.rc, gTransRCAg,
depth=str(visit.iDepth), color=color)
def plotAgents(self): def plotAgents(self):
rt = self.__class__ rt = self.__class__
...@@ -148,13 +150,12 @@ class RenderTool(object): ...@@ -148,13 +150,12 @@ class RenderTool(object):
rt = self.__class__ rt = self.__class__
xyPos = np.matmul(rcPos, rt.grc2xy) + rt.xyHalf xyPos = np.matmul(rcPos, rt.grc2xy) + rt.xyHalf
gxyTrans = xyPos + np.matmul(gTransRCAg, rt.grc2xy/2.4) gxyTrans = xyPos + np.matmul(gTransRCAg, rt.grc2xy/2.4)
# print(gxyTrans)
plt.scatter(*gxyTrans.T, color=color, marker="o", s=50, alpha=0.2) plt.scatter(*gxyTrans.T, color=color, marker="o", s=50, alpha=0.2)
if depth is not None: if depth is not None:
for x, y in gxyTrans: for x, y in gxyTrans:
plt.text(x, y, depth) 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. Generate a tree from the env starting at rcPos, iDir.
""" """
...@@ -194,7 +195,10 @@ class RenderTool(object): ...@@ -194,7 +195,10 @@ class RenderTool(object):
stack.append(visitNext) stack.append(visitNext)
# plot the available transitions from this node # 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 return lVisits
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -61,10 +61,11 @@ def test_render_env(): ...@@ -61,10 +61,11 @@ def test_render_env():
plt.figure(figsize=(10,10)) plt.figure(figsize=(10,10))
oRT.renderEnv() oRT.renderEnv()
lVisits = oRT.plotTreeOnRail(
lVisits = oRT.getTreeFromRail(
oEnv.agents_position[0], oEnv.agents_position[0],
oEnv.agents_direction[0], oEnv.agents_direction[0],
nDepth=17) nDepth=17, bPlot=True)
checkFrozenImage("env-tree-spatial.png") checkFrozenImage("env-tree-spatial.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