diff --git a/city_model_structure/attributes/polyhedron.py b/city_model_structure/attributes/polyhedron.py index 7af0a38f..b792eee5 100644 --- a/city_model_structure/attributes/polyhedron.py +++ b/city_model_structure/attributes/polyhedron.py @@ -30,7 +30,7 @@ class Polyhedron: self._min_z = None self._min_y = None self._min_x = None - self._geometry = GeometryHelper(delta=5.0, area_delta=0.01) + self._geometry = GeometryHelper(delta=0.5, area_delta=0.001) def _position_of(self, point, face): vertices = self.vertices diff --git a/city_model_structure/city_object.py b/city_model_structure/city_object.py index 3244fae9..21cb91a6 100644 --- a/city_model_structure/city_object.py +++ b/city_model_structure/city_object.py @@ -19,7 +19,6 @@ class CityObject: self._lod = lod self._surfaces = surfaces self._polyhedron = None - self._geometry = GeometryHelper() @property def lod(self): diff --git a/helpers/geometry_helper.py b/helpers/geometry_helper.py index 4365863e..a5d4e197 100644 --- a/helpers/geometry_helper.py +++ b/helpers/geometry_helper.py @@ -17,10 +17,15 @@ class GeometryHelper: """ Geometry helper class """ + def __init__(self, delta=0.5, area_delta=0.5): self._delta = delta self._area_delta = area_delta + @property + def config(self): + print(f'delta {self._delta} area {self._area_delta}') + @staticmethod def adjacent_locations(location1, location2): """ @@ -46,7 +51,7 @@ class GeometryHelper: delta = math.fabs(a1 - a2) return delta <= self._area_delta - def almost_equal(self, v1, v2, debug=False): + def almost_equal(self, v1, v2): """ Compare two points and decides if they are almost equal (quadratic error under delta) :param v1: [x,y,z] diff --git a/tests/test_geometry_factory.py b/tests/test_geometry_factory.py index b73ea27a..4d36871f 100644 --- a/tests/test_geometry_factory.py +++ b/tests/test_geometry_factory.py @@ -9,6 +9,7 @@ from unittest import TestCase from city_model_structure.city import City from factories.geometry_factory import GeometryFactory +from helpers.geometry_helper import GeometryHelper class TestGeometryFactory(TestCase): @@ -23,7 +24,8 @@ class TestGeometryFactory(TestCase): self._city_gml = None self._example_path = (Path(__file__).parent.parent / 'tests_data').resolve() self._pickle_file = (self._example_path / 'city.pickle').resolve() - self._big_pickle_file = (self._example_path / 'big.pickle').resolve() + self._kelowna_pickle_file = (self._example_path / 'kelowna_test_case.pickle').resolve() + self._output_path = (Path(__file__).parent / 'surface_outputs').resolve() def _get_citygml(self): if self._city_gml is None: @@ -69,6 +71,21 @@ class TestGeometryFactory(TestCase): self.assertIsNotNone(city.country_code, 'country code is none') os.remove(self._pickle_file.resolve()) + def test_surfaces_triangulation(self): + """ + Test city surfaces triangulation and polygon creation + :return: + """ + city = City.load(self._kelowna_pickle_file) + helper = GeometryHelper(delta=0.0, area_delta=0.5) + errors = 0 + for building in city.buildings: + building._polyhedron._geometry = helper + if str(building.volume) == 'inf': + building.obj_export(self._output_path) + errors += 1 + print(f'{errors} buildings aren\'t closed volumes') + def test_citygml_buildings(self): """ Test city objects in the city diff --git a/tests_data/kelowna_test_case.pickle b/tests_data/kelowna_test_case.pickle new file mode 100644 index 00000000..4897d569 Binary files /dev/null and b/tests_data/kelowna_test_case.pickle differ