Пример #1
0
	def solve_triangular_faces(self):
		"""Modify the decomposition mesh from polylines to make it a quad mesh by converting the degenerated quad faces that appear as triangular faces.

		"""

		mesh = self.mesh

		for fkey in list(mesh.faces()):
			if len(mesh.face_vertices(fkey)) == 3:

				boundary_vertices = [vkey for vkey in mesh.face_vertices(fkey) if mesh.is_vertex_on_boundary(vkey)]
				case = sum(mesh.is_vertex_on_boundary(vkey) for vkey in mesh.face_vertices(fkey))

				if case == 1:
					#convert triangular face to quad by duplicating the boundary vertex
					#due to compas_singular face vertices at the same location
					u = boundary_vertices[0]
					v = mesh.add_vertex(attr_dict = {attr: xyz for attr, xyz in zip(['x', 'y', 'z'], mesh.vertex_coordinates(u))})

					# modify adjacent faces
					vertex_faces = mesh.vertex_faces(u, ordered = True)
					mesh_substitute_vertex_in_faces(mesh, u, v, vertex_faces[: vertex_faces.index(fkey)])

					# modify triangular face
					mesh_insert_vertex_on_edge(mesh, u, mesh.face_vertex_ancestor(fkey, u), v)

				elif case == 2:
					# remove triangular face and merge the two boundary vertices
					# due to singularities at the same location
					polyline = Polyline(self.decomposition_polyline(*map(lambda x: geometric_key(mesh.vertex_coordinates(x)), boundary_vertices)))
					point = polyline.point(t = .5, snap = True)
					new_vkey = mesh.add_vertex(attr_dict = {'x': point.x, 'y': point.y , 'z': point.z})

					# modify triangular face
					mesh.delete_face(fkey)

					# modify adjacent faces
					for old_vkey in boundary_vertices:
						mesh_substitute_vertex_in_faces(mesh, old_vkey, new_vkey, mesh.vertex_faces(old_vkey))
						mesh.delete_vertex(old_vkey)

		to_move = {}
		# give some length to the new edge
		for edge in mesh.edges():
			threshold = 1e-6
			if mesh.edge_length(*edge) < threshold:
				for vkey in edge:
					xyz = centroid_points([mesh.vertex_coordinates(nbr) for nbr in mesh.vertex_neighbors(vkey)])
					xyz0 = mesh.vertex_coordinates(vkey)
					to_move[vkey] = [0.1 * (a - a0) for a, a0 in zip(xyz, xyz0)]

		for vkey, xyz in to_move.items():
			attr = mesh.vertex[vkey]
			attr['x'] += xyz[0]
			attr['y'] += xyz[1]
			attr['z'] += xyz[2]
Пример #2
0
def test_insert_vertex_on_edge(mesh_0):
    mesh_insert_vertex_on_edge(mesh_0, 0, 1)
    assert len(mesh_0.face_vertices(0)) == 4
    assert len(mesh_0.face_vertices(1)) == 4
    assert mesh_0.face_vertex_descendant(0, 0) == 5
    assert mesh_0.face_vertex_descendant(1, 1) == 5

    mesh_insert_vertex_on_edge(mesh_0, 0, 2, 4)
    assert len(mesh_0.face_vertices(0)) == 5
    assert mesh_0.face_vertex_descendant(0, 2) == 4