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

fixed up MPL GL again - colors in [0,1]^3, spurious plt.figure

parent 026c3e10
No related branches found
No related tags found
No related merge requests found
......@@ -155,7 +155,7 @@ def main(render=True, delay=0.0):
env_done = 0
# Run episode
for step in range(50):
for step in range(100):
# if trials > 114:
# env_renderer.renderEnv(show=True)
# print(step)
......
......@@ -58,7 +58,7 @@ class View(object):
def init_canvas(self):
# update the rendertool with the env
self.new_env()
plt.figure(figsize=(10, 10))
#plt.figure(figsize=(10, 10))
self.oRT.renderEnv(spacing=False, arrows=False, sRailColor="gray", show=False)
img = self.oRT.getImage()
plt.clf()
......@@ -363,7 +363,7 @@ class EditorModel(object):
set a new env for the editor, used by load and regenerate.
"""
self.env = env
self.yxBase = array([6, 21]) # pixel offset
# self.yxBase = array([6, 21]) # pixel offset
# self.nPixCell = 700 / self.env.rail.width # 35
# self.oRT = rt.RenderTool(env)
......@@ -680,3 +680,6 @@ class EditorModel(object):
binTrans,
sbinTrans,
[sbinTrans[i:(i + 4)] for i in range(0, len(sbinTrans), 4)])
\ No newline at end of file
......@@ -19,7 +19,7 @@ class MPLGL(GraphicsLayer):
self.height = height
self.yxBase = array([6, 21]) # pixel offset
self.nPixCell = 700 / width
pass
self.img = None
def plot(self, *args, **kwargs):
plt.plot(*args, **kwargs)
......@@ -67,23 +67,31 @@ class MPLGL(GraphicsLayer):
return plt.get_cmap(*args, **kwargs)
def beginFrame(self):
self.img = None
plt.figure(figsize=(10, 10))
pass
def endFrame(self):
# plt.clf()
# plt.close()
pass
def getImage(self):
ax = plt.gca()
fig = ax.get_figure()
fig.tight_layout(pad=0)
fig.canvas.draw()
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
return data
self.img = self.getImage(force=True)
plt.clf()
plt.close()
def getImage(self, force=False):
if self.img is None or force:
ax = plt.gca()
fig = ax.get_figure()
fig.tight_layout(pad=0)
fig.canvas.draw()
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
self.img = data
return self.img
def adaptColor(self, color, lighten=False):
color = super(self.__class__, self).adaptColor(color, lighten)
# MPL has RGBA in [0,1]^4 not \mathbb{N} \cap [0,255]^4
color = tuple([iRGBA / 255 for iRGBA in color])
return color
class RenderTool(object):
Visit = recordtype("Visit", ["rc", "iDir", "iDepth", "prev"])
......@@ -469,7 +477,7 @@ class RenderTool(object):
# so for now I've changed it to 1 (from 10)
cell_size = 1
self.gl.beginFrame()
self.gl.clf()
# self.gl.clf()
# if oFigure is None:
# oFigure = self.gl.figure()
......
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