Merge remote-tracking branch 'origin/shared_surfaces_method' into main

# Conflicts:
#	hub/helpers/geometry_helper.py
This commit is contained in:
Pilar 2023-03-09 12:38:52 -05:00
commit a72e0d11fd
2 changed files with 32 additions and 61 deletions

View File

@ -32,7 +32,6 @@ class Surface:
self._area = None
self._lower_corner = None
self._upper_corner = None
self._shared_surfaces = []
self._global_irradiance = dict()
self._perimeter_polygon = perimeter_polygon
self._holes_polygons = holes_polygons
@ -42,6 +41,7 @@ class Surface:
self._inverse = None
self._associated_thermal_boundaries = []
self._vegetation = None
self._percentage_shared = None
@property
def name(self):
@ -283,12 +283,6 @@ class Surface:
self._inverse = Surface(new_solid_polygon, new_perimeter_polygon, new_holes_polygons, cte.VIRTUAL_INTERNAL)
return self._inverse
def shared_surfaces(self):
"""
Raises not implemented error
"""
raise NotImplementedError
def divide(self, z):
"""
Divides a surface at Z plane
@ -336,3 +330,19 @@ class Surface:
:param value: None or [ThermalBoundary]
"""
self._associated_thermal_boundaries = value
@property
def percentage_shared(self):
"""
Get percentage of the wall shared with other walls
:return: float
"""
return self._percentage_shared
@percentage_shared.setter
def percentage_shared(self, value):
"""
Set percentage of the wall shared with other walls
:param value: float
"""
self._percentage_shared = value

View File

@ -6,16 +6,16 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import math
import numpy as np
import requests
from trimesh import Trimesh
from trimesh import intersections
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):
@ -63,7 +63,7 @@ class GeometryHelper:
return MapPoint(((city.upper_corner[0] - coordinate[0]) * 0.5), ((city.upper_corner[1] - coordinate[1]) * 0.5))
@staticmethod
def city_mapping(city, building_names=None):
def city_mapping(city, building_names=None, plot=False):
"""
Returns a shared_information dictionary like
@ -71,15 +71,17 @@ class GeometryHelper:
"building_name" : [{line: 0 coordinate_1: [x,y,z], coordinate_2:[x, y, z], points: 0}]
}
"""
lines_information = {}
shared_information = {}
if building_names is None:
building_names = [b.name for b in city.buildings]
x = int((city.upper_corner[0] - city.lower_corner[0]) * 0.5) + 1
y = int((city.upper_corner[1] - city.lower_corner[1]) * 0.5) + 1
city_map = [['' for _ in range(y + 1)] for _ in range(x + 1)]
map_info = [[{} for _ in range(y + 1)] for _ in range(x + 1)]
city_map = [[{} 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)
shared_information[building_name]: []
line = 0
for ground in building.grounds:
length = len(ground.perimeter_polygon.coordinates) - 1
@ -88,63 +90,21 @@ class GeometryHelper:
if i == length:
j = 0
next_coordinate = ground.perimeter_polygon.coordinates[j]
line_dictionary = {"line": line, "coordinate_1": coordinate, "coordinate_2":next_coordinate, "points": 0}
point = GeometryHelper.coordinate_to_map_point(coordinate, city)
distance = int(GeometryHelper.distance_between_points(coordinate, next_coordinate))
distance = GeometryHelper.distance_between_points(coordinate, next_coordinate)
if distance == 0:
continue
delta_x = (coordinate[0] - next_coordinate[0]) / (distance / 0.5)
delta_y = (coordinate[1] - next_coordinate[1]) / (distance / 0.5)
for k in range(0, distance):
for k in range(0, int(distance)):
x = MapPoint(point.x + (delta_x * k), point.y + (delta_y * k)).x
y = MapPoint(point.x + (delta_x * k), point.y + (delta_y * k)).y
if city_map[x][y] == '':
if city_map[x][y] == {}:
city_map[x][y] = building.name
map_info[x][y] = {
'line_start': (coordinate[0], coordinate[1]),
'line_end': (next_coordinate[0], next_coordinate[1]),
}
city_image[x, y] = (100, 0, 0)
elif city_map[x][y] != building.name:
neighbour = city.city_object(city_map[x][y])
neighbour_info = map_info[x][y]
# prepare the keys
neighbour_start_coordinate = f'{neighbour_info["line_start"][0]}_{neighbour_info["line_start"][1]}'
building_start_coordinate = f'{coordinate[0]}_{coordinate[1]}'
neighbour_key = f'{neighbour.name}_{neighbour_start_coordinate}_{building_start_coordinate}'
building_key = f'{building.name}_{building_start_coordinate}_{neighbour_start_coordinate}'
# Add my neighbour info to my shared lines
if building.name in lines_information.keys() and neighbour_key in lines_information[building.name]:
shared_points = int(lines_information[building.name][neighbour_key]['shared_points'])
lines_information[building.name][neighbour_key]['shared_points'] = shared_points + 1
else:
if building.name not in lines_information.keys():
lines_information[building.name] = {}
lines_information[building.name][neighbour_key] = {
'neighbour_name': neighbour.name,
'line_start': (coordinate[0], coordinate[1]),
'line_end': (next_coordinate[0], next_coordinate[1]),
'neighbour_line_start': neighbour_info['line_start'],
'neighbour_line_end': neighbour_info['line_end'],
'shared_points': 1
}
# Add my info to my neighbour shared lines
if neighbour.name in lines_information.keys() and building_key in lines_information[neighbour.name]:
shared_points = int(lines_information[neighbour.name][building_key]['shared_points'])
lines_information[neighbour.name][building_key]['shared_points'] = shared_points + 1
else:
if neighbour.name not in lines_information.keys():
lines_information[neighbour.name] = {}
lines_information[neighbour.name][building_key] = {
'neighbour_name': building.name,
'line_start': neighbour_info['line_start'],
'line_end': neighbour_info['line_end'],
'neighbour_line_start': (coordinate[0], coordinate[1]),
'neighbour_line_end': (next_coordinate[0], next_coordinate[1]),
'shared_points': 1
}
if building.neighbours is None:
building.neighbours = [neighbour]
elif neighbour not in building.neighbours:
@ -154,7 +114,8 @@ class GeometryHelper:
elif building not in neighbour.neighbours:
neighbour.neighbours.append(building)
line += 1
return lines_information
if plot:
img.show()
@staticmethod
def segment_list_to_trimesh(lines) -> Trimesh: