From 5290cb6ba94a3b480fc6db15fb3e482757c60281 Mon Sep 17 00:00:00 2001 From: Pilar Date: Wed, 7 Apr 2021 11:47:39 -0400 Subject: [PATCH] adding import obj (not yet working). Also erased accent from Alvarez --- city_model_structure/attributes/occupants.py | 2 +- city_model_structure/attributes/polygon.py | 2 +- city_model_structure/attributes/surface.py | 2 +- .../attributes/thermal_boundary.py | 2 +- .../attributes/thermal_opening.py | 2 +- .../attributes/thermal_zone.py | 2 +- helpers/geometry_helper.py | 2 +- imports/geometry_factory.py | 12 ++- imports/geometry_feeders/citygml.py | 2 - imports/geometry_feeders/obj.py | 15 +++- tests/test_building.py | 2 +- tests/test_exports.py | 1 + tests/test_geometry_factory.py | 2 +- tests/test_imports.py | 33 ++++++++ tests/tests_data/kelowna.obj | 81 +++++++++++++++++++ 15 files changed, 149 insertions(+), 13 deletions(-) create mode 100644 tests/test_imports.py create mode 100644 tests/tests_data/kelowna.obj diff --git a/city_model_structure/attributes/occupants.py b/city_model_structure/attributes/occupants.py index bdc7263e..51d4ea57 100644 --- a/city_model_structure/attributes/occupants.py +++ b/city_model_structure/attributes/occupants.py @@ -2,7 +2,7 @@ Occupants module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Sanam Dabirian sanam.dabirian@mail.concordia.ca -Contributors Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca +Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ from typing import TypeVar diff --git a/city_model_structure/attributes/polygon.py b/city_model_structure/attributes/polygon.py index 2544139c..58d8706e 100644 --- a/city_model_structure/attributes/polygon.py +++ b/city_model_structure/attributes/polygon.py @@ -1,7 +1,7 @@ """ Polygon module SPDX - License - Identifier: LGPL - 3.0 - or -later -Copyright © 2020 Project Author Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca +Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ import sys diff --git a/city_model_structure/attributes/surface.py b/city_model_structure/attributes/surface.py index eee48949..5fefd4ce 100644 --- a/city_model_structure/attributes/surface.py +++ b/city_model_structure/attributes/surface.py @@ -2,7 +2,7 @@ Surface module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca -contributors Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca +contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ from __future__ import annotations diff --git a/city_model_structure/attributes/thermal_boundary.py b/city_model_structure/attributes/thermal_boundary.py index 3f8e280d..e725b596 100644 --- a/city_model_structure/attributes/thermal_boundary.py +++ b/city_model_structure/attributes/thermal_boundary.py @@ -2,7 +2,7 @@ ThermalBoundary module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca -Contributors Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca +Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ from typing import List, TypeVar from city_model_structure.attributes.layer import Layer diff --git a/city_model_structure/attributes/thermal_opening.py b/city_model_structure/attributes/thermal_opening.py index 05c6732f..fc63f24e 100644 --- a/city_model_structure/attributes/thermal_opening.py +++ b/city_model_structure/attributes/thermal_opening.py @@ -2,7 +2,7 @@ ThermalOpening module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca -Contributors Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca +Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ from typing import TypeVar diff --git a/city_model_structure/attributes/thermal_zone.py b/city_model_structure/attributes/thermal_zone.py index 2e23088c..e5cd3441 100644 --- a/city_model_structure/attributes/thermal_zone.py +++ b/city_model_structure/attributes/thermal_zone.py @@ -2,7 +2,7 @@ ThermalZone module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca -Contributors Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca +Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ import uuid from typing import List, TypeVar diff --git a/helpers/geometry_helper.py b/helpers/geometry_helper.py index fd5df211..4362b667 100644 --- a/helpers/geometry_helper.py +++ b/helpers/geometry_helper.py @@ -2,7 +2,7 @@ Geometry helper SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca -Contributors Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca +Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ import math import numpy as np diff --git a/imports/geometry_factory.py b/imports/geometry_factory.py index 64a5ce69..7f932613 100644 --- a/imports/geometry_factory.py +++ b/imports/geometry_factory.py @@ -50,12 +50,22 @@ class GeometryFactory: def scene(self): """ Load the city model structure from a geometry source - :return: Trimesh + :return: Trimesh scene """ return getattr(self, self._file_type, lambda: None) + @property + def _scene_debug(self): + """ + just for debug. More information is provided without the lambda parameter + """ + return getattr(self, self._file_type) + @property def _city_debug(self): + """ + just for debug. More information is provided without the lambda parameter + """ return CityGml(self._path).city @property diff --git a/imports/geometry_feeders/citygml.py b/imports/geometry_feeders/citygml.py index 2671162c..d7b7f089 100644 --- a/imports/geometry_feeders/citygml.py +++ b/imports/geometry_feeders/citygml.py @@ -5,7 +5,6 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc """ import numpy as np import xmltodict -import time from city_model_structure.city import City from city_model_structure.building import Building @@ -70,7 +69,6 @@ class CityGml: City model structure enriched with the geometry information :return: City """ - init = time.process_time_ns() if self._city is None: # todo: refactor this method to clearly choose the gml type self._city = City(self._lower_corner, self._upper_corner, self._srs_name) diff --git a/imports/geometry_feeders/obj.py b/imports/geometry_feeders/obj.py index fc82847a..cd2672b7 100644 --- a/imports/geometry_feeders/obj.py +++ b/imports/geometry_feeders/obj.py @@ -1,9 +1,14 @@ """ Obj module parses obj files and import the geometry into the city model structure SPDX - License - Identifier: LGPL - 3.0 - or -later -Copyright © 2020 Project Author Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca +Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ import trimesh.exchange.obj +from city_model_structure.city import City +from city_model_structure.building import Building +from city_model_structure.attributes.surface import Surface +from helpers.geometry_helper import GeometryHelper +from city_model_structure.attributes.polygon import Polygon class Obj: @@ -19,3 +24,11 @@ class Obj: @property def scene(self) -> dict: return self._scene + + @property + def city(self) -> dict: + if self._city is None: + # todo: refactor this method to clearly choose the gml type + self._city = City(self._lower_corner, self._upper_corner, self._srs_name) + + return self._city diff --git a/tests/test_building.py b/tests/test_building.py index d83b06da..98424a8e 100644 --- a/tests/test_building.py +++ b/tests/test_building.py @@ -1,7 +1,7 @@ """ Building test SPDX - License - Identifier: LGPL - 3.0 - or -later -Copyright © 2020 Project Author Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca +Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ from pathlib import Path from unittest import TestCase diff --git a/tests/test_exports.py b/tests/test_exports.py index 51005633..849a2738 100644 --- a/tests/test_exports.py +++ b/tests/test_exports.py @@ -2,6 +2,7 @@ TestExports test and validate the city export formats SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca +Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ from pathlib import Path diff --git a/tests/test_geometry_factory.py b/tests/test_geometry_factory.py index 5c1c8f5e..40d53af9 100644 --- a/tests/test_geometry_factory.py +++ b/tests/test_geometry_factory.py @@ -2,7 +2,7 @@ TestGeometryFactory test and validate the city model structure geometric parameters SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca -Contributors Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca +Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ import os from pathlib import Path diff --git a/tests/test_imports.py b/tests/test_imports.py new file mode 100644 index 00000000..1c9c22e2 --- /dev/null +++ b/tests/test_imports.py @@ -0,0 +1,33 @@ +""" +TestImports test and validate the city export formats +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca +""" + +from pathlib import Path +from unittest import TestCase +from imports.geometry_factory import GeometryFactory + + +class MyTestCase(TestCase): + def test_something(self): + self.assertEqual(True, False) + """ + TestImports + """ + def setUp(self) -> None: + """ + Test setup + :return: None + """ + self._city_gml = None + self._example_path = (Path(__file__).parent / 'tests_data').resolve() + self._output_path = (Path(__file__).parent / 'tests_outputs').resolve() + + def _get_city(self): + if self._city_gml is None: + file_path = (self._example_path / 'kelowna.obj').resolve() + scene = GeometryFactory('obj', file_path)._scene_debug + self._city_gml = scene.city + return self._city_gml + diff --git a/tests/tests_data/kelowna.obj b/tests/tests_data/kelowna.obj new file mode 100644 index 00000000..ef0ebad6 --- /dev/null +++ b/tests/tests_data/kelowna.obj @@ -0,0 +1,81 @@ +# https://github.com/mikedh/trimesh +v 329238.00000000 5528272.00000000 0.00000000 +v 329238.00000000 5528272.00000000 3.79999995 +v 329254.12500000 5528263.00000000 0.00000000 +v 329254.12500000 5528263.00000000 3.79999995 +v 329245.12500000 5528267.50000000 4.93084002 +v 329246.15625000 5528272.50000000 0.00000000 +v 329246.15625000 5528272.50000000 3.79999995 +v 329229.15625000 5528271.00000000 0.00000000 +v 329229.15625000 5528271.00000000 3.79999995 +v 329242.18750000 5528267.00000000 5.29822016 +v 329238.31250000 5528266.50000000 4.68875980 +v 329229.31250000 5528269.50000000 0.00000000 +v 329229.31250000 5528269.50000000 3.79999995 +v 329244.34375000 5528267.00000000 4.99910021 +v 329242.34375000 5528267.00000000 5.30000019 +v 329233.34375000 5528276.00000000 0.00000000 +v 329233.34375000 5528276.00000000 3.79999995 +v 329247.34375000 5528262.50000000 0.00000000 +v 329247.34375000 5528262.50000000 3.79999995 +v 329242.40625000 5528257.50000000 0.00000000 +v 329242.40625000 5528257.50000000 3.79999995 +v 329231.50000000 5528270.50000000 4.31147003 +v 329253.53125000 5528273.00000000 0.00000000 +v 329253.53125000 5528273.00000000 3.79999995 +v 329241.71875000 5528276.50000000 0.00000000 +v 329241.71875000 5528276.50000000 3.79999995 +v 329233.81250000 5528270.50000000 4.68364000 +v 329248.81250000 5528267.50000000 4.92572021 +f 22 9 13 +f 28 4 24 +f 23 6 7 +f 7 24 23 +f 6 25 26 +f 26 7 6 +f 25 1 2 +f 2 26 25 +f 1 16 17 +f 17 2 1 +f 16 8 9 +f 9 17 16 +f 8 12 13 +f 13 9 8 +f 12 20 21 +f 21 13 12 +f 20 18 19 +f 19 21 20 +f 18 3 4 +f 4 19 18 +f 3 23 24 +f 24 4 3 +f 6 23 3 +f 6 3 18 +f 6 18 20 +f 6 20 12 +f 6 12 8 +f 8 16 1 +f 6 8 1 +f 1 25 6 +f 24 7 14 +f 24 14 5 +f 5 28 24 +f 7 26 15 +f 15 14 7 +f 26 2 11 +f 26 11 10 +f 10 15 26 +f 2 17 27 +f 27 11 2 +f 17 9 22 +f 22 27 17 +f 21 10 11 +f 13 21 11 +f 13 11 27 +f 27 22 13 +f 21 19 5 +f 21 5 14 +f 21 14 15 +f 15 10 21 +f 19 4 28 +f 28 5 19 \ No newline at end of file