Partial implementation neighbours detection.
This commit is contained in:
parent
804648a9f0
commit
8a4fdc0397
|
@ -458,3 +458,5 @@ class City:
|
||||||
:return: LevelOfDetail
|
:return: LevelOfDetail
|
||||||
"""
|
"""
|
||||||
return self._level_of_detail
|
return self._level_of_detail
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,13 @@ Copyright © 2022 Concordia CERC group
|
||||||
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
from hub.city_model_structure.iot.sensor import Sensor
|
from hub.city_model_structure.iot.sensor import Sensor
|
||||||
from hub.city_model_structure.building_demand.surface import Surface
|
from hub.city_model_structure.building_demand.surface import Surface
|
||||||
from hub.city_model_structure.attributes.polyhedron import Polyhedron
|
from hub.city_model_structure.attributes.polyhedron import Polyhedron
|
||||||
|
|
||||||
from hub.helpers.configuration_helper import ConfigurationHelper
|
from hub.helpers.configuration_helper import ConfigurationHelper
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +35,7 @@ class CityObject:
|
||||||
self._diffuse = dict()
|
self._diffuse = dict()
|
||||||
self._beam = dict()
|
self._beam = dict()
|
||||||
self._sensors = []
|
self._sensors = []
|
||||||
|
self._neighbours = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -224,3 +227,17 @@ class CityObject:
|
||||||
:param value: [Sensor]
|
:param value: [Sensor]
|
||||||
"""
|
"""
|
||||||
self._sensors = value
|
self._sensors = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def neighbours(self) -> Union[None, List[CityObject]]:
|
||||||
|
"""
|
||||||
|
Get the list of neighbour_objects and their properties associated to the current city_object
|
||||||
|
"""
|
||||||
|
return self._neighbours
|
||||||
|
|
||||||
|
@neighbours.setter
|
||||||
|
def neighbours(self, value):
|
||||||
|
"""
|
||||||
|
Set the list of neighbour_objects and their properties associated to the current city_object
|
||||||
|
"""
|
||||||
|
self._neighbours = value
|
||||||
|
|
|
@ -13,8 +13,14 @@ from trimesh import intersections
|
||||||
from hub.city_model_structure.attributes.polygon import Polygon
|
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 hub.helpers.configuration_helper import ConfigurationHelper
|
|
||||||
|
|
||||||
|
class MapPoint:
|
||||||
|
def __init__(self, x, y):
|
||||||
|
self.x = int(x)
|
||||||
|
self.y = int(y)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'({self.x}, {self.y})'
|
||||||
|
|
||||||
class GeometryHelper:
|
class GeometryHelper:
|
||||||
"""
|
"""
|
||||||
|
@ -29,15 +35,76 @@ class GeometryHelper:
|
||||||
self._area_delta = area_delta
|
self._area_delta = area_delta
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def adjacent_locations(location1, location2):
|
def coordinate_to_map_point(coordinate, city):
|
||||||
"""
|
return MapPoint((city.upper_corner[0] - coordinate[0])/2, (city.upper_corner[1] - coordinate[1])/2)
|
||||||
Determine when two attributes may be adjacent or not based in the dis
|
|
||||||
:param location1:
|
@staticmethod
|
||||||
:param location2:
|
def point_between_point(point_1, point_2, x):
|
||||||
:return: Boolean
|
m = (point_1.y - point_2.y)/(point_1.x - point_2.x)
|
||||||
"""
|
c = point_2.y - (m*point_2.x)
|
||||||
max_distance = ConfigurationHelper().max_location_distance_for_shared_walls
|
y = (m*x)+c
|
||||||
return GeometryHelper.distance_between_points(location1, location2) < max_distance
|
return MapPoint(x,y)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
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)
|
||||||
|
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)]
|
||||||
|
for building_name in building_names:
|
||||||
|
building = city.city_object(building_name)
|
||||||
|
for ground in building.grounds:
|
||||||
|
length = len(ground.perimeter_polygon.coordinates) - 1
|
||||||
|
for i, coordinate in enumerate(ground.perimeter_polygon.coordinates):
|
||||||
|
j = i+1
|
||||||
|
if i == length:
|
||||||
|
j = 0
|
||||||
|
next_coordinate = ground.perimeter_polygon.coordinates[j]
|
||||||
|
point_1 = GeometryHelper.coordinate_to_map_point(coordinate, city)
|
||||||
|
point_2 = GeometryHelper.coordinate_to_map_point(next_coordinate, city)
|
||||||
|
for x in range(point_1.x, point_2.x):
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def segment_list_to_trimesh(lines) -> Trimesh:
|
def segment_list_to_trimesh(lines) -> Trimesh:
|
||||||
|
|
|
@ -4,8 +4,10 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||||
Copyright © 2022 Concordia CERC group
|
Copyright © 2022 Concordia CERC group
|
||||||
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||||
"""
|
"""
|
||||||
|
import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
from hub.helpers.geometry_helper import GeometryHelper
|
||||||
|
|
||||||
from numpy import inf
|
from numpy import inf
|
||||||
|
|
||||||
|
@ -146,3 +148,26 @@ class TestGeometryFactory(TestCase):
|
||||||
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
|
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
|
||||||
self.assertEqual(207, len(city.buildings), 'wrong number of buildings')
|
self.assertEqual(207, len(city.buildings), 'wrong number of buildings')
|
||||||
self._check_buildings(city)
|
self._check_buildings(city)
|
||||||
|
|
||||||
|
def test_map_neighbours(self):
|
||||||
|
"""
|
||||||
|
Test neighbours map creation
|
||||||
|
"""
|
||||||
|
start = datetime.datetime.now()
|
||||||
|
file = 'concordia.geojson'
|
||||||
|
city = self._get_city(file, 'geojson',
|
||||||
|
height_field='citygml_me',
|
||||||
|
year_of_construction_field='ANNEE_CONS',
|
||||||
|
function_field='LIBELLE_UT')
|
||||||
|
city_end = datetime.datetime.now()
|
||||||
|
print(f'city load {city_end-start}')
|
||||||
|
GeometryHelper.city_mapping(city)
|
||||||
|
end = datetime.datetime.now()
|
||||||
|
print(f'city map {end-city_end}')
|
||||||
|
|
||||||
|
for building in city.buildings:
|
||||||
|
if building.neighbours is not None:
|
||||||
|
print(f'{building.name} [{[b.name for b in building.neighbours]}]')
|
||||||
|
else:
|
||||||
|
print(f'{building.name} has no neighbours')
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user