render obstacle color

This commit is contained in:
Laura Klünder 2019-12-22 20:51:47 +01:00
parent bfd75f9ee3
commit 4826930bbb
4 changed files with 50 additions and 32 deletions

View file

@ -37,16 +37,15 @@ class AltitudeAreaGeometries:
faces = deque() faces = deque()
for color, areas in self.colors.items(): for color, areas in self.colors.items():
for key in tuple(areas.keys()): for height in tuple(areas.keys()):
faces_offset, vertices_offset = self._call_create_full(areas, key, faces, vertices, faces_offset, vertices_offset = self._call_create_full(areas, height, faces, vertices,
faces_offset, vertices_offset) faces_offset, vertices_offset)
for key in tuple(self.obstacles.keys()): for height_obstacles in self.obstacles.values():
height_obstacles = list(self.obstacles[key]) for color_obstacles in height_obstacles.values():
for i in range(len(height_obstacles)): for i in range(len(color_obstacles)):
faces_offset, vertices_offset = self._call_create_full(height_obstacles, i, faces, vertices, faces_offset, vertices_offset = self._call_create_full(color_obstacles, i, faces, vertices,
faces_offset, vertices_offset) faces_offset, vertices_offset)
self.obstacles[key] = tuple(height_obstacles)
if not vertices: if not vertices:
return np.empty((0, 2), dtype=np.int32), np.empty((0, 3), dtype=np.uint32) return np.empty((0, 2), dtype=np.int32), np.empty((0, 3), dtype=np.uint32)
@ -94,8 +93,9 @@ class AltitudeAreaGeometries:
upper=altitudes + int(0.001 * 1000), upper=altitudes + int(0.001 * 1000),
crops=crops) crops=crops)
for height, height_geometries in self.obstacles.items(): for height, height_geometries in self.obstacles.items():
for geometry in height_geometries: for color, color_geometries in height_geometries.items():
geometry.build_polyhedron(create_polyhedron, for geometry in color_geometries:
lower=altitudes, geometry.build_polyhedron(create_polyhedron,
upper=altitudes + height, lower=altitudes,
crops=crops) upper=altitudes + height,
crops=crops)

View file

@ -151,14 +151,14 @@ class LevelGeometries:
for obstacle in space.obstacles.all(): for obstacle in space.obstacles.all():
if not obstacle.height: if not obstacle.height:
continue continue
obstacles.setdefault(int(obstacle.height*1000), []).append( obstacles.setdefault(int(obstacle.height*1000), {}).setdefault(obstacle.color, []).append(
obstacle.geometry.intersection(space.walkable_geom) obstacle.geometry.intersection(space.walkable_geom)
) )
for lineobstacle in space.lineobstacles.all(): for lineobstacle in space.lineobstacles.all():
if not lineobstacle.height: if not lineobstacle.height:
continue continue
obstacles.setdefault(int(lineobstacle.height*1000), []).append( obstacles.setdefault(int(lineobstacle.height*1000), {}).setdefault(lineobstacle.color, []).append(
lineobstacle.buffered_geometry.intersection(space.walkable_geom) lineobstacle.buffered_geometry.intersection(space.walkable_geom)
) )
@ -183,13 +183,19 @@ class LevelGeometries:
for color, areas in colors.items()} for color, areas in colors.items()}
altitudearea_colors = {color: areas for color, areas in altitudearea_colors.items() if areas} altitudearea_colors = {color: areas for color, areas in altitudearea_colors.items() if areas}
altitudearea_obstacles = {height: tuple(obstacle.intersection(altitudearea.geometry) altitudearea_obstacles = {}
for obstacle in height_obstacles for height, height_obstacles in obstacles.items():
if altitudearea_prep.intersects(obstacle)) new_height_obstacles = {}
for height, height_obstacles in obstacles.items()} for color, color_obstacles in height_obstacles.items():
altitudearea_obstacles = {height: height_obstacles new_color_obstacles = []
for height, height_obstacles in obstacles.items() for obstacle in color_obstacles:
if height_obstacles} if altitudearea_prep.intersects(obstacle):
new_color_obstacles.append(obstacle.intersection(altitudearea.geometry))
if new_color_obstacles:
new_height_obstacles[color] = new_color_obstacles
if new_height_obstacles:
altitudearea_obstacles[height] = new_height_obstacles
geoms.altitudeareas.append(AltitudeAreaGeometries(altitudearea, geoms.altitudeareas.append(AltitudeAreaGeometries(altitudearea,
altitudearea_colors, altitudearea_colors,
altitudearea_obstacles)) altitudearea_obstacles))

View file

@ -204,13 +204,19 @@ class LevelRenderData:
new_colors[color] = new_areas new_colors[color] = new_areas
new_altitudearea.colors = new_colors new_altitudearea.colors = new_colors
new_altitudearea.obstacles = {key: tuple(new_geometry.intersection(obstacle) new_altitudearea_obstacles = {}
for obstacle in height_obstacles for height, height_obstacles in altitudearea.obstacles.items():
if new_geometry_prep.intersects(obstacle)) new_height_obstacles = {}
for key, height_obstacles in altitudearea.obstacles.items()} for color, color_obstacles in height_obstacles.items():
new_altitudearea.obstacles = {height: height_obstacles new_color_obstacles = []
for height, height_obstacles in new_altitudearea.obstacles.items() for obstacle in color_obstacles:
if height_obstacles} if new_geometry_prep.intersects(obstacle):
new_color_obstacles.append(obstacle.intersection(altitudearea.geometry))
if new_color_obstacles:
new_height_obstacles[color] = new_color_obstacles
if new_height_obstacles:
new_altitudearea_obstacles[height] = new_height_obstacles
new_altitudearea.obstacles = new_altitudearea_obstacles
new_geoms.altitudeareas.append(new_altitudearea) new_geoms.altitudeareas.append(new_altitudearea)

View file

@ -106,9 +106,15 @@ class MapRenderer:
# add obstacles after everything related to ground for the nice right order # add obstacles after everything related to ground for the nice right order
for i, altitudearea in enumerate(geoms.altitudeareas): for i, altitudearea in enumerate(geoms.altitudeareas):
for height, height_obstacles in altitudearea.obstacles.items(): for height, height_obstacles in altitudearea.obstacles.items():
for obstacle in height_obstacles: for color, color_obstacles in height_obstacles.items():
engine.add_geometry(obstacle, fill=FillAttribs('#B7B7B7'), print(height, color)
stroke=StrokeAttribs('#888888', 0.05, min_px=0.2), category='obstacles') for obstacle in color_obstacles:
engine.add_geometry(
obstacle,
fill=FillAttribs(color or '#B7B7B7'),
stroke=None if color else StrokeAttribs('#888888', 0.05, min_px=0.2),
category='obstacles'
)
# add walls, stroke_px makes sure that all walls are at least 1px thick on all zoom levels, # add walls, stroke_px makes sure that all walls are at least 1px thick on all zoom levels,
walls = None walls = None