Skip to content

Commit

Permalink
Added brain$electrodes$fix_electrode_color to fix contacts to a color…
Browse files Browse the repository at this point in the history
… for given clip names; added electrode visibility mode: use threshold only to show contacts that pass threhsold but have no values
  • Loading branch information
dipterix committed Jan 20, 2024
1 parent 467eac5 commit 9a5d74a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 8 deletions.
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: 3D Brain Visualization
Version: 1.0.1.9103
Version: 1.0.1.9104
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
15 changes: 15 additions & 0 deletions R/class_brainelectrodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,21 @@ BrainElectrodes <- R6::R6Class(
}
},

fix_electrode_color = function(number, color, names = NULL, inclusive = TRUE) {
names <- as.character(names)
inclusive <- as.logical(inclusive)[[1]]
el <- self$objects[[ number ]]
if(!is.null(el)) {
el$fixed_color <- list(
color[[1]],
names,
inclusive
)
return(TRUE)
}
return(FALSE)
},

# function to set values to electrodes
set_values = function(table_or_path){
if( missing(table_or_path) ){
Expand Down
27 changes: 26 additions & 1 deletion R/geom_electrode.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,36 @@ ElectrodeGeom <- R6::R6Class(
sphere_position = c(0,0,0),
number = NULL,

# case 1: hex color, then will show in all values
# case 2: list(color, names, [true/false]): colors that will only be activated
# when names in(true) or not in(false) given names
fixed_color = NULL,

# ------------ for sub cortical electrodes only ------------

# Not yet implemented

# ------------ G ------------
to_list = function(){
fixed_color <- self$fixed_color
if( !length( fixed_color ) ) {
fixed_color <- NULL
} else if(is.list(fixed_color) && length(fixed_color) > 1) {
if(length(fixed_color) < 3) {
fixed_color[[3]] <- TRUE
}
fixed_color <- list(
color = dipsaus::col2hexStr(fixed_color[[1]]),
names = as.character(fixed_color[[2]]),
inclusive = isTRUE(as.logical(fixed_color[[3]]))
)
} else {
fixed_color <- list(
color = dipsaus::col2hexStr(fixed_color[[1]]),
names = character(0L),
inclusive = FALSE
)
}
re <- c(
super$to_list(),
list(
Expand All @@ -41,7 +65,8 @@ ElectrodeGeom <- R6::R6Class(
sphere_position = self$sphere_position,
sub_cortical = !self$is_surface_electrode,
search_geoms = self$hemisphere,
number = c(self$number, NA)[[1]]
number = c(self$number, NA)[[1]],
fixed_color = fixed_color
)
)
return( re )
Expand Down
26 changes: 22 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
#/bin/bash

########## Use the following command to register shortcut ######################
# dipsaus::rs_add_shortcut(5, {
# dipsaus::rs_focus_console()
# cwd <- getwd()
# on.exit({
# setwd(cwd)
# })
# proj_dir <- .rs.getProjectDirectory()
# build_sh <- file.path(proj_dir, "build.sh")
# if(file.exists(build_sh)) {
# system2("bash", shQuote(build_sh), env = c("USE_DIPSAUS=1"))
# }
# devtools::load_all(proj_dir)
# setwd(cwd)
# }, force = TRUE)
################################################################################

cd inst/three-brain-js

npm run build
Expand All @@ -9,7 +26,8 @@ cd ../../
cp -r inst/three-brain-js/dist inst/threeBrainJS

# git submodule update --recursive --remote

Rscript -e "devtools::document(roclets = c('rd', 'collate', 'namespace', 'vignette'))"
source_file=$(Rscript -e "cat(devtools::build(vignettes = FALSE, manual = FALSE, path = './adhoc/', quiet = TRUE))")
R CMD INSTALL --preclean --no-multiarch --with-keep.source "$source_file"
if [[ "$USE_DIPSAUS" != "1" ]]; then
Rscript -e "devtools::document(roclets = c('rd', 'collate', 'namespace', 'vignette'))"
source_file=$(Rscript -e "cat(devtools::build(vignettes = FALSE, manual = FALSE, path = './adhoc/', quiet = TRUE))")
R CMD INSTALL --preclean --no-multiarch --with-keep.source "$source_file"
fi
2 changes: 1 addition & 1 deletion inst/threeBrainJS/dist/threebrain.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

0 comments on commit 9a5d74a

Please sign in to comment.