def render_object(cls, obj, tile_size, subdivs): img = np.zeros((tile_size * subdivs, tile_size * subdivs, 3), dtype=np.uint8) obj.render(img) # if 'Agent' not in obj.type and len(obj.agents) > 0: # obj.agents[0].render(img) return downsample(img, subdivs).astype(np.uint8)
def render_tile(cls, obj, highlight=False, tile_size=TILE_PIXELS, subdivs=3): if obj is None: key = ( tile_size, highlight, ) else: key = (tile_size, highlight, *obj.encode()) if key in cls.tile_cache: img = cls.tile_cache[key] else: img = np.zeros( shape=(tile_size * subdivs, tile_size * subdivs, 3), dtype=np.uint8 ) # Draw the grid lines (top and left edges) fill_coords(img, point_in_rect(0, 0.031, 0, 1), (100, 100, 100)) fill_coords(img, point_in_rect(0, 1, 0, 0.031), (100, 100, 100)) if obj != None: obj.render(img) if highlight: highlight_img(img) img = downsample(img, subdivs) cls.tile_cache[key] = img return img
def render_tile( cls, obj, highlight=None, tile_size=minigrid.TILE_PIXELS, subdivs=3, cell_type=None, ): """Render a tile and cache the result.""" # Hash map lookup key for the cache if isinstance(highlight, list): key = (tuple(highlight), tile_size) else: key = (highlight, tile_size) key = obj.encode() + key if obj else key if key in cls.tile_cache: return cls.tile_cache[key] img = np.zeros(shape=(tile_size * subdivs, tile_size * subdivs, 3), dtype=np.uint8) # Draw the grid lines (top and left edges) rendering.fill_coords(img, rendering.point_in_rect(0, 0.031, 0, 1), (100, 100, 100)) rendering.fill_coords(img, rendering.point_in_rect(0, 1, 0, 0.031), (100, 100, 100)) if obj is not None and obj.type != "agent": obj.render(img) # Highlight the cell if needed (do not highlight walls) if highlight and not (cell_type is not None and cell_type == "wall"): if isinstance(highlight, list): for a, agent_highlight in enumerate(highlight): if agent_highlight: rendering.highlight_img(img, color=AGENT_COLOURS[a]) else: # Default highlighting for agent's partially observed views rendering.highlight_img(img) # Render agents after highlight to avoid highlighting agent triangle (the # combination of colours makes it difficult to ID agent) if obj is not None and obj.type == "agent": obj.render(img) # Downsample the image to perform supersampling/anti-aliasing img = rendering.downsample(img, subdivs) # Cache the rendered tile cls.tile_cache[key] = img return img