Skip to content
Snippets Groups Projects
Commit 12924c5a authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files

1st flatland world

parent 198b72bf
No related branches found
No related tags found
No related merge requests found
...@@ -173,3 +173,9 @@ demo_001 = None ...@@ -173,3 +173,9 @@ demo_001 = None
demo_002 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_network_002.pkl')) demo_002 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_network_002.pkl'))
demo_002.run_demo() demo_002.run_demo()
demo_002 = None demo_002 = None
demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_000.pkl'))
demo_flatland_000.renderer.resize()
demo_flatland_000.run_demo(100)
demo_flatland_000 = None
...@@ -68,3 +68,6 @@ class GraphicsLayer(object): ...@@ -68,3 +68,6 @@ class GraphicsLayer(object):
def setAgentAt(self, iAgent, row, col, iDirIn, iDirOut): def setAgentAt(self, iAgent, row, col, iDirIn, iDirOut):
pass pass
def resize(self,env):
pass
from flatland.utils.graphics_qt import QtRenderer
from numpy import array
from flatland.utils.graphics_layer import GraphicsLayer
# from matplotlib import pyplot as plt
import numpy as np
import time import time
from flatland.utils.svg import Track, Zug
from flatland.envs.agent_utils import EnvAgent
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout # from matplotlib import pyplot as plt
import numpy as np
from PyQt5 import QtSvg from PyQt5 import QtSvg
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout
from numpy import array
from flatland.envs.agent_utils import EnvAgent
from flatland.utils.graphics_layer import GraphicsLayer
from flatland.utils.graphics_qt import QtRenderer
from flatland.utils.svg import Track, Zug
def transform_string_svg(sSVG): def transform_string_svg(sSVG):
...@@ -16,6 +17,7 @@ def transform_string_svg(sSVG): ...@@ -16,6 +17,7 @@ def transform_string_svg(sSVG):
bySVG = bytearray(sSVG, encoding='utf-8') bySVG = bytearray(sSVG, encoding='utf-8')
return bySVG return bySVG
def create_QtSvgWidget_from_svg_string(sSVG): def create_QtSvgWidget_from_svg_string(sSVG):
svgWidget = QtSvg.QSvgWidget() svgWidget = QtSvg.QSvgWidget()
ret = svgWidget.renderer().load(transform_string_svg(sSVG)) ret = svgWidget.renderer().load(transform_string_svg(sSVG))
...@@ -45,10 +47,10 @@ class QTGL(GraphicsLayer): ...@@ -45,10 +47,10 @@ class QTGL(GraphicsLayer):
# use the renderer to scale back to the desired size # use the renderer to scale back to the desired size
self.qtr.scale(self.tile_size / self.cell_pixels, self.tile_size / self.cell_pixels) self.qtr.scale(self.tile_size / self.cell_pixels, self.tile_size / self.cell_pixels)
self.tColBg = (255, 255, 255) # white background self.tColBg = (255, 255, 255) # white background
# self.tColBg = (220, 120, 40) # background color # self.tColBg = (220, 120, 40) # background color
self.tColRail = (0, 0, 0) # black rails self.tColRail = (0, 0, 0) # black rails
self.tColGrid = (230,) * 3 # light grey for grid self.tColGrid = (230,) * 3 # light grey for grid
# Draw the background of the in-world cells # Draw the background of the in-world cells
self.qtr.fillRect(0, 0, self.widthPx, self.heightPx, *self.tColBg) self.qtr.fillRect(0, 0, self.widthPx, self.heightPx, *self.tColBg)
...@@ -195,8 +197,8 @@ class QTSVG(GraphicsLayer): ...@@ -195,8 +197,8 @@ class QTSVG(GraphicsLayer):
# We can only reuse the image if noth new and old are straight and the same: # We can only reuse the image if noth new and old are straight and the same:
if iDirIn == iDirOut and \ if iDirIn == iDirOut and \
agentPrev.direction == iDirIn and \ agentPrev.direction == iDirIn and \
agentPrev.old_direction == agentPrev.direction: agentPrev.old_direction == agentPrev.direction:
return return
else: else:
# need to load new image # need to load new image
...@@ -222,6 +224,13 @@ class QTSVG(GraphicsLayer): ...@@ -222,6 +224,13 @@ class QTSVG(GraphicsLayer):
def show(self, block=False): def show(self, block=False):
self.wMain.update() self.wMain.update()
def resize(self, env):
screen_resolution = self.app.desktop().screenGeometry()
width, height = screen_resolution.width(), screen_resolution.height()
w = np.ceil(width * 0.8 / env.width)
h = np.ceil(height * 0.8 / env.height)
self.wWinMain.resize(env.width * w, env.height * h)
def main2(): def main2():
gl = QTGL(10, 10) gl = QTGL(10, 10)
......
...@@ -137,6 +137,9 @@ class RenderTool(object): ...@@ -137,6 +137,9 @@ class RenderTool(object):
self.new_rail = True self.new_rail = True
def resize(self):
self.gl.resize(self.env)
def set_new_rail(self): def set_new_rail(self):
self.new_rail = True self.new_rail = True
......
...@@ -114,7 +114,7 @@ ...@@ -114,7 +114,7 @@
{ {
"data": { "data": {
"application/vnd.jupyter.widget-view+json": { "application/vnd.jupyter.widget-view+json": {
"model_id": "31e3248d9a0e4b5da8f2439abd13558d", "model_id": "ece47ccd72af4638b61e9d93a66e9a57",
"version_major": 2, "version_major": 2,
"version_minor": 0 "version_minor": 0
}, },
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
{ {
"data": { "data": {
"application/vnd.jupyter.widget-view+json": { "application/vnd.jupyter.widget-view+json": {
"model_id": "c22754b330ce490383eb05972bc96afe", "model_id": "86207439e5a94055bb3d837028f195fc",
"version_major": 2, "version_major": 2,
"version_minor": 0 "version_minor": 0
}, },
......
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