algorithm/surf_tools.py
def threshold_by_rggrow(seedvx, vxnum, faces, scalarmap, option='descend', restrictedROI=None):
    """
    Threshold scalarmap with specific vertex number (vxnum) by region growing algorithm.

    Parameters:
    ------------
        seedvx: seed vertex
        vxnum: number of vertices to generate
        faces: relationship of geometry connection
        scalarmap: scalar map, e.g. activation map.
        option: 'descend', selected vertices with value smaller than seedvx.
                'ascend', selected vertices with value larger than seedvx.
        restrictedROI: ROI to limit range of region growing.

    Returns:
    --------
    rg_scalar: a new scalar map generated from the region growing algorithm
    vxpack: packed vertices

    Example:
    --------
    >>> rg_scalar, vxpack = threshold_by_rggrow(24, 300, faces, scalarmap)
    """
    assert np.ndim(scalarmap) == 1, "Please flatten scalarmap first."
    if option == 'ascend':
        actdata = -1.0*scalarmap
    else:
        actdata = 1.0*scalarmap 
    if restrictedROI is None:
        restrictedROI = np.ones_like(actdata)
    vxpack = set()
    vxpack.add(seedvx)
    backupvx = set()
    seed_neighbor = get_n_ring_neighbor(seedvx, faces, 1, ordinal=True)[0]
    backupvx.update(seed_neighbor.difference(vxpack))
    while (len(vxpack)<vxnum+1):
        # print('{} vertices contained'.format(len(vxpack)))
        backupvx = backupvx.difference(vxpack)
        if len(backupvx)==0:
            break
        array_backupvx = np.array(list(backupvx))
        array_vxpack = np.array(list(vxpack))
        seed_bp = int(array_backupvx[np.argmax(actdata[array_backupvx])])
        if restrictedROI[seed_bp] != 0:
            vxpack.add(seed_bp)
            seed_bp_neigh = get_n_ring_neighbor(seed_bp, faces, 1, ordinal=True)[0]
            backupvx.update(seed_bp_neigh)
        else:
            # Outside to restrictedROI 
            backupvx.discard(seed_bp)
            continue
    rg_scalar = np.zeros_like(scalarmap)
    rg_scalar[np.array(list(vxpack))] = 1
    rg_scalar = rg_scalar*scalarmap
    return rg_scalar, array_vxpack

    Threshold scalarmap with specific vertex number (vxnum) by region growing algorithm.

    Parameters:
    ------------
        seedvx: seed vertex
        vxnum: number of vertices to generate
        faces: relationship of geometry connection
        scalarmap: scalar map, e.g. activation map.
        option: 'descend', selected vertices with value smaller than seedvx.
                'ascend', selected vertices with value larger than seedvx.
        restrictedROI: ROI to limit range of region growing.

    Returns:
    --------
    rg_scalar: a new scalar map generated from the region growing algorithm
    vxpack: packed vertices

    Example:
    --------
    >>> rg_scalar, vxpack = threshold_by_rggrow(24, 300, faces, scalarmap)
    
Threshold scalarmap with specific vertex number (vxnum) by region growing algorithm.
Threshold scalarmap with specific vertex number ( vxnum ) by region growing algorithm .
def threshold_by_rggrow(seedvx, vxnum, faces, scalarmap, option='descend', restrictedROI=None):
    assert np.ndim(scalarmap) == 1, "Please flatten scalarmap first."
    if option == 'ascend':
        actdata = -1.0*scalarmap
    else:
        actdata = 1.0*scalarmap 
    if restrictedROI is None:
        restrictedROI = np.ones_like(actdata)
    vxpack = set()
    vxpack.add(seedvx)
    backupvx = set()
    seed_neighbor = get_n_ring_neighbor(seedvx, faces, 1, ordinal=True)[0]
    backupvx.update(seed_neighbor.difference(vxpack))
    while (len(vxpack)<vxnum+1):
        backupvx = backupvx.difference(vxpack)
        if len(backupvx)==0:
            break
        array_backupvx = np.array(list(backupvx))
        array_vxpack = np.array(list(vxpack))
        seed_bp = int(array_backupvx[np.argmax(actdata[array_backupvx])])
        if restrictedROI[seed_bp] != 0:
            vxpack.add(seed_bp)
            seed_bp_neigh = get_n_ring_neighbor(seed_bp, faces, 1, ordinal=True)[0]
            backupvx.update(seed_bp_neigh)
        else:
            backupvx.discard(seed_bp)
            continue
    rg_scalar = np.zeros_like(scalarmap)
    rg_scalar[np.array(list(vxpack))] = 1
    rg_scalar = rg_scalar*scalarmap
    return rg_scalar, array_vxpack
