Пример #1
0
def get_dense_mesh():
    guid = rs.GetObject('get dense mesh', filter=32)
    vertices, faces = RhinoMesh.from_guid(guid).get_vertices_and_faces()
    clean_faces(faces)
    poles = []
    for face in faces:
        if len(face) != 4:
            poles = [
                rs.PointCoordinates(point)
                for point in rs.GetObjects('get pole points', filter=1)
            ]
            break
    singularity_mesh = CoarsePseudoQuadMesh.from_quad_mesh(
        PseudoQuadMesh.from_vertices_and_faces_with_poles(
            vertices, faces, poles))
    return singularity_mesh
Пример #2
0
import rhinoscriptsyntax as rs
from compas_rhino.geometry import RhinoMesh
from compas_pattern.datastructures.mesh_quad_pseudo.mesh_quad_pseudo import PseudoQuadMesh
from compas_pattern.cad.rhino.draw import draw_graph

guids = rs.GetObjects('get quad meshes', filter=32)
poles = rs.GetObjects('get pole points', filter=1)
if poles is None:
    poles = []
else:
    poles = [rs.PointCoordinates(pole) for pole in poles]
rs.EnableRedraw(False)
for guid in guids:
    vertices, faces = RhinoMesh.from_guid(guid).get_vertices_and_faces()
    mesh = PseudoQuadMesh.from_vertices_and_faces_with_poles(
        vertices, faces, poles)
    #mesh = QuadMesh.from_vertices_and_faces(*RhinoMesh.from_guid(guid).get_vertices_and_faces())
    #print('euler', mesh.euler())
    #print('nb_boundaries', len(mesh.boundaries()))
    #mesh.collect_strips()
    #mesh.collect_polyedges()
    #polylines = [rs.AddPolyline(mesh.strip_edge_midpoint_polyline(skey)) for skey in mesh.strips()]
    #for i, polyline in enumerate(polylines):
    #
    #polylines = [rs.AddPolyline(polyline) for polyline in mesh.singularity_polylines()]
    #polylines = [rs.AddPolyline(polyline) for polyline in mesh.polylines()]
    #for polyline in polylines:
    #    rs.CurveArrows(polyline, 3)
    #for i, vkey in enumerate(mesh.vertices()):
    #    rs.AddCircle(mesh.vertex_coordinates(vkey), 2)
    #    rs.AddText(str(i), mesh.vertex_coordinates(vkey), 2)
Пример #3
0
    def densification(self):
        """Generate a denser quad mesh from the coarse quad mesh and its strip densities.

		Returns
		-------
		QuadMesh
			A denser quad mesh.

		"""

        edge_strip = {}
        for skey, edges in self.strips(data=True):
            for edge in edges:
                edge_strip[edge] = skey
                edge_strip[tuple(reversed(edge))] = skey

        pole_map = tuple([
            geometric_key(self.vertex_coordinates(pole))
            for pole in self.poles()
        ])

        meshes = []
        for fkey in self.faces():
            polylines = [[
                self.edge_point(
                    u, v,
                    float(i) /
                    float(self.get_strip_density(edge_strip[(u, v)])))
                for i in range(0,
                               self.get_strip_density(edge_strip[(u, v)]) + 1)
            ] for u, v in self.face_halfedges(fkey)]
            if self.is_face_pseudo_quad(fkey):
                pole = self.data['attributes']['face_pole'][fkey]
                idx = self.face_vertices(fkey).index(pole)
                polylines.insert(idx, None)
            ab, bc, cd, da = polylines
            if cd is not None:
                dc = list(reversed(cd))
            else:
                dc = None
            if da is not None:
                ad = list(reversed(da))
            else:
                ad = None
            vertices, faces = discrete_coons_patch(ab, bc, dc, ad)
            faces = [[u for u, v in pairwise(face + face[:1]) if u != v]
                     for face in faces]
            mesh = PseudoQuadMesh.from_vertices_and_faces_with_face_poles(
                vertices, faces)
            meshes.append(mesh)

        face_pole_map = {}
        for mesh in meshes:
            for fkey in mesh.faces():
                for u, v in pairwise(
                        mesh.face_vertices(fkey) +
                        mesh.face_vertices(fkey)[:1]):
                    if geometric_key(mesh.vertex_coordinates(
                            u)) in pole_map and geometric_key(
                                mesh.vertex_coordinates(u)) == geometric_key(
                                    mesh.vertex_coordinates(v)):
                        face_pole_map[geometric_key(
                            mesh.face_center(fkey))] = geometric_key(
                                mesh.vertex_coordinates(u))
                        break

        self.set_quad_mesh(meshes_join_and_weld(meshes))

        face_pole = {}
        for fkey in self.get_quad_mesh().faces():
            if geometric_key(
                    self.get_quad_mesh().face_center(fkey)) in face_pole_map:
                for vkey in self.get_quad_mesh().face_vertices(fkey):
                    if geometric_key(self.get_quad_mesh().vertex_coordinates(
                            vkey)) == face_pole_map[geometric_key(
                                self.get_quad_mesh().face_center(fkey))]:
                        face_pole[fkey] = vkey
                        break
        self.get_quad_mesh().data['attributes']['face_pole'] = face_pole
        return self.get_quad_mesh()
