forked from s_ranjbar/city_retrofit
103 lines
2.6 KiB
Python
103 lines
2.6 KiB
Python
"""
|
|
CityObject module
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|
"""
|
|
from pathlib import Path
|
|
from typing import List, Union
|
|
from city_model_structure.attributes.surface import Surface
|
|
from helpers.geometry_helper import GeometryHelper
|
|
from city_model_structure.attributes.polyhedron import Polyhedron
|
|
|
|
|
|
class CityObject:
|
|
"""
|
|
class CityObject
|
|
"""
|
|
def __init__(self, lod, surfaces, name):
|
|
self._name = name
|
|
self._lod = lod
|
|
self._surfaces = surfaces
|
|
self._polyhedron = None
|
|
self._geometry = GeometryHelper()
|
|
|
|
@property
|
|
def lod(self):
|
|
"""
|
|
City object level of detail 1, 2, 3 or 4
|
|
:return: int
|
|
"""
|
|
return self._lod
|
|
|
|
@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)
|
|
return self._polyhedron.centroid
|
|
|
|
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()
|
|
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)
|
|
|
|
def show(self):
|
|
if self._polyhedron is None:
|
|
self._polyhedron = Polyhedron(self.surfaces)
|
|
self._polyhedron.show()
|
|
|
|
@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
|