Exemple #1
0
def plot_surfaces(vtk_files, use_colormap=False, colormap_file=''):
    """
    Use vtkviewer to visualize one or more VTK surface files.

    Optionally provide colormap file or set $COLORMAP environment variable.

    Parameters
    ----------
    vtk_files : string or list of strings
        name of VTK surface mesh file or list of file names
    use_colormap : Boolean
        use Paraview-style XML colormap file?
    colormap_file : string
        use colormap in given file if use_colormap==True?  if empty and
        use_colormap==True, use file set by $COLORMAP environment variable

    Examples
    --------
    >>> import os
    >>> from mindboggle.utils.plots import plot_surfaces
    >>> path = os.environ['MINDBOGGLE_DATA']
    >>> vtk_files = os.path.join(path, 'arno', 'labels', 'lh.labels.DKT31.manual.vtk')
    >>> #vtk_files = [os.path.join(path, 'cube.vtk'), os.path.join(path, 'test_one_label.vtk')]
    >>> use_colormap = True
    >>> colormap_file = '/software/mindboggle_tools/colormap.xml'
    >>> plot_surfaces(vtk_files, use_colormap, colormap_file)

    """
    import os
    import sys

    import mindboggle.thirdparty.vtkviewer as vtkviewer

    if isinstance(vtk_files, str):
        vtk_files = [vtk_files]

    vv = vtkviewer.VTKViewer()

    colormap = None
    if use_colormap:
        if colormap_file and os.path.isfile(colormap_file):
            colormap = vv.LoadColorMap(colormap_file)
        elif "COLORMAP" in os.environ:
            colormap = vv.LoadColorMap(os.environ["COLORMAP"])

    for vtk_file in vtk_files:
        if os.path.isfile(vtk_file):
            vv.AddFile(vtk_file, colormap)
        else:
            sys.exit("Huh?: {0}".format(vtk_file))

    vv.Start()
Exemple #2
0
def plot_surfaces(vtk_files, use_colormap=False, colormap_file=''):
    """
    Use vtkviewer to visualize one or more VTK surface files.

    Optionally provide colormap file or set $COLORMAP environment variable.

    Parameters
    ----------
    vtk_files : string or list of strings
        name of VTK surface mesh file or list of file names
    use_colormap : bool
        use Paraview-style XML colormap file?
    colormap_file : string
        use colormap in given file if use_colormap==True?  if empty and
        use_colormap==True, use file set by $COLORMAP environment variable

    Examples
    --------
    >>> import os
    >>> from mindboggle.mio.plots import plot_surfaces
    >>> from mindboggle.mio.fetch_data import prep_tests
    >>> urls, fetch_data = prep_tests()
    >>> label_file = fetch_data(urls['freesurfer_labels'])
    >>> use_colormap = True
    >>> colormap_file = '/software/vtk_cpp_tools/colormap.xml' # doctest: +SKIP
    >>> plot_surfaces(vtk_files, use_colormap, colormap_file) # doctest: +SKIP

    """
    import os
    import sys

    import mindboggle.thirdparty.vtkviewer as vtkviewer

    if isinstance(vtk_files, str):
        vtk_files = [vtk_files]

    vv = vtkviewer.VTKViewer()

    colormap = None
    if use_colormap:
        if colormap_file and os.path.isfile(colormap_file):
            colormap = vv.LoadColorMap(colormap_file)
        elif "COLORMAP" in os.environ:
            colormap = vv.LoadColorMap(os.environ["COLORMAP"])

    for vtk_file in vtk_files:
        if os.path.isfile(vtk_file):
            vv.AddFile(vtk_file, colormap)
        else:
            sys.exit("Huh?: {0}".format(vtk_file))

    vv.Start()
Exemple #3
0
def plot_surfaces(vtk_files, use_colormap=False, colormap_file=''):
    """
    Use vtkviewer to visualize one or more VTK surface files.

    Optionally provide colormap file or set $COLORMAP environment variable.

    Parameters
    ----------
    vtk_files : string or list of strings
        name of VTK surface mesh file or list of file names
    use_colormap : bool
        use Paraview-style XML colormap file?
    colormap_file : string
        use colormap in given file if use_colormap==True?  if empty and
        use_colormap==True, use file set by $COLORMAP environment variable

    Examples
    --------
    >>> from mindboggle.mio.plots import plot_surfaces
    >>> from mindboggle.mio.fetch_data import prep_tests
    >>> urls, fetch_data = prep_tests()
    >>> labels_file = fetch_data(urls['left_manual_labels'], '', '.vtk') #'left_freesurfer_labels'
    >>> use_colormap = True
    >>> colormap_file = '/software/vtk_cpp_tools/colormap.xml' # doctest: +SKIP
    >>> plot_surfaces(labels_file, use_colormap, colormap_file) # doctest: +SKIP

    Plot manual labels on folds of the left hemisphere:

    >>> from mindboggle.mio.vtks import read_scalars
    >>> from mindboggle.mio.fetch_data import prep_tests
    >>> from mindboggle.mio.vtks import rewrite_scalars
    >>> from mindboggle.mio.plots import plot_surfaces
    >>> urls, fetch_data = prep_tests()
    >>> labels_file = fetch_data(urls['left_manual_labels'], '', '.vtk') #'left_freesurfer_labels'
    >>> folds_file = fetch_data(urls['left_folds'], '', '.vtk')
    >>> labels, name = read_scalars(labels_file, True, True)
    >>> folds, name = read_scalars(folds_file, True, True)
    >>> background_value = -1
    >>> # Limit number of folds to speed up the test:
    >>> limit_folds = False
    >>> if limit_folds:
    ...     fold_numbers = [4] #[4, 6]
    ...     indices = [i for i,x in enumerate(folds) if x in fold_numbers]
    ...     i0 = [i for i,x in enumerate(folds) if x not in fold_numbers]
    ...     folds[i0] = background_value
    ... else:
    ...     indices = [i for i,x in enumerate(folds) if x != background_value]
    >>> folds[indices] = labels[indices]
    >>> rewrite_scalars(labels_file, 'labeled_folds.vtk',
    ...                 folds, 'skeleton', folds, background_value) # doctest: +SKIP
    >>> plot_surfaces('labeled_folds.vtk') # doctest: +SKIP

    """
    import os
    import sys

    import mindboggle.thirdparty.vtkviewer as vtkviewer

    if isinstance(vtk_files, str):
        vtk_files = [vtk_files]

    vv = vtkviewer.VTKViewer()

    colormap = None
    if use_colormap:
        if colormap_file and os.path.isfile(colormap_file):
            colormap = vv.LoadColorMap(colormap_file)
        elif "COLORMAP" in os.environ:
            colormap = vv.LoadColorMap(os.environ["COLORMAP"])

    for vtk_file in vtk_files:
        if os.path.isfile(vtk_file):
            vv.AddFile(vtk_file, colormap)
        else:
            sys.exit("Huh?: {0}".format(vtk_file))

    vv.Start()