Пример #4
0
    b = mesh.face_vertex_descendant(fkey_2, a)
    d = mesh.face_vertex_descendant(fkey_1, c)

    mesh.delete_face(fkey_1)
    mesh.delete_face(fkey_2)

    return mesh.add_face([a, b, c, d])


# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

    import compas
    from compas_pattern.datastructures.mesh_quad_pseudo.mesh_quad_pseudo import PseudoQuadMesh

    vertices = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0],
                [0.0, 1.0, 0.0]]

    faces = [[0, 1, 2, 3]]

    mesh = PseudoQuadMesh.from_vertices_and_faces(vertices, faces)
    print(split_quad_in_pseudo_quads(mesh, 0, 0))
    for fkey in mesh.faces():
        print(fkey, mesh.face_vertices(fkey))
    print(merge_pseudo_quads_in_quad(mesh, 1, 2))
    for fkey in mesh.faces():
        print(fkey, mesh.face_vertices(fkey))
Пример #5
0
    # meshes, interpolated_meshes = interpolation(meshes)
    # print(interpolated_meshes)
    
    # #interpolation_layout_primary(meshes, interpolated_meshes, 200.0)
    # #interpolation_layout_secondary(interpolated_meshes, 20.0)
    # interpolation_layout_two_meshes(interpolated_meshes, 10, 20)

    # super_mesh = meshes_join(list(interpolated_meshes.keys()))

    # plotter = MeshPlotter(super_mesh, figsize = (20, 20))
    # plotter.draw_vertices(radius = 0.01)
    # plotter.draw_edges()
    # plotter.draw_faces()
    # plotter.show()

    mesh_1 = PseudoQuadMesh.from_json('/Users/Robin/Desktop/distance_validation/50.json')
    mesh_2 = PseudoQuadMesh.from_json('/Users/Robin/Desktop/distance_validation/51.json')

    # new_face_pole_1 = {int(fkey): vkey for fkey, vkey in mesh_1.data['attributes']['face_pole'].items()}
    # mesh_1.data['attributes']['face_pole'] = new_face_pole_1
    mesh_1.collect_strips()

    # new_face_pole_2 = {int(fkey): vkey for fkey, vkey in mesh_2.data['attributes']['face_pole'].items()}
    # mesh_2.data['attributes']['face_pole'] = new_face_pole_2
    mesh_2.collect_strips()

    #n1 > n2
    n1, n2 = mesh_1.number_of_strips(), mesh_2.number_of_strips()
    print(n1, n2)
    t = []
    for i in range(1):
