src/compas_3gs/algorithms/duality.py
def volmesh_dual_volmesh(volmesh, cls=None):
    """Constructs the dual volmesh of a volmesh.

    Parameters
    ----------
    volmesh : VolMesh
        A volmesh object.

    Returns
    -------
    volmesh : VolMesh
        The dual volmesh object of the input volmesh.

    """

    if not cls:
        cls = VolMesh

    # 1. make volmesh instance -------------------------------------------------
    dual_volmesh = cls()
    dual_volmesh.attributes['name'] = 'volmesh_dual_volmesh'

    # 2. add vertex for each cell ----------------------------------------------
    for cell in volmesh.cells():
        x, y, z = volmesh.cell_centroid(cell)
        dual_volmesh.add_vertex(vkey=cell, x=x, y=y, z=z)

    # 3. find interior vertices ------------------------------------------------
    ext_vkeys = []
    boundary_hfkeys = volmesh.halffaces_on_boundaries()
    for halfface in boundary_hfkeys:
        for vertex in volmesh.halfface_vertices(halfface):
            ext_vkeys.append(vertex)
    int_vkeys = list(set(volmesh.vertices()) - set(ext_vkeys))

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

    # 4. for each interior vertex, find neighbors ------------------------------
    for u in int_vkeys:
        cell_halffaces = []
        for v in volmesh.vertex_neighbors(u):
            halfface = volmesh.edge_cells((u, v))
            # 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_descendent(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
Constructs the dual volmesh of a volmesh.

    Parameters
    ----------
    volmesh : VolMesh
        A volmesh object.

    Returns
    -------
    volmesh : VolMesh
        The dual volmesh object of the input volmesh.

    
Constructs the dual volmesh of a volmesh.
Parameters

volmesh : VolMesh
A volmesh object.

Returns

volmesh : VolMesh
The dual volmesh object of the input volmesh.
Constructs the dual volmesh of a volmesh . Parameters volmesh : VolMesh A volmesh object . Returns volmesh : VolMesh The dual volmesh object of the input volmesh .
def volmesh_dual_volmesh(volmesh, cls=None):
    if not cls:
        cls = VolMesh
    dual_volmesh = cls()
    dual_volmesh.attributes['name'] = 'volmesh_dual_volmesh'
    for cell in volmesh.cells():
        x, y, z = volmesh.cell_centroid(cell)
        dual_volmesh.add_vertex(vkey=cell, x=x, y=y, z=z)
    ext_vkeys = []
    boundary_hfkeys = volmesh.halffaces_on_boundaries()
    for halfface in boundary_hfkeys:
        for vertex in volmesh.halfface_vertices(halfface):
            ext_vkeys.append(vertex)
    int_vkeys = list(set(volmesh.vertices()) - set(ext_vkeys))
    if len(int_vkeys) < 1:
        raise Exception('Not enough cells to create a dual volmesh.')
    for u in int_vkeys:
        cell_halffaces = []
        for v in volmesh.vertex_neighbors(u):
            halfface = volmesh.edge_cells((u, v))
            cell_halffaces.append(halfface)
        dual_volmesh.add_cell(cell_halffaces, ckey=u)
    return dual_volmesh
def volmesh_dual_volmesh ( volmesh , cls = None ) : if not cls : cls = VolMesh dual_volmesh = cls ( ) dual_volmesh . attributes [ 'name' ] = 'volmesh_dual_volmesh' for cell in volmesh . cells ( ) : x , y , z = volmesh . cell_centroid ( cell ) dual_volmesh . add_vertex ( vkey = cell , x = x , y = y , z = z ) ext_vkeys = [ ] boundary_hfkeys = volmesh . halffaces_on_boundaries ( ) for halfface in boundary_hfkeys : for vertex in volmesh . halfface_vertices ( halfface ) : ext_vkeys . append ( vertex ) int_vkeys = list ( set ( volmesh . vertices ( ) ) - set ( ext_vkeys ) ) if len ( int_vkeys ) < 1 : raise Exception ( 'Not enough cells to create a dual volmesh.' ) for u in int_vkeys : cell_halffaces = [ ] for v in volmesh . vertex_neighbors ( u ) : halfface = volmesh . edge_cells ( ( u , v ) ) cell_halffaces . append ( halfface ) dual_volmesh . add_cell ( cell_halffaces , ckey = u ) return dual_volmesh
Constructs the dual volmesh of a volmesh.
Constructs the dual volmesh of a volmesh .
"""Constructs the dual volmesh of a volmesh.

    Parameters
    ----------
    volmesh : VolMesh
        A volmesh object.

    Returns
    -------
    volmesh : VolMesh
        The dual volmesh object of the input volmesh.

    """ # 1. make volmesh instance ------------------------------------------------- # 2. add vertex for each cell ---------------------------------------------- # 3. find interior vertices ------------------------------------------------ # 4. for each interior vertex, find neighbors ------------------------------ # 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_descendent(hfkey, v) #     ckey  = volmesh.plane[w][v][u] #     halfface.append(ckey)
volmesh
cls