View source: R/volvis_shells.R
| volvis.shells | R Documentation |
Visualize the iso-surfaces (shells) of a volume at several levels as nested, semi-transparent meshes, like the nested contour lines of a topographic map. This is useful to show the shape and the internal structure of a volume at the same time, e.g., for a statistical map: the outer shells (low levels) are rendered more transparently than the inner ones (high levels), so that the inner structure remains visible. The volume is extracted in voxel space and transformed to surface RAS with the index2ras_tkr matrix, so the result is spatially aligned with surface renderings of the same subject (see vis.subject.morph.native). To combine the shells with a surface rendering, use the rglactions parameter of the surface function (key 'no_vis') to keep the rendering window open, or call this function with views = NULL and render the returned meshes yourself.
volvis.shells(
volume,
levels = NULL,
num_levels = 4L,
level_type = "quantile",
level_range = c(0.2, 0.95),
frame = 1L,
colors = NULL,
alphas = NULL,
palette = "grey_context",
alpha_range = NULL,
smoothing = 1L,
downsample = 1L,
cut_away = NULL,
cut_fraction = 0.5,
backend = "auto",
views = c("sd_lateral_lh", "sd_medial_lh", "sd_lateral_rh", "sd_medial_rh"),
rgloptions = rglo(),
rglactions = list(),
silent = FALSE
)
volume |
a 3D numerical array (or an |
levels |
numerical vector or |
num_levels |
positive integer, the number of shells to create. Ignored if |
level_type |
character string, how to compute the levels if |
level_range |
numerical vector of length 2, the range from which the automatic levels are taken. For |
frame |
positive integer, the frame (4th dimension) to use for a 4D volume. Defaults to 1. |
colors |
character vector of colors, one per shell (outermost shell first). Defaults to |
alphas |
numerical vector of alpha values, one per shell (outermost shell first), values between 0 and 1. Defaults to |
palette |
character string, the color and transparency recipe used for the shells if |
alpha_range |
numerical vector of length 2 or |
smoothing |
non-negative integer, the number of 3x3x3 box blur passes applied to the volume before the shells are extracted. This removes the staircase artifacts of the marching cubes algorithm and leads to much nicer surfaces. Defaults to 1. Set to 0 to disable and extract the shells from the raw volume. |
downsample |
positive integer, a factor by which the volume is subsampled before the shells are extracted. Values larger than 1 reduce the number of triangles (and thus the rendering time) considerably, at the cost of a less detailed surface. The coordinates of the subsampled shells are corrected, so the result is still aligned with the original volume. Defaults to 1. Note that the volume is smoothed before subsampling if |
cut_away |
character string or |
cut_fraction |
numerical value between 0 and 1, the position of the cut along the axis given by |
backend |
character string, the backend used to extract the iso-surfaces. One of 'auto' (the default: use the |
views |
list of character strings, the views to visualize. Available views are |
rgloptions |
option list passed to |
rglactions |
named list, passed to the visualization functions, see |
silent |
logical, whether to suppress the console messages which report the levels and the backend used. Defaults to |
the list of fs.coloredmesh instances, one per shell (from the outermost to the innermost), invisibly. Note that the colorbar of the rendering functions is not used here, the color of a shell encodes its level, which is reported in the console unless silent is TRUE.
Both renderers are used with the mesh's own style (see get.rglstyle), which sets the alpha value of the shell. Note that backfaces are rendered for the shells (back = 'filled'): if they were culled, the rgl renderer would composite the nested transparent shells in the wrong order (the innermost shell would end up on top of the outer ones).
volvis.contour for a single iso-surface, volvis.voxels for a voxel-based rendering of a volume, and vis.volume.on.surface to combine a volume with a surface rendering.
## Not run:
fsbrain::download_optional_data();
subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
brain = subject.volume(subjects_dir, 'subject1', 'brain');
# Show the 5 inner shells of the brain, cut open from the right:
shells = volvis.shells(brain, num_levels = 5, downsample = 2, cut_away = 'right', views = NULL);
# Combine the 4 standard views into a single image:
view_angles = c('sd_lateral_lh', 'sd_medial_lh', 'sd_lateral_rh', 'sd_medial_rh');
fsbrain::export(shells, view_angles = view_angles, output_img = 'shells.png');
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.