storey division working, code needs to be cleaned

This commit is contained in:
Pilar 2021-03-30 17:57:28 -04:00
parent 2702c77a33
commit e5e6b19ed9

View File

@ -110,19 +110,22 @@ class GeometryHelper:
return points return points
@staticmethod @staticmethod
def _segment_list_to_point_cloud(segment_list): def segment_list_to_point_cloud(lines):
point_list = np.asarray(segment_list[0]) line_points = [lines[0][0], lines[0][1]]
for segment in segment_list: lines.remove(lines[0])
for new_point in segment: while len(lines) > 1:
found = False i = 0
for point in point_list: for line in lines:
same_point = np.allclose(new_point, point) i += 1
if same_point: if GeometryHelper.distance_between_points(line[0], line_points[len(line_points) - 1]) < 1e-8:
found = True line_points.append(line[1])
break lines.pop(i - 1)
if not found: break
point_list = np.concatenate((point_list, [new_point])) elif GeometryHelper.distance_between_points(line[1], line_points[len(line_points) - 1]) < 1e-8:
return point_list line_points.append(line[0])
lines.pop(i - 1)
break
return line_points
@staticmethod @staticmethod
def _point_cloud_to_mesh(point_list, normal_list): def _point_cloud_to_mesh(point_list, normal_list):
@ -187,7 +190,7 @@ class GeometryHelper:
mesh_final.append(mesh) mesh_final.append(mesh)
break break
else: else:
points = GeometryHelper._segment_list_to_point_cloud(mesh_1_segments) points = GeometryHelper.segment_list_to_point_cloud(mesh_1_segments)
points_normals = [[None] * 3] * len(points) points_normals = [[None] * 3] * len(points)
for j in range(0, len(points_normals)): for j in range(0, len(points_normals)):
points_normals[j] = normal_opp[i] points_normals[j] = normal_opp[i]
@ -256,6 +259,11 @@ class GeometryHelper:
if np.linalg.norm(vec_1) == 0 or np.linalg.norm(vec_2) == 0: if np.linalg.norm(vec_1) == 0 or np.linalg.norm(vec_2) == 0:
sys.stderr.write("Warning: impossible to calculate angle between planes' normal. Return 0\n") sys.stderr.write("Warning: impossible to calculate angle between planes' normal. Return 0\n")
return 0 return 0
alpha = math.acos(np.dot(vec_1, vec_2) / np.linalg.norm(vec_1) / np.linalg.norm(vec_2)) cosine = np.dot(vec_1, vec_2) / np.linalg.norm(vec_1) / np.linalg.norm(vec_2)
if cosine > 1 and cosine-1 < 1e-5:
cosine = 1
elif cosine < -1 and cosine+1 > -1e-5:
cosine = -1
alpha = math.acos(cosine)
return alpha return alpha