Пример #6
0
def singular():
    """Explore a pattern, its topology (singularities, densities and symmetries) and its geoemtry (via smoothing).

    """

    layer = rs.CurrentLayer()

    pattern_from = rs.GetString('start pattern from?',
                                strings=[
                                    'coarse_pseudo_quad_mesh',
                                    'pseudo_quad_mesh', 'surface_and_features'
                                ])

    if pattern_from == 'coarse_pseudo_quad_mesh':
        guid = rs.GetObject('get coarse quad mesh', filter=32)
        vertices, faces = RhinoMesh.from_guid(guid).get_vertices_and_faces()
        clean_faces(faces)
        poles = []
        #print(faces)
        for face in faces:
            if len(face) != 4:
                poles = [
                    rs.PointCoordinates(point)
                    for point in rs.GetObjects('get pole points', filter=1)
                ]
                break
        coarse_pseudo_quad_mesh = CoarsePseudoQuadMesh.from_vertices_and_faces_with_poles(
            vertices, faces, poles)
        coarse_pseudo_quad_mesh.collect_strips()
        print(coarse_pseudo_quad_mesh.data['attributes']['strips'])
        coarse_pseudo_quad_mesh.set_strips_density(1)
        coarse_pseudo_quad_mesh.set_quad_mesh(coarse_pseudo_quad_mesh.copy())
        coarse_pseudo_quad_mesh.set_polygonal_mesh(
            coarse_pseudo_quad_mesh.copy())
        print(coarse_pseudo_quad_mesh.data['attributes']['strips'])
    elif pattern_from == 'pseudo_quad_mesh':
        guid = rs.GetObject('get quad mesh', filter=32)
        vertices, faces = RhinoMesh.from_guid(guid).get_vertices_and_faces()
        clean_faces(faces)
        poles = []
        for face in faces:
            if len(face) != 4:
                poles = [
                    rs.PointCoordinates(point)
                    for point in rs.GetObjects('get pole points', filter=1)
                ]
                break
        coarse_pseudo_quad_mesh = CoarsePseudoQuadMesh.from_quad_mesh(
            PseudoQuadMesh.from_vertices_and_faces_with_poles(
                vertices, faces, poles))
    elif pattern_from == 'surface_and_features':
        srf_guid = rs.GetObject('get surface', filter=8)
        crv_guids = rs.GetObjects('get optional curve features', filter=4)
        if crv_guids is None:
            crv_guids = []
        pt_guids = rs.GetObjects('get optional point features', filter=1)
        if pt_guids is None:
            pt_guids = []
        coarse_pseudo_quad_mesh = surface_decomposition(
            srf_guid,
            rs.GetReal('precision', number=1.),
            crv_guids=crv_guids,
            pt_guids=pt_guids,
            output_skeleton=False)[0]
        coarse_pseudo_quad_mesh.collect_strips()
        coarse_pseudo_quad_mesh.set_strips_density(1)
        coarse_pseudo_quad_mesh.set_quad_mesh(coarse_pseudo_quad_mesh.copy())
        coarse_pseudo_quad_mesh.set_polygonal_mesh(
            coarse_pseudo_quad_mesh.copy())
        artist = rhino_artist.MeshArtist(coarse_pseudo_quad_mesh)
        guid = artist.draw_mesh()
    else:
        return 0

    while True:

        #edit = rs.GetString('edit pattern?', strings = ['topology', 'density', 'symmetry', 'geometry', 'evaluate', 'exit'])
        edit = rs.GetString('edit pattern?',
                            strings=[
                                'topology', 'density', 'symmetry', 'geometry',
                                'save', 'exit'
                            ])

        if type(guid) == list:
            rs.DeleteObjects(guid)
        else:
            rs.DeleteObject(guid)

        if edit is None or edit == 'exit':
            rs.EnableRedraw(False)
            artist = rhino_artist.MeshArtist(
                coarse_pseudo_quad_mesh.get_polygonal_mesh())
            return artist.draw_mesh()

        if edit == 'topology':
            editing_topology(coarse_pseudo_quad_mesh)
            coarse_pseudo_quad_mesh.densification()
            coarse_pseudo_quad_mesh.set_polygonal_mesh(
                coarse_pseudo_quad_mesh.get_quad_mesh().copy())

        elif edit == 'density':
            editing_density(coarse_pseudo_quad_mesh)
            coarse_pseudo_quad_mesh.set_polygonal_mesh(
                coarse_pseudo_quad_mesh.get_quad_mesh().copy())

        elif edit == 'symmetry':
            editing_symmetry(coarse_pseudo_quad_mesh)

        elif edit == 'geometry':
            editing_geometry(coarse_pseudo_quad_mesh)

        rs.EnableRedraw(False)
        artist = rhino_artist.MeshArtist(
            coarse_pseudo_quad_mesh.get_polygonal_mesh())
        guid = artist.draw_mesh()
        rs.EnableRedraw(True)

        if edit == 'save':
            save_design(coarse_pseudo_quad_mesh, layer)

        if edit == 'evaluate':
            evaluate_pattern(coarse_pseudo_quad_mesh.get_polygonal_mesh())