diff --git a/hub/helpers/geometry_helper.py b/hub/helpers/geometry_helper.py index f2008fb4..fdf3cbdb 100644 --- a/hub/helpers/geometry_helper.py +++ b/hub/helpers/geometry_helper.py @@ -14,6 +14,8 @@ from hub.city_model_structure.attributes.polygon import Polygon from hub.city_model_structure.attributes.polyhedron import Polyhedron from hub.helpers.location import Location +from PIL import Image + class MapPoint: def __init__(self, x, y): self.x = int(x) @@ -36,7 +38,7 @@ class GeometryHelper: @staticmethod def coordinate_to_map_point(coordinate, city): - return MapPoint((city.upper_corner[0] - coordinate[0])/2, (city.upper_corner[1] - coordinate[1])/2) + return MapPoint((city.upper_corner[0] - coordinate[0])*2, (city.upper_corner[1] - coordinate[1])*2) @staticmethod def point_between_point(point_1, point_2, x): @@ -49,10 +51,12 @@ class GeometryHelper: def city_mapping(city, building_names=None): if building_names is None: building_names = [b.name for b in city.buildings] - x = int((city.upper_corner[0] - city.lower_corner[0]) / 2) - y = int((city.upper_corner[1] - city.lower_corner[1]) / 2) + x = int((city.upper_corner[0] - city.lower_corner[0]) * 2) + y = int((city.upper_corner[1] - city.lower_corner[1]) * 2) city_map = [['' for _ in range(y+1)] for _ in range(x+1)] - city_image = [[0 for _ in range(y+1)] for _ in range(x+1)] + img = Image.new('RGB', (x+1, y+1), "black") # create a new black image + city_image = img.load() # create the pixel map + for building_name in building_names: building = city.city_object(building_name) for ground in building.grounds: @@ -68,7 +72,7 @@ class GeometryHelper: y = GeometryHelper.point_between_point(point_1, point_2, x).y if city_map[x][y] == '': city_map[x][y] = building.name - city_image[x][y] = 1 + city_image[x, y] = (90, 90, 90) elif city_map[x][y] != building.name: neighbour = city.city_object(city_map[x][y]) if building.neighbours is None: @@ -79,32 +83,7 @@ class GeometryHelper: neighbour.neighbours = [building] elif building not in neighbour.neighbours: neighbour.neighbours.append(building) - - - - - - - - - - """ - x = int((city.upper_corner[0] - coordinate[0]) / 2) - y = int((city.upper_corner[1] - coordinate[1]) / 2) - if city_map[x][y] == '': - city_map[x][y] = building.name - city_image[x][y] = 1 - elif city_map[x][y] != building.name: - neighbour = city.city_object(city_map[x][y]) - if building.neighbours is None: - building.neighbours = [neighbour] - elif neighbour not in building.neighbours: - building.neighbours.append(neighbour) - if neighbour.neighbours is None: - neighbour.neighbours = [building] - elif building not in neighbour.neighbours: - neighbour.neighbours.append(building) - """ + img.show() @staticmethod def segment_list_to_trimesh(lines) -> Trimesh: