Skip to content

Commit

Permalink
Merge pull request #48 from dmurdoch/rgl
Browse files Browse the repository at this point in the history
Change rgl.* calls to *3d calls.
  • Loading branch information
dfsp-spirit committed Jan 15, 2023
2 parents 6245ce8 + d105a9c commit f6ab0aa
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 56 deletions.
4 changes: 1 addition & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,16 @@ importFrom(rgl,next3d)
importFrom(rgl,open3d)
importFrom(rgl,par3d)
importFrom(rgl,play3d)
importFrom(rgl,rgl.lines)
importFrom(rgl,rgl.open)
importFrom(rgl,rgl.postscript)
importFrom(rgl,rgl.snapshot)
importFrom(rgl,rgl.viewpoint)
importFrom(rgl,segments3d)
importFrom(rgl,shade3d)
importFrom(rgl,spin3d)
importFrom(rgl,text3d)
importFrom(rgl,tmesh3d)
importFrom(rgl,translate3d)
importFrom(rgl,triangles3d)
importFrom(rgl,view3d)
importFrom(rgl,wire3d)
importFrom(squash,blueorange)
importFrom(squash,cmap)
Expand Down
12 changes: 6 additions & 6 deletions R/coloredmesh.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#'
#' @export
#' @importFrom squash cmap makecmap
#' @importFrom rgl tmesh3d rgl.open wire3d
#' @importFrom rgl tmesh3d open3d wire3d
coloredmesh.from.morph.native <- function(subjects_dir, subject_id, measure, hemi, surface="white", clip=NULL, cortex_only=FALSE, makecmap_options=mkco.seq()) {

if(!(hemi %in% c("lh", "rh"))) {
Expand Down Expand Up @@ -113,7 +113,7 @@ tmesh3d.to.fs.surface <- function(tmesh) {
#' @note Do not call this directly, use \code{\link[fsbrain]{coloredmeshes.from.color}} instead.
#'
#' @keywords internal
#' @importFrom rgl tmesh3d rgl.open wire3d
#' @importFrom rgl tmesh3d open3d wire3d
coloredmesh.from.color <- function(subjects_dir, subject_id, color_data, hemi, surface="white", metadata=list()) {

if(!(hemi %in% c("lh", "rh"))) {
Expand Down Expand Up @@ -221,7 +221,7 @@ coloredmeshes.from.color <- function(subjects_dir, subject_id, color_data, hemi,
#'
#' @export
#' @importFrom squash cmap makecmap
#' @importFrom rgl tmesh3d rgl.open wire3d
#' @importFrom rgl tmesh3d open3d wire3d
coloredmesh.from.morph.standard <- function(subjects_dir, subject_id, measure, hemi, fwhm, surface="white", template_subject='fsaverage', template_subjects_dir=NULL, clip = NULL, cortex_only=FALSE, makecmap_options=mkco.seq()) {

if(!(hemi %in% c("lh", "rh"))) {
Expand Down Expand Up @@ -290,7 +290,7 @@ coloredmesh.from.morph.standard <- function(subjects_dir, subject_id, measure, h
#'
#' @export
#' @importFrom squash cmap makecmap
#' @importFrom rgl tmesh3d rgl.open wire3d
#' @importFrom rgl tmesh3d open3d wire3d
#' @importFrom utils modifyList
coloredmesh.from.morphdata <- function(subjects_dir, vis_subject_id, morph_data, hemi, surface="white", makecmap_options=mkco.seq()) {

Expand Down Expand Up @@ -388,7 +388,7 @@ coloredmesh.from.preloaded.data <- function(fs_surface, morph_data=NULL, col=NUL
#'
#' @export
#' @importFrom squash cmap makecmap
#' @importFrom rgl tmesh3d rgl.open wire3d
#' @importFrom rgl tmesh3d open3d wire3d
#' @importFrom utils modifyList
coloredmesh.from.annot <- function(subjects_dir, subject_id, atlas, hemi, surface="white", outline=FALSE) {

Expand Down Expand Up @@ -445,7 +445,7 @@ coloredmesh.from.annot <- function(subjects_dir, subject_id, atlas, hemi, surfac
#'
#' @export
#' @importFrom squash cmap makecmap rainbow2
#' @importFrom rgl tmesh3d rgl.open wire3d
#' @importFrom rgl tmesh3d open3d wire3d
coloredmesh.from.label <- function(subjects_dir, subject_id, label, hemi, surface="white", makecmap_options=list('colFn'=squash::rainbow2), binary = TRUE) {

if(!(hemi %in% c("lh", "rh"))) {
Expand Down
2 changes: 1 addition & 1 deletion R/highlight.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ highlight.points.spheres <- function(coords, color = "#FF0000", radius = 1.0) {
if(is.vector(coords)) {
coords = matrix(coords, ncol = 3, byrow = TRUE);
}
rgl::rgl.spheres(coords[,1], coords[,2], coords[,3], radius = radius, col = color);
rgl::spheres3d(coords[,1], coords[,2], coords[,3], radius = radius, col = color);
}


Expand Down
8 changes: 4 additions & 4 deletions R/spherical.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ eeg_coords <- function(label_subset=NULL) {
#'
#' @note The x, y and z axes are plotted in red, green, and blue, respectively.
#'
#' @importFrom rgl rgl.lines
#' @importFrom rgl segments3d
#' @keywords internal
rgl.coord.lines <- function(len = 100) {
len = recycle(len, 3L);
rgl::rgl.lines(x=c(0, len[1]), y=c(0,0), z=c(0,0), col="red");
rgl::rgl.lines(x=c(0, 0), y=c(0,len[2]), z=c(0,0), col="green");
rgl::rgl.lines(x=c(0, 0), y=c(0,0), z=c(0,len[3]), col="blue");
rgl::segments3d(x=c(0, len[1]), y=c(0,0), z=c(0,0), col="red");
rgl::segments3d(x=c(0, 0), y=c(0,len[2]), z=c(0,0), col="green");
rgl::segments3d(x=c(0, 0), y=c(0,0), z=c(0,len[3]), col="blue");
return(invisible(NULL));
}

Expand Down
2 changes: 1 addition & 1 deletion R/vis_meshes.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ vis.coloredmeshes.rotating <- function(coloredmeshes, background="white", skip_a
for(cmesh in coloredmeshes) {
vis.renderable(cmesh, skip_all_na=TRUE, style=style);
}
rgl::rgl.viewpoint(-90, 0);
rgl::view3d(-90, 0);

if (!rgl::rgl.useNULL()) {
if(rglactions.has.key(rglactions, 'movie')) {
Expand Down
50 changes: 25 additions & 25 deletions R/vis_multiview.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ get.view.angle.names <- function(angle_set="all", add_sd_prefix=TRUE) {
#' @param draw_colorbar logical, whether to draw a colorbar. WARNING: The colorbar is drawn to a subplot, and this only works if there is enough space for it. You will have to increase the plot size using the 'rlgoptions' parameter for the colorbar to show up. Defaults to FALSE.
#'
#' @keywords internal
#' @importFrom rgl open3d bg3d wire3d shade3d mfrow3d next3d text3d rgl.viewpoint
#' @importFrom rgl open3d bg3d wire3d shade3d mfrow3d next3d text3d view3d
brainview.si <- function(coloredmeshes, background="white", skip_all_na=TRUE, style="default", draw_labels = FALSE, rgloptions = rglo(), rglactions=list(), draw_colorbar = FALSE) {

if(!is.list(coloredmeshes)) {
Expand Down Expand Up @@ -161,7 +161,7 @@ brainview.si <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
#' @param draw_colorbar logical, whether to draw a colorbar. WARNING: The colorbar is drawn to a subplot, and this only works if there is enough space for it. You will have to increase the plot size using the 'rlgoptions' parameter for the colorbar to show up. Defaults to FALSE.
#'
#' @keywords internal
#' @importFrom rgl open3d bg3d wire3d shade3d mfrow3d next3d text3d rgl.viewpoint
#' @importFrom rgl open3d bg3d wire3d shade3d mfrow3d next3d text3d view3d
brainview.sr <- function(coloredmeshes, background="white", skip_all_na=TRUE, style="default", draw_labels = FALSE, x=0, y=1, z=0, rpm=6, duration=10, rgloptions = rglo(), rglactions=list(), draw_colorbar = FALSE) {

if(!is.list(coloredmeshes)) {
Expand Down Expand Up @@ -245,7 +245,7 @@ handle.rglactions.highlight.points <- function(rglactions, angle_rad, x, y, z, h
#' @param draw_colorbar logical, whether to draw a colorbar. WARNING: The colorbar is drawn to a subplot, and this only works if there is enough space for it. You will have to increase the plot size using the 'rlgoptions' parameter for the colorbar to show up. Defaults to FALSE.
#'
#' @keywords internal
#' @importFrom rgl open3d bg3d wire3d shade3d mfrow3d next3d text3d rgl.viewpoint
#' @importFrom rgl open3d bg3d wire3d shade3d mfrow3d next3d text3d view3d
brainview.t4 <- function(coloredmeshes, background="white", skip_all_na=TRUE, style="default", draw_labels = FALSE, rgloptions = rglo(), rglactions = list(), draw_colorbar = FALSE) {

label_shift_y = -20;
Expand Down Expand Up @@ -293,7 +293,7 @@ brainview.t4 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
rgl::next3d(reuse=TRUE);
vis.rotated.coloredmeshes(lh_meshes, pi/2, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "lh");
rgl::rgl.viewpoint(-90, 0, fov=0, interactive=FALSE);
rgl::view3d(-90, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y,0,"lateral lh");
}
Expand All @@ -306,7 +306,7 @@ brainview.t4 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
rgl::next3d(reuse=FALSE);
vis.rotated.coloredmeshes(rh_meshes, pi/2, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "rh");
rgl::rgl.viewpoint(90, 0, fov=0, interactive=FALSE);
rgl::view3d(90, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y,0,"lateral rh");
}
Expand All @@ -319,7 +319,7 @@ brainview.t4 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
rgl::next3d(reuse=FALSE);
vis.rotated.coloredmeshes(lh_meshes, pi/2, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "lh");
rgl::rgl.viewpoint(90, 0, fov=0, interactive=FALSE);
rgl::view3d(90, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y,0,"medial lh");
}
Expand All @@ -332,7 +332,7 @@ brainview.t4 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
rgl::next3d(reuse=FALSE);
vis.rotated.coloredmeshes(rh_meshes, pi/2, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "rh");
rgl::rgl.viewpoint(-90, 0, fov=0, interactive=FALSE);
rgl::view3d(-90, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y,0,"medial rh");
}
Expand Down Expand Up @@ -375,7 +375,7 @@ brainview.t4 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
#' @param draw_colorbar logical, whether to draw a colorbar. WARNING: The colorbar is drawn to a subplot, and this only works if there is enough space for it. You will have to increase the plot size using the 'rlgoptions' parameter for the colorbar to show up. Defaults to FALSE.
#'
#' @keywords internal
#' @importFrom rgl open3d bg3d wire3d shade3d mfrow3d next3d text3d rgl.viewpoint
#' @importFrom rgl open3d bg3d wire3d shade3d mfrow3d next3d text3d view3d
brainview.t9 <- function(coloredmeshes, background="white", skip_all_na=TRUE, style="default", draw_labels = FALSE, rgloptions = rglo(), rglactions = list(), draw_colorbar = FALSE) {


Expand Down Expand Up @@ -429,7 +429,7 @@ brainview.t9 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
# Create the upper left view: draw only the left hemi, from the left
rgl::next3d(reuse=TRUE);
vis.rotated.coloredmeshes(lh_meshes, pi/2, 1, 0, 0, style=style);
rgl::rgl.viewpoint(-90, 0, fov=0, interactive=FALSE);
rgl::view3d(-90, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y,0,"lateral lh");
}
Expand All @@ -440,7 +440,7 @@ brainview.t9 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
# Create the upper central view: draw both hemis from above (top view)
rgl::next3d(reuse=FALSE);
vis.rotated.coloredmeshes(coloredmeshes_potentially_shifted, 0, 1, 0, 0, style=style);
rgl::rgl.viewpoint(0, 0, fov=0, interactive=FALSE);
rgl::view3d(0, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y_dorsal,0,"dorsal");
}
Expand All @@ -451,7 +451,7 @@ brainview.t9 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
# Create the upper right view
rgl::next3d(reuse=FALSE);
vis.rotated.coloredmeshes(rh_meshes, pi/2, 1, 0, 0, style=style);
rgl::rgl.viewpoint(90, 0, fov=0, interactive=FALSE);
rgl::view3d(90, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y,0,"lateral rh");
}
Expand All @@ -466,7 +466,7 @@ brainview.t9 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
# Create the 2nd row left view
rgl::next3d(reuse=FALSE);
vis.rotated.coloredmeshes(lh_meshes, pi/2, 1, 0, 0, style=style);
rgl::rgl.viewpoint(90, 0, fov=0, interactive=FALSE);
rgl::view3d(90, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y,0,"medial lh");
}
Expand All @@ -477,7 +477,7 @@ brainview.t9 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
# Create the 2nd row central view: draw both hemis from below (bottom view)
rgl::next3d(reuse=FALSE);
vis.rotated.coloredmeshes(coloredmeshes_potentially_shifted, pi, 1, 0, 0, style=style);
rgl::rgl.viewpoint(0, 0, fov=0, interactive=FALSE);
rgl::view3d(0, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y_ventral,0,"ventral");
}
Expand All @@ -489,7 +489,7 @@ brainview.t9 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
# Create the 2nd row right view
rgl::next3d(reuse=FALSE);
vis.rotated.coloredmeshes(rh_meshes, pi/2, 1, 0, 0, style=style);
rgl::rgl.viewpoint(-90, 0, fov=0, interactive=FALSE);
rgl::view3d(-90, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y,0,"medial rh");
}
Expand All @@ -504,7 +504,7 @@ brainview.t9 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
# Create the bottom left view: draw only the left hemi, from the left
rgl::next3d(reuse=FALSE);
vis.rotated.coloredmeshes(coloredmeshes_potentially_shifted, pi/2, 1, 0, 0, style=style);
rgl.viewpoint(0, 0, fov=0, interactive=FALSE);
view3d(0, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y,0,"rostral");
}
Expand All @@ -521,7 +521,7 @@ brainview.t9 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
# Create the bottom right view
rgl::next3d(reuse=FALSE);
vis.rotated.coloredmeshes(coloredmeshes_potentially_shifted, pi/2, 1, 0, 0, style=style);
rgl::rgl.viewpoint(180, 0, fov=0, interactive=FALSE);
rgl::view3d(180, 0, fov=0, interactive=FALSE);
if(draw_labels) {
rgl::text3d(0,label_shift_y,0,"caudal");
}
Expand Down Expand Up @@ -563,7 +563,7 @@ brainview.t9 <- function(coloredmeshes, background="white", skip_all_na=TRUE, st
#' @param draw_colorbar logical, whether to draw a colorbar. WARNING: The colorbar is drawn to a subplot, and this only works if there is enough space for it. You will have to increase the plot size using the 'rlgoptions' parameter for the colorbar to show up. Defaults to FALSE.
#'
#' @keywords internal
#' @importFrom rgl open3d bg3d rgl.viewpoint
#' @importFrom rgl open3d bg3d view3d
brainview.sd <- function(coloredmeshes, view_angle, background="white", skip_all_na=TRUE, style="default", rgloptions = rglo(), rglactions = list(), draw_colorbar = FALSE) {


Expand Down Expand Up @@ -614,42 +614,42 @@ brainview.sd <- function(coloredmeshes, view_angle, background="white", skip_all
if(view_angle == "lateral_lh") {
vis.rotated.coloredmeshes(lh_meshes, pi/2, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "lh");
rgl::rgl.viewpoint(-90, 0, fov=0, interactive=FALSE);
rgl::view3d(-90, 0, fov=0, interactive=FALSE);
if(is.function(callback_after_render)) { callback_after_render('lateral_lh'); }
} else if (view_angle == "dorsal") {
vis.rotated.coloredmeshes(coloredmeshes, 0, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, 0, 1, 0, 0, hemi = "both");
rgl::rgl.viewpoint(0, 0, fov=0, interactive=FALSE);
rgl::view3d(0, 0, fov=0, interactive=FALSE);
if(is.function(callback_after_render)) { callback_after_render('dorsal'); }
} else if(view_angle == "lateral_rh") {
vis.rotated.coloredmeshes(rh_meshes, pi/2, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "rh");
rgl::rgl.viewpoint(90, 0, fov=0, interactive=FALSE);
rgl::view3d(90, 0, fov=0, interactive=FALSE);
if(is.function(callback_after_render)) { callback_after_render('lateral_lh'); }
} else if(view_angle == "medial_lh") {
vis.rotated.coloredmeshes(lh_meshes, pi/2, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "lh");
rgl::rgl.viewpoint(90, 0, fov=0, interactive=FALSE);
rgl::view3d(90, 0, fov=0, interactive=FALSE);
if(is.function(callback_after_render)) { callback_after_render('medial_lh'); }
} else if(view_angle == "ventral") {
vis.rotated.coloredmeshes(coloredmeshes, pi, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "both");
rgl::rgl.viewpoint(0, 0, fov=0, interactive=FALSE);
rgl::view3d(0, 0, fov=0, interactive=FALSE);
if(is.function(callback_after_render)) { callback_after_render('ventral'); }
} else if(view_angle == "medial_rh") {
vis.rotated.coloredmeshes(rh_meshes, pi/2, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "rh");
rgl::rgl.viewpoint(-90, 0, fov=0, interactive=FALSE);
rgl::view3d(-90, 0, fov=0, interactive=FALSE);
if(is.function(callback_after_render)) { callback_after_render('medial_rh'); }
} else if(view_angle == "rostral") {
vis.rotated.coloredmeshes(coloredmeshes, pi/2, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "both");
rgl.viewpoint(0, 0, fov=0, interactive=FALSE);
view3d(0, 0, fov=0, interactive=FALSE);
if(is.function(callback_after_render)) { callback_after_render('rostral'); }
} else if(view_angle == "caudal") {
vis.rotated.coloredmeshes(coloredmeshes, pi/2, 1, 0, 0, style=style);
handle.rglactions.highlight.points(rglactions, pi/2, 1, 0, 0, hemi = "both");
rgl::rgl.viewpoint(180, 0, fov=0, interactive=FALSE);
rgl::view3d(180, 0, fov=0, interactive=FALSE);
if(is.function(callback_after_render)) { callback_after_render('caudal'); }
} else {
stop(sprintf("Invalid view_angle '%s'. Must be one of 'lateral_lh', 'dorsal', 'lateral_rh', 'medial_lh', 'ventral', 'medial_rh', 'rostral' or 'caudal'.\n", view_angle));
Expand Down
4 changes: 2 additions & 2 deletions R/vis_volume_3d.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ volvis.voxels <- function(volume, render_every=1, voxelcol=NULL, ...) {
row_idx = rendered_voxels[idx];
surface_ras[idx,] = (vox2surface_ras_matrix %*% voxel_crs[row_idx,])[1:3];
}
#rgl::rgl.spheres(surface_ras, r = 0.5, ...);
#rgl::spheres3d(surface_ras, r = 0.5, ...);
return(invisible(rglvoxels(surface_ras, r = 1.0, voxelcol=voxelcol, ...)));
} else {
warning("No foreground voxels in volume, nothing to visualize.");
Expand Down Expand Up @@ -339,7 +339,7 @@ apply.transform <- function(object, matrix_fun) {

#' @title Draw 3D boxes at locations using rgl.
#'
#' @description Draw 3D boxes at all given coordinates using rgl, analogous to \code{\link{rgl.spheres}}. Constructs the coordinates for triangles making up the boxes, then uses \code{\link{triangles3d}} to render them.
#' @description Draw 3D boxes at all given coordinates using rgl, analogous to \code{\link{spheres3d}}. Constructs the coordinates for triangles making up the boxes, then uses \code{\link{triangles3d}} to render them.
#'
#' @param centers numerical matrix with 3 columns. Each column represents the x, y, z coordinates of a center at which to create a cube.
#'
Expand Down
2 changes: 1 addition & 1 deletion man/rglvoxels.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/helper-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ get.demo.volume <- function(vd = 30L, bg = NA, num_centers = 8L) {

#' @title Close rgl windows after test.
close.all.rgl.windows <- function() {
while (rgl::rgl.cur() > 0) {
rgl::rgl.close();
while (rgl::cur3d() > 0) {
rgl::close3d();
}
}

Expand Down
Loading

0 comments on commit f6ab0aa

Please sign in to comment.