| vis.tracts | R Documentation |
Draws white matter streamlines (tractography data) as lines, with
an optional semi-transparent brain surface as context. The streamlines can come
from a tract file (TRK or TCK format), from a directory of such files (a tract
atlas with one file per bundle, e.g. the XTRACT atlas, see
download_xtract_tracts), or from in-memory data. This is
the fsbrain equivalent of the plot_tracts function of the Python package
yabplot.
vis.tracts(
tracts,
bundle_values = NULL,
subjects_dir = NULL,
template_id = "fs_LR_32",
context = list(surface = "midthickness", alpha = 0.08, color = "#B0B0B0"),
coords = "ras",
transform_matrix = NULL,
max_tracks = Inf,
skip_tracks = 0L,
bbox = NULL,
tract_color = NULL,
tract_makecmap_options = mkco.seq(),
tract_width = 1,
tract_width_range = NULL,
tract_width_scale = c("none", "value"),
color_by_orientation = FALSE,
views = c("sd_lateral_lh", "sd_medial_lh", "sd_lateral_rh", "sd_medial_rh"),
rgloptions = rglo(),
rglactions = list(),
style = "default",
draw_colorbar = FALSE,
silent = FALSE
)
tracts |
the tracts to draw. One of: a character string, the path to a
tract file (TRK or TCK format) or to a directory containing one file per
bundle (a tract atlas); a vector of tract file paths; an |
bundle_values |
numeric vector or NULL, one value per bundle, in the order of the bundles (or named with the bundle names). The values are mapped to colors, see the details. |
subjects_dir |
character string or NULL, the subjects directory that
contains the template. If NULL, the standard fsbrain locations are searched,
see |
template_id |
character string, the template or subject to draw the context
surface for. Defaults to 'fs_LR_32', the HCP-style surface space that is
widely used for tractography data. Note that the template meshes are not part
of this package, see |
context |
named list or NULL, the semi-transparent brain surface drawn around the tracts. Entries are 'surface' (the surface name, default 'midthickness'), 'alpha' (the transparency, default 0.08) and 'color' (default '#B0B0B0'). Set to NULL to draw the tracts without any context surface. |
coords |
character string or NULL, the coordinate system of TRK files, see
|
transform_matrix |
a 4x4 numeric matrix or NULL, a transformation that is applied to all tract coordinates after reading them. Note that tract data and template surfaces have to be in the same space for the overlay to be correct: the XTRACT atlas, for example, is defined in MNI152 space, while the fs_LR_32 and fsaverage templates use an fsaverage-like (MNI305) space, which is close but not identical, and both are close enough for the overlay to look right without a transformation. Use this parameter if you have an accurate transformation, e.g. from a registration of the template to MNI152 space. |
max_tracks |
numeric, the maximum number of streamlines to read per file,
see |
skip_tracks |
integer, the number of streamlines to skip per file, see
|
bbox |
numeric vector of length 6 or NULL, a bounding box to select the
streamlines that pass through a region, see
|
tract_color |
vector of hex color strings, the color(s) of the tracts.
Either a single color which is used for all bundles, or one color per bundle.
Ignored if |
tract_makecmap_options |
named list of colormap options, see
|
tract_width |
a single positive number, the line width in pixels. |
tract_width_range |
numeric vector of length 2 or NULL, the range of the
line widths used when the widths are scaled by the bundle values, see
|
tract_width_scale |
character string, either 'none' (all lines have the
same width, the default) or 'value' (the line width encodes the bundle values,
which requires |
color_by_orientation |
logical, whether to color the segments by their direction instead of by bundle, see the details. The colors then do not encode the bundle values, so no colorbar is drawn. |
views |
vector of character strings, the views to render, see
|
rgloptions |
named list, options for |
rglactions |
named list, actions to perform, see
|
style |
character string, the rendering style for the tracts, see
|
draw_colorbar |
logical or one of the character strings 'vertical' or
'horizontal', whether to draw a colorbar for the bundle values. Note that the
headless scimesh renderer backend does not support colorbars in this function,
use |
silent |
logical, whether to suppress the progress messages. |
The streamlines are drawn with the line renderable of the connectome
code, see fs.coloredpaths, so the result is a regular
fsbrain renderable list which works with both renderer backends (rgl and the
headless scimesh renderer) and can be passed to export
to create publication quality figures with a colorbar.
The colors can be defined in three ways: (1) as one value per bundle via
bundle_values (e.g. a tractometry measure like the mean fractional
anisotropy of each bundle), which is mapped to colors with
tract_makecmap_options and produces a colorbar; (2) as a single color
for all bundles via tract_color; or (3) per segment, based on the
direction of the segment, via color_by_orientation, which is the
classic DTI look (red/green/blue for left-right/anterior-posterior/superior-inferior).
invisible named list of renderables: the entry tracts are the
lines (an fs.coloredpaths instance), and context_lh and
context_rh the context surfaces (if context is not NULL). The
list can be passed to export.
Other tracts functions:
download_xtract_tracts(),
read.tract.bundles()
## Not run:
# Download the XTRACT tract atlas (see the function documentation):
download_xtract_tracts("xtract_tiny");
atlas_dir = file.path(get_optional_data_filepath("tracts"), "xtract_tiny");
bundles = read.tract.bundles(atlas_dir);
# One color per bundle, colors follow a colormap, with a colorbar in the figure:
values = seq(0.2, 0.8, length.out = length(bundles));
names(values) = names(bundles);
tracts = vis.tracts(bundles, bundle_values = values,
views = c("sd_lateral_lh", "sd_lateral_rh"));
# Or a publication quality figure with 3 views and a colorbar:
export(tracts, view_angles = c("sd_lateral_lh", "sd_dorsal", "sd_rostral"),
draw_colorbar = "horizontal", colorbar_legend = "Mean FA",
output_img = "tracts.png");
# Draw a whole-brain tractogram from MRtrix (a subset, it is huge):
vis.tracts("~/data/sub-01_streamlines.tck.gz", max_tracks = 20000);
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.