How to use the brainspace.vtk_interface.pipeline.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 / mesh / mesh_io.py View on Github external
--------
    :func:`read_surface`

    """
    if otype is None:
        otype = opth.split('.')[-1]

    writer = _select_writer(otype)
    writer.filename = opth
    if otype not in ['vtp', 'tri', 'gii', 'obj']:
        if oformat == 'ascii' or otype == 'asc':
            writer.SetFileTypeToASCII()
        else:
            writer.SetFileTypeToBinary()

    serial_connect(ifilter, writer, update=True, as_data=False, port=None)
github MICA-MNI / BrainSpace / brainspace / plotting / base.py View on Github external
ext = ext[1:]

        fmts1 = {'bmp', 'jpeg', 'jpg', 'png', 'tif', 'tiff'}
        fmts2 = {'eps', 'pdf', 'ps', 'svg'}
        if ext in fmts1:
            wimg = self._win2img(transparent_bg, scale)
            if ext == 'bmp':
                writer = BSBMPWriter(filename=filename)
            elif ext in ['jpg', 'jpeg']:
                writer = BSJPEGWriter(filename=filename)
            elif ext == 'png':
                writer = BSPNGWriter(filename=filename)
            else:  # if ext in ['tif', 'tiff']:
                writer = BSTIFFWriter(filename=filename)

            serial_connect(wimg, writer, as_data=False)

        elif ext in fmts2:
            self._check_closed()
            self._check_offscreen()

            orig_sz = self.ren_win.size
            self.ren_win.size = np.array(scale) * orig_sz

            w = BSGL2PSExporter(input=self.ren_win, fileFormat=ext,
                                compress=False, simpleLineOffset=True,
                                filePrefix=pth_no_ext,
                                title='', write3DPropsAsRasterImage=True)
            w.UsePainterSettings()
            w.Update()

            self.ren_win.size = orig_sz
github MICA-MNI / BrainSpace / brainspace / mesh / mesh_creation.py View on Github external
surf : vtkPolyData or BSPolyData
        Input surface.

    Returns
    -------
    output : BSPolyData
        PolyData with vertex points.

    See Also
    --------
    :func:`to_lines`
    :func:`build_polydata`

    """

    return serial_connect(surf, vtkVertexGlyphFilter())
github MICA-MNI / BrainSpace / brainspace / plotting / base.py View on Github external
def to_notebook(self, transparent_bg=True, scale=(1, 1)):
        # if not in_notebook():
        #     raise ValueError("Cannot find notebook.")

        wimg = self._win2img(transparent_bg, scale)
        writer = BSPNGWriter(writeToMemory=True)
        result = serial_connect(wimg, writer, as_data=False).result
        data = memoryview(result).tobytes()
        from IPython.display import Image
        return Image(data)
github MICA-MNI / BrainSpace / brainspace / mesh / mesh_creation.py View on Github external
points.

    """

    s = BSPolyData(points=points)
    if cells is not None:
        n_cells, n_points_cell = cells.shape
        if n_points_cell == 1:
            s.SetVerts(cells)
        elif n_points_cell == 2:
            s.SetLines(cells)
        else:
            s.SetPolys(cells)

    # Triangulation needed
    return serial_connect(s, vtkTriangleFilter())
github MICA-MNI / BrainSpace / brainspace / mesh / mesh_cluster.py View on Github external
n_pts = surf.GetNumberOfPoints()

    # Increase to account for points outside mask
    if mask is not None:
        keep *= (1 + np.count_nonzero(~mask) / n_pts)

    if isinstance(keep, int):
        factor = (n_pts - keep) / n_pts
    elif 0 < keep < 1:
        factor = 1 - keep
    else:
        ValueError('The value of \'keep\' is not valid.')

    cf = vtkDecimatePro()
    cf.SetTargetReduction(factor)
    decimated_surf = serial_connect(surf, cf)

    idx = find_point_correspondence(decimated_surf, surf, eps=0, n_jobs=n_jobs)
    sampled_points = np.zeros(n_pts, dtype=np.uint8)
    sampled_points[idx] = 1

    # Remove points sampled outside mask
    if mask is not None:
        sampled_points[~mask] = 0

    return sampled_points