2020-06-16 15:34:35 -04:00
|
|
|
"""
|
|
|
|
CityObject module
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|
|
|
"""
|
2020-06-16 16:19:14 -04:00
|
|
|
from pathlib import Path
|
2020-06-16 16:06:33 -04:00
|
|
|
from typing import List, Union
|
2020-10-28 13:14:05 -04:00
|
|
|
from city_model_structure.attributes.surface import Surface
|
2020-06-16 10:34:17 -04:00
|
|
|
from helpers.geometry_helper import GeometryHelper
|
2020-10-28 13:14:05 -04:00
|
|
|
from city_model_structure.attributes.polyhedron import Polyhedron
|
2020-06-09 15:14:47 -04:00
|
|
|
|
2020-05-18 13:25:08 -04:00
|
|
|
|
|
|
|
class CityObject:
|
2020-06-16 15:34:35 -04:00
|
|
|
"""
|
|
|
|
class CityObject
|
|
|
|
"""
|
2020-06-16 16:19:14 -04:00
|
|
|
def __init__(self, lod, surfaces, name):
|
|
|
|
self._name = name
|
2020-05-18 13:25:08 -04:00
|
|
|
self._lod = lod
|
2020-06-16 16:06:33 -04:00
|
|
|
self._surfaces = surfaces
|
2020-05-18 13:25:08 -04:00
|
|
|
self._polyhedron = None
|
2020-06-16 15:34:35 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def lod(self):
|
|
|
|
"""
|
|
|
|
City object level of detail 1, 2, 3 or 4
|
|
|
|
:return: int
|
|
|
|
"""
|
|
|
|
return self._lod
|
2020-06-16 16:06:33 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def volume(self):
|
|
|
|
"""
|
|
|
|
City object volume in cubic meters
|
|
|
|
:return: float
|
|
|
|
"""
|
|
|
|
if self._polyhedron is None:
|
|
|
|
self._polyhedron = Polyhedron(self.surfaces)
|
|
|
|
return self._polyhedron.volume
|
|
|
|
|
|
|
|
@property
|
|
|
|
def surfaces(self) -> List[Surface]:
|
|
|
|
"""
|
|
|
|
City object surfaces
|
|
|
|
:return: [Surface]
|
|
|
|
"""
|
|
|
|
return self._surfaces
|
|
|
|
|
|
|
|
def surface(self, name) -> Union[Surface, None]:
|
|
|
|
"""
|
|
|
|
Get the city object surface with a given name
|
|
|
|
:param name: str
|
|
|
|
:return: None or Surface
|
|
|
|
"""
|
|
|
|
for s in self.surfaces:
|
|
|
|
if s.name == name:
|
|
|
|
return s
|
|
|
|
return None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def location(self):
|
|
|
|
"""
|
|
|
|
City object location
|
|
|
|
:return: [x,y,z]
|
|
|
|
"""
|
|
|
|
if self._polyhedron is None:
|
|
|
|
self._polyhedron = Polyhedron(self.surfaces)
|
2020-12-21 11:08:54 -05:00
|
|
|
return self._polyhedron.center
|
2020-06-16 16:19:14 -04:00
|
|
|
|
|
|
|
def stl_export(self, path):
|
|
|
|
"""
|
|
|
|
Export the city object to stl file (city_object_name.stl) to the given path
|
|
|
|
:param path: str
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
# todo: this is a method just for debugging, it will be soon removed
|
|
|
|
if self._polyhedron is None:
|
|
|
|
self._polyhedron = Polyhedron(self.surfaces)
|
|
|
|
full_path = (Path(path) / (self._name + '.stl')).resolve()
|
2020-11-18 08:58:37 -05:00
|
|
|
self._polyhedron.stl_export(full_path)
|
|
|
|
|
|
|
|
def obj_export(self, path):
|
|
|
|
if self._polyhedron is None:
|
|
|
|
self._polyhedron = Polyhedron(self.surfaces)
|
|
|
|
full_path = (Path(path) / (self._name + '.obj')).resolve()
|
|
|
|
self._polyhedron.obj_export(full_path)
|
2020-06-16 16:19:14 -04:00
|
|
|
|
2020-11-04 08:54:10 -05:00
|
|
|
def show(self):
|
|
|
|
if self._polyhedron is None:
|
|
|
|
self._polyhedron = Polyhedron(self.surfaces)
|
|
|
|
self._polyhedron.show()
|
|
|
|
|
2020-06-16 16:19:14 -04:00
|
|
|
@property
|
|
|
|
def max_height(self):
|
|
|
|
"""
|
|
|
|
City object maximal height in meters
|
|
|
|
:return: float
|
|
|
|
"""
|
|
|
|
if self._polyhedron is None:
|
|
|
|
self._polyhedron = Polyhedron(self.surfaces)
|
|
|
|
return self._polyhedron.max_z
|