diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py index ea1e00bbe5ca32cf0d070ce51834d9056e5c6bdf..4cac5edc0021a87e6a68cceba5e7d107999aecf4 100644 --- a/flatland/utils/rendertools.py +++ b/flatland/utils/rendertools.py @@ -199,73 +199,74 @@ class RenderTool(object): """ if not curves and not dead_end: + # just a straigt line, no curve nor dead_end included in this basic rail element self.gl.plot( [line[0][0], line[1][0]], # x [line[0][1], line[1][1]], # y color=color ) - return + else: + # it was not a simple line to draw: the rail has a curve or dead_end included. + rt = self.__class__ + straight = rotation in [0, 2] + dx, dy = np.squeeze(np.diff(line, axis=0)) * spacing / 2 - rt = self.__class__ - straight = rotation in [0, 2] - dx, dy = np.squeeze(np.diff(line, axis=0)) * spacing / 2 + if straight: - if straight: + if color == "auto": + if dx > 0 or dy > 0: + color = "C1" # N or E + else: + color = "C2" # S or W - if color == "auto": - if dx > 0 or dy > 0: - color = "C1" # N or E + if dead_end: + line_xy = array([ + line[1] + [dy, dx], + center, + line[1] - [dy, dx], + ]) + self.gl.plot(*line_xy.T, color=color) else: - color = "C2" # S or W - - if dead_end: - line_xy = array([ - line[1] + [dy, dx], - center, - line[1] - [dy, dx], - ]) - self.gl.plot(*line_xy.T, color=color) + line_xy = line + [-dy, dx] + self.gl.plot(*line_xy.T, color=color) + + if arrow: + middle_xy = np.sum(line_xy * [[1 / 4], [3 / 4]], axis=0) + + arrow_xy = array([ + middle_xy + [-dx - dy, +dx - dy], + middle_xy, + middle_xy + [-dx + dy, -dx - dy]]) + self.gl.plot(*arrow_xy.T, color=color) + else: - line_xy = line + [-dy, dx] - self.gl.plot(*line_xy.T, color=color) - if arrow: - middle_xy = np.sum(line_xy * [[1 / 4], [3 / 4]], axis=0) + middle_xy = np.mean(line, axis=0) + dxy = middle_xy - center + corner = middle_xy + dxy + if rotation == 1: + arc_factor = 1 - spacing + color_auto = "C1" + else: + arc_factor = 1 + spacing + color_auto = "C2" + dxy2 = (center - corner) * arc_factor # for scaling the arc + + if color == "auto": + color = color_auto + self.gl.plot(*(rt.arc * dxy2 + corner).T, color=color) + + if arrow: + dx, dy = np.squeeze(np.diff(line, axis=0)) / 20 + iArc = int(len(rt.arc) / 2) + middle_xy = corner + rt.arc[iArc] * dxy2 arrow_xy = array([ middle_xy + [-dx - dy, +dx - dy], middle_xy, middle_xy + [-dx + dy, -dx - dy]]) self.gl.plot(*arrow_xy.T, color=color) - else: - - middle_xy = np.mean(line, axis=0) - dxy = middle_xy - center - corner = middle_xy + dxy - if rotation == 1: - arc_factor = 1 - spacing - color_auto = "C1" - else: - arc_factor = 1 + spacing - color_auto = "C2" - dxy2 = (center - corner) * arc_factor # for scaling the arc - - if color == "auto": - color = color_auto - - self.gl.plot(*(rt.arc * dxy2 + corner).T, color=color) - - if arrow: - dx, dy = np.squeeze(np.diff(line, axis=0)) / 20 - iArc = int(len(rt.arc) / 2) - middle_xy = corner + rt.arc[iArc] * dxy2 - arrow_xy = array([ - middle_xy + [-dx - dy, +dx - dy], - middle_xy, - middle_xy + [-dx + dy, -dx - dy]]) - self.gl.plot(*arrow_xy.T, color=color) - def render_observation(self, agent_handles, observation_dict): """ Render the extent of the observation of each agent. All cells that appear in the agent diff --git a/notebooks/Scene_Editor.ipynb b/notebooks/Scene_Editor.ipynb index 38024cc6673858eb6047bd34c030a0b8977ce42b..9ed6bafd3bd21763eb26ffe383cd356c1c1121b6 100644 --- a/notebooks/Scene_Editor.ipynb +++ b/notebooks/Scene_Editor.ipynb @@ -57,13 +57,6 @@ "source": [ "mvc.view.display()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/notebooks/Simple_Rendering_Demo.ipynb b/notebooks/Simple_Rendering_Demo.ipynb index fd3166c208b750914fa1a553e811ac8b11bdc691..11cfb9da5c78c7b68aaf8062dd1baab804335d05 100644 --- a/notebooks/Simple_Rendering_Demo.ipynb +++ b/notebooks/Simple_Rendering_Demo.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -53,22 +53,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<style>.container { width:90% !important; }</style>" - ], - "text/plain": [ - "<IPython.core.display.HTML object>" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "from IPython.core.display import display, HTML\n", "display(HTML(\"<style>.container { width:90% !important; }</style>\"))" @@ -83,7 +70,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -105,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -116,24 +103,29 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f3c1051ad450465f8d98701eb229ea0e", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Canvas()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], + "source": [ + "jpy_canvas.Canvas(img)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "oRT = rt.RenderTool(env,gl=\"PIL\")\n", + "oRT.render_env()\n", + "img = oRT.get_image()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "jpy_canvas.Canvas(img)" ] @@ -156,7 +148,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.8" }, "latex_envs": { "LaTeX_envs_menu_present": true, diff --git a/notebooks/simple_example_3_manual_control.ipynb b/notebooks/simple_example_3_manual_control.ipynb index 08d894cc73634b353cc454a4b4f6b0df15339ab7..50f228055b320c15e0411c2b086254a1f4d4ceef 100644 --- a/notebooks/simple_example_3_manual_control.ipynb +++ b/notebooks/simple_example_3_manual_control.ipynb @@ -33,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -48,59 +48,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{ '': [0, 0, 0, 0, 0, 0, 3.0, 0, 0],\n", - " 'B': { '': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf],\n", - " 'B': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'F': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'L': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'R': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]}},\n", - " 'F': { '': [inf, inf, inf, inf, 1, 2, 1.0, 0, 0],\n", - " 'B': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'F': {'': [inf, inf, inf, inf, 4, 5, 8.0, 0, 0]},\n", - " 'L': {'': [3, inf, inf, inf, inf, 3, 0, 0, 0]},\n", - " 'R': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]}},\n", - " 'L': { '': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf],\n", - " 'B': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'F': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'L': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'R': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]}},\n", - " 'R': { '': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf],\n", - " 'B': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'F': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'L': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'R': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]}}}\n", - "{ '': [0, 0, 0, 0, 0, 0, 8.0, 0, 0],\n", - " 'B': { '': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf],\n", - " 'B': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'F': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'L': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'R': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]}},\n", - " 'F': { '': [inf, inf, inf, inf, 1, 2, 6.0, 0, 0],\n", - " 'B': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'F': {'': [inf, inf, inf, inf, inf, 3, 5.0, 0, 0]},\n", - " 'L': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'R': {'': [inf, inf, inf, inf, 5, 6, 6.0, 0, 0]}},\n", - " 'L': { '': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf],\n", - " 'B': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'F': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'L': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'R': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]}},\n", - " 'R': { '': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf],\n", - " 'B': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'F': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'L': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]},\n", - " 'R': {'': [-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]}}}\n", - "Manual control: s=perform step, q=quit, [agent id] [1-2-3 action] (turnleft+move, move to front, turnright+move)\n" - ] - } - ], + "outputs": [], "source": [ "random.seed(1)\n", "np.random.seed(1)\n", @@ -127,26 +77,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Rewards: {0: -1.0, 1: -1.0} [done= {0: False, 1: False, '__all__': False} ]\n", - "Rewards: {0: -1.0, 1: -1.0} [done= {0: False, 1: False, '__all__': False} ]\n", - "Rewards: {0: -1.0, 1: -1.0} [done= {0: False, 1: False, '__all__': False} ]\n", - "Rewards: {0: -1.0, 1: -1.0} [done= {0: False, 1: False, '__all__': False} ]\n", - "Rewards: {0: -1.0, 1: -1.0} [done= {0: False, 1: False, '__all__': False} ]\n", - "Rewards: {0: -1.0, 1: -1.0} [done= {0: False, 1: False, '__all__': False} ]\n", - "Rewards: {0: -1.0, 1: -1.0} [done= {0: False, 1: False, '__all__': False} ]\n", - "Rewards: {0: -1.0, 1: -1.0} [done= {0: False, 1: False, '__all__': False} ]\n", - "Rewards: {0: -1.0, 1: -1.0} [done= {0: False, 1: False, '__all__': False} ]\n", - "Rewards: {0: -1.0, 1: -1.0} [done= {0: False, 1: False, '__all__': False} ]\n" - ] - } - ], + "outputs": [], "source": [ "for step in range(10):\n", "\n", @@ -201,7 +134,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.8" }, "latex_envs": { "LaTeX_envs_menu_present": true,