Learn R Programming

brainR (version 1.6.0)

write4D.file: Write a 4D scene

Description

This function takes in a scene and writes it out to a series of files either with the stl format or obj format

Usage

write4D.file(
  scene = NULL,
  outfile = "index_4D.html",
  fnames,
  visible = TRUE,
  opacity = 1,
  colors = NULL,
  captions = "",
  standalone = FALSE,
  rescale = FALSE,
  index.file = system.file("index_template.html", package = "brainR"),
  toggle = "checkbox",
  xtkgui = FALSE
)

Arguments

scene

- list of 3D triangles (see contour3d). If a multicolored object is to be rendered (multiple contours with one control) - it must be in a list

outfile

- html filename that is to be exported

fnames

- filenames for the 3D surfaces in the scene - needs to be the same length as scene

visible

- logical vector indicating which structures are visible in html file

opacity

- list of alpha values - same length as scene; if sub-structures are present, then the each list element has length the number of structures

colors

- character vector of colors (col2rgb is applied)

captions

- labels for checkboxes on html webpage

standalone

- logical - should this be able to be rendered offline?

rescale

- rescale the scene? - in beta

index.file

- template html file used

toggle

- (experimental) "checkbox" (default) or "radio" for radio or checkboxes to switch thing

xtkgui

- (experimental) Logical to use xtkgui for objects

See Also

writeOBJ, writeSTL, contour3d

Examples

Run this code
# NOT RUN {
template <- readNIfTI(system.file("MNI152_T1_8mm_brain.nii.gz", package="brainR")
, reorient=FALSE)
dtemp <- dim(template)
### 4500 - value that empirically value that presented a brain with gyri
### lower values result in a smoother surface
brain <- contour3d(template, x=1:dtemp[1], y=1:dtemp[2],
z=1:dtemp[3], level = 4500, alpha = 0.8, draw = FALSE)

### Example data courtesy of Daniel Reich
### Each visit is a binary mask of lesions in the brain
imgs <- paste("Visit_", 1:5, "_8mm.nii.gz", sep="")
files <- sapply(imgs, system.file, package='brainR')
scene <- list(brain)
## loop through images and thresh
nimgs <- length(imgs)
cols <- rainbow(nimgs)
for (iimg in 1:nimgs) {
mask <- readNIfTI(files[iimg], reorient=FALSE)
if (length(dim(mask)) > 3) mask <- mask[,,,1]
### use 0.99 for level of mask - binary
  activation <- contour3d(mask, level = c(0.99), alpha = 1,
  add = TRUE, color=cols[iimg], draw=FALSE)
## add these triangles to the list
scene <- c(scene, list(activation))
}
## make output image names from image names
fnames <- c("brain.stl", gsub(".nii.gz", ".stl", imgs, fixed=TRUE))
fnames = file.path(tempdir(), fnames)
outfile <-  file.path(tempdir(), "index.html")
write4D.file(
scene=scene, fnames=fnames, 
visible = FALSE,
outfile=outfile, standalone=TRUE, rescale=TRUE)



unlink(outfile)
unlink(fnames)
# }

Run the code above in your browser using DataLab