share on google plus share on facebook share on twitter share on linkedin share via email
from compas.datastructures import VolMesh

def volmesh_dual_volmesh(volmesh):

    dual_volmesh = VolMesh()

    for ckey in volmesh.cell:
        x, y, z = volmesh.cell_centroid(ckey)
        dual_volmesh.add_vertex(vkey=ckey, x=x, y=y, z=z) ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd

    ext_vkeys = []
    boundary_hfkeys = volmesh.halffaces_on_boundary()
    for hfkey in boundary_hfkeys:
        for vkey in volmesh.halfface[hfkey]:
            ext_vkeys.append(vkey)
    int_vkeys = list(set(volmesh.vertices()) - set(ext_vkeys))

    if len(int_vkeys) < 1:
        raise ValueError('Not enough cells to create a dual volmesh.')

    for u in int_vkeys:
        cell_halffaces = []
        for v in volmesh.vertex_neighbours(u):
            edge_ckeys = volmesh.plane[u][v].values()
            ckey       = edge_ckeys[0]
            halfface   = [ckey]
            for i in range(len(edge_ckeys) - 1):
                hfkey = volmesh.cell[ckey][u][v]
                w     = volmesh.halfface_vertex_descendant(hfkey, v)
                ckey  = volmesh.plane[w][v][u]
                halfface.append(ckey)
            cell_halffaces.append(halfface)
        dual_volmesh.add_cell(cell_halffaces, ckey=u)

    return dual_volmesh

Leave a response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>