Color maps for volume or surface data

create_colormap(
  gtype = c("surface", "volume"),
  dtype = c("continuous", "discrete"),
  key,
  color,
  value,
  alpha = FALSE,
  con = NULL,
  ...
)

save_colormap(cmap, con)

freeserfer_colormap(con)

load_colormap(con)

Arguments

gtype

geometry type, choices are "surface", "volume"

dtype

data type, "continuous" or "discrete"

key

non-negative integer vector corresponding to color values; its length must exceed 1; see 'Details'

color

characters, corresponding to color strings for each key

value

actual value for each key

alpha

whether to respect transparency

con

a file path to write results to or to read from. The file path can be passed as voxel_colormap into threejs_brain.

...

used by continuous color maps, passed to colorRampPalette

cmap

color map object

Value

A list of color map information

Details

Internal 'JavaScript' shader implementation uses integer color keys to connect color palettes and corresponding values. The keys must be non-negative.

Zero key is a special color key reserved by system. Please avoid using it for valid values.

Examples


# Creates a symmetric continuous colormap with 3 keys
# The color range is -10 to 10
# The colors are 'blue','white','red' for these keys

pal <- create_colormap(
  gtype = "volume", dtype = "continuous",
  key = c(1,2,3), value = c(-10,0,10),
  color = c('blue','white','red'))

print( pal )
#> <threeBrain Colormap>
#>   Version: 1.0
#>   Geometry Type: volume
#>   Data Type: continuous
#>   Transparent: FALSE
#>   # of keys: 3
#>   Min key: 1
#>   Max key: 3
#>   Value Range: -10 ~ 10

# ---------------- Get colormap key from a value ------------

# returns key index starting from
pal$get_key( -10 )
#> [1] 1

# nearest value
pal$get_key( 2 )
#> [1] 2

# set threshold, key is now 0 (no color)
pal$get_key( 2, max_delta = 1 )
#> [1] 0


# ---------------- Save and load ----------------
f <- tempfile( fileext = '.json' )
save_colormap( pal, f )
cat(readLines(f), sep = '\n')
#> {"__global_data__.VolumeColorLUT":{"map":{"1":{"ColorID":1,"Label":-10,"R":0,"G":0,"B":255},"2":{"ColorID":2,"Label":0,"R":255,"G":255,"B":255},"3":{"ColorID":3,"Label":10,"R":255,"G":0,"B":0}},"mapAlpha":false,"mapMinColorID":1,"mapMaxColorID":3,"mapValueRange":[-10,10],"mapDataType":"continuous","mapGeomType":"volume","mapVersion":1}}

load_colormap(f)
#> <threeBrain Colormap>
#>   Version: 1.0
#>   Geometry Type: volume
#>   Data Type: continuous
#>   Transparent: FALSE
#>   # of keys: 3
#>   Min key: 1
#>   Max key: 3
#>   Value Range: -10 ~ 10