1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
##
## R source file
## This file is part of rgl
##
##
##
## ===[ SECTION: device management ]==========================================
##
rgl.useNULL <- function() {
if (noOpenGL)
return(TRUE)
opt <- getOption("rgl.useNULL", Sys.getenv("RGL_USE_NULL"))
if (is.logical(opt)) return(opt)
opt <- as.character(opt)
if (nchar(opt)) {
opt <- pmatch(tolower(opt), c("yes", "true"), nomatch=3)
return(c(TRUE, TRUE, FALSE)[opt])
}
FALSE
}
##
## open device
##
##
rgl.open <- function(useNULL = rgl.useNULL()) {
.Defunct("open3d")
}
##
## close device
##
##
rgl.close <- function() {
.Defunct("close3d")
}
##
## get all devices
##
##
rgl.dev.list <- function()
.Call( rgl_dev_list )
##
## set current device
##
##
rgl.set <- function(which, silent = FALSE) {
.Defunct("set3d")
}
##
## export image
##
##
rgl.snapshot <- function( filename, fmt="png", top=TRUE ) {
if (top) rgl.bringtotop()
idata <- as.integer(rgl.enum.pixfmt(fmt))
if (length(filename) != 1)
stop("filename is length ", length(filename))
filename <- normalizePath(filename, mustWork = FALSE)
ret <- .C( rgl_snapshot,
success=FALSE,
idata,
filename
)
if (! ret$success)
warning("'rgl.snapshot' failed")
invisible(filename)
}
##
## export postscript image
##
##
rgl.postscript <- function( filename, fmt="eps", drawText=TRUE ) {
idata <- as.integer(c(rgl.enum.gl2ps(fmt), as.logical(drawText)))
if (length(filename) != 1)
stop("filename is length ", length(filename))
ret <- .C( rgl_postscript,
success=FALSE,
idata,
normalizePath(filename, mustWork = FALSE, winslash = "/")
)
if (! ret$success)
warning("Postscript conversion failed")
}
##
## read image
##
##
rgl.pixels <- function(component = c("red", "green", "blue"), viewport = par3d("viewport"), top=TRUE ) {
if (top) rgl.bringtotop()
compnum <- as.integer(sapply(component, rgl.enum.pixelcomponent))
stopifnot(length(viewport) == 4)
ll <- as.integer(viewport[1:2])
stopifnot(all(!is.na(ll)), all(ll >= 0))
size <- as.integer(viewport[3:4])
stopifnot(all(!is.na(size), all(size >= 0)))
result <- array(NA_real_, dim=c(size[1], size[2], length(component)))
dimnames(result) <- list(NULL, NULL, component)
if (length(result) > 0)
for (i in seq_along(compnum)) {
ret <- .C( rgl_pixels,
success=FALSE,
ll, size, compnum[i],
values = double(size[1]*size[2]))
if (! ret$success)
warning(gettextf("Error reading component '%s'", component[i]), domain = NA)
result[,,i] <- ret$values
}
if (length(component) > 1) return(result)
else return(result[,,1])
}
|