Skip to contents

Create a Threejs Brain and View it in Browsers

Usage

threejs_brain(
  ...,
  .list = list(),
  width = NULL,
  height = NULL,
  background = "#FFFFFF",
  cex = 1,
  timestamp = TRUE,
  title = "",
  side_canvas = FALSE,
  side_zoom = 1,
  side_width = 250,
  side_shift = c(0, 0),
  side_display = TRUE,
  control_panel = TRUE,
  control_presets = NULL,
  control_display = TRUE,
  camera_center = c(0, 0, 0),
  camera_pos = c(500, 0, 0),
  start_zoom = 1,
  symmetric = 0,
  default_colormap = "Value",
  palettes = NULL,
  value_ranges = NULL,
  value_alias = NULL,
  show_inactive_electrodes = TRUE,
  surface_colormap = system.file("palettes", "surface", "ContinuousSample.json", package
    = "threeBrain"),
  voxel_colormap = system.file("palettes", "datacube2", "FreeSurferColorLUT.json",
    package = "threeBrain"),
  videos = list(),
  widget_id = "threebrain_data",
  tmp_dirname = NULL,
  debug = FALSE,
  enable_cache = FALSE,
  token = NULL,
  controllers = list(),
  browser_external = TRUE,
  global_data = list(),
  global_files = list(),
  qrcode = NULL,
  custom_javascript = NULL,
  show_modal = "auto",
  embed = FALSE
)

Arguments

..., .list

geometries inherit from AbstractGeom

width, height

positive integers. Width and height of the widget. By default width=`100%`, and height varies.

background

character, background color such as "#FFFFFF" or "white"

cex

positive number, relative text magnification level

timestamp

logical, whether to show time-stamp at the beginning

title

viewer title

side_canvas

logical, enable side cameras to view objects from fixed perspective

side_zoom

numerical, if side camera is enabled, zoom-in level, from 1 to 5

side_width

positive integer, side panel size in pixels

side_shift

integer of length two, side panel shift in pixels (`CSS style`: top, left)

side_display

logical, show/hide side panels at beginning

control_panel

logical, enable control panels for the widget

control_presets

characters, presets to be shown in control panels

control_display

logical, whether to expand/collapse control UI at the beginning

camera_center

numerical, length of three, XYZ position where camera should focus at

camera_pos

XYZ position of camera itself, default (0, 0, 500)

start_zoom

numerical, positive number indicating camera zoom level

symmetric

numerical, default 0, color center will be mapped to this value

default_colormap

character, which color map name to display at startup

palettes

named list, names corresponds to color-map names if you want to change color palettes

value_ranges

named list, similar to palettes, value range for each values

value_alias

named list, legend title for corresponding variable

show_inactive_electrodes

logical, whether to show electrodes with no values

surface_colormap

a color map or its path generated by create_colormap(gtype="surface") to render surfaces vertices; see create_colormap for details.

voxel_colormap

a color map or its path generated by create_colormap(gtype="volume") to render volume such as atlases; see create_colormap for details.

videos

named list, names corresponds to color-map names, and items are generated from video_content

widget_id

character, internally used as unique identifiers for widgets; only use it when you have multiple widgets in one website

tmp_dirname

character path, internally used, where to store temporary files

debug

logical, internally used for debugging

enable_cache

whether to enable cache, useful when rendering the viewers repeatedly in shiny applications

token

unique character, internally used to identify widgets in 'JavaScript' 'localStorage'

controllers

list to override the settings, for example proxy$get_controllers()

browser_external

logical, use system default browser (default) or built-in one.

global_data, global_files

internally use, mainly to store orientation matrices and files.

qrcode

'URL' to show in the 'QR' code; can be a character string or a named list of 'url' and 'text' (hyper-reference text)

custom_javascript

customized temporary 'JavaScript' code that runs after ready state; available 'JavaScript' variables are:

'groups'

input information about each group

'geoms'

input information about each geometry

'settings'

input information about canvas settings

'scene'

'threejs' scene object

'canvas'

canvas object

'gui'

controls data panel

'presets'

preset 'gui' methods

show_modal

logical or "auto", whether to show a modal instead of direct rendering the viewers; designed for users who do not have 'WebGL' support; only used in shiny applications

embed

whether to try embedding the viewer in current run-time; default is false (will launch default web browser); set to true if running in 'rmarkdown' or 'quarto', or to see the viewer in 'RStudio' default panel.

Author

Zhengjia Wang

Examples

if( interactive() ) {
library(threeBrain)

# Please use `download_N27` to download N27 Collins template brain
n27_path <- file.path(default_template_directory(), "N27")
if( dir.exists(n27_path) ) {

  brain <- threeBrain(path = n27_path, subject_code = "N27",
                             surface_types = c('pial', 'smoothwm'))
  print(brain)

  brain$plot(
    background = "#000000",
    controllers = list(
      'Voxel Type' = 'aparc_aseg',
      'Surface Type' = 'smoothwm',
      'Blend Factor' = 1,
      'Right Opacity' = 0.3,
      'Overlay Sagittal' = TRUE
    ),
    show_modal = TRUE
  )

}
}