performance improvements in city import

This commit is contained in:
Guille Gutierrez 2023-03-17 16:32:54 -04:00
parent b722125c3e
commit 2781696f95
4 changed files with 9 additions and 8 deletions

View File

@ -60,6 +60,7 @@ class City:
self._stations = [] self._stations = []
self._lca_materials = None self._lca_materials = None
self._level_of_detail = LevelOfDetail() self._level_of_detail = LevelOfDetail()
self._city_objects_dictionary = {}
@property @property
def fuels(self) -> [Fuel]: def fuels(self) -> [Fuel]:
@ -198,9 +199,8 @@ class City:
:param name:str :param name:str
:return: None or CityObject :return: None or CityObject
""" """
for city_object in self.buildings: if name in self._city_objects_dictionary:
if str(city_object.name) == str(name): return self.buildings[self._city_objects_dictionary[name]]
return city_object
return None return None
def add_city_object(self, new_city_object): def add_city_object(self, new_city_object):
@ -213,6 +213,7 @@ class City:
if self._buildings is None: if self._buildings is None:
self._buildings = [] self._buildings = []
self._buildings.append(new_city_object) self._buildings.append(new_city_object)
self._city_objects_dictionary[new_city_object.name] = len(self._buildings) - 1
elif new_city_object.type == 'energy_system': elif new_city_object.type == 'energy_system':
if self._energy_systems is None: if self._energy_systems is None:
self._energy_systems = [] self._energy_systems = []

View File

@ -6,8 +6,10 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
import math import math
import numpy as np import numpy as np
import requests import requests
from PIL import Image
from trimesh import Trimesh from trimesh import Trimesh
from trimesh import intersections from trimesh import intersections
@ -15,8 +17,6 @@ from hub.city_model_structure.attributes.polygon import Polygon
from hub.city_model_structure.attributes.polyhedron import Polyhedron from hub.city_model_structure.attributes.polyhedron import Polyhedron
from hub.helpers.location import Location from hub.helpers.location import Location
from PIL import Image
class MapPoint: class MapPoint:
def __init__(self, x, y): def __init__(self, x, y):
@ -87,6 +87,7 @@ class GeometryHelper:
for ground in building.grounds: for ground in building.grounds:
length = len(ground.perimeter_polygon.coordinates) - 1 length = len(ground.perimeter_polygon.coordinates) - 1
for i, coordinate in enumerate(ground.perimeter_polygon.coordinates): for i, coordinate in enumerate(ground.perimeter_polygon.coordinates):
j = i + 1 j = i + 1
if i == length: if i == length:
j = 0 j = 0
@ -166,6 +167,7 @@ class GeometryHelper:
elif building not in neighbour.neighbours: elif building not in neighbour.neighbours:
neighbour.neighbours.append(building) neighbour.neighbours.append(building)
line += 1 line += 1
if plot: if plot:
img.show() img.show()
return lines_information return lines_information

View File

@ -237,8 +237,7 @@ class Geojson:
self._city.level_of_detail.geometry = lod self._city.level_of_detail.geometry = lod
if lod == 1: if lod == 1:
start = datetime.datetime.now() start = datetime.datetime.now()
lines_information = GeometryHelper.city_mapping(self._city, plot=True) lines_information = GeometryHelper.city_mapping(self._city, plot=False)
print(lines_information)
print(f'mapping: {datetime.datetime.now() - start}') print(f'mapping: {datetime.datetime.now() - start}')
start = datetime.datetime.now() start = datetime.datetime.now()
self._store_shared_percentage_to_walls(self._city, lines_information) self._store_shared_percentage_to_walls(self._city, lines_information)

View File

@ -105,4 +105,3 @@ class GeometryHelper:
cosine = -1 cosine = -1
alpha = math.acos(cosine) alpha = math.acos(cosine)
return alpha return alpha