Skip to content

Commit

Permalink
Allow masks to be added to T1; Added D99v2 for monkey brain; Adde…
Browse files Browse the repository at this point in the history
…d demo code; Export `GLTF` for `datacube2`
  • Loading branch information
dipterix committed Jun 20, 2024
1 parent 9268886 commit a14cd3f
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 9 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Changes since last CRAN release
* `f2170170 (HEAD -> master)` [_`dipterix`_]: Fixed `fix_electrode_color` bug
* `62567274 (origin/master, origin/HEAD)` [_`dipterix`_]: Supported `ISO` surface generation from voxels
* `a4f02e0e (HEAD -> master)` [_`dipterix`_]: Allow masks to be added to `T1`; Added `D99v2` for monkey brain; Added demo code; Export `GLTF` for `datacube2`
* `9268886f (origin/master, origin/HEAD)` [_`dipterix`_]: Fixed `fix_electrode_color` bug
* `62567274` [_`dipterix`_]: Supported `ISO` surface generation from voxels
* `a6295c2c` [_`dipterix`_]: Added white-matter segmentation as default atlas if user has this file
* `cd8e15e8` [_`dipterix`_]: Exporting `GLTF` is wrapped with try-catch
* `963859ed` [_`dipterix`_]: `fix_electrode_color` is exclusive by default; fixed color fixing issue for naive sphere electrodes
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: threeBrain
Type: Package
Title: Your Advanced 3D Brain Visualization
Version: 1.1.0.9020
Version: 1.1.0.9021
Authors@R: c(
person("Zhengjia", "Wang", email = "dipterix.wang@gmail.com", role = c("aut", "cre", "cph")),
person("John", "Magnotti", email = "John.Magnotti@Pennmedicine.upenn.edu", role = c("aut", "res")),
Expand Down
21 changes: 17 additions & 4 deletions R/geom_datacube.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,38 @@ VolumeGeom <- R6::R6Class(
color_format = "RedFormat",
color_map = NULL,
initialize = function(
name, path, group = GeomGroup$new(name = 'default'), layer = 13,
color_format = c("RedFormat", "RGBAFormat"), ...){
name, path, mask = NULL,
group = GeomGroup$new(name = 'default'), layer = 13,
color_format = c("RedFormat", "RGBAFormat"), ...){

color_format <- match.arg(color_format)
abspath <- normalizePath(path, mustWork = TRUE)
super$initialize(name, position = c(0, 0, 0), layer = layer, ...)
self$group <- group

re <- list(
volume_data <- list(
path = path,
absolute_path = abspath,
file_name = filename(abspath),
is_nifti = TRUE,
is_new_cache = FALSE,
is_cache = TRUE
)
group$set_group_data("volume_data", value = re, is_cached = TRUE)
group$set_group_data("volume_data", value = volume_data, is_cached = TRUE)
self$color_format <- color_format

if(length(mask) == 1 && !is.na(mask) && file.exists(mask)) {
volume_mask <- list(
path = mask,
absolute_path = normalizePath(mask, mustWork = TRUE),
file_name = filename(mask),
is_nifti = TRUE,
is_new_cache = FALSE,
is_cache = TRUE
)
group$set_group_data("volume_mask", value = volume_mask, is_cached = TRUE)
}

},

to_list = function(){
Expand Down
13 changes: 13 additions & 0 deletions R/threeBrain.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ threeBrain <- function(
"brain.finalsurfs", "synthSR.norm", "synthSR", "brain",
"brainmask", "brainmask.auto", "T1"
)
allowed_mri_mask_prefix <- c(
"brainmask", "brainmask.auto"
)

path_mri <- file.path(fs_path, "mri", as.vector(rbind(
sprintf("%s.nii.gz", allowed_mri_prefix),
Expand All @@ -192,6 +195,7 @@ threeBrain <- function(
)))
path_mri <- path_mri[file.exists(path_mri)]
if(length(path_mri)){ path_mri <- path_mri[[1]] }

path_fsmri <- file.path(fs_path, "mri", as.vector(rbind(
sprintf("%s.nii.gz", allowed_fsmri_prefix),
sprintf("%s.nii", allowed_fsmri_prefix),
Expand All @@ -200,6 +204,14 @@ threeBrain <- function(
path_fsmri <- path_fsmri[file.exists(path_fsmri)]
if(length(path_fsmri)){ path_fsmri <- path_fsmri[[1]] }

path_mask <- file.path(fs_path, "mri", as.vector(rbind(
sprintf("%s.nii.gz", allowed_mri_mask_prefix),
sprintf("%s.nii", allowed_mri_mask_prefix),
sprintf("%s.mgz", allowed_mri_mask_prefix)
)))
path_mask <- path_mask[file.exists(path_mask)]
if(length(path_mask)){ path_mask <- path_mask[[1]] }

# xfm
path_xfm <- file.path(fs_path, "mri", "transforms", "talairach.xfm")

Expand Down Expand Up @@ -309,6 +321,7 @@ threeBrain <- function(
volume = VolumeGeom$new(
name = sprintf('T1 (%s)', subject_code),
path = normalizePath(path_mri, winslash = "/"),
mask = normalizePath(path_mask, winslash = "/"),

# JS engine requires a group
group = group
Expand Down
31 changes: 31 additions & 0 deletions adhoc/demo_stage.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# script to generate demo stages

# run in console:
'
JSON.stringify(app.controllerGUI.controllersRecursive().map(c => {
return({name: c._name, value: c.getValue()})
}))
'


json <- '[{"name":"Background Color","value":"#faf7f4"},{"name":"Camera Position","value":"[free rotate]"},{"name":"Display Coordinates","value":false},{"name":"Record","value":false},{"name":"Screenshot"},{"name":"Download GLTF"},{"name":"Reset Canvas"},{"name":"Copy Controller State"},{"name":"Paste to Set State","value":""},{"name":"QR Code"},{"name":"Show Panels","value":false},{"name":"Slice Brightness","value":0},{"name":"Slice Contrast","value":0},{"name":"Slice Mode","value":"canonical"},{"name":"Crosshair Gap","value":0},{"name":"Reset Slice Canvas"},{"name":"Coronal (P - A)","value":0},{"name":"Axial (I - S)","value":0},{"name":"Sagittal (L - R)","value":0},{"name":"Intersect MNI305","value":"-1.4, -18.5, 17.7"},{"name":"Overlay Coronal","value":true},{"name":"Overlay Axial","value":true},{"name":"Overlay Sagittal","value":true},{"name":"Frustum Near","value":5},{"name":"Frustum Far","value":10},{"name":"Voxel Type","value":"none"},{"name":"Voxel Display","value":"anat. slices"},{"name":"Voxel Opacity","value":1},{"name":"Voxel Min","value":-100000},{"name":"Voxel Max","value":100000},{"name":"Voxel Label","value":"1035,3035,1034,3034,1001,1030,3030,2015,2009"},{"name":"ISO Surface","value":false},{"name":"Update ISO Surface"},{"name":"Surface Material","value":"MeshPhysicalMaterial"},{"name":"Surface Type","value":"pial"},{"name":"Clipping Plane","value":"disabled"},{"name":"Left Hemisphere","value":"mesh clipping x 0.3"},{"name":"Right Hemisphere","value":"mesh clipping x 0.3"},{"name":"Left Opacity","value":0.39999999999999997},{"name":"Right Opacity","value":0.39999999999999997},{"name":"Left Mesh Clipping","value":0.20000000000000004},{"name":"Right Mesh Clipping","value":0.20000000000000004},{"name":"Surface Color","value":"none"},{"name":"Blend Factor","value":1},{"name":"Sigma","value":1},{"name":"Decay","value":0.6},{"name":"Range Limit","value":5},{"name":"Subject","value":"cvs_avg35_inMNI152"},{"name":"Map Electrodes","value":true},{"name":"Surface Mapping","value":"sphere.reg"},{"name":"Volume Mapping","value":"mni305"},{"name":"Visibility","value":"all visible"},{"name":"Electrode Shape","value":"prototype+sphere"},{"name":"Outlines","value":"auto"},{"name":"Translucent","value":"contact+outline"},{"name":"Text Scale","value":1.5},{"name":"Text Visibility","value":false},{"name":"Dragdrop Uploader"},{"name":"Clear Uploaded Surfaces"},{"name":"Visibility (all surfaces)","value":"visible"},{"name":"Opacity (all surfaces)","value":1},{"name":"Clear Uploaded Volumes"},{"name":"Visibility (all volumes)","value":"visible"},{"name":"Opacity (all volumes)","value":1},{"name":"Display Data","value":"LabelPrefix"},{"name":"Display Range","value":""},{"name":"Threshold Data","value":"[None]"},{"name":"Threshold Range","value":""},{"name":"Threshold Method","value":"|v| >= T1"},{"name":"Additional Data","value":"[None]"},{"name":"Inactive Color","value":"#c2c2c2"},{"name":"Play/Pause","value":false},{"name":"Speed","value":0.5},{"name":"Time","value":0},{"name":"Video Mode","value":"muted"},{"name":"Show Legend","value":false},{"name":"Show Time","value":false},{"name":"Highlight Box","value":false},{"name":"Info Text","value":false}]'

ignore_names <- c("Time", "Play/Pause", "Speed", "Subject", "Surface Mapping",
"Volume Mapping", "Surface Material", "Intersect MNI305",
"Camera Position", "Record", "Paste to Set State", "Background Color",
"Map Electrodes", "Video Mode")
on_completion_names <- c(
# "Overlay Coronal", "Overlay Axial", "Overlay Sagittal"
)
data <- jsonlite::fromJSON(txt = json, flatten = FALSE, simplifyDataFrame = FALSE)
data <- data[ vapply(data, function(item) { length(item$value) && !is.na(item$value) && !item$name %in% ignore_names }, FALSE) ]
is_transition <- sapply(data, function(item) { is.numeric(item$value) || startsWith(as.character(item$value), "#")})
is_post_completion <- sapply(data, function(item) { item$name %in% on_completion_names })

s <- jsonlite::toJSON(list(
immediate = data[!is_transition & !is_post_completion],
transition = data[is_transition & !is_post_completion],
onCompletion = data[is_post_completion]
), auto_unbox = TRUE, pretty = FALSE)

clipr::write_clip(s)
1 change: 1 addition & 0 deletions inst/palettes/datacube2/D99V2.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/threeBrainJS/dist/threebrain-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/threeBrainJS/dist/threebrain-main.js.map

Large diffs are not rendered by default.

0 comments on commit a14cd3f

Please sign in to comment.