diff --git a/flatland/utils/graphics_layer.py b/flatland/utils/graphics_layer.py index ed92249ca422fa837a447f2765c70864f79c00a8..f33d8bccd50aa43d424030770c191386681790cd 100644 --- a/flatland/utils/graphics_layer.py +++ b/flatland/utils/graphics_layer.py @@ -79,6 +79,9 @@ class GraphicsLayer(object): def setAgentAt(self, iAgent, row, col, iDirIn, iDirOut, isSelected=False): pass + def setCellOccupied(self, iAgent, row, col): + pass + def resize(self, env): pass diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py index 6a8f17f9f73c10ad6d33f51fcbea173ed1a455fc..e1c0bbf2148fee02aa96d7a2a634d595b88e4130 100644 --- a/flatland/utils/graphics_pil.py +++ b/flatland/utils/graphics_pil.py @@ -383,6 +383,9 @@ class PILSVG(PILGL): station = self.pilFromSvgFile("svg", "Bahnhof_#d50000_target.svg") self.ltStationColors = self.recolorImage(station, [0, 0, 0], self.ltAgentColors, False) + cellOccupied = self.pilFromSvgFile("svg", "Cell_occupied.svg") + self.ltCellOccupied = self.recolorImage(cellOccupied, [0, 0, 0], self.ltAgentColors, False) + # Merge them with the regular rails. # https://stackoverflow.com/questions/38987/how-to-merge-two-dictionaries-in-a-single-expression self.dPilRail = {**dPilRailFiles, **dPilTargetFiles} @@ -538,6 +541,10 @@ class PILSVG(PILGL): self.clear_layer(2, 0) self.drawImageRC(svgBG, (row, col), layer=2) + def setCellOccupied(self, iAgent, row, col): + occIm = self.ltCellOccupied[iAgent % len(self.ltCellOccupied)] + self.drawImageRC(occIm, (row, col), 1) + def main2(): gl = PILSVG(10, 10) diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py index 9b04f9c1a536183bddc6b4618e01cc2c702d09ad..4172dadb7de79156f1950ce276ac0a8976fc3673 100644 --- a/flatland/utils/rendertools.py +++ b/flatland/utils/rendertools.py @@ -673,8 +673,13 @@ class RenderTool(object): direction = agent.direction old_direction = agent.direction - # setAgentAt uses the agent index for the color - self.gl.setAgentAt(iAgent, *position, old_direction, direction, iSelectedAgent == iAgent) + if agent.position == agent.target: + # setAgentAt uses the agent index for the color + self.gl.setCellOccupied(iAgent, *(agent.position)) + else: + # setAgentAt uses the agent index for the color + self.gl.setCellOccupied(iAgent, *(agent.position)) + self.gl.setAgentAt(iAgent, *position, old_direction, direction, iSelectedAgent == iAgent) if show_observations: self.renderObs(range(env.get_num_agents()), env.dev_obs_dict) diff --git a/notebooks/Scene_Editor.ipynb b/notebooks/Scene_Editor.ipynb index 2877d19d8325dc5baad0344026c632582b6ef6f9..06d3fe914cb74a21704bbe221049914ab799f0fd 100644 --- a/notebooks/Scene_Editor.ipynb +++ b/notebooks/Scene_Editor.ipynb @@ -70,7 +70,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "d0b362c4de2849fe93f505143d04b243", + "model_id": "d1b14568dc1a48ba9ca3eb6afb7f2eff", "version_major": 2, "version_minor": 0 }, diff --git a/svg/Cell_occupied.svg b/svg/Cell_occupied.svg new file mode 100644 index 0000000000000000000000000000000000000000..3666b723e0d99dc59aa1d06ccab4a495d1697d8d --- /dev/null +++ b/svg/Cell_occupied.svg @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.1" + id="Ebene_1" + x="0px" + y="0px" + viewBox="0 0 240 240" + style="enable-background:new 0 0 240 240;" + xml:space="preserve" + sodipodi:docname="Cell_occupied.svg" + inkscape:version="0.92.4 (5da689c313, 2019-01-14)"><metadata + id="metadata11"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata> + <defs + id="defs9" /><sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1017" + id="namedview7" + showgrid="false" + inkscape:zoom="2.7812867" + inkscape:cx="24.994769" + inkscape:cy="123.32931" + inkscape:window-x="-8" + inkscape:window-y="-8" + inkscape:window-maximized="1" + inkscape:current-layer="Ebene_1" /> +<style + type="text/css" + id="style2"> + .st0{fill:#9CCB89;} +</style> + + + + + <rect + style="fill:#000000;fill-opacity:0.90196079;stroke-width:1.00000226" + id="rect874" + width="240.89569" + height="241.25525" + x="9.5030348e-09" + y="0.18293978" /></svg> \ No newline at end of file