Пример #1
0
def subd_tracked(mesh, k):
    levels = []
    for _ in range(k):
        mesh.update_default_face_attributes({'children': None})
        mesh.update_default_edge_attributes({'child': None})
        subd = mesh_subdivide(mesh, scheme='quad', k=1)
        subd.update_default_face_attributes({'children': None})
        subd.update_default_edge_attributes({'child': None})
        for fkey in mesh.faces():
            children = []
            for u, v in mesh.face_halfedges(fkey):
                u_nbrs = subd.vertex_neighbors(u)
                v_nbrs = subd.vertex_neighbors(v)
                shared = list(set(u_nbrs) & set(v_nbrs))
                children += shared
                mesh.set_edge_attribute((u, v), 'child', shared[0])
            keys = list(
                set.intersection(
                    *[set(subd.vertex_neighbors(key)) for key in children]))
            mesh.set_face_attribute(fkey, 'children', children + keys)
        levels.append(subd)
        mesh = subd
    return levels
mesh.update_default_vertex_attributes({'is_fixed': False})

# make an artist for visualisation
artist = MeshArtist(mesh, layer='SubdModeling::Control')

# draw the control mesh
draw_mesh()

# allow the user to change the attributes of the vertices
while True:
    keys = VertexSelector.select_vertices(mesh)
    if not keys:
        break
    VertexModifier.update_vertex_attributes(mesh, keys)
    draw_mesh()

# make a subd mesh (using catmullclark)
subd = mesh_subdivide(mesh,
                      scheme='catmullclark',
                      k=4,
                      fixed=mesh.vertices_where({'is_fixed': True}))

# give the subdivision mesh a different name
subd.attributes['name'] = 'Mesh'

# draw the result
artist.mesh = subd
artist.layer = 'SubdModeling::Mesh'
artist.clear_layer()
artist.draw_mesh()
Пример #3
0
from compas.datastructures import Mesh
from compas.datastructures import mesh_subdivide

from compas_ghpython.artists import MeshArtist

# make a control mesh
mesh = Mesh.from_polyhedron(6)

# set default vertex attributes
mesh.update_default_vertex_attributes({'is_fixed': False})

# make an artist for drawing
artist = MeshArtist(mesh)

# draw the control mesh into outputs P, L
P = artist.draw_vertices()
L = artist.draw_edges()

# keep some of the vertices fixed and make a subd mesh (using catmullclark)
for key, value in zip(range(len(is_fixed)), is_fixed):
    mesh.set_vertex_attribute(key, 'is_fixed', value)

fixed = mesh.vertices_where({'is_fixed': True})
subd = mesh_subdivide(mesh, scheme='catmullclark', k=k, fixed=fixed)

# pass the new mesh to the artist
artist.mesh = subd

# draw the result into output M
M = artist.draw_mesh()
Пример #4
0
 def subdivide(self, scheme, k):
     self.mesh = mesh_subdivide(self.mesh, scheme=scheme, k=k)
     self.view.make_buffers()
     self.view.updateGL()
Пример #5
0
def test_tris_subdivide_quad(mesh_tris):
    subd = mesh_subdivide(mesh_tris, scheme='quad')
    assert subd.number_of_faces() == 3 * mesh_tris.number_of_faces()
    assert subd.number_of_vertices() == (mesh_tris.number_of_vertices() +
                                         mesh_tris.number_of_edges() +
                                         mesh_tris.number_of_faces())
Пример #6
0
def test_tris_subdivide_tri(mesh_tris):
    subd = mesh_subdivide(mesh_tris, scheme='tri')
    assert subd.number_of_faces() == 3 * mesh_tris.number_of_faces()
    assert subd.number_of_vertices(
    ) == mesh_tris.number_of_vertices() + mesh_tris.number_of_faces()
Пример #7
0
def test_quads_subdivide_tri(mesh_quads):
    subd = mesh_subdivide(mesh_quads, scheme='tri')
    assert subd.number_of_faces() == 4 * mesh_quads.number_of_faces()
    assert subd.number_of_vertices(
    ) == mesh_quads.number_of_vertices() + mesh_quads.number_of_faces()
Пример #8
0
def test_tris_subdivide(mesh_tris):
    subd = mesh_subdivide(mesh_tris)
    assert subd.number_of_faces() == 3 * mesh_tris.number_of_faces()
    assert subd.number_of_vertices() == (mesh_tris.number_of_vertices() +
                                         mesh_tris.number_of_edges() +
                                         mesh_tris.number_of_faces())
Пример #9
0
def test_quads_subdivide(mesh_quads):
    subd = mesh_subdivide(mesh_quads)
    assert subd.number_of_faces() == 4 * mesh_quads.number_of_faces()
    assert subd.number_of_vertices() == (mesh_quads.number_of_vertices() +
                                         mesh_quads.number_of_edges() +
                                         mesh_quads.number_of_faces())
Пример #10
0
# Initialise
# ==============================================================================

HERE = os.path.dirname(__file__)
DATA = os.path.abspath(os.path.join(HERE, '..', 'data'))
FILE_I = os.path.join(DATA, 'data.json')

SHELL = Shell.from_json(FILE_I)

SHELL.update_default_face_attributes({'children': None})

# ==============================================================================
# Subdivide
# ==============================================================================

SUBD1 = mesh_subdivide(SHELL, scheme='quad', k=1)

SUBD1.update_default_face_attributes({'children': None})

for fkey in SHELL.faces():
    children = []
    for u, v in SHELL.face_halfedges(fkey):
        u_nbrs = SUBD1.vertex_neighbors(u)
        v_nbrs = SUBD1.vertex_neighbors(v)
        shared = list(set(u_nbrs) & set(v_nbrs))
        children += shared
    key = list(
        set.intersection(
            *[set(SUBD1.vertex_neighbors(key)) for key in children]))[0]
    children.append(key)
    SHELL.set_face_attribute(fkey, 'children', children)