Skip to content

Commit

Permalink
ported multiple dipsaus package (plan to remove this dep in the next …
Browse files Browse the repository at this point in the history
…3 versions); bump the version for CRAN
  • Loading branch information
dipterix committed May 30, 2022
1 parent 598b4d4 commit 602dbf2
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 40 deletions.
17 changes: 9 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: threeBrain
Type: Package
Title: 3D Brain Visualization
Version: 0.2.4.9003
Version: 0.2.5
Authors@R: c(
person("Zhengjia", "Wang", email = "[email protected]", role = c("aut", "cre", "cph")),
person("John", "Magnotti", email = "[email protected]", role = c("aut")),
Expand All @@ -15,19 +15,20 @@ Description: A fast, interactive cross-platform, and easy to share
'WebGL'-based 3D brain viewer that visualizes 'FreeSurfer' and/or
'AFNI/SUMA' surfaces. The viewer widget can be either standalone or
embedded into 'R-shiny' applications. The standalone version only require
a web browser with 'WebGL2' support (for example, 'Chrome'). It can be
inserted into any websites; see <https://dipterix.org/project/threebrain/>).
as an example. The 'R-shiny' support allows the 3D viewer to be dynamically
generated from reactive user inputs. This feature has been fully adopted by
'RAVE' <https://openwetware.org/wiki/RAVE>, an interactive toolbox to
analyze 'iEEG/eCoG' data. Documentation about 'threeBrain' is provided
a web browser with 'WebGL2' support (for example, 'Chrome', 'Firefox',
'Safari'). It can be inserted into any websites; see
<https://dipterix.org/project/threebrain/>) as an example. The 'R-shiny'
support allows the 3D viewer to be dynamically generated from reactive user
inputs. This feature has been fully adopted by 'RAVE'
<https://openwetware.org/wiki/RAVE>, an interactive toolbox to
analyze 'iEEG' data. Documentation about 'threeBrain' is provided
by <https://dipterix.org/threeBrain/> and several vignettes included
in this package. To cite the package, please check our 'NeuroImage' paper
by Magnotti, Wang, and Beauchamp (2020, <doi:10.1016/j.neuroimage.2020.117341>),
or see 'citation("threeBrain")' for details.
License: GPL-3 | file LICENSE
Encoding: UTF-8
RoxygenNote: 7.1.2
RoxygenNote: 7.2.0
Roxygen: list(r6 = FALSE)
Language: en-US
URL: https://dipterix.org/threeBrain/ https://github.com/dipterix/threeBrain
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ threeBrain 0.2.5
* Volume `fragmentShader` uses non-linear function to calculate fragment colors combined with face normal; this will create smoother results
* `DataCube2` geometry uses `ConvexHull` instead of box/sphere to improve the performance
* `DataCube2` are no longer hidden when `sync from voxels` is on: users can use shortcuts `l` and `k` to easily control the visibility.
* `download_template_subject` can download other templates such as `fsaverage`, `cvs_avg35`, `bert`.

## Bug fixes

Expand Down
40 changes: 40 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,43 @@ get_os <- function(){
}
return('unknown')
}

package_installed <- function(pkgs, all = FALSE){
re <- sapply(pkgs, function(p){
system.file('', package = p) != ''
})
if(all){
re <- all(re)
}
re
}

col2hexStr <- function(col, alpha = NULL, prefix = '#', ...){
if(is.null(alpha)){
alpha <- 1
transparent <- FALSE
}else{
transparent <- TRUE
}
re <- grDevices::adjustcolor(col, alpha.f = alpha)
if(!transparent){
re <- substr(re, start = 1L, stop = 7L)
}
gsub('^[^0-9A-F]*', replacement = prefix, x = re)
}

rs_avail <- function(){
tryCatch({
spath <- search()
if('tools:rstudio' %in% spath) {
rs_ver <- get("RStudio.Version", inherits = TRUE, envir = parent.env(globalenv()))
if(is.function(rs_ver)) {
rs_ver()
return(TRUE)
}
}
return(FALSE)
}, error = function(e){
return(FALSE)
})
}
2 changes: 1 addition & 1 deletion R/class_proxy.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ViewerProxy <- R6::R6Class(
},