def threshold_by_rggrow ( seedvx , vxnum , faces , scalarmap , option = 'descend' , restrictedROI = None ) : assert np . ndim ( scalarmap ) == 1 , "Please flatten scalarmap first." if option == 'ascend' : actdata = - 1.0 * scalarmap else : actdata = 1.0 * scalarmap if restrictedROI is None : restrictedROI = np . ones_like ( actdata ) vxpack = set ( ) vxpack . add ( seedvx ) backupvx = set ( ) seed_neighbor = get_n_ring_neighbor ( seedvx , faces , 1 , ordinal = True ) [ 0 ] backupvx . update ( seed_neighbor . difference ( vxpack ) ) while ( len ( vxpack ) < vxnum + 1 ) : backupvx = backupvx . difference ( vxpack ) if len ( backupvx ) == 0 : break array_backupvx = np . array ( list ( backupvx ) ) array_vxpack = np . array ( list ( vxpack ) ) seed_bp = int ( array_backupvx [ np . argmax ( actdata [ array_backupvx ] ) ] ) if restrictedROI [ seed_bp ] != 0 : vxpack . add ( seed_bp ) seed_bp_neigh = get_n_ring_neighbor ( seed_bp , faces , 1 , ordinal = True ) [ 0 ] backupvx . update ( seed_bp_neigh ) else : backupvx . discard ( seed_bp ) continue rg_scalar = np . zeros_like ( scalarmap ) rg_scalar [ np . array ( list ( vxpack ) ) ] = 1 rg_scalar = rg_scalar * scalarmap return rg_scalar , array_vxpack
Threshold scalarmap with specific vertex number (vxnum) by region growing algorithm.
Threshold scalarmap with specific vertex number ( vxnum ) by region growing algorithm .
"""
    Threshold scalarmap with specific vertex number (vxnum) by region growing algorithm.

    Parameters:
    ------------
        seedvx: seed vertex
        vxnum: number of vertices to generate
        faces: relationship of geometry connection
        scalarmap: scalar map, e.g. activation map.
        option: 'descend', selected vertices with value smaller than seedvx.
                'ascend', selected vertices with value larger than seedvx.
        restrictedROI: ROI to limit range of region growing.

    Returns:
    --------
    rg_scalar: a new scalar map generated from the region growing algorithm
    vxpack: packed vertices

    Example:
    --------
    >>> rg_scalar, vxpack = threshold_by_rggrow(24, 300, faces, scalarmap)
    """ # print('{} vertices contained'.format(len(vxpack))) # Outside to restrictedROI 
None
seedvx
None
vxnum
number of vertices to generate
number of vertices to generate
faces
relationship of geometry connection
relationship of geometry connection
scalarmap
scalar map, e.g. activation map.
scalar map e . g . activation map .
option
'descend', selected vertices with value smaller than seedvx.
'ascend', selected vertices with value larger than seedvx.
' descend ' selected vertices with value smaller than seedvx . ' ascend ' selected vertices with value larger than seedvx .
restrictedROI
ROI to limit range of region growing.
ROI to limit range of region growing .
examples
None