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()
for color, areas in self.colors.items():
for key in tuple(areas.keys()):
faces_offset, vertices_offset = self._call_create_full(areas, key, faces, vertices,
for height in tuple(areas.keys()):
faces_offset, vertices_offset = self._call_create_full(areas, height, faces, vertices,
faces_offset, vertices_offset)
for key in tuple(self.obstacles.keys()):
height_obstacles = list(self.obstacles[key])
for i in range(len(height_obstacles)):
faces_offset, vertices_offset = self._call_create_full(height_obstacles, i, faces, vertices,
faces_offset, vertices_offset)
self.obstacles[key] = tuple(height_obstacles)
for height_obstacles in self.obstacles.values():
for color_obstacles in height_obstacles.values():
for i in range(len(color_obstacles)):
faces_offset, vertices_offset = self._call_create_full(color_obstacles, i, faces, vertices,
faces_offset, vertices_offset)
if not vertices:
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),
crops=crops)
for height, height_geometries in self.obstacles.items():
for geometry in height_geometries:
geometry.build_polyhedron(create_polyhedron,
lower=altitudes,
upper=altitudes + height,
crops=crops)
for color, color_geometries in height_geometries.items():
for geometry in color_geometries:
geometry.build_polyhedron(create_polyhedron,
lower=altitudes,
upper=altitudes + height,
crops=crops)

View file

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

View file

@ -204,13 +204,19 @@ class LevelRenderData:
new_colors[color] = new_areas
new_altitudearea.colors = new_colors
new_altitudearea.obstacles = {key: tuple(new_geometry.intersection(obstacle)
for obstacle in height_obstacles
if new_geometry_prep.intersects(obstacle))
for key, height_obstacles in altitudearea.obstacles.items()}
new_altitudearea.obstacles = {height: height_obstacles
for height, height_obstacles in new_altitudearea.obstacles.items()
if height_obstacles}
new_altitudearea_obstacles = {}
for height, height_obstacles in altitudearea.obstacles.items():
new_height_obstacles = {}
for color, color_obstacles in height_obstacles.items():
new_color_obstacles = []
for obstacle in color_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)

View file

@ -106,9 +106,15 @@ class MapRenderer:
# add obstacles after everything related to ground for the nice right order
for i, altitudearea in enumerate(geoms.altitudeareas):
for height, height_obstacles in altitudearea.obstacles.items():
for obstacle in height_obstacles:
engine.add_geometry(obstacle, fill=FillAttribs('#B7B7B7'),
stroke=StrokeAttribs('#888888', 0.05, min_px=0.2), category='obstacles')
for color, color_obstacles in height_obstacles.items():
print(height, color)
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,
walls = None