set_background = function(col){
private$set_value('background', dipsaus::col2hexStr(col))
private$set_value('background', col2hexStr(col))
},

set_zoom_level = function( zoom ){
Expand Down
49 changes: 34 additions & 15 deletions R/loaders.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@
NULL

#' @rdname template_subject
#' @param subject_code character with only letters and numbers (Important). Default is `N27`
#' @param url zip file address
#' @param subject_code character with only letters and numbers (Important); default is `N27`
#' @param url zip file address; must be specified if \code{subject_code} is not from the followings: \code{'bert'}, \code{'cvs_avg35'}, \code{'cvs_avg35_inMNI152'}, \code{'fsaverage'}, \code{'fsaverage_sym'}, or \code{'N27'}
#' @param template_dir parent directory where subject's `FreeSurfer` folder should be stored
#' @export
download_template_subject <- function(
subject_code = 'N27',
url = 'https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/N27.zip',
subject_code = 'N27', url,
template_dir = default_template_directory()
){

force(subject_code)
if(missing(url) || is.null(url)) {
avails <- available_templates()
if(!subject_code %in% names(avails)) {
stop("`download_template_subject`: please specify the url for your template if subject code is not from the followings: ", paste(names(avails), collapse = ", "))
}
url <- avails[[subject_code]]
}

# = 'https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/N27.zip'


dir_create(template_dir)
dir <- normalizePath(template_dir)

Expand Down Expand Up @@ -131,15 +143,22 @@ threebrain_finalize_installation <- function(upgrade = c('ask', 'always', 'never
})

if(has_n27 && upgrade %in% c('never')){
dipsaus::cat2('N27 brain has been installed', level = 'DEFAULT')
cat2('N27 brain has been installed', level = 'DEFAULT')
return(invisible())
}

if(has_n27 && upgrade %in% c('ask')){
if(interactive()){
reinst <- tryCatch({
dipsaus::ask_yesno('N27 template brain detected at \n ', template_dir,
'\nDo you want to reinstall?', error_if_canceled = FALSE)
if(package_installed("dipsaus")) {
dipsaus::ask_yesno('N27 template brain detected at \n ', template_dir,
'\nDo you want to reinstall?', error_if_canceled = FALSE)
} else {
utils::askYesNo(msg = paste0(
'N27 template brain detected at `', template_dir,
'`. Do you want to reinstall? '
), default = FALSE)
}
}, error = function(e){
FALSE
})
Expand All @@ -148,31 +167,31 @@ threebrain_finalize_installation <- function(upgrade = c('ask', 'always', 'never
}

if(!isTRUE(reinst)){
dipsaus::cat2('N27 template brain... skip', level = 'DEFAULT')
cat2('N27 template brain... skip', level = 'DEFAULT')
return(invisible())
}
}

# install N27 brain

if( async ){
if( async && package_installed("dipsaus") ){
code <- sprintf(
"{
dipsaus::cat2('Installing N27 template brain...', level = 'INFO')
threeBrain:::cat2('Installing N27 template brain...', level = 'INFO')
threeBrain::download_N27(template_dir = '%s')
# load N27
dipsaus::cat2('Expand the template, creating cache...', level = 'INFO')
threeBrain:::cat2('Expand the template, creating cache...', level = 'INFO')
threeBrain::merge_brain(template_subject = 'N27')
}", template_dir)

dipsaus::rs_exec(parse(text = code)[[1]], name = 'Finalize threeBrain N27 installation', quoted = TRUE)
} else {
dipsaus::cat2('Installing N27 template brain...', level = 'INFO')
threeBrain::download_N27(template_dir = template_dir)
cat2('Installing N27 template brain...', level = 'INFO')
download_N27(template_dir = template_dir)
# load N27
dipsaus::cat2('Expand the template, creating cache...', level = 'INFO')
threeBrain::merge_brain(template_subject = 'N27', template_dir = template_dir)
cat2('Expand the template, creating cache...', level = 'INFO')
merge_brain(template_subject = 'N27', template_dir = template_dir)
}


Expand Down
2 changes: 1 addition & 1 deletion R/shiny-localization.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ localization_module <- function(
..., control_presets = NULL, side_display = FALSE, controllers = list()
){

if(!dipsaus::package_installed("DT")){
if(!package_installed("DT")){
stop("Package `DT` is needed to run this module. Please install it by running\n ",
"install.packages('DT')")
}
Expand Down
10 changes: 5 additions & 5 deletions R/threejs_brain.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ threejs_brain <- function(
}

# backgrounds
background <- dipsaus::col2hexStr(background)
# side_background = dipsaus::col2hexStr(side_background)
background <- col2hexStr(background)
# side_background = col2hexStr(side_background)



Expand Down Expand Up @@ -519,7 +519,7 @@ save_brain <- function(widget, directory, filename = 'index.html', assetpath = '
}

grey_col <- function(...){
if( dipsaus::rs_avail() ){
if( rs_avail() ){
cat("\033[38;5;246m", paste(..., sep = " ", collapse = "\n"),
"\033[39m", sep = "")
} else {
Expand All @@ -528,7 +528,7 @@ grey_col <- function(...){
}

green_col <- function(...){
if( dipsaus::rs_avail() ){
if( rs_avail() ){
cat("\033[38;5;35m", paste(..., sep = " ", collapse = "\n"),
"\033[39m", sep = "")
} else {
Expand All @@ -537,7 +537,7 @@ green_col <- function(...){
}

red_col <- function(...){
if( dipsaus::rs_avail() ){
if( rs_avail() ){
cat("\033[38;5;215m", paste(..., sep = " ", collapse = "\n"),
"\033[39m", sep = "")
} else {
Expand Down
10 changes: 5 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ cat2 <- function(
'WARNING' = '#ec942c',
'ERROR' = '#f02c2c',
'FATAL' = '#763053',
'DEFAULT' = '#000000'
'DEFAULT' = 'grey60'
)
){
level <- toupper(level)
Expand All @@ -63,11 +63,11 @@ cat2 <- function(
}
.col <- pal[[level]]
if(is.null(.col)){
.col <- '#000000'
.col <- 'grey60'
}

# check if interactive
if(dipsaus::rs_avail() && !nzchar(file)){
if(rs_avail() && !nzchar(file)){
if(print_level){
base::cat('[', level, ']: ', sep = '')
}
Expand All @@ -79,10 +79,10 @@ cat2 <- function(
'WARNING' = '\033[38;5;215m',
'ERROR' = '\033[38;5;203m',
'FATAL' = '\033[38;5;95m',
'DEFAULT' = '\033[38;5;232m'
'DEFAULT' = '\033[38;5;246m'
)[[level]]
if(is.null(prefix)){
prefix <- '\033[38;5;232m'
prefix <- '\033[38;5;246m'
}
s <- paste(..., sep = sep)
base::cat(prefix, s, "\033[39m", end, file = file, fill = fill, labels = labels, append = append, sep = '')
Expand Down
14 changes: 12 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Update logs (for R-cran only)

## 2021-12-02
**Version 0.2.4 (current)**
## 2022-05-29
**Version 0.2.5 (current)**

Self check: 0 errors | 0 warnings | 1 notes

Expand All @@ -10,6 +10,16 @@ checking installed package size ... NOTE
installed size is 5.3Mb
```

## 2021-12-02
**Version 0.2.4 (passed)**

Starting from this version, the package size will be greater than `5Mb`, which will trigger the check note. However, I can't reduce the size since most are from the `JavaScript` engine.

```
checking installed package size ... NOTE
installed size is 5.3Mb
```

## 2021-10-13
**Version 0.2.3 (passed)**

Expand Down
6 changes: 3 additions & 3 deletions man/template_subject.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 602dbf2

Please sign in to comment.