From 9c0483f1d86afd955b652c4a298c640ba589ea25 Mon Sep 17 00:00:00 2001 From: Guille Date: Mon, 21 Dec 2020 11:08:54 -0500 Subject: [PATCH] Correct surface triangulation algorithms --- city_model_structure/attributes/polyhedron.py | 19 ++++++++++++------- city_model_structure/attributes/surface.py | 2 ++ city_model_structure/city_object.py | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/city_model_structure/attributes/polyhedron.py b/city_model_structure/attributes/polyhedron.py index 7996b106..4f30ecf5 100644 --- a/city_model_structure/attributes/polyhedron.py +++ b/city_model_structure/attributes/polyhedron.py @@ -105,12 +105,9 @@ class Polyhedron: return (Surface(triangle_left, remove_last=False), Surface(rest_points_left, remove_last=False)), \ (Surface(triangle_right, remove_last=False), Surface(rest_points_right, remove_last=False)) - def _print(self, surface): - for point in surface.points: - print(point[0]-surface.min_x, point[1]-surface.min_y, point[2]-surface.min_z) - def _triangulate(self, surface): triangles = [] + complementary_surface = None triangles_count = len(surface.points) - 2 points_list = surface.points_list point_index = 0 @@ -126,18 +123,21 @@ class Polyhedron: point_index = 0 triangles.append(left_direction[0]) points_list = left_direction[1].points_list + complementary_surface = left_direction[1] elif self._geometry.almost_same_area(area, right_area): area = right_direction[1].area point_index = 0 triangles.append(right_direction[0]) points_list = right_direction[1].points_list + complementary_surface = right_direction[1] else: point_index = point_index + 3 if point_index > len(points_list): raise Exception('not ear found!') if len(points_list) == 9: # the rest point's are already a triangle - triangles.append(Surface(points_list, remove_last=False)) + triangles.append(complementary_surface) + return triangles @property @@ -160,6 +160,7 @@ class Polyhedron: for sub_surface in sub_surfaces: face = [] points = sub_surface.points + print(points) for point in points: face.append(self._position_of(point, face)) self._faces.append(face) @@ -172,6 +173,7 @@ class Polyhedron: @property def _polyhedron_mesh(self): if self._mesh is None: + print(self.faces) self._mesh = Trimesh(vertices=self.vertices, faces=self.faces) return self._mesh @@ -272,12 +274,15 @@ class Polyhedron: return self._min_x @property - def centroid(self): + def center(self): """ Polyhedron centroid :return: [x,y,z] """ - return [self.max_x - self.min_x, self.max_y - self.min_y, self.max_z - self.min_z] + x = (self.max_x + self.min_x) / 2 + y = (self.max_y + self.min_y) / 2 + z = (self.max_z + self.min_z) / 2 + return [x, y, z] def stl_export(self, full_path): """ diff --git a/city_model_structure/attributes/surface.py b/city_model_structure/attributes/surface.py index 759091be..5ccd83c2 100644 --- a/city_model_structure/attributes/surface.py +++ b/city_model_structure/attributes/surface.py @@ -13,6 +13,8 @@ import math from helpers.geometry_helper import GeometryHelper +# todo: remove pyny3d, seems to not be supported and has some issues + class Surface: """ diff --git a/city_model_structure/city_object.py b/city_model_structure/city_object.py index e40872bb..3244fae9 100644 --- a/city_model_structure/city_object.py +++ b/city_model_structure/city_object.py @@ -66,7 +66,7 @@ class CityObject: """ if self._polyhedron is None: self._polyhedron = Polyhedron(self.surfaces) - return self._polyhedron.centroid + return self._polyhedron.center def stl_export(self, path): """