How to use the brainspace.vtk_interface.serial_connect function in brainspace

To help you get started, we’ve selected a few brainspace examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MICA-MNI / BrainSpace / brainspace / datasets / base.py View on Github external
surf : tuple of BSPolyData or BSPolyData
        Surfaces for left and right hemispheres. If ``join == True``, one
        surface with both hemispheres.
    """

    root_pth = os.path.dirname(__file__)
    fname = 'fsa5.pial.{}.gii'

    ipth = os.path.join(root_pth, 'surfaces', fname)
    surfs = [None] * 2
    for i, side in enumerate(['lh', 'rh']):
        surfs[i] = read_surface(ipth.format(side))
        if with_normals:
            nf = wrap_vtk(vtkPolyDataNormals, splitting=False,
                          featureAngle=0.1)
            surfs[i] = serial_connect(surfs[i], nf)

    if join:
        return combine_surfaces(*surfs)
    return surfs[0], surfs[1]
github MICA-MNI / BrainSpace / brainspace / mesh / mesh_operations.py View on Github external
if upp == np.inf:
        upp = array.max()

    if keep is False:
        raise ValueError("Don't support 'keep=False'.")

    # tf = wrap_vtk(vtkThreshold, invert=not keep)
    tf = wrap_vtk(vtkThreshold)
    tf.ThresholdBetween(low, upp)
    if use_cell:
        tf.SetInputArrayToProcess(0, 0, 0, ASSOC_CELLS, array_name)
    else:
        tf.SetInputArrayToProcess(0, 0, 0, ASSOC_POINTS, array_name)

    gf = wrap_vtk(vtkGeometryFilter(), merging=False)
    surf_sel = serial_connect(surf, tf, gf)

    # Check results
    mask = np.logical_and(array >= low, array <= upp)
    if keep:
        n_expected = np.count_nonzero(mask)
    else:
        n_expected = np.count_nonzero(~mask)

    n_sel = surf_sel.n_cells if use_cell else surf_sel.n_points
    if n_expected != n_sel:
        element = 'cells' if use_cell else 'points'
        warnings.warn('The number of selected {0} is different than expected. '
                      'This may be due to the topology after after selection: '
                      'expected={1}, selected={2}.'.
                      format(element, n_expected, n_sel))
github MICA-MNI / BrainSpace / brainspace / mesh / array_operations.py View on Github external
key : str, optional
        Array name to append to surface's cell data attributes. Only used if
        ``append == True``. Default is 'cell_area'.

    Returns
    -------
    output : vtkPolyData, BSPolyData or ndarray
        Return ndarray if ``append == False``. Otherwise, return input surface
        with the new array.

    """

    alg = wrap_vtk(vtkCellSizeFilter, computeArea=True, areaArrayName=key,
                   computeVolume=False, computeLength=False, computeSum=False,
                   computeVertexCount=False)
    return serial_connect(surf, alg).CellData[key]
github MICA-MNI / BrainSpace / brainspace / mesh / array_operations.py View on Github external
append : bool, optional
        If True, append array to cell data attributes of input surface and
        return surface. Otherwise, only return array. Default is False.
    key : str, optional
        Array name to append to surface's cell data attributes. Only used if
        ``append == True``. Default is 'cell_center'.

    Returns
    -------
    output : vtkPolyData, BSPolyData or ndarray
        Return ndarray if ``append == False``. Otherwise, return input surface
        with the new array.

    """

    return serial_connect(surf, vtkCellCenters()).Points
github MICA-MNI / BrainSpace / brainspace / datasets / base.py View on Github external
"""

    root_pth = os.path.dirname(__file__)
    if as_sphere:
        fname = 'conte69_32k_{}_sphere.gii'
    else:
        fname = 'conte69_32k_{}.gii'

    ipth = os.path.join(root_pth, 'surfaces', fname)
    surfs = [None] * 2
    for i, side in enumerate(['lh', 'rh']):
        surfs[i] = read_surface(ipth.format(side))
        if with_normals:
            nf = wrap_vtk(vtkPolyDataNormals, splitting=False,
                          featureAngle=0.1)
            surfs[i] = serial_connect(surfs[i], nf)

    if join:
        return combine_surfaces(*surfs)
    return surfs[0], surfs[1]
github MICA-MNI / BrainSpace / brainspace / mesh / mesh_elements.py View on Github external
Parameters
    ----------
    surf : vtkPolyData or BSPolyData

    Returns
    -------
    surf_boundary : BSPolyData
        PolyData with cells as boundary edges.
    boundary_points : 1D ndarray
        Array of point ids in the boundary.
    """

    an = surf.append_array(np.arange(surf.n_points))
    fe = wrap_vtk(vtk.vtkFeatureEdges, boundaryEdges=True, manifoldEdges=False,
                  nonManifoldEdges=False, featureEdges=False)
    bs = serial_connect(surf, fe)
    surf.remove_array(an)
    return bs, bs.get_array(an, at